定位Library Cache pin,Library Cache lock等待的解决方法
定位Library Cache pin,Library Cache lock等待的解决方法
这个星期一我去客户巡检时,客户告知我们派综系统数据库在前面几个月
日志中有时会出现很多Waited too long for library cache load lock错误
因为当时不在现场,所以无法确定是由什么引起的。
可以建议客户在出现此类情况时,用以下sql进行监控,捕获相关信息进行分析:
这三个sql已经经过测试,没有问题。
1.获得Library Cache pin,Library Cache lock等待的对象,其中kglnaobj是object_name
spool object_name.log
SELECT addr, kglhdadr, kglhdpar, kglnaown, kglnaobj, kglnahsh, kglhdobj
FROM x$kglob
WHERE kglhdadr IN (SELECT p1raw
FROM v$session_wait
WHERE event LIKE 'library%')
spool off;
2.获得持有等待对象的session信息
spool session.log
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%')
spool off;
3.获得持有对象用户执行的代码
spool sql_code.log
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%')))
spool off;