SQL> select kaddr,sid,type,id1,id2,decode(lmode,0,'none',1,'null',2,'row-share',3,'row-exclusive',4,'share',5,'share row exclusive',6,'exclusive') lmode,
decode(request,0,'none',1,'null',2,'row-share',3,'row-exclusive',4,'share',5,'share row exclusive',6,'exclusive') request,block
from v$lock where sid in(149,145) order by 2;
KADDR SID TY ID1 ID2 LMODE REQUEST
---------------- ---------- -- ---------- ---------- ------------------- ---------- --id1及id2含义取决于锁的类型,lmode为持锁类型或叫模式,共有6种类型,请求锁模式同理,type为锁类型:分为用户锁和系统锁,此外
我们是用户锁,具体请查阅官方手册
00000000703B8758 149 TM 51356 0 row-exclusive 0
00000000704A7788 149 TX 65581 299 none 6
000000006F4A76E0 159 TX 65581 299 exclusive 0
00000000703B8658 159 TM 51356 0 row-exclusive 0
--搞清所有锁类型及锁模式的含义及作用
--id1及id2的含义
SQL> select * from test where deptno in(10,20,30) for update; --持锁会话
DEPTNO DNAME LOC
---------- -------------- -------------
10 ACCOUNTING NEW YORK
20 RESEARCH DALLAS
30 SALES CHICAGO
SQL> select distinct sid from v$mystat;
SID
----------
159
SQL>
SQL> update test set dname='x' where deptno=30; ---请求锁会话
SQL> update test set deptno=88;--145 会话,持锁会话
6 rows updated.
SQL> create index idx_test on test(deptno);--149会话,请求锁会话(select for update同理),注:select * from test nowait,nowait用于dml语句请求锁资源是否马上向客户端返回提示错误信息(如:资源正忙之类)
create index idx_test on test(deptno)
*
ERROR at line 1:
ORA-00054: resource busy and acquire with NOWAIT specified
SQL> /
KADDR SID TY ID1 ID2 LMODE REQUEST BLOCK
---------------- ---------- -- ---------- ---------- ------------------- ------------------- ----------
000000006F466990 145 TX 327701 310 exclusive none 0 --block=1表示持锁会话,block=0为非持锁会话
小结:
select for update会形成排它锁及行级排它锁(tx及tm锁),且会阻塞其它dml及create|drop index相关动作
select for date及dml不会阻塞dbms_stats收集统计信息动作
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/9240380/viewspace-671013/ ,如需转载,请注明出处,否则将追究法律责任。