此文主要是關於Oracle數據庫調試和優化方面的相關內容的介紹,還有涉及到Oracle數據庫中命裡率的相關問題的解答,其中包括不同的算法之間性能的比對。以下就是相關內容的介紹。
關於Oracle中各個命中率的計算以及相關的調優
1)Library Cache的命中率:
計算公式:
- Library Cache Hit Ratio = sum(pinhits) / sum(pins)
- SQL>SELECT SUM(pinhits)/sum(pins) FROM V$LIBRARYCACHE;
通常在98%以上,否則,需要要考慮加大共享池,綁定變量,修改cursor_sharing等參數。
2)計算共享池內存使用率:
- SQL>SELECT (1 - ROUND(BYTES /
(&TSP_IN_M * 1024 * 1024), 2)) * 100
|| '%' FROM V$SGASTAT WHERE NAME =
'free memory' AND POOL = 'shared pool';
其中: &TSP_IN_M是你的總的共享池的SIZE(M),共享池內存使用率,應該穩定在75%-90%間,太小浪費內存,太大則內存不足。
查詢空閒的共享池內存:
- SQL>SELECT * FROM V$SGASTAT WHERE NAME =
'free memory' AND POOL = 'shared pool';
3)db buffer cache命中率:
計算公式:
- Hit ratio = 1 - [physical reads/(block gets + consistent gets)]
- SQL>SELECT NAME, PHYSICAL_READS, DB_BLOCK_GETS, CONSISTENT_GETS,
1 - (PHYSICAL_READS / (DB_BLOCK_GETS + CONSISTENT_GETS))
"Hit Ratio" FROM V$BUFFER_POOL_STATISTICS WHERE NAME='DEFAULT';
通常應在90%以上,否則,需要調整,加大DB_CACHE_SIZE,另外一種計算命中率的方法(摘自ORACLE官方文檔<<Oracle數據庫性能優化>>):命中率的計算公式為:
- Hit Ratio = 1 - ((physical reads - physical reads
direct - physical reads direct (lob)) /
(db block gets + consistent gets - physical
reads direct - physical reads direct (lob))
分別代入上一查詢中的結果值,就得出了Buffer cache的命中率
- SQL>SELECT NAME, VALUE FROM V$SYSSTAT WHERE NAME
IN('session logical reads', 'physical reads',
'physical reads direct', 'physical reads direct
(lob)', 'db block gets', 'consistent gets');
4)數據緩沖區命中率:
- SQL> select value from v$sysstat where name =
'physical reads'; SQL> select value from v$sysstat where name
='physical reads direct'; SQL> select value from v$sysstat
where name ='physical reads direct (lob)'; SQL>
select value from v$sysstat where name ='consistent gets';
SQL> select value from v$sysstat where name = 'db block gets';
這裡命中率的計算應該是令
- x = physical reads direct + physical reads direct (lob)
命中率
- =100 - ( physical reads - x) / (consistent gets + db block gets - x)*100
通常如果發現命中率低於90%,則應該調整應用可可以考慮是否增大數據緩沖區
5)共享池的命中率:
- SQL> select sum(pinhits-reloads)/sum(pins)*100 "hit radio" from v$librarycache;
假如共享池的命中率低於95%,就要考慮調整應用(通常是沒使用bind var )或者增加內存
6)計算在內存中排序的比率:
- SQL>SELECT * FROM v$sysstat t WHERE NAME='sorts (memory)';
—查詢內存排序數
- SQL>SELECT * FROM v$sysstat t WHERE NAME='sorts (disk)';
—查詢磁盤排序數
- --caculate sort in memory ratio SQL>SELECT
round(&sort_in_memory/
(&sort_in_memory+&sort_in_disk),4)*100||'%' FROM dual;
此比率越大越好,太小整要考慮調整,加大PGA
7)PGA的命中率:
計算公式:BP x 100 / (BP + EBP)
BP: bytes processed
EBP: extra bytes read/written
- SQL>SELECT * FROM V$PGASTAT WHERE NAME='cache hit percentage';
或者從OEM的圖形界面中查看,我們可以查看一個視圖以獲取Oracle的建議值:
- SQL>SELECT round(PGA_TARGET_FOR_ESTIMATE/1024/1024)
target_mb, ESTD_PGA_CACHE_HIT_PERCENTAGE cache_hit_perc,
ESTD_OVERALLOC_COUNT FROM V$PGA_TARGET_ADVICE; The output
of this query might look like the following: TARGET_MB
CACHE_HIT_PERC ESTD_OVERALLOC_COUNT 63 23 367 125 24 30
250 30 3 375 39 0 500 58 0 600 59 0 700 59 0 800 60 0 900 60 0
在此例中:PGA至少要分配375M,我個人認為PGA命中率不應該低於50%,以下的SQL統計sql語句執行在三種模式的次數:
- optimal memory size, one-pass memory size, multi-pass memory size:
- SQL>SELECT name profile, cnt, decode
(total, 0, 0, round(cnt*100/total,4)) percentage FROM
(SELECT name, value cnt, (sum(value) over ())
total FROM V$SYSSTAT WHERE name like 'workarea exec%');