我运行Oracle 11g Release 2。如何手动提高缓存命中率?有没有可以运行的命令来增加它?

最佳答案

Source
许多dba尽最大努力获得99%或更好的缓冲区缓存命中率,但很快发现,随着命中率的提高,数据库的性能并没有提高。
以下是获取数据库当前命中率的查询:

SQL> -- Get initial Buffer Hit Ratio reading...
SQL> SELECT ROUND((1-(phy.value / (cur.value + con.value)))*100,2) "Cache Hit Ratio"
  2    FROM v$sysstat cur, v$sysstat con, v$sysstat phy
  3   WHERE cur.name = 'db block gets'
  4     AND con.name = 'consistent gets'
  5     AND phy.name = 'physical reads'
  6  /

Cache Hit Ratio
---------------
         90.75

然而,为了说明这个数字有多无意义,让我们人为地增加它:
SQL> -- Let's artificially increase the buffer hit ratio...
SQL> DECLARE
  2    v_dummy dual.dummy%TYPE;
  3  BEGIN
  4    FOR I IN 1..10000000 LOOP
  5      SELECT dummy INTO v_dummy FROM dual;
  6    END LOOP;
  7  END;
  8  /

PL/SQL procedure successfully completed.

让我们看看发生了什么:
SQL> -- Let's measure it again...
SQL> SELECT ROUND((1-(phy.value / (cur.value + con.value)))*100,2) "Cache Hit Ratio"
  2    FROM v$sysstat cur, v$sysstat con, v$sysstat phy
  3   WHERE cur.name = 'db block gets'
  4     AND con.name = 'consistent gets'
  5     AND phy.name = 'physical reads'
  6  /

Cache Hit Ratio
---------------
          99.94

结论:不要费心调整缓冲区命中率!
现在有更好的调音方法。oracle等待接口(owi)提供了确切的详细信息。不再需要依赖模糊无意义的计数器。

08-06 22:04