librarycache相關(guān)知識點有哪些

library cache相關(guān)知識點有哪些,針對這個問題,這篇文章詳細介紹了相對應(yīng)的分析和解答,希望可以幫助更多想解決這個問題的小伙伴找到更簡單易行的方法。

創(chuàng)新互聯(lián)建站從2013年開始,是專業(yè)互聯(lián)網(wǎng)技術(shù)服務(wù)公司,擁有項目成都網(wǎng)站設(shè)計、網(wǎng)站制作網(wǎng)站策劃,項目實施與項目整合能力。我們以讓每一個夢想脫穎而出為使命,1280元蒲縣做網(wǎng)站,已為上家服務(wù),為蒲縣各地企業(yè)和個人服務(wù),聯(lián)系電話:18982081108

共享游標
Sql首次解析后會生成父游標和1個子游標(DDL除外),其可共享的部分包括解析樹,執(zhí)行計劃,綁定變量和sql文本等;
父游標主要保存游標名即sql text,文本一致的sql即可共享;
子游標保存剩余信息,只有當執(zhí)行計劃/綁定變量/環(huán)境變量(NLS & optimization mode)/實際引用對象一致時才可共享,否則新建1個子游標;


硬解析:沒有可重用的共享游標,僅僅共享父游標也是硬解析;
軟解析:重用父游標和子游標;
軟軟解析:緩存PGA中關(guān)閉的session cursor,相比軟解析省去了游標open/close,同時可快速定位library cache中的共享游標;僅供當前session使用;


游標的生命周期
正常情況為open – parse – bind – execute – fetch - close
而應(yīng)用據(jù)此可分4種類型
1 不使用綁定變量
 每次執(zhí)行都經(jīng)歷一遍open/close,游標不可重用,每次都進行硬解析;設(shè)置cursor_sharing=force/similar可使用軟解析;
2 使用綁定變量
 每次執(zhí)行都經(jīng)歷一遍open/close,游標可重用,后續(xù)執(zhí)行進行軟解析;設(shè)置session_cached_cursors可使用軟軟解析,而且避免每次都open/close游標;
3 open once + parse-bind-execute-fetch loop + close once
 開啟HOLD_CURSOR=NO & RELEASE_CURSOR=NO選項的oracle precompilers采用此種應(yīng)用;每次都執(zhí)行軟解析,但避免了頻繁的開關(guān)游標;
4 open once + parse + bind + execute-fetch loop + close once
 設(shè)計良好的OCI或precompiler可能采用此應(yīng)用;設(shè)置cursor_space_for_time=true可提升性能(11g廢棄)


如何優(yōu)化軟解析
V$statname中的session cursor cache hits/session cursor cache count/parse count (total)分別代表會話游標緩存命中次數(shù)/緩存總數(shù)/解析總數(shù),當hits/total比例很低時說明軟解析很嚴重,而軟解析同樣需要library cache latch;
1 服務(wù)器: 調(diào)整session_cache_cursor
2 應(yīng)用: 改寫pl/sql,采用上述第4種類型的應(yīng)用


Library cache
由KGL管理,采用哈希表結(jié)構(gòu),每個bucket由handle鏈表組成,每個handle包含一系列heap,其指向heap 0;
 

library cache相關(guān)知識點有哪些


Handle存儲有對象名/命名空間/標志位
 

library cache相關(guān)知識點有哪些

library cache相關(guān)知識點有哪些
 


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
關(guān)于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失效,相應(yīng)cursor必須重新解析方可再次運行,即如果對表作DDL相應(yīng)游標都會失效,極容易爆發(fā)library cache pin等待;


pin和lock都是添加于handle之上的;

library cache相關(guān)知識點有哪些

Library cache latch:用于串行訪問library cache中的對象;lock并非原子操作,上鎖前后需要latch保護;
Library cache load lock latch/library cache load lock—對象不在內(nèi)存時無法lock,此時需先加載;前者避免對象被多次加載,先獲取前者直到load lock被分配,由后者負責(zé)將對象加載至內(nèi)存;


library cache相關(guān)知識點有哪些 



找出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;

關(guān)于library cache相關(guān)知識點有哪些問題的解答就分享到這里了,希望以上內(nèi)容可以對大家有一定的幫助,如果你還有很多疑惑沒有解開,可以關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道了解更多相關(guān)知識。

分享文章:librarycache相關(guān)知識點有哪些
分享路徑:http://bm7419.com/article10/igiego.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供品牌網(wǎng)站設(shè)計移動網(wǎng)站建設(shè)、建站公司Google、自適應(yīng)網(wǎng)站做網(wǎng)站

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)

搜索引擎優(yōu)化