当我们查询v$session_wait时如果发现有大量library cache pin等待事件,此时要怎样去找出library cache pin等待的具体是什么呢?
下面就library cache pin等待事件做个介绍:
library cache pin是用来管理Library Cache的并发访问的,pin一个Object会引起相应的heap被载入内存中(如果此前没有被加载),pins可以在以下三个模式下得到:Null、Share和Exclusive,可以把pin看做是一种特定形式的锁。
当Library Cache Pin等待事件出现时,通常说明该pin被其他用户以非兼容模式持有。
Library Cache Pin的等待事件为3秒,其中有1秒用于PMON后台进程。
Library Cache Pin的参数如下,有用的主要是P1和P2:
*P1 --------------------KGL Handle address
*P2 --------------------Pin address
*P3 --------------------Encoded Mode & Namespace
下面去查找library cache pin原因
1、获得library cache pin等待的对象
SELECT addr, kglhdadr, kglhdpar, kglnaown, kglnaobj, kglnahsh, kglhdobj
FROM x$kglob
WHERE kglhdadr IN (SELECT p1raw
FROM v$session_wait
WHERE event LIKE 'library%');
2、获得持有等待对象的session信息:
SELECT a.SID, a.username, a.program, b.addr, b.kglpnadr, b.kglpnuse,
b.kglpnses, b.kglpnhdl, b.kglpnlck, b.kglpnmod, b.kglpnreq
FROM v$session a, x$kglpn b
WHERE a.saddr = b.kglpnuse
AND b.kglpnmod <> 0
AND b.kglpnhdl IN (SELECT p1raw
FROM v$session_wait
WHERE event LIKE 'library%');
3、获得持有对象用户执行的代码:
SELECT sql_text
FROM v$sqlarea
WHERE (v$sqlarea.address, v$sqlarea.hash_value) IN (
SELECT sql_address, sql_hash_value
FROM v$session
WHERE SID IN (
SELECT SID
FROM v$session a, x$kglpn b
WHERE a.saddr = b.kglpnuse
AND b.kglpnmod <> 0
AND b.kglpnhdl IN (SELECT p1raw
FROM v$session_wait WHERE event LIKE 'library%')));