The following three statements are used to refresh the Oracle cache. Here is a summary.
1)Alter system flush global context
Note:
For multi-tier architectures such as application servers and data block servers that communicate through the connection pool, the information about the connection pool is kept in SGA. This statement clears the connection information.
2)Alter system flush shared_pool
Make the library cache and data dictionary cachePreviousAll saved SQL Execution plans are cleared, but the recently executed entries cached in the shared SQL area or pl/SQL area are not cleared. Refreshing the shared pool can helpMerge shards(Small chunks) to release a few shared pool resources and temporarily solve the shared_pool fragmentation problem. However, this approach is generally not recommended. The reason is as follows:
· Flush Shared Pool will cause unused cursor to be cleared out of the Shared Pool. If these SQL statements need to be executed subsequently, the database will experience a lot of hard parsing, the system will experience severe CPU contention, and the database will have fierce Latch competition.
· If the application does not use Bound variables and a large number of similar SQL statements are not executed, the Flush Shared Pool may only provide a short improvement and the database will return to the original state soon.
· If the Shared Pool is large and the system is very busy, refreshing the Shared Pool may cause the system to be suspended. For systems like this, try to do it when the system is idle.
The following tests the effect of refreshing on Shared Pool fragments:
- SQL>Select Count(*)FromX $ ksmsp;
-
- COUNT(*)
- ----------
- 41637
-
- SQL>AlterSystem flush shared_pool;
-
- The system has been changed.
-
- SQL>Select Count(*)FromX $ ksmsp;
-
- COUNT(*)
- ----------
- 9276
3)Alter system flush buffer_cache
To minimize the impact of the cache on the test experiment, you need to manually refresh the buffer cache to urge oracle to re-Execute physical access (in statistics:Physical reads).
Test Environment
- SQL>Select Count(*)FromTt;
-
- COUNT(*)
- ----------
- 1614112
-
- SQL> showUser;
- USERIs"HR"
- SQL>ExecDbms_stats.gather_table_stats ('Hr','TT');
-
- The PL/SQL process is successfully completed.
-
- SQL>SelectBlocks, empty_blocksFromDba_tablesWhereTable_name ='TT' AndOwner ='Hr';
-
- BLOCKS EMPTY_BLOCKS
- ----------------------
- 22357 0
- Table TT has a total of 22357 Blocks
Observe the state = 0 with x $ bh
- SQL>Select Count(*)FromX $ bhWhereState = 0;
-
- COUNT(*)
- ----------
- 0
-
- SQL>AlterSystem flush buffer_cache;
-
- The system has been changed.
-
- SQL>Select Count(*)FromX $ bhWhereState = 0;
-
- COUNT(*)
- ----------
- 40440
State = 0 indicates that the buffer state is free. After the cache is flush, all the buffers are marked as free.
Observe the impact of flush cache on queries:
- SQL>SetAutotOn Statistics
- SQL>Select Count(*)FromTt;
-
- COUNT(*)
- ----------
- 1614112
-
-
- Statistics
- ----------------------------------------------------------
- 0 recursive cballs
- 0 db block gets
- 22288 consistent gets
- 22277 physical reads
- 0 redoSize
- 416 bytes sent via SQL * NetToClient
- 385 bytes encoded ed via SQL * NetFromClient
- 2 SQL * Net roundtripsTo/FromClient
- 0 sorts (memory)
- 0 sorts (disk)
- 1RowsProcessed
-
- SQL>/
-
- COUNT(*)
- ----------
- 1614112
-
-
- Statistics
- ----------------------------------------------------------
- 0 recursive cballs
- 0 db block gets
- 22288 consistent gets
- 0 physical reads
- 0 redoSize
- 416 bytes sent via SQL * NetToClient
- 385 bytes encoded ed via SQL * NetFromClient
- 2 SQL * Net roundtripsTo/FromClient
- 0 sorts (memory)
- 0 sorts (disk)
- 1RowsProcessed
-
- SQL>AlterSystem flush buffer_cache;
-
- The system has been changed.
-
- SQL>Select Count(*)FromTt;
-
- COUNT(*)
- ----------
- 1614112
-
-
- Statistics
- ----------------------------------------------------------
- 0 recursive cballs
- 0 db block gets
- 22288 consistent gets
- 22277 physical reads
- 0 redoSize
- 416 bytes sent via SQL * NetToClient
- 385 bytes encoded ed via SQL * NetFromClient
- 2 SQL * Net roundtripsTo/FromClient
- 0 sorts (memory)
- 0 sorts (disk)
- 1RowsProcessed