Know Oracle Lock Mode

Value   Name(s)                    Table method (TM lock)
    0   No lock                    n/a

    1   Null lock (NL)             Used during some parallel DML operations (e.g. update) by
                                   the pX slaves while the QC is holding an exclusive lock.

    2   Sub-share (SS)             Until 9.2.0.5/6 "select for update"
        Row-share (RS)             Since 9.2.0.1/2 used at opposite end of RI during DML
                                   Lock table in row share mode
                                   Lock table in share update mode

    3   Sub-exclusive(SX)          Update (also "select for update" from 9.2.0.5/6)
        Row-exclusive(RX)          Lock table in row exclusive mode
                                   Since 11.1 used at opposite end of RI during DML

    4   Share (S)                  Lock table in share mode
                                   Can appear during parallel DML with id2 = 1, in the PX slave sessions
                                   Common symptom of "foreign key locking" (missing index) problem

    5   share sub exclusive (SSX)  Lock table in share row exclusive mode
        share row exclusive (SRX)  Less common symptom of "foreign key locking" but likely to be more
                                   frequent if the FK constraint is defined with "on delete cascade."

    6   Exclusive (X)              Lock table in exclusive mode

Summary of Locks Obtained by DML Statements

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 MODE SSYYYYN
ROW EXCLUSIVE MODE SXYYNNN
SHARE MODE SYNYNN
SHARE ROW EXCLUSIVE MODE SSXYNNNN
EXCLUSIVE MODE XNNNNN
* Yes, if no conflicting row locks are held by another transaction. Otherwise, waits occur.

 

mode 1:NL Null   N
mode 2:SSRSRow-SRow Share(d)SubShareIntended Share (IS)L
mode 3:SXRXRow-XRow ExclusiveSubExclusiveIntended Exclusive (IX)R
mode 4:S Share   S
mode 5:SSXSRXS/Row-XShare(d) Row ExclusiveShare-SubExclusive C
mode 6:X Exclusive   X



compatible ?SS,RSSX,RXSSSX,SRXX
SS,RSyesyesyesyesno
SX,RXyesyesnonono
Syesnoyesnono
SSX, SRXyesnononono
Xnonononono

GES (global enqueue resources) enqueues having different values for the lock mode:

#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)

Global Wait-For-Graph(WFG) at ddTS[0.db] :
BLOCKED 0xd876a630 5 wq 2 cvtops x1 TX 0x70015.0x81e(ext 0x2,0x0)[2B000-0001-0000057A] inst 1
BLOCKER 0xd8767a10 5 wq 1 cvtops x28 TX 0x70015.0x81e(ext 0x2,0x0)[2E000-0001-00000347] inst 1
BLOCKED 0xd876ab70 5 wq 2 cvtops x1 TX 0x40008.0x7d9(ext 0x2,0x0)[2E000-0001-00000347] inst 1
BLOCKER 0xd876a7f0 5 wq 1 cvtops x28 TX 0x40008.0x7d9(ext 0x2,0x0)[2B000-0001-0000057A] inst 1

5 means KJUSEREX ,cross instance "TX mode 6" locks


Constants
Lock ModeData TypeValue
global

NUMBER

1
local

NUMBER

0
maxwait

NUMBER

32767
nl_mode

NUMBER

1
ss_modeNUMBER2
sx_modeNUMBER3
s_modeNUMBER4
ssx_modeNUMBER5
x_modeNUMBER6


Lock Compatibility Rules

When another process holds "held", an attempt to get "get" does  the following
HeldNLSSSXSSSXX
NLSuccessSuccessSuccessSuccessSuccessSuccess
SSSuccessSuccessSuccessSuccessSuccessFail
SXSuccessSuccessSuccessFailFailFail
SSuccessSuccessFailFailFailFail
SSXSuccessSuccessFailFailFailFail
XSuccessFailFailFailFailFail


参考文献:
1. Know Oracle Lock Mode. MACLEAN LIU. 2008/06/22. http://www.askmaclean.com/archives/know-oracle-lock-mode.html 
2. Oracle USER_LOCK Version 11.1. http://psoug.org/reference/user_lock.html
3. Oracle Database Online Documentation 11g Release 2 (11.2) V$LOCK. http://docs.oracle.com/cd/E11882_01/server.112/e40402/dynviews_2027.htm

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值