(转)Oracle HowTo:如何强制刷新Buffer Cache
2008-04-28 13:27
507 查看
很多时候,为了排除Cache对于测试的影响,我们常常需要手动刷新Buffer Cache,以促使Oracle重新执行物理访问。我曾经在使用 db_file_multiblock_read_count测试Oracle在不同系统中的IO能力一文中用到这个方法,在Itpub上也有朋友问到,今天整理一下并作简要说明。
在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.创建测试表
表T共有79个Block.
2. x$bh
我们注意到flush_cache以后,所有Buffer都被标记为free.
3. 观察flush_cache对于查询的影响
以上说明仅供参考。
在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 |
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 |
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> |
相关文章推荐
- Oracle HowTo:如何强制刷新Buffer Cache
- Oracle HowTo:如何强制刷新Buffer Cache
- Oracle HowTo:如何强制刷新Buffer Cache
- Oracle HowTo:如何强制刷新Buffer Cache
- Oracle 如何强制刷新Buffer Cache 6
- Oracle HowTo:如何使用Oracle case函数
- Oracle HowTo:如何获得数据库的DBID
- 如何强制刷新Buffer Cache
- (学) 如何将 Oracle 序列 重置 清零 How to reset an Oracle sequence
- Oracle HowTo:如何在Oracle10g中启动和关闭OEM
- Oracle HowTo:如何移动数据文件的位置?
- [HOWTO]ORACLE中如何实现ASC字符串和16进制串互相转换
- Oracle HowTo:如何快速杀死占用过多资源(CPU,内存)的数据库进程
- Oracle HowTo:如何在Oracle10g中启动和关闭OEM
- Oracle HowTo:如何使用Leading提示改变表连接方式
- Oracle HowTo:Oracle中如何进行进制转换
- How to change the language of oracle sqlplus from chinese to english in windows(如何将oracle sql plus中的中文变成英文版)
- Oracle HowTo:如何使用Leading提示改变表连接方式
- Oacle 如何强制刷新Buffer Cache
- Oracle HowTo:如何快速杀死占用过多资源(CPU,内存)的数据库进程