DDL的鎖,編譯包經常hang住的場景

lusklusklusk發表於2016-10-12

參考ORACLE官方文件 ID 122793.1

共享池(Shared Pool)用於快取最近執行過的SQL語句、PL/SQL程式和資料字典資訊,是對SQL語句、PL/SQL程式進行語法分析、編譯、執行的區域,其的主要元件有library cache和dictionary cache。library cache 儲存了最近的SQL/PLSQL程式碼的可執行模式(解析或編譯版本)。


X$KGLLK   ##主要用來檢視library cache 的物件的鎖(v$session.event=’library cache lock’)

x$kglpn   ##主要用來處理library cache pin holder(v$session_wait.event=’library cache pin’)

X$KGLPN--[K]ernel [G]eneric [L]ibrary Cache Manager object [P]i[N]s



最簡單的 SQL

select * from V$SESSION_BLOCKERS
V$SESSION_BLOCKERS displays the blocker sessions for each blocked session



最常用的SQL

select sid,status,LOGON_TIME,sql_id,blocking_session "死鎖直接源",FINAL_BLOCKING_SESSION "死鎖最終源",event,seconds_in_wait "會話鎖住時間_S",LAST_CALL_ET "會話STATUS持續時間_S" from v$session where event like 'library cache%' and state='WAITING' and BLOCKING_SESSION_STATUS='VALID' and FINAL_BLOCKING_SESSION_STATUS='VALID'




查詢Cache Pin鎖(最準確的一種)

x$kglpn.KGLPNHDL對應v$session_wait中的v$session_wait.P1RAW

x$kglpn.KGLPNUSE對應v$session.saddr


查詢DDL pin鎖的sql

SELECT s.sid,s.event,s.p1raw,s.seconds_in_wait,kglpnmod "Mode", kglpnreq "Req", s.LOGON_TIME

FROM x$kglpn p, v$session s

WHERE p.kglpnuse=s.saddr

and kglpnhdl in (SELECT p1raw FROM v$session WHERE event like 'library cache %')

kglpnmod "Mode"表示持有pin的模式(0為no lock/pin held﹐1為null,2為share﹐3為exclusive)

kglpnreq "Req"表示請求pin的模式(0為no lock/pin held﹐1為null,2為share﹐3為exclusive)






查詢Cache Lock鎖(最準確的一種)

x$kgllk.KGLLKUSE還是x$kgllk.KGLLKSES對應v$session.saddr,好像兩者都行

x$kgllk.KGLLKSNM對應 v$session.sid                


查詢DDL lock鎖的sql(含鎖住的物件)

select s.sid,s.SERIAL#,s.event,s.seconds_in_wait,kgllkmod Mod,kgllkreq Request, x$kgllk.USER_NAME,kglnaobj Object,s.LOGON_TIME

from x$kgllk ,v$session s where kgllkses=s.saddr and KGLLKHDL in (select p1raw from v$session where event= 'library cache lock') order by s.LOGON_TIME

kgllkmod表示持有pin的模式(0no lock/pin held1null,2share3exclusive)

kgllkreq表示請求pin的模式(0no lock/pin held1null,2share3exclusive)

 

 

 

查詢鎖住的DDL物件

select d.session_id,s.SERIAL#,d.name from dba_ddl_locks d,v$session s where d.owner='MKLMIGEM' and d.SESSION_ID=s.sid

 

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/30126024/viewspace-2126196/,如需轉載,請註明出處,否則將追究法律責任。

相關文章