Oracle(四):鎖

v$lock:視圖列出當前系統持有的或正在申請的全部鎖的狀況sql

v$locked_object:視圖列出當前系統中哪些對象正被鎖定數據庫

1)、查詢當前數據庫鎖的狀況,以及致使鎖的sql語句:session

Select object_name as 對象名稱,s.sid,s.serial#,p.spid as 系統進程號,sq.SQL_TEXT
From v$locked_object l , dba_objects o , v$session s , v$process p,v$sqlarea sq
Where l.object_id=o.object_id and l.session_id=s.sid and s.paddr=p.addr and s.SQL_ADDRESS = sq.ADDRESS;

2)、殺掉非正常的一些鎖oop

alter system kill session 'sid,serial#';

3)、批量殺掉未釋放的鎖spa

declare cursor mycur is  
select b.sid,b.serial#  
  from v$locked_object a,v$session b  
  where a.session_id = b.sid group by b.sid,b.serial#;  
  
  
begin  
  for cur in mycur  
    loop    
     execute immediate ( 'alter system  kill session  '''||cur.sid || ','|| cur.SERIAL# ||''' ');  
     end loop;  
  
end;  
相關文章
相關標籤/搜索