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.

LIBRARY_CACHE plays a vital role in the articles which we discussed “EXPLAIN PLAN for multiple SQL statements”, “Ways of generating EXECUTION PLAN in Oracle Database”, “New SQL_ID ? Does not mean hard parsing or new EXECUTION plan” and many more.

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

Are you really flushing out SHARED_POOL with ALTER SYSTEM command in #Oracle #Database Click To Tweet

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.

Flushing SHARED_POOL means flushing LIBRARY_CAHCE #Oracle #Database Click To Tweet

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:

I love to see your comments!

Feel free to give additional information in the comments, that I can validate and include in blog posts or update this as well.

Related Posts

About The Author

30 Comments

  1. vnairaj@gmail.com'
    Vinay Malla
    May 20, 2016
    • Pawan Kumar Yaddanapudi
      May 20, 2016
  2. Pspasov@abv.bg'
    Petar Spasov
    May 21, 2016
    • Pawan Kumar Yaddanapudi
      May 21, 2016
  3. pinto.das88@yahoo.com'
    Pinto
    May 22, 2016
    • Pawan Kumar Yaddanapudi
      May 22, 2016
  4. ravikumardba@outlook.com'
    Ravikumar
    May 27, 2016
    • Pawan Kumar Yaddanapudi
      May 27, 2016
  5. rajmca.lohani87@gmail.com'
    Rakesh kumar
    June 1, 2016
    • Pawan Kumar Yaddanapudi
      June 2, 2016
  6. yashodhan.harne@polarisft.com'
    Yash
    June 13, 2016
    • Pawan Kumar Yaddanapudi
      June 13, 2016
  7. gopal892@gmail.com'
    Gopal
    June 20, 2016
    • Pawan Kumar Yaddanapudi
      June 20, 2016
  8. Krishna.ys01@gmail.com'
    Ramakrishna
    July 16, 2016
    • Pawan Kumar Yaddanapudi
      July 17, 2016
  9. rk.abbadi@gmail.com'
    Rama Krishna
    July 19, 2016
    • Pawan Kumar Yaddanapudi
      July 19, 2016
  10. Sivasai376@gmail.com'
    Raju
    December 14, 2016
    • Pawan Kumar Yaddanapudi
      December 15, 2016
  11. rajapandian009@gmail.com'
    Raja
    March 15, 2017
    • Pawan Kumar Yaddanapudi
      March 16, 2017
  12. younus.choudhary@gmail.com'
    Younus
    July 26, 2017
    • Pawan Kumar Yaddanapudi
      July 27, 2017
  13. shihab79@gmail.com'
    shihab abdulrahiman
    August 4, 2017
  14. vijay.esnapur@gmail.com'
    Vijay
    August 22, 2017
    • Pawan Kumar Yaddanapudi
      August 22, 2017
  15. vijay.esnapur@gmail.com'
    Vijay
    August 23, 2017
  16. Kvsatya.apps@gmail.com'
    Satyanarayana k v
    September 25, 2017
    • Pawan Kumar Yaddanapudi
      September 26, 2017

Add Comment