您好,登錄后才能下訂單哦!
library cache相關知識點有哪些,針對這個問題,這篇文章詳細介紹了相對應的分析和解答,希望可以幫助更多想解決這個問題的小伙伴找到更簡單易行的方法。
共享游標
Sql首次解析后會生成父游標和1個子游標(DDL除外),其可共享的部分包括解析樹,執行計劃,綁定變量和sql文本等;
父游標主要保存游標名即sql text,文本一致的sql即可共享;
子游標保存剩余信息,只有當執行計劃/綁定變量/環境變量(NLS & optimization mode)/實際引用對象一致時才可共享,否則新建1個子游標;
硬解析:沒有可重用的共享游標,僅僅共享父游標也是硬解析;
軟解析:重用父游標和子游標;
軟軟解析:緩存PGA中關閉的session cursor,相比軟解析省去了游標open/close,同時可快速定位library cache中的共享游標;僅供當前session使用;
游標的生命周期
正常情況為open – parse – bind – execute – fetch - close
而應用據此可分4種類型
1 不使用綁定變量
每次執行都經歷一遍open/close,游標不可重用,每次都進行硬解析;設置cursor_sharing=force/similar可使用軟解析;
2 使用綁定變量
每次執行都經歷一遍open/close,游標可重用,后續執行進行軟解析;設置session_cached_cursors可使用軟軟解析,而且避免每次都open/close游標;
3 open once + parse-bind-execute-fetch loop + close once
開啟HOLD_CURSOR=NO & RELEASE_CURSOR=NO選項的oracle precompilers采用此種應用;每次都執行軟解析,但避免了頻繁的開關游標;
4 open once + parse + bind + execute-fetch loop + close once
設計良好的OCI或precompiler可能采用此應用;設置cursor_space_for_time=true可提升性能(11g廢棄)
如何優化軟解析
V$statname中的session cursor cache hits/session cursor cache count/parse count (total)分別代表會話游標緩存命中次數/緩存總數/解析總數,當hits/total比例很低時說明軟解析很嚴重,而軟解析同樣需要library cache latch;
1 服務器: 調整session_cache_cursor
2 應用: 改寫pl/sql,采用上述第4種類型的應用
Library cache
由KGL管理,采用哈希表結構,每個bucket由handle鏈表組成,每個handle包含一系列heap,其指向heap 0;
Handle存儲有對象名/命名空間/標志位
Lock & Pin
作用
Library cache lock manages concurrency between processes, whereas library cache pin manages cache coherence。
In order to access an object in library cache, a process must first lock the library cache object handle, and then pin the object data heap itself.
Acquiring a library cache lock is also the only way to locate an object in cache—a process locates and locks an object in a single operation.
If the process wants to actually examine or modify the object, then it must acquire a library cache pin on the object data heap itself (after acquiring a library cache lock on the library cache object handle.
lock保護handle pin保護heap,要想訪問library cache中的對象必須先后獲取lock和pin;
10202采用mutex替換了針對cursor的library cache pin;
模式
Library cache lock和pin都是enqueue鎖,
lock分為S,X和null(cursor只能用null維護依賴一致性),pin只有S和X;
軟解析使用S pin,硬解析使用X pin;無論硬解析還是軟解析,cursor只是用null lock;可使用10049跟蹤http://www.dbsnake.net/library-cache-pin-and-lock-continue.html
關于pin,
An X request (3) will be blocked by any pins held S mode (2) on the object.
An S request (2) will be blocked by any X mode (3) pin held, or may queue behind some other X request.
X pin會讓null lock失效,相應cursor必須重新解析方可再次運行,即如果對表作DDL相應游標都會失效,極容易爆發library cache pin等待;
pin和lock都是添加于handle之上的;
Library cache latch:用于串行訪問library cache中的對象;lock并非原子操作,上鎖前后需要latch保護;
Library cache load lock latch/library cache load lock—對象不在內存時無法lock,此時需先加載;前者避免對象被多次加載,先獲取前者直到load lock被分配,由后者負責將對象加載至內存;
找出blocker
select
waiter.sid waiter,
waiter.event wevent,
to_char(blocker_event.sid)||','||to_char(blocker_session.serial#) blocker,
substr(decode(blocker_event.wait_time, 0, blocker_event.event, 'ON CPU'),1,30) bevent
from
x$kglpn p,
gv$session blocker_session,
gv$session_wait waiter,
gv$session_wait blocker_event
where
p.kglpnuse=blocker_session.saddr
and p.kglpnhdl=waiter.p1raw
and waiter.event in ( 'library cache pin' , 'library cache lock' , 'library cache load lock')
and blocker_event.sid=blocker_session.sid
and waiter.sid != blocker_event.sid
order by waiter.p1raw,waiter.sid;
select
ash.session_id sid,
ash.blocking_session bsid,
nvl(o.object_name,to_char(CURRENT_OBJ#)) obj,
o.object_type otype,
CURRENT_FILE# filen,
CURRENT_BLOCK# blockn,
ash.SQL_ID,
nvl(rc.name,to_char(ash.p3)) row_cache
from v$active_session_history ash, ( select cache#, parameter name from v$rowcache ) rc, all_objects o
where event='row cache lock'
and rc.cache#(+)=ash.p1
and o.object_id (+)= ash.CURRENT_OBJ#
and ash.session_state='WAITING'
and ash.sample_time > sysdate - &minutes/(60*24)
Order by sample_time;
關于library cache相關知識點有哪些問題的解答就分享到這里了,希望以上內容可以對大家有一定的幫助,如果你還有很多疑惑沒有解開,可以關注億速云行業資訊頻道了解更多相關知識。
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。