Oracle Locks之DML锁
Note:
The database never locks rows when performing simple reads.
| Lock | Description |
|---|---|
| DML Locks | Protect data. For example, table locks lock entire tables, while row locks lock selected rows. See "DML Locks". |
| DDL Locks | Protect the structure of schema objects—for example, the dictionary definitions of tables and views. See "DDL Locks". |
| System Locks | Protect internal database structures such as data files. Latches, mutexes, and internal locks are entirely automatic. See "System Locks". |
DML Locks
A DML lock, also called a data lock, guarantees the integrity of data accessed concurrently by multiple users. For example, a DML lock prevents two customers from buying the last copy of a book available from an online bookseller. DML locks prevent destructive interference of simultaneous conflicting DML or DDL operations.
DML statements automatically acquire the following types of locks:
DML锁有:行级(事务级)锁和表级锁
In the following sections, the acronym in parentheses after each type of lock or lock mode is the abbreviation used in the Locks Monitor of Oracle Enterprise Manager (Enterprise Manager). Enterprise Manager might display TM for any table lock, rather than indicate the mode of table lock (such as RS or SRX).
If a transaction obtains a lock for a row, then the transaction also acquires a lock for the table containing the row. The table lock prevents conflicting DDL operations that would override data changes in a current transaction. Figure 9-2 illustrates an update of the third row in a table. Oracle Database automatically places an exclusive lock on the updated row and a subexclusive lock on the table.
如果一个事务获得了一个行级锁,那么它会同时获得包含该行的表级锁,避免DDL操作导致当前事务中的数据修改而引起冲突。
下图是表级锁TM和行级锁TX的示意图
Storage of Row Locks
Unlike some databases, which use a lock manager to maintain a list of locks in memory, Oracle Database stores lock information in the data block that contains the locked row.
一些数据库管理系统,在内存中通过锁管理来维护一系列的锁,而Oracle数据库通过包含了锁住行的数据块来存储锁的相关信息。
The database uses a queuing mechanism for acquisition of row locks. If a transaction requires a lock for an unlocked row, then the transaction places a lock in the data block. Each row modified by this transaction points to a copy of the transaction ID stored in the block header (see "Overview of Data Blocks").
使用队列的机制来获取行级锁。
When a transaction ends, the transaction ID remains in the block header. If a different transaction wants to modify a row, then it uses the transaction ID to determine whether the lock is active. If the lock is active, then the session asks to be notified when the lock is released. Otherwise, the transaction acquires the lock.
See Also:
Oracle Database Reference to learn about
V$TRANSACTION
Table Locks (TM)
A table lock, also called a TM lock, is acquired by a transaction when a table is modified by an INSERT, UPDATE, DELETE, MERGE, SELECT with the FORUPDATE clause, or LOCK TABLE statement. DML operations require table locks to reserve DML access to the table on behalf of a transaction and to prevent DDL operations that would conflict with the transaction.
A table lock can be held in any of the following modes:
表级锁包含了以下几种模式:
Row Share (RS)
This lock, also called a subshare table lock (SS), indicates that the transaction holding the lock on the table has locked rows in the table and intends to update them. A row share lock is the least restrictive mode of table lock, offering the highest degree of concurrency for a table.
行共享:表级锁中最低限度的锁表模式,能够提供最高的并发度。此时不希望其他用户或绘画对改行进行更新操作。
Row Exclusive Table Lock (RX)
This lock, also called a subexclusive table lock (SX), generally indicates that the transaction holding the lock has updated table rows or issued
SELECT ... FOR UPDATE. An SX lock allows other transactions to query, insert, update, delete, or lock rows concurrently in the same table. Therefore, SX locks allow multiple transactions to obtain simultaneous SX and subshare table locks for the same table.行级排他锁,表示获得该锁的事务将对表进行DML操作,SX锁允许其他事务对相同的表进行查询、插入、更新、修改或者锁其他行。因此SX锁允许多个事务获得SX锁和S锁,但是不能获得X锁
Share Table Lock (S)
A share table lock held by a transaction allows other transactions to query the table (without using
SELECT ... FOR UPDATE), but updates are allowed only if a single transaction holds the share table lock. Because multiple transactions may hold a share table lock concurrently, holding this lock is not sufficient to ensure that a transaction can modify the table.共享锁,不允许任何用户更新表,但是允许其他用户发出select ... for update添加RS锁
Share Row Exclusive Table Lock (SRX)
This lock, also called a share-subexclusive table lock (SSX), is more restrictive than a share table lock. Only one transaction at a time can acquire an SSX lock on a given table. An SSX lock held by a transaction allows other transactions to query the table (except for
SELECT ...FOR UPDATE) but not to update the table.同时只有一个事务可以获得该共享行级排他锁,此时只允许其他事务查询表,但不能进行DML操作,也不能使用select ... for update。
Exclusive Table Lock (X)
This lock is the most restrictive, prohibiting other transactions from performing any type of DML statement or placing any type of lock on the table.
排他锁,其他事务不能对该表进行任何DML和DDL操作,也不能添加任何类型的锁。
各个模式的锁之间的兼容性如下:

