命中率:
命中率在Oracle数据库的多个地方都会被提起
例如当一个进程需要访问数据时,首先确定数据是否存在Buffer Cache中,如果存在(称为高速缓存命中),则直接读取数据(逻辑IO/内存读);如果不存在(称为高速缓存未命中),则需要在Buffer Cache中寻找足够的空间将磁盘上需要的数据块复制到Buffer Cache中(物理IO/硬盘读)。
命中率=逻辑IO/(逻辑IO+物理IO)*100%
注:如果命中率低肯定有问题,但命中率高不一定没问题(逻辑IO远高于物理IO,但物理IO仍旧很高的情况下)
可以通过操作系统命令vmstat、iostat查看当前系统的IO情况
[oracle@ora11g ~]$ vmstat 1 5
procs -----------memory---------- ---swap-- -----io---- --system-- -----cpu------
r b swpd free buff cache si so bi bo in cs us sy id wa st
1 0 0 374572 25260 788168 0 0 262 34 239 253 1 4 80 16 0
2 0 0 374556 25268 788172 0 0 0 36 909 1341 0 1 99 0 0
0 0 0 374556 25268 788172 0 0 0 0 876 1248 0 1 99 0 0
0 0 0 374556 25268 788172 0 0 16 80 974 1495 0 1 99 0 0
0 0 0 374556 25276 788164 0 0 0 48 966 1428 0 1 99 0 0
[oracle@ora11g ~]$ iostat 1 5
Linux 2.6.18-308.el5 (ora11g.example.com) 07/17/2013
avg-cpu: %user %nice %system %iowait %steal %idle
1.00 0.00 3.85 15.19 0.00 79.96
Device: tps Blk_read/s Blk_wrtn/s Blk_read Blk_wrtn
sda 33.72 1551.26 202.49 1052263 137352
sda1 0.10 2.58 0.01 1749 4
sda2 22.27 1256.66 141.92 852432 96271
sda3 0.07 2.37 0.00 1610 0
sda4 0.01 0.02 0.00 11 0
sda5 2.17 58.06 4.54 39382 3080
sda6 2.40 60.32 15.53 40920 10532
sda7 2.85 77.55 16.47 52605 11173
sda8 3.01 76.16 8.77 51663 5949
sda9 0.80 17.03 15.25 11554 10343
avg-cpu: %user %nice %system %iowait %steal %idle
0.00 0.00 0.55 0.00 0.00 99.45
Device: tps Blk_read/s Blk_wrtn/s Blk_read Blk_wrtn
sda 5.00 32.00 128.00 32 128
sda1 0.00 0.00 0.00 0 0
sda2 0.00 0.00 0.00 0 0
sda3 0.00 0.00 0.00 0 0
sda4 0.00 0.00 0.00 0 0
sda5 0.00 0.00 0.00 0 0
sda6 1.00 0.00 32.00 0 32
sda7 2.00 32.00 32.00 32 32
sda8 1.00 0.00 32.00 0 32
sda9 1.00 0.00 32.00 0 32
avg-cpu: %user %nice %system %iowait %steal %idle
0.26 0.00 0.77 0.26 0.00 98.71
Device: tps Blk_read/s Blk_wrtn/s Blk_read Blk_wrtn
sda 2.00 0.00 104.00 0 104
sda1 0.00 0.00 0.00 0 0
sda2 2.00 0.00 104.00 0 104
sda3 0.00 0.00 0.00 0 0
sda4 0.00 0.00 0.00 0 0
sda5 0.00 0.00 0.00 0 0
sda6 0.00 0.00 0.00 0 0
sda7 0.00 0.00 0.00 0 0
sda8 0.00 0.00 0.00 0 0
sda9 0.00 0.00 0.00 0 0
avg-cpu: %user %nice %system %iowait %steal %idle
0.26 0.00 0.26 0.00 0.00 99.48
Device: tps Blk_read/s Blk_wrtn/s Blk_read Blk_wrtn
sda 4.00 0.00 32.00 0 32
sda1 0.00 0.00 0.00 0 0
sda2 0.00 0.00 0.00 0 0
sda3 0.00 0.00 0.00 0 0
sda4 0.00 0.00 0.00 0 0
sda5 1.00 0.00 8.00 0 8
sda6 1.00 0.00 8.00 0 8
sda7 1.00 0.00 8.00 0 8
sda8 0.00 0.00 0.00 0 0
sda9 1.00 0.00 8.00 0 8
avg-cpu: %user %nice %system %iowait %steal %idle
0.00 0.00 0.78 0.00 0.00 99.22
Device: tps Blk_read/s Blk_wrtn/s Blk_read Blk_wrtn
sda 13.00 160.00 208.00 160 208
sda1 0.00 0.00 0.00 0 0
sda2 4.00 0.00 80.00 0 80
sda3 0.00 0.00 0.00 0 0
sda4 0.00 0.00 0.00 0 0
sda5 0.00 0.00 0.00 0 0
sda6 1.00 0.00 32.00 0 32
sda7 3.00 64.00 32.00 64 32
sda8 4.00 96.00 32.00 96 32
sda9 1.00 0.00 32.00 0 32
也可以通过v$buffer_pool_statistics视图查看命中率的情况
SQL> SELECT NAME, PHYSICAL_READS, DB_BLOCK_GETS, CONSISTENT_GETS,(1-(PHYSICAL_READS/(DB_BLOCK_GETS+CONSISTENT_GETS)))*100 "Hit Ratio" FROM V$BUFFER_POOL_STATISTICS WHERE NAME='DEFAULT';
NAME PHYSICAL_READS DB_BLOCK_GETS CONSISTENT_GETS Hit Ratio
-------------------- -------------- ------------- --------------- ----------
DEFAULT 12786 14986 158305 92.6216595