oracle怎样清空缓冲区缓存

在Oracle9i里,Oracle提供了一个内部事件,用以强制刷新Buffer Cache,其语法为:

alter session set events 'immediate trace name flush_cache level 1';

或者:

alter session set events = 'immediate trace name flush_cache';

类似的也可以使用alter system系统级设置:

alter system set events = 'immediate trace name flush_cache';

在Oracle10g中,Oracle提供一个新的特性,可以通过如下命令刷新Buffer Cache:

alter system flush buffer_cache;

我们通过试验来看一下刷新Cache的作用:


1.创建测试表

SQL> create table t as select * from dba_objects;
Table created.
SQL> analyze table t compute statistics;
Table analyzed.
SQL> select blocks,empty_blocks from dba_tables 
   2 where table_name='T' and owner='SYS';
    BLOCKS EMPTY_BLOCKS
---------- ------------
        78            1

表T共有79个Block.

2. x$bh

SQL> select count(*) from x$bh;
  COUNT(*)
----------
     14375
SQL> select count(*) from x$bh where state=0;  -- state =0 is free
  COUNT(*)
----------
     13960
SQL> alter system set events = 'immediate trace name flush_cache';
System altered.
SQL> select count(*) from x$bh where state=0;
  COUNT(*)
----------
     14375

我们注意到flush_cache以后,所有Buffer都被标记为free.

3. 观察flush_cache对于查询的影响

SQL> set autotrace trace stat
SQL> select count(*) from t;
Statistics
----------------------------------------------------------
          0  recursive calls
          0  db block gets
         81  consistent gets
         79  physical reads
          0  redo size
....
SQL> 
SQL> select count(*) from t;
Statistics
----------------------------------------------------------
          0  recursive calls
          0  db block gets
         81  consistent gets
          0  physical reads
          0  redo size
....
SQL> alter system set events = 'immediate trace name flush_cache';
System altered.
SQL> select count(*) from t;
Statistics
----------------------------------------------------------
          0  recursive calls
          0  db block gets
         81  consistent gets
         79  physical reads
          0  redo size
....
SQL> 
  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值