See Also:
Oracle Database Advanced Application Developer's Guide to learn more about table locks
Oracle Locks之DML锁的更多相关文章
- Oracle事务之一:锁和隔离
Oracle事务之一:锁和隔离 一. 事务概述 事务管理是数据库处理的核心.数据库既要保证用户能并发地执行事务,还要保证数据库的一致性. 当第一条可执行的SQL开始执行,就隐形地开始了一个事务,直到遇 ...
- (转)DB2和 Oracle的并发控制(锁)比较
DB2和 Oracle的并发控制(锁)比较 牛 新庄2005 年 12 月 26 日发布 原文:https://www.ibm.com/developerworks/cn/data/library/t ...
- oracle之事务和锁
Oracle的事务和锁(PPT-I-283-293) 10.1 什么是事务 必须具备以下四个属性,简称ACID 属性:原子性(Atomicity): 事务是一个完整的操作.事务的各步操作是不可分的( ...
- 理解Oracle TM和TX锁
在Oracle中有很多锁,通过v$lock_type视图可以查看Oracle中所有类型的锁,在本篇文章中我们熟悉一下TM和TX锁的类型 SQL> select * from v$lock_typ ...
- [Oracle]TM lock (DML enqueue) 的相容性
[Oracle]TM lock (DML enqueue) 的相容性 RS(SS): 行共享 LMODE =2 RX(SX): 行独占 LMODE =3 S: 共享 ...
- 查看Oracle中是否有锁表
转: 查看Oracle中是否有锁表 2018-04-23 17:59 alapha 阅读(19450) 评论(0) 编辑 收藏 一.用dba用户登录,或者将用户赋权为DBA用户 命令: su - or ...
- Oracle数据库查找持有锁的SQL语句,而不是请求锁的SQL语句(原创)
Oracle数据库查找持有锁的SQL语句,而不是请求锁的SQL语句 查找活动的事务以及活动事务关联的会话信息 select s.sid 会话ID, s.serial# 会话序列号, s.usernam ...
- ORACLE外键和锁
在oracle中,如果外键未加索引,对父表的修改,会导致子表被加上全表锁.这包括两种情况: 1.删除父表中的行,如果外键上没有索引,会导致子表被加上全表锁 2.更新父表的主键(根据关系数据库的原则,更 ...
- Oracle学习笔记七 锁
锁的概念 锁是数据库用来控制共享资源并发访问的机制. 锁用于保护正在被修改的数据 直到提交或回滚了事务之后,其他用户才可以更新数据 对数据的并发控制,保证一致性.完整性.
随机推荐
- java开发规范总结_命名规范
规范需要平时编码过程中注意,是一个慢慢养成的好习惯 1.文件 1.属性文件后缀为properties,并且符合java中i18n的规范: 2.对于各产品模块自己的配置文件必须放置在自己模块的con ...
- 【转】 OC基础数据类型-NSSet
原文 : http://www.cnblogs.com/GISerYang/p/3340937.html 1.集合:集合(NSSet)和数组(NSArray)有相似之处,都是存储不同的对象的地址:不过 ...
- SQL中distinct的用法和left join查询的含义
SQL中distinct的用法 1.作用于单列 2.作用于多列 3.COUNT统计 4.distinct必须放在开头 5.其他 在表中,可能会包含重复值.这并不成问题,不过,有时您也许希望仅仅列出 ...
- C# .NET3.5 改为 到.NET2.0 时 TypedTableBase 报错解决方法
NET 3.5 降版本 到.NET 2.0.不出意外,问题必然来了.编译错误一:错误 1 命名空间“System”中不存在类型或命名空间名称“Linq”(是缺少程序集引用吗?)解决:删掉该引用--没用 ...
- ThinkPHP框架下,给jq动态添加的标签添加点击事件移除标签
jq移除标签主要就是$("#要移除的id").remove();不再赘述,这里要提醒的是jq中动态添加标签后怎样添加点击事件.一般的jq添加点击事件是用这种方法$("#i ...
- js获取屏幕(设备)宽高
平常获取设备的宽高无非就那几 <script language="javascript"> var h = ""; h += " 网页可见 ...
- QTP插入Output Value和插入CheckPoint,注意点
1. 必须打开程序才能进行Output value和CheckPoint的插入. 2. 也有可能是对象获取不到,从新加载对象库. 提示如下图:
- sphinx ---rotate 运行机制
如果sphinx在运行中,要indexer时,需要加上--rotate参数,这样索引完就直接生效了. 原因是sphinx的searchd在启动时会创建一个 .spl 锁文件,并在关闭时会删除它.在in ...
- PHP: 使用CURL访问FTP
今天要做FTP上传.本想用PHP自带的FTP函数来实现,结果发现这个模块没有编译进来,重新编译PHP太麻烦,改用其他方式实现吧 FTP上传 if (isset($_POST['Submit'])) ...
- Keil的使用-1创建项目和工程
下载keil,注意不要使用MDK版本(主要是arm开发使用),大小约54M 安装过程不再详述 安装Keil成功并运行后,新建项目, 创建新项目,然后弹出下图,选择对应的单片机芯片(双击) ...