參考:https://blog.csdn.net/haiross/article/details/48653333
1.查詢資料庫中的鎖
select * from v$lock;
select * from v$lock where block=1;
2.查詢被鎖的物件
select * from v$locked_object;
3.查詢阻塞
查被阻塞的會話
select * from v$lock where lmode=0 and type in ('TM','TX');
查阻塞別的會話鎖
select * from v$lock where lmode>0 and type in ('TM','TX');
4.查詢資料庫正在等待鎖的程序
select * from v$session where lockwait is not null;
5.查詢會話之間鎖等待的關係
select a.sid holdsid,b.sid waitsid,a.type,a.id1,a.id2,a.ctime from v$lock a,v$lock b
where a.id1=b.id1 and a.id2=b.id2 and a.block=1 and b.block=0;
6.查詢鎖等待事件
select * from v$session_wait where event='enqueue';
解決方案:
select session_id from v$locked_object; --首先得到被鎖物件的session_id
SELECT sid, serial#, username, osuser FROM v$session where sid = session_id; --透過上面得到的session_id去取得v$session的sid和serial#,然後對該程序進行終止。
ALTER SYSTEM KILL SESSION 'sid,serial';
example:
ALTER SYSTEM KILL SESSION '13, 8';