查询缓冲区高速缓存命中率

时间:2018-01-20 06:41:14

标签: sql oracle

我想计算缓冲区缓存命中率和逐个实例。为此,我有以下公式;

1 - ( physical reads cache / (consistent gets from cache + db block gets from cache)

我需要计算公式的查询,如下所示;

select inst_id,name,value 
from gv$sysstat 
where name in ('consistent gets from cache','db block gets from cache','physical reads cache')

我尝试使用3个子查询来制作它,但它没用,而且无法正常工作。

此查询的示例输出如下所示;

1   db block gets from cache    3980038
1   consistent gets from cache  16692788
1   physical reads cache        174385

我想要的示例输出如下所示;

INST_ID   VALUE
1         0.92   
2         0.93

如何编写此查询以获取缓存命中率?

1 个答案:

答案 0 :(得分:0)

您可以将其用作RAC数据库的缓冲区高速缓存命中无线电查询:

select s1.inst_id, s3.value / (s1.value + s2.value) value
  from gv$sysstat s1, gv$sysstat s2, gv$sysstat s3
 where s1.name = 'consistent gets from cache'
   and s2.name = 'db block gets from cache'
   and s3.name = 'physical reads cache'
   and s1.inst_id = s2.inst_id
   and s1.inst_id = s3.inst_id
 order by s1.inst_id;

或者使用ANSI SQL,可以使用以下查询:

select s1.inst_id, s3.value / (s1.value + s2.value) value
  from gv$sysstat s1 join gv$sysstat s2 on ( s1.inst_id = s2.inst_id ) 
                     join gv$sysstat s3 on ( s1.inst_id = s3.inst_id )
 where s1.name = 'consistent gets from cache'
   and s2.name = 'db block gets from cache'
   and s3.name = 'physical reads cache'
 order by s1.inst_id;