視圖學習:v$Latch (X$KSLLT) 與 v$Latch_Children(X$KSLLT, X$KSLLD)


10gR2中關於Latch的視圖:有5個除了v$Latch之外還有以下4個,他們都可以和v$Latch視圖連接,連接字段如下:
v$Latch_CHILDREN.NAME/LATCH#
v$LatchHOLDER.NAME
v$LatchNAME.NAME/LATCH# 
v$Latch_MISSES.PARENT_NAME

什么是Latch
latch有40余種,但作為DBA關心的主要應有以下幾種:
Cache buffers chains latch:當用戶進程搜索SGA尋找database cache buffers時需要使用此latch。 見《Buffer Cache Management
Cache buffers LRU chain latch:當用戶進程要搜索buffer cache中包括所有 dirty blocks的LRU (least recently used) 鏈時使用該種latch。 見《Buffer Cache Management
Redo log buffer latch:這種latch控制redo log buffer中每條redo entries的空間分配。 稍后
Row cache objects latch:當用戶進程訪問緩存的數據字典數值時,將使用Row cache objects latch。 稍后
首先來看看v$latch,在10gR2下統計有 382種latch,V$LATCH視圖在選取X$KSLLT記錄時,進行了Group By及SUM運算,從而得出了一個匯總信息。 本視圖保存自實例啟動各類栓鎖的統計信息。常用於當v$session_wait中發現栓鎖競爭時鑒別SGA區中問題所在區域
SQL> select count(*) from v$LATCH;
  COUNT(*)
----------
       382
SQL> select VIEW_DEFINITION from V$FIXED_VIEW_DEFINITION where VIEW_NAME like 'V$LATCH';
VIEW_DEFINITION
--------------------------------------------------------------------------------
select addr,latch#,level#,name,hash,gets,misses,sleeps,immediate_gets, immediate
_misses,waiters_woken,waits_holding_latch,spin_gets, sleep1,sleep2,sleep3,sleep4
,sleep5,sleep6,sleep7,sleep8,sleep9, sleep10,sleep11,wait_time from gv$latch whe
re inst_id = USERENV('Instance')
SQL> select * from V$FIXED_TABLE where name like 'V$LATCH_CHILDREN';
NAME                            OBJECT_ID TYPE   TABLE_NUM
------------------------------ ---------- ----- ----------
V$LATCH                        4294950921   VIEW         65537
SQL> select VIEW_DEFINITION from V$FIXED_VIEW_DEFINITION where VIEW_NAME like 'GV$LATCH';
VIEW_DEFINITION
--------------------------------------------------------------------------------
select d.inst_id,d.kslldadr,la.latch#,d.kslldlvl,d.kslldnam,d.kslldhsh,        l
a.gets,la.misses,        la.sleeps,la.immediate_gets,la.immediate_misses,la.wait
ers_woken,        la.waits_holding_latch,la.spin_gets,la.sleep1,la.sleep2,
  la.sleep3,la.sleep4,la.sleep5,la.sleep6,la.sleep7,la.sleep8,la.sleep9,
