How Does Oracle force refresh Buffer Cache?

Source: Internet
Author: User

In Oracle9i, Oracle provides an internal event to force refresh the Buffer Cache. Its syntax is:

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

Or:

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

Similarly, you can use alter system-level settings:

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

In Oracle 10 Gb, Oracle provides a new feature. You can use the following command to refresh the Buffer Cache:

Alter system flush buffer_cache;

Let's test the function of refreshing the Cache:


1. Create a test table

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

Table T has a total of 79 blocks.

2. x $ bh


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


We noticed that after flush_cache, all buffers are marked as free.

3. Observe the impact of flush_cache on queries.


SQL> set autotrace trace stat
SQL> select count (*) from t; Statistics
----------------------------------------------------------
0 recursive cballs
0 db block gets
81 consistent gets
79 physical reads
0 redo size
... SQL> select count (*) from t; Statistics
----------------------------------------------------------
0 recursive cballs
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 cballs
0 db block gets
81 consistent gets
79 physical reads
0 redo size
... SQL>


The preceding description is for reference only.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.