Can you really flush Oracle SHARED_POOL?


One of the major player in the SGA is SHARED_POOL, without which we can say that there are no query executions. During some performance tuning trials, you would have used ALTER SYSTEM command to flush out the contents in SHARED_POOL. Do you really know what exactly this command cleans out? As we know that internally SHARED_POOL has LIBRARY_CACHE, RESULT_CACHE, DATA_DICTIONARY_CACHE as most important parts. Are these components also gets cleaned when you FLUSH SHARED_POOL? Let us deep dive in to this instance functionality through this blog and get answers by a step by step analysis.
Concepts:
Before we run the Case Study to find answers to our questions raised, let us look at some basic concepts on SHARED_POOL in Oracle Database. Being an Oracle DBA, the more you know about Architecture, the best you can work on Oracle Performance Tuning.
Untitled
This image will help you to quickly refresh about all that SHARED_POOL is capable being the part of SGA.
  • Library Cache: is used for storing the recently executed SQL and PL/SQL statements and hence these statements if encountered again will be shared which will subsequently boost the performance of the database.
  • Data Dictionary Cache: is used for storing the most recently used data definitions in the Oracle DB. These data definitions may include information about: database files, tables, indexes, privileges, users, etc.
  • Result Cache: The server result cache is a memory pool within the shared pool. This memory pool consists of the SQL query result cache—which stores results of SQL queries—and the PL/SQL function result cache, which stores values returned by PL/SQL functions.
  • Private SQL Area: This behaves as UGA (User Global Area) for Shared Server architecture.
Environment details:
  • OS: OEL 64 bit
  • Database: Oracle 11gR2
Case Study:
Before we actually flush SHARED POOL, let us check the contents of all the internal components by querying multiple dynamic performance views or packages as below.
1.Checking the contents of Library cache: A simple count from v$SQL tells us how many SQL statement details are currently available in LIBRARY CACHE.
SQL> select count(*) from v$sql;/
 COUNT(*)
———-
356
2. Checking the contents of Data Dictionary Cache: Running a query on v$rowcache dynamic performance view.
SET PAGESIZE 59
SET LINESIZE 100 echo off
COLUMN parameter FORMAT A20
COLUMN type FORMAT a10
COLUMN percent FORMAT 999.99 HEADING “%”;
SELECT   parameter, TYPE, gets, getmisses,
   (getmisses / gets * 100) PERCENT, COUNT, usage
  FROM v$rowcache
 WHERE gets > 100 AND getmisses > 0
ORDER BY parameter;SQL> SQL> SQL> SQL> SQL>   2    3    4    5
PARAMETER            TYPE             GETS  GETMISSES       %      COUNT      USAGE
———————————— ———————————— ———————– ———————- ——————- ———————-
dc_awr_control       PARENT            328          5    1.52          1          1
dc_global_oids       PARENT           2523        166    6.58         31         31
dc_histogram_data    SUBORDINAT       9604       1273   13.25        220        220
3. Checking the contents of Result cache: By running DBMS_RESULT_CACHE.MEMORY_REPORT procedure.
SQL> set serveroutput on
SQL> EXECUTE DBMS_RESULT_CACHE.MEMORY_REPORT;
R e s u l t   C a c h e   M e m o r y   R e p o r t
[Parameters]
Block Size          = 1K bytes
Maximum Cache Size  = 1248K bytes (1248 blocks)
Maximum Result Size = 62K bytes (62 blocks)
[Memory]
Total Memory = 5180 bytes [0.004% of the Shared Pool]
… Fixed Memory = 5180 bytes [0.004% of the Shared Pool]
… Dynamic Memory = 0 bytes [0.000% of the Shared Pool]
Seems that result cache is empty. Let us load some results from a query using Oracle HINT.
SELECT /*+ RESULT_CACHE */ department_id, AVG(salary)
FROM hr.employees
GROUP BY department_id;
SQL> EXECUTE DBMS_RESULT_CACHE.MEMORY_REPORT;
R e s u l t   C a c h e   M e m o r y   R e p o r t
[Parameters]
Block Size          = 1K bytes
Maximum Cache Size  = 1248K bytes (1248 blocks)
Maximum Result Size = 62K bytes (62 blocks)
[Memory]
Total Memory = 103532 bytes [0.082% of the Shared Pool]
… Fixed Memory = 5180 bytes [0.004% of the Shared Pool]
… Dynamic Memory = 98352 bytes [0.078% of the Shared Pool]
……. Overhead = 65584 bytes
……. Cache Memory = 32K bytes (32 blocks)
……….. Unused Memory = 30 blocks
……….. Used Memory = 2 blocks
…………… Dependencies = 1 blocks (1 count)
…………… Results = 1 blocks
………………. SQL     = 1 blocks (1 count)
Now RESULT_CACHE is also loaded with some data.
4. Now that all the components of SHARED_POOL are filled with some content in it. Let us FLUSH it now.
SQL> alter system flush shared_pool;
System altered.
5. Now let us recheck contents in all the above components.
6. Contents of LIBRARY_CACHE after flush:
SQL> select count(*) from v$SQL;
 COUNT(*)
———-
62
Yeah – there was an impact.
7. Contents of DATA_DICTIONARY_CACHE after flush:
SET PAGESIZE 59
SET LINESIZE 100 echo off
COLUMN parameter FORMAT A20
COLUMN type FORMAT a10
COLUMN percent FORMAT 999.99 HEADING “%”;
SELECT   parameter, TYPE, gets, getmisses,
   (getmisses / gets * 100) PERCENT, COUNT, usage
  FROM v$rowcache
 WHERE gets > 100 AND getmisses > 0
ORDER BY parameter;SQL> SQL> SQL> SQL> SQL>   2    3    4    5
PARAMETER            TYPE             GETS  GETMISSES       %      COUNT      USAGE
———————————— ———————————— ———————– ———————- ——————- ———————-
dc_awr_control       PARENT            334          6    1.80          1          1
dc_global_oids       PARENT           2616        177    6.77         10         10
dc_histogram_data    SUBORDINAT       9828       1315   13.38         41         41
E
NOTE: There was no impact of SHARED_POOL flush.
8. Contents of RESULT_CACHE after flush:
SQL> EXECUTE DBMS_RESULT_CACHE.MEMORY_REPORT;
R e s u l t   C a c h e   M e m o r y   R e p o r t
[Parameters]
Block Size          = 1K bytes
Maximum Cache Size  = 1248K bytes (1248 blocks)
Maximum Result Size = 62K bytes (62 blocks)
[Memory]
Total Memory = 103532 bytes [0.082% of the Shared Pool]
… Fixed Memory = 5180 bytes [0.004% of the Shared Pool]
… Dynamic Memory = 98352 bytes [0.078% of the Shared Pool]
……. Overhead = 65584 bytes
……. Cache Memory = 32K bytes (32 blocks)
……….. Unused Memory = 30 blocks
……….. Used Memory = 2 blocks
…………… Dependencies = 1 blocks (1 count)
…………… Results = 1 blocks
………………. SQL     = 1 blocks (1 count)
NOTE: Even RESULT_CACHE. has no impact of SHARED_POOL flush.
Conclusion:

Comments