您好,登錄后才能下訂單哦!
常見的library cache lock產生的原因是什么,相信很多沒有經驗的人對此束手無策,為此本文總結了問題出現的原因和解決方法,通過這篇文章希望你能解決這個問題。
Troubleshooting Library Cache: Lock, Pin and Load Lock (Doc ID 444560.1)
一般可以理解的是alter table或者alter package/procedure會以X模式持有library cache lock,造成阻塞。
但是常見的問題還有以下幾種原因:
1)錯誤的用戶名密碼:
一般需要通過ASH或者SSD/hang analyze去獲取p3進行namespace分析。
1. event: 'library cache lock'
time waited: 43 min 12 sec
wait id: 9 p1: 'handle address'=0x7000003117dfca0
p2: 'lock address'=0x700000310866c80
p3: '100*mode+namespace'=0x4f0003
* time between wait #1 and #2: 0.000164 sec
<=================p3: '100*mode+namespace'=0x4f0003
mode=3
namespace=4f
HEX: 4f =>DEC: 79
select * FROM V$DB_OBJECT_CACHE;
SQL> select distinct KGLHDNSP,KGLHDNSD from x$kglob;
KGLHDNSP KGLHDNSD
---------- ----------------------------------------------------------------
0 SQL AREA
4 INDEX
1 TABLE/PROCEDURE
3 TRIGGER
52 SCHEDULER EARLIEST START TIME
64 EDITION
69 DBLINK
2 BODY
10 QUEUE
79 ACCOUNT_STATUS
23 RULESET
24 RESOURCE MANAGER
73 SCHEMA
74 DBINSTANCE
51 SCHEDULER GLOBAL ATTRIBUTE
38 RULE EVALUATION CONTEXT
82 SQL AREA BUILD
75 SQL AREA STATS
5 CLUSTER
18 PUB SUB INTERNAL INFORMATION
<======79 ACCOUNT_STATUS
ACCOUNT_STATUS說明library cache lock是在account上,可能是用錯誤的用戶名密碼登錄,或者是當時正有人alter user(這種幾率極低)。
可以通過以下SQL去確認錯誤的用戶名密碼登錄:
select username,
os_username,
userhost,
client_id,
trunc(timestamp),
count(*) failed_logins
from dba_audit_trail
where returncode=1017 and --1017 is invalid username/password
timestamp < sysdate -7
group by username,os_username,userhost, client_id,trunc(timestamp);
Or run following sql:
SELECT "USERNAME", "OS_USERNAME", "USERHOST", "EXTENDED_TIMESTAMP",returncode FROM "SYS"."DBA_AUDIT_SESSION" WHERE returncode != 0;
當然必須確保audit 打開,并且有audit CREATE SESSION動作
To turn on audit:
Alter system set audit_trail=DB scope=spfile;
restart DB
audit CREATE SESSION;
audit ALTER USER;
檢查:
show parameter audit_trail
select * from DBA_STMT_AUDIT_OPTS;
2)正在執行搜集統計信息,這是大家往往會忽略的,一般會看last_ddl_time,卻忽略了last_analyzed,
檢查腳本如下:
比如EMP是遇到library cache lock中的表名:
select owner,object_name,object_type,to_char(last_ddl_time,'yyyy-mm-dd hh34:mi:ss') from dba_objects where object_name='EMP';
select table_name,to_char(last_analyzed,'yyyy-mm-dd hh34:mi:ss') from dba_tables where table_name='EMP';
也需要檢查所有dependency的對象,因為oracle對象是相互關聯的,一個對象失效會導致一串失效。
select owner,object_name,object_type,to_char(last_ddl_time,'yyyy-mm-dd hh34:mi:ss') ddl_time from dba_objects where object_name in
(
select p.name
from sys.obj$ d, sys.dependency$ dep, sys.obj$ p
where d.obj# = dep.d_obj# and p.obj# = dep.p_obj#
start with d.name='EMP'
connect by prior dep.p_obj#=dep.d_obj#)
order by ddl_time desc;
select table_name,to_char(last_analyzed,'yyyy-mm-dd hh34:mi:ss') from dba_tables where table_name in
(
select p.name
from sys.obj$ d, sys.dependency$ dep, sys.obj$ p
where d.obj# = dep.d_obj# and p.obj# = dep.p_obj#
start with d.name='EMP'
connect by prior dep.p_obj#=dep.d_obj#)
order by last_analyzed desc;
比較典型的一個用戶實例:
select to_char(last_analyzed,'yyyy-mm-dd hh34:mi:ss') from dba_tables where table_name='XXXXX';
--2014-11-25 16:52:50
<=============gathering statistics in the issue time
2014-11-25 16:52:52 16620 c34q5c8gf6kum library cache lock
2014-11-25 16:52:52 16643 c34q5c8gf6kum library cache lock
<======The issue starts from 16:52:52 while statistics was gathered at 16:52:50
3)錯誤的語句解析(failed parse)
這是通常很難注意到的一個問題,因為被解析的語句往往在AWR中找不到(因為沒有通過parse),要注意查看AWR中的“failed parse elapsed time”
Event Waits Time(s) Avg wait (ms) % DB time Wait Class
library cache lock 6,714,208 363,093 54 67.14 Concurrency
library cache: mutex X 11,977,886 99,050 8 18.31 Concurrency
DB CPU 38,971 7.21
db file sequential read 350,069 2,465 7 0.46 User I/O
log file sync 217,673 1,969 9 0.36 Commit
Statistic Name Time (s) % of DB Time
sql execute elapsed time 537,418.09 99.37
parse time elapsed 467,101.99 86.37
failed parse elapsed time 460,663.79 85.18 <===============failed parse elapsed time was high. That means the issue was caused by parse failed.
看完上述內容,你們掌握常見的library cache lock產生的原因是什么的方法了嗎?如果還想學到更多技能或想了解更多相關內容,歡迎關注億速云行業資訊頻道,感謝各位的閱讀!
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。