Oracle的邏輯結構(表空間、段、區間、塊)——Oracle資料塊(二)

bq_wang發表於2009-02-10
Normal 0 7.8 磅 0 2 false false false EN-US ZH-CN X-NONE

以下指令碼來自於網際網路,具體出處已經找不到了,如有知道還請告知!


關於熱點塊的查詢


====查詢當前資料庫最繁忙的BufferTCH(Touch)表示訪問次數越高,熱點快競爭問題就存在=====

SELECT *

  FROM (SELECT   addr, ts#, file#, dbarfil, dbablk, tch

            FROM x$bh

        ORDER BY tch DESC)

 WHERE ROWNUM < 11;

 

====查詢當前資料庫最繁忙的Buffer,結合dba_extents查詢得到這些熱點Buffer來自哪些物件=====

SELECT e.owner, e.segment_name, e.segment_type

           FROM dba_extents e,

                (SELECT *

                   FROM (SELECT   addr, ts#, file#, dbarfil, dbablk, tch

                             FROM x$bh

                         ORDER BY tch DESC)

                  WHERE ROWNUM < 11) b

          WHERE e.relative_fno = b.dbarfil

            AND e.block_id <= b.dbablk

            AND e.block_id + e.blocks > b.dbablk;

 

=============如果在Top 5中發現latch free熱點塊事件時,可以從V$latch_children中查詢具體的子Latch資訊============

SELECT *

  FROM (SELECT   addr, child#, gets, misses, sleeps, immediate_gets igets,

                 immediate_misses imiss, spin_gets sgets

            FROM v$latch_children

           WHERE NAME = 'cache buffers chains'

        ORDER BY sleeps DESC)

 WHERE ROWNUM < 11;

 

================獲取當前持有最熱點資料塊的Latchbuffer資訊==========

SELECT b.addr, a.ts#, a.dbarfil, a.dbablk, a.tch, b.gets, b.misses, b.sleeps

  FROM (SELECT *

          FROM (SELECT   addr, ts#, file#, dbarfil, dbablk, tch, hladdr

                    FROM x$bh

                ORDER BY tch DESC)

         WHERE ROWNUM < 11) a,

       (SELECT addr, gets, misses, sleeps

          FROM v$latch_children

         WHERE NAME = 'cache buffers chains') b

 WHERE a.hladdr = b.addr;

 

===============利用前面的SQL可以找到這些熱點Buffer的物件資訊===========

SELECT distinct e.owner, e.segment_name, e.segment_type

           FROM dba_extents e,

                (SELECT *

                   FROM (SELECT   addr, ts#, file#, dbarfil, dbablk, tch

                             FROM x$bh

                         ORDER BY tch DESC)

                  WHERE ROWNUM < 11) b

          WHERE e.relative_fno = b.dbarfil

            AND e.block_id <= b.dbablk

            AND e.block_id + e.blocks > b.dbablk;

 

================結合SQL檢視可以找到操作這些物件的相關SQL,然後透過最佳化SQL減少資料的訪問,

或者最佳化某些容易引起爭用的操作(如connect by等操作)來減少熱點塊競爭=================

 

break on hash_value skip 1

SELECT /*+ rule */ hash_value,sql_text

    FROM v$sqltext

   WHERE (hash_value, address) IN (

            SELECT a.hash_value, a.address

              FROM v$sqltext a,

                   (SELECT DISTINCT a.owner, a.segment_name, a.segment_type

                               FROM dba_extents a,

                                    (SELECT dbarfil, dbablk

                                       FROM (SELECT   dbarfil, dbablk

                                                 FROM x$bh

                                             ORDER BY tch DESC)

                                      WHERE ROWNUM < 11) b

                              WHERE a.relative_fno = b.dbarfil

                                AND a.block_id <= b.dbablk

                                AND a.block_id + a.blocks > b.dbablk) b

             WHERE a.sql_text LIKE '%' || b.segment_name || '%'

               AND b.segment_type = 'TABLE')

ORDER BY hash_value, address, piece;


也可以參看 熱點塊競爭和解決(cache buffers chains)

http://blog.oracle.com.cn/html/32/203732-4268.html


來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/6517/viewspace-545697/,如需轉載,請註明出處,否則將追究法律責任。

相關文章