1.显示数据库中锁信息
select sid,addr kaddr,type,lmode,block from v$lock;
SID KADDR TY LMODE BLOCK
---------- ---------------- -- ---------- ----------
3 0000000077459298 XR 1 0
3 0000000077459368 RD 1 0
3 0000000077459438 CF 2 0
3 00000000774595D8 RS 2 0
127 00000000774596A8 PW 3 0
189 0000000077459778 RT 6 0
196 0000000077459848 AE 4 0
190 0000000077459918 AE 4 0
66 00000000774599E8 TS 3 0
127 0000000077459AB8 MR 4 0
127 0000000077459B88 MR 4 0
SID KADDR TY LMODE BLOCK
---------- ---------------- -- ---------- ----------
127 0000000077459C58 MR 4 0
127 0000000077459D28 MR 4 0
127 0000000077459DF8 MR 4 0
191 0000000077459EC8 AE 4 0
191 0000000077459FB0 TX 0 0
133 000000007745A080 AE 4 0
196 00007F913A138DE0 TM 3 0
191 00007F913A138DE0 TM 3 0
196 0000000076034228 TX 6 1
2.持有锁session 196 信息
执行语句
SQL> update dept set dname='sale' where deptno='30';
1 row updated.
SQL> SELECT SID FROM V$MYSTAT WHERE ROWNUM =1;
SID
----------
196
SQL> select sid,username from v$session where sid in
2 (select sid from v$lock where block=1);
SID USERNAME
---------- ------------------------------
196 SYS
3.显示争用锁session 191的 SID,username,ID1,执行SQL语句
争用session执行语句
SQL> update dept set dname='sale' where deptno='30';
session 191无法获得RX锁,等待持有锁session 196释放RX
select B.sid,b.username,D.id1,a.sql_text
from v$session b,v$lock D,v$sqltext A
where B.lockwait=d.kaddr
and a.address=b.sql_address
and a.hash_value=b.sql_hash_value;
SID USERNAME ID1 SQL_TEXT
---------- ------------------------------ ---------- ----------------------------------------------------------------
191 SYS 393226 update dept set dname='sale' where deptno='30'
4.显示锁会话进程信息
SELECT s.osuser "os_user",
s.username "user",
s.sid "sid",
s.serial# "serial#",
s.process "pid",
s.status "status",
l.name "Object_locked",
l.mode_held "lock Held"
FROM v$session s,dba_dml_locks l,v$process p
where l.session_id = s.sid and p.addr=s.paddr;
os_user user sid serial# pid status Object_locked lock Held
------------------------------ ------------------------------ ---------- ---------- ------------------------ -------- ------------------------------ -------------
oracle SYS 196 25 4549 INACTIVE DEPT Row-X (SX)
oracle SYS 191 19 4867 ACTIVE DEPT Row-X (SX)
持有TX 196 session status为inactive,想要获得TX锁191 session status 为Active
5.kill Session
可以选择杀掉连个中的任何一个session,以保证更新成功。
SQL> alter system kill session 'sid,serial#';
SQL> alter system kill session '196,25';
本文转自 pgmia 51CTO博客,原文链接:http://blog.51cto.com/heyiyi/900290