Library cache resource types waited for over the life of the instance
set linesize 152
column average_wait format 9999990.00
select substr(e.event, 1, 40) event,
e.time_waited,e.time_waited / decode(e.event,
‘latch free’, e.total_waits,
decode(e.total_waits – e.total_timeouts,0, 1,e.total_waits – e.total_timeouts)) average_wait
from sys.v$system_event e,sys.v$instance i
where e.event like ‘%library cache%’;
Detect sessions waiting for a Library Cache Locks
select sid Waiter, p1raw,
substr(rawtohex(p1),1,30) Handle,
substr(rawtohex(p2),1,30) Pin_addr
from v$session_wait where wait_time=0 and event like ‘%library cache%’;
Sessions waiting for lib cache in RAC
select a.sid Waiter,b.SERIAL#,a.event,a.p1raw,
substr(rawtohex(a.p1),1,30) Handle,
substr(rawtohex(a.p2),1,30) Pin_addr
from v$session_wait a,v$session b where a.sid=b.sid
and a.wait_time=0 and a.event like ‘library cache%’;
Objects locked by Library Cache based on sessions detected above
select to_char(SESSION_ID,’999′) sid ,
substr(LOCK_TYPE,1,30) Type,
substr(lock_id1,1,23) Object_Name,
substr(mode_held,1,4) HELD, substr(mode_requested,1,4) REQ,
lock_id2 Lock_addr
from dba_lock_internal
where
mode_requested<>’None’
and mode_requested<>mode_held
and session_id in ( select sid
from v$session_wait where wait_time=0
and event like ‘%library cache%’) ;
Detect Library Cache holders that sessions are waiting for
select sid Holder ,KGLPNUSE Sesion , KGLPNMOD Held, KGLPNREQ Req
from x$kglpn , v$session
where KGLPNHDL in (select p1raw from v$session_wait
where wait_time=0 and event like ‘%library cache%’)
and KGLPNMOD <> 0
and v$session.saddr=x$kglpn.kglpnuse ;
Sessions holding the lib cache in RAC
select a.sid Holder ,a.SERIAL#,b.INST_ID,b.KGLPNUSE Sesion , b.KGLPNMOD Held, b.KGLPNREQ Req
from x$kglpn b , v$session a
where b.KGLPNHDL in (select p1raw from v$session_wait
where wait_time=0 and event like ‘library cache%’)
and b.KGLPNMOD <> 0
and a.saddr=b.kglpnuse ;
Library cache pin sessions
SELECT s.sid,
waiter.p1raw w_p1r,
holder.event h_wait,
holder.p1raw h_p1r,
holder.p2raw h_p2r,
holder.p3raw h_p2r,
count(s.sid) users_blocked,
sql.hash_value
FROM
v$sql sql,
v$session s,
x$kglpn p,
v$session_wait waiter,
v$session_wait holder
WHERE
s.sql_hash_value = sql.hash_value and
p.kglpnhdl=waiter.p1raw and
s.saddr=p.kglpnuse and
waiter.event like ‘library cache pin’ and
holder.sid=s.sid
GROUP BY
s.sid,
waiter.p1raw ,
holder.event ,
holder.p1raw ,
holder.p2raw ,
holder.p3raw ,
sql.hash_value;
Library Cache lock Query
select decode(lob.kglobtyp,
0, ‘NEXT OBJECT ‘,
1, ‘INDEX ‘,
2, ‘TABLE ‘,
3, ‘CLUSTER ‘,
4, ‘VIEW ‘,
5, ‘SYNONYM ‘,
6, ‘SEQUENCE ‘,
7, ‘PROCEDURE ‘,
8, ‘FUNCTION ‘,
9, ‘PACKAGE ‘,
11, ‘PACKAGE BODY ‘,
12, ‘TRIGGER ‘,
13, ‘TYPE ‘,
14, ‘TYPE BODY ‘,
19, ‘TABLE PARTITION ‘,
20, ‘INDEX PARTITION ‘,
21, ‘LOB ‘,
22, ‘LIBRARY ‘,
23, ‘DIRECTORY ‘,
24, ‘QUEUE ‘,
28, ‘JAVA SOURCE ‘,
29, ‘JAVA CLASS ‘,
30, ‘JAVA RESOURCE ‘,
32, ‘INDEXTYPE ‘,
33, ‘OPERATOR ‘,
34, ‘TABLE SUBPARTITION ‘,
35, ‘INDEX SUBPARTITION ‘,
40, ‘LOB PARTITION ‘,
41, ‘LOB SUBPARTITION ‘,
42, ‘MATERIALIZED VIEW ‘,
43, ‘DIMENSION ‘,
44, ‘CONTEXT ‘,
46, ‘RULE SET ‘,
47, ‘RESOURCE PLAN ‘,
48, ‘CONSUMER GROUP ‘,
51, ‘SUBSCRIPTION ‘,
52, ‘LOCATION ‘,
55, ‘XML SCHEMA ‘,
56, ‘JAVA DATA ‘,
57, ‘SECURITY PROFILE ‘,
59, ‘RULE ‘,
62, ‘EVALUATION CONTEXT ‘,
‘UNDEFINED ‘) object_type,
lob.kglnaobj object_name,
pn.kglpnmod lock_mode_held,
pn.kglpnreq lock_mode_requested,
ses.sid,
ses.serial#,
ses.username
from sys.v$session_wait vsw,
sys.x$kglob lob,
sys.x$kglpn pn,
sys.v$session ses
where vsw.event = ‘library cache lock ‘
and vsw.p1raw = lob.kglhdadr
and lob.kglhdadr = pn.kglpnhdl
and pn.kglpnmod != 0
and pn.kglpnuse = ses.saddr
/
Detect Library Cache holders that sessions are waiting for
set pagesize 40
select x$kglpn.inst_id,sid Holder ,KGLPNUSE Sesion , KGLPNMOD Held, KGLPNREQ Req
from x$kglpn , gv$session
where KGLPNHDL in (select p1raw from gv$session_wait
where wait_time=0 and event like ‘library cache%’)
and KGLPNMOD <> 0
and gv$session.saddr=x$kglpn.kglpnuse ;
PROMPT Detect Library Cache holders that sessions are waiting for
Detect sessions waiting for a Library Cache Locks
select sid Waiter, p1raw,
substr(rawtohex(p1),1,30) Handle,
substr(rawtohex(p2),1,30) Pin_addr
from gv$session_wait where wait_time=0 and event like ‘library cache%’;