在什么情况下会出现行级锁???
发布网友
发布时间:2022-04-07 14:54
我来回答
共1个回答
热心网友
时间:2022-04-07 16:23
可从下面一个实验中得到启发:
会话1:
[oracle@ligle-db ~]$ sqlplus ligle/ligle;
SQL*Plus: Release 10.2.0.4.0 - Proction on Fri Dec 10 19:39:31 2010
Copyright (c) 1982, 2007, Oracle. All Rights Reserved.
Connected to:
Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - Proction
With the Partitioning, OLAP, Data Mining and Real Application Testing options
SQL> select * from test;
ID NAME
---------- --------------------
1 li
2 zhuwu
3 caogui
SQL> savepoint a;
Savepoint created.
SQL> update test set name='qinshihuang' where id=2;
1 row updated.
SQL> select userenv('sid') from al;
USERENV('SID')
--------------
159
会话2:
SQL> update test set name='mu' where id=2;
此时,我们会发现会话2锁执行的update语句被挂起,这是因为会话2是被会话1的TX锁阻塞的,而不是被会话1的行级锁阻塞。
在会话3中查看锁的情况:
SQL> select username,event,sid,blocking_session from v$session where username='LIGLE'
USERNAME EVENT SID BLOCKING_SESSION
------------------------------ ------------------------------ ---------- ----------------
LIGLE enq: TX - row lock contention 144 159
LIGLE SQL*Net message from client 151
LIGLE SQL*Net message from client 159
从第一行,可以看到会话144被会话159的TX锁阻塞。
详情可以参照如下链接,行级锁原理都解释得比较清楚了:
http://fffo.blog.163.com/blog/static/211913068201302745214844/