la.sleep10, la.sleep11, la.wait_time  from x$kslld d,    (select kslltnum latch#
,        sum(kslltwgt) gets,sum(kslltwff) misses,sum(kslltwsl) sleeps,        su
m(kslltngt) immediate_gets,sum(kslltnfa) immediate_misses,        sum(kslltwkc)
waiters_woken,sum(kslltwth) waits_holding_latch,        sum(ksllthst0) spin_gets
,sum(ksllthst1) sleep1,sum(ksllthst2) sleep2,        sum(ksllthst3) sleep3,sum(k
sllthst4) sleep4,sum(ksllthst5) sleep5,        sum(ksllthst6) sleep6,sum(ksllths
t7) sleep7,sum(ksllthst8) sleep8,        sum(ksllthst9) sleep9,sum(ksllthst10) s
leep10,sum(ksllthst11) sleep11,        sum(kslltwtt) wait_time    from x$ksllt g
roup by kslltnum) la  where la.latch# = d.indx
X$KSLLT [K]ernel [S]ervice [L]ock Management Latch statistics + Child latches 
SQL> select * from V$FIXED_TABLE where name like 'GV$LATCH_CHILDREN';
NAME                            OBJECT_ID TYPE   TABLE_NUM
------------------------------ ---------- ----- ----------
GV$LATCH_CHILDREN              4294951269   VIEW         65537
SQL> select VIEW_DEFINITION from V$FIXED_VIEW_DEFINITION where VIEW_NAME like 'X$KSLLT';
no rows selected 看來X$KSLLT已經是最低層的表而不是視圖了
SQL> select * from V$FIXED_TABLE where name like 'X$KSLLT';
NAME                            OBJECT_ID TYPE   TABLE_NUM
------------------------------ ---------- ----- ----------
X$KSLLT                        4294950993   TABLE            6
V$LATCH中的常用列:拿《 library cache lock和library cache pin到底是什么》里邊的這條語句來解釋V$LATCH視圖
SQL>   select name,level#,gets,misses,sleeps,immediate_gets,immediate_misses from v$latch where name like 'library%';

NAME                                                   LEVEL#       GETS     MISSES     SLEEPS IMMEDIATE_GETS IMMEDIATE_MISSES
-------------------------------------------------- ---------- ---------- ---------- ---------- -------------- ----------------
library cache                                               5    9221760         1608      800          2596            76766
library cache lock                                        6   13548247        582        6             0                0
library cache lock allocation                            3     208273          0           0             0                0
library cache pin                                          6    4207462        193        0             2                0
library cache hash chains                            9             0          0          0             0                0
library cache pin allocation                              3      57276          0          0             0                0
library cache load lock                                    5      24848          0          0             1                0
NAME:latch名稱
IMMEDIATE_GETS:以Immediate模式latch請求數
IMMEDIATE_MISSES:請求失敗數
GETS:以Willing to wait請求模式latch的請求數
MISSES:初次嘗試請求不成功次數
SLEEPS:成功獲取前sleeping次數
還有兩個重點的沒有出現在這里
SPIN_GETS:第一次嘗試失敗,但在以后的輪次中成功
WAIT_TIME:花費在等待latch的時間
再來看看V$LATCH_CHILDREN,V$LATCH_CHILDREN視圖和v$Latch視圖的差別與v$sql和v$sqlarea的區別相似並不進行匯總運算,所以也就顯示了子Latch的相關信息
SQL> select count(*) from V$LATCH_CHILDREN;
  COUNT(*)
----------
      1925
SQL> select VIEW_DEFINITION from V$FIXED_VIEW_DEFINITION where VIEW_NAME like 'V$LATCH_CHILDREN';
VIEW_DEFINITION
--------------------------------------------------------------------------------
select  ADDR , LATCH# , CHILD# , LEVEL# , NAME , HASH , GETS , MISSES , SLEEPS
, IMMEDIATE_GETS , IMMEDIATE_MISSES , WAITERS_WOKEN , WAITS_HOLDING_LATCH , SPIN
_GETS , SLEEP1 , SLEEP2 , SLEEP3 , SLEEP4 , SLEEP5 , SLEEP6 , SLEEP7 , SLEEP8 ,
SLEEP9 , SLEEP10 , SLEEP11 , WAIT_TIME from GV$LATCH_CHILDREN where inst_id = US
ERENV('Instance')
SQL> select * from V$FIXED_TABLE where name like 'V$LATCH_CHILDREN';
NAME                            OBJECT_ID TYPE   TABLE_NUM
------------------------------ ---------- ----- ----------
V$LATCH_CHILDREN               4294951168 VIEW       65537
SQL> select VIEW_DEFINITION from V$FIXED_VIEW_DEFINITION where VIEW_NAME like 'GV$LATCH_CHILDREN';
VIEW_DEFINITION
--------------------------------------------------------------------------------
select t.inst_id,t.addr,t.kslltnum,t.kslltcnm,n.kslldlvl,        n.kslldnam,n.ks
lldhsh,        t.kslltwgt,t.kslltwff,t.kslltwsl,t.kslltngt,t.kslltnfa,        t.
kslltwkc,t.kslltwth,t.ksllthst0,t.ksllthst1,        t.ksllthst2,t.ksllthst3,t.ks
llthst4,t.ksllthst5,        t.ksllthst6,t.ksllthst7,t.ksllthst8,        t.ksllth
st9,t.ksllthst10, t.ksllthst11,        t.kslltwtt  from x$ksllt t, x$kslld n  wh
ere t.kslltcnm > 0 and t.kslltnum = n.indx
X$KSLLD [K]ernel [S]ervice [L]ock Management Latch [D]escriptor (name)

SQL> select * from V$FIXED_TABLE where name like 'GV$LATCH_CHILDREN';
NAME                            OBJECT_ID TYPE   TABLE_NUM
------------------------------ ---------- ----- ----------
GV$LATCH_CHILDREN              4294951269 VIEW       65537
對比v$latch與v$latch_children視圖
重復一下上邊說的:
V$LATCH視圖在選取X$KSLLT記錄時,進行了Group By及SUM運算,從而得出了一個匯總信息
V$LATCH_CHILDREN視圖和v$Latch視圖的差別與v$sql和v$sqlarea的區別相似並不進行匯總運算,所以也就顯示了子Latch的相關信息
所謂子Latch就是library cache在系統中包含了多少個具體的物理數量的library cache,他們的分配原則是這樣的
v$latch_children內容的條數一般都是v$latch cpu+1倍,例如:下邊這個v$latch的相同查詢,都是查詢有多少相關的library cache latch。這里cpu的個數為2,顯然上述library cache latches的子latch應該為3:
SQL> select name,level#,gets,misses,sleeps,immediate_gets,immediate_misses from v$latch where name like 'library%';

NAME                                                   LEVEL#       GETS     MISSES     SLEEPS IMMEDIATE_GETS IMMEDIATE_MISSES
-------------------------------------------------- ---------- ---------- ---------- ---------- -------------- ----------------
library cache                                               5    9221760         1608      800          2596            76766
library cache lock                                        6   13548247        582        6             0                0
library cache lock allocation                            3     208273          0           0             0                0
library cache pin                                          6    4207462        193        0             2                0
library cache hash chains                            9             0          0          0             0                0
library cache pin allocation                              3      57276          0          0             0                0
library cache load lock                                    5      24848          0          0             1                0

SQL>   select name,level#,gets,misses,sleeps,immediate_gets,immediate_misses from v$ latch_children  where name like 'library%';
NAME                                                   LEVEL#       GETS     MISSES     SLEEPS IMMEDIATE_GETS IMMEDIATE_MISSES
-------------------------------------------------- ---------- ---------- ---------- ---------- -------------- ----------------
library cache                                               5    3274551       1301         94           187                0
library cache                                               5    2218356        116         80           933                0
library cache                                               5    3731320        191        626          1476            76766
library cache lock                                          6    5339737        362          3             0                0
library cache lock                                          6    6223353        194          3             0                0
library cache lock                                          6    1987799         26          0             0                0
library cache pin                                           6    1484918        184          0             0                0
library cache pin                                           6     891695          3          0             2                0
library cache pin                                           6    1831837          6          0             0                0
library cache pin allocation                                3      23177          0          0             0                0
library cache pin allocation                                3       8272          0          0             0                0
library cache pin allocation                                3      25849          0          0             0                0
library cache lock allocation                               3      75900          0          0             0                0
library cache lock allocation                               3      28229          0          0             0                0
library cache lock allocation                               3     104237          0          0             0                0
library cache hash chains                                   9          0          0          0             0                0
library cache hash chains                                   9          0          0          0             0                0
library cache hash chains                                   9          0          0          0             0                0
--EOF--

注意!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系我们删除。



 
粤ICP备14056181号  © 2014-2020 ITdaan.com