来源:北大青鸟飞迅校区|发布时间:2013-05-05 11:18:30
本文是关于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官方文档<<数据库性能优化>>):
命中率的计算公式为:
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;
招生热线: 4008-0731-86 / 0731-82186801
学校地址: 长沙市天心区团结路6号
Copyright © 2006 | 湖南大计信息科技有限公司 版权所有
湘ICP备14017520号-3