You are on page 1of 8

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 youFLUSH 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.

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 queriesand 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>
PARAMETER
%

TYPE

COUNT

GETS

GETMISSES

USAGE


- - dc_awr_control
1.52

dc_global_oids
6.58

PARENT

31

328

2523

166

1
PARENT
31

dc_histogram_data
13.25

SUBORDINAT

220

9604

1273

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 #DatabaseCLICK 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>
PARAMETER
%

TYPE

COUNT

GETS

GETMISSES

USAGE


- - dc_awr_control
1.80

PARENT
1

334

dc_global_oids
6.77

10

dc_histogram_data
13.38

PARENT

2616

177

9828

1315

10
SUBORDINAT

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:

With ALTER SYSTEM FLUSH SHARED_POOL; you are not flushing out the

complete
Only LIBRARY_CACHE is what gets flushed off.
To flush RESULT_CACHE of SQLs which are manually cached,
issue EXECUTE DBMS_RESULT_CACHE.FLUSH;
RESULT_CACHE data is automatically flushed everytime when you are
running SQL or PL/SQL for which Oracle internally

requires RESULT_CACHE.
DATA_DICTIONARY_CACHE cannot be flushed as the contents in it are

pretty much consistent and are very much required for semantic check.
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.