Oracle数据库中的TM锁模式

Oracle数据库支持如下TM锁(表锁)模式:

  • 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.

  • 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.

  • 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.

  • 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.


在RAC环境中, GES (global enqueue resources) 对这些锁模式有不同的称呼,对应关系如下:

#define KJUSERNL 0          /* no permissions */    (Null)
#define KJUSERCR 1          /* concurrent read */   (Row-S (SS))
#define KJUSERCW 2          /* concurrent write */  (Row-X (SX))
#define KJUSERPR 3          /* protected read */    (Share)
#define KJUSERPW 4          /* protected write */   (S/Row-X (SSX))
#define KJUSEREX 5          /* exclusive access */  (Exclusive)

这些锁模式的相互兼容性如下:
compatible ?SS,RS,CRSX,RX,CWS,PRSSX,SRX,PWX,EX
SS,RS,CRyesyesyesyesno
SX,RX,CWyesyesnonono
S,PRyesnoyesnono
SSX, SRX,PWyesnononono
X,EXnonononono

下面列出了一些常见DML语句需要获得的锁模式:
SQL StatementRow LocksTable Lock ModeRSRXSSRXX
SELECT ... FROM table...noneYYYYY
INSERT INTO table ...YesSXYYNNN
UPDATE table ...YesSXY*Y*NNN
MERGE INTO table ...YesSXYYNNN
DELETE FROM table ...YesSXY*Y*NNN
SELECT ... FROM table FOR UPDATE OF ...YesSXY*Y*NNN
LOCK TABLE table IN ...
ROW SHARE MODESSYYYYN
ROW EXCLUSIVE MODESXYYNNN
SHARE MODESYNYNN
SHARE ROW EXCLUSIVE MODESSXYNNNN
EXCLUSIVE MODEXNNNNN
* Yes, if no conflicting row locks are held by another transaction. Otherwise, waits occur.
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值