[20181122]瞭解資料庫快取被那些物件佔用.txt

lfree發表於2018-11-22

[20181122]瞭解資料庫快取被那些物件佔用.txt


--//沒事,隨手寫一個指令碼,看看資料庫快取被那些物件佔用:


column object_name format a30

column owner format a20

column number_MB format 99999999.99

SELECT *

  FROM (  SELECT o.owner,

                 o.object_name,

                 COUNT (*) number_of_blocks,

                 COUNT (DISTINCT FILE# || '.' || BLOCK#) distinct_block_count,

sum (decode(dirty,'Y',1,0)) dirty_block,

                 COUNT (*) - COUNT (DISTINCT FILE# || '.' || BLOCK#)

                    diff_number_block,

                 ROUND (COUNT (*) * 8 / 1024, 2) number_Mb, ROUND ( (ratio_to_report (SUM (1)) OVER () * 100),2) rr

            FROM dba_objects o, v$bh v

           WHERE o.data_object_id = v.objd AND o.owner != 'SYS' and v.status <> 'free'

        GROUP BY o.owner, o.object_name

        ORDER BY COUNT (*) DESC)

 WHERE ROWNUM <= 50;


--//我直接按照8k資料塊計算.取前50個物件.

--//順便提一下,對於cluster table物件無效.不過一般應用很少應用這種型別的表.

--//把條件o.owner != 'SYS'改寫成o.owner = 'SYS',就明白什麼回事.


column object_name format a30

column owner format a20

column number_MB format 99999999.99

SELECT *

  FROM (  SELECT o.owner,

                 o.object_name,

                 v.objd,

                 COUNT (*) number_of_blocks,

                 COUNT (DISTINCT FILE# || '.' || BLOCK#) distinct_block_count,

                 sum (decode(dirty,'Y',1,0)) dirty_block,

                 COUNT (*) - COUNT (DISTINCT FILE# || '.' || BLOCK#)

                    diff_number_block,

                 ROUND (COUNT (*) * 8 / 1024, 2) number_Mb, ROUND ( (ratio_to_report (SUM (1)) OVER () * 100),2) rr

            FROM dba_objects o, v$bh v

           WHERE o.data_object_id = v.objd AND o.owner = 'SYS' and v.status <> 'free'

        GROUP BY o.owner, o.object_name,v.objd

        ORDER BY COUNT (*) DESC)

 WHERE ROWNUM <= 50;


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

相關文章