Sei sulla pagina 1di 40

8

Tuning the Shared Pool

Copyright © 2006, Oracle. All rights reserved.


Objectives

After completing this lesson, you should be able to do


the following:
• Diagnose shared pool problems
• Size the shared pool
• Size the reserved area
• Keep objects in the shared pool

8-2 Copyright © 2006, Oracle. All rights reserved.


Shared Pool Architecture

Major components of the shared pool are:


• Library cache
• Data dictionary cache
• User global area (UGA) for shared server sessions

Databas Redo Shared pool Large


e buffer log Library cache pool
cache buffer
UGA

Data dictionary
cache

Shared areas

8-3 Copyright © 2006, Oracle. All rights reserved.


Shared Pool Operation

The shared pool is managed by an LRU algorithm.


• New objects require memory allocations.
• Re-creatable objects are aged out of the cache.
• Objects are made up of chunks of memory.
• A memory allocation is a whole chunk.
• A chunk is contiguous.

8-4 Copyright © 2006, Oracle. All rights reserved.


The Library Cache

• Stores complex object metadata associated with


cursors
• Stores SQL statements and PL/SQL blocks that
are to be shared by users
• Prevents statement reparsing

8-5 Copyright © 2006, Oracle. All rights reserved.


SQL and PL/SQL Storage

Shared pool

SQLAREA

Cursor Cursor
context area context area
for SELECT for SELECT
statement 2 statement 1

SELECT SELECT SELECT


statement 2 statement 1 statement 1

8-6 Copyright © 2006, Oracle. All rights reserved.


Cursor Usage and Parsing

Session memory (UGA) Shared pool (SGA)

Open cursors Cursor handles


1 3

Closed cursors
2
Hash chains

4
Parse procedure:
1. Find and execute an open cursor.
2. Find a closed cursor in the session cache.
3. Search the hash chains (soft parse).
4. Construct the cursor (hard parse).

8-7 Copyright © 2006, Oracle. All rights reserved.


Important Shared Pool Latches

• latch: shared pool protects memory allocations


in the shared pool.
• latch: library cache locates matching SQL in
the shared pool.

8-9 Copyright © 2006, Oracle. All rights reserved.


Mutex

A mutual exclusion object allows:


• Sharing of a resource without corruption
• Shared access for reads
• Exclusive access for update
• Each object to have its own mutex

8-10 Copyright © 2006, Oracle. All rights reserved.


Benefits of Mutex

Performance is improved with mutexes. Mutexes:


• Are smaller and faster
• Have less potential for contention
• Replace latches and pins

8-11 Copyright © 2006, Oracle. All rights reserved.


Mutex Views and Statistics

• Mutex views:
– V$MUTEX_SLEEP
– V$MUTEX_SLEEP_HISTORY
• Mutex wait events:
– cursor:mutex X
– cursor:mutex S
– cursor:pin X
– cursor:pin S
– cursor:pin S wait on X

8-13 Copyright © 2006, Oracle. All rights reserved.


Mutex-Protected Operations

From 10.2.0.2 onward, mutex protects:


• Selects from V$SQLSTAT
• Searches of child cursor lists

8-15 Copyright © 2006, Oracle. All rights reserved.


Statspack/AWR Indicators

Statspack and AWR reports include indicators:


• Load Profile
• Instance Efficiencies
• Top Wait Events
• Time Model

8-16 Copyright © 2006, Oracle. All rights reserved.


Load Profile

Load Profile Per Second Per Transaction


~~~~~~~~~~~~ --------------- ---------------
User calls: 4.29 21.78
Parses: 188.09 954.20
Hard parses: 80.00 405.85

% Blocks changed per Read: 0.18


Recursive Call %: 99.78
Rollback per transaction %: 9.76
Rows per Sort: 8.47

8-17 Copyright © 2006, Oracle. All rights reserved.


Instance Efficiencies

Instance Efficiency Percentages


~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Buffer Nowait %: 100.00 Redo NoWait %: 100.00
Buffer Hit %: 99.87 In-memory Sort %: 100.00
Library Hit %: 87.90 Soft Parse %: 57.47
Execute to Parse %: 22.50 Latch Hit %: 100.00
Parse CPU to Parse Elapsd %: 83.16
% Non-Parse CPU: 17.88

Shared Pool Statistics Begin End


------ ------
Memory Usage %: 92.75 92.97
% SQL with executions>1: 72.62 72.28
% Memory for SQL w/exec>1: 92.35 92.17

8-18 Copyright © 2006, Oracle. All rights reserved.


Top Waits

Top 5 Timed Events Avg %Total


~~~~~~~~~~~~~~~~~~ wait Call
Event Waits Time (s) (ms) Time
----------------- ------------ ----------- ------ ------
CPU time 190 98.0
latch: library cache 76 1 19 .8
latch: shared pool 49 1 16 .4
db file sequential read 1,343 0 0 .2
log file parallel write 54 0 5 .1
-------------------------------------------------------

8-19 Copyright © 2006, Oracle. All rights reserved.


Time Model

Time Model System Stats


-> Ordered by % of DB time desc, Statistic name
% of
Statistic Time (s) DB time
----------------------------------- ---------- ---------
sql execute elapsed time 399.5 95.6
DB CPU 269.3 64.4
parse time elapsed 126.8 30.3
hard parse elapsed time 111.9 26.8
PL/SQL compilation elapsed time 6.6 1.6
PL/SQL execution elapsed time 5.9 1.4
connection management call elapsed 4.9 1.2
failed parse elapsed time 4.0 1.0
hard parse (sharing criteria) elaps 2.3 .5
sequence load elapsed time 0.5 .1
hard parse (bind mismatch) elapsed 0.2 .0
repeated bind elapsed time 0.1 .0
DB time 417.9

8-20 Copyright © 2006, Oracle. All rights reserved.


Library Cache Activity

Library Cache Activity DB/Inst: ORCL/orcl Snaps: 61-71


->"Pct Misses" should be very low
Get Pct Pin Pct Invali-
Namespace Requests Miss Requests Miss Reloads dations
---------- --------- ------ -------------- ------ ------ --------
BODY 33 27.3 450 14.0 46 0
CLUSTER 49 0.0 200 3.0 6 0
INDEX 5 100.0 35,300 0.0 0 0
SQL AREA 18,880 96.9 89,904 36.5 496 0

8-22 Copyright © 2006, Oracle. All rights reserved.


Terminology

• Gets: (Parse) The number of lookups for objects


of the namespace
• Pins: (Execution) The number of reads or
executions of the objects of the namespace
• Reloads: (Parse) The number of library cache
misses on the execution step, thereby causing an
implicit reparsing of the SQL statement
• Invalidations: The number of times an object is
modified by a DDL, causing all dependent objects
to be marked invalid

8-23 Copyright © 2006, Oracle. All rights reserved.


Diagnostic Tools
for Tuning the Shared Pool
Views
V$SGASTAT V$SGAINFO Shared pool
V$LIBRARYCACHE Library cache
V$LIBRARY_CACHE_MEMORY sp_m_n.lst
Shared SQL
V$SHARED_POOL_RESERVED
V$SQLSTATS
and PL/SQL
V$SQL report.txt
V$SQLAREA
V$SQLTEXT Data dictionary
V$DB_OBJECT_CACHE cache

Parameters affecting the components:


SHARED_POOL_SIZE, OPEN_CURSORS
SESSION_CACHED_CURSORS, CURSOR_SPACE_FOR_TIME
CURSOR_SHARING, SHARED_POOL_RESERVED_SIZE

8-24 Copyright © 2006, Oracle. All rights reserved.


Library Cache Reloads

• Reloads should be less than 1% of the pins:


SQL> SELECT SUM(pins) "Executions",
2 SUM(reloads) "Cache Misses",
3 SUM(reloads)/SUM(pins)
4 FROM V$LIBRARYCACHE;

• If the reloads-to-pins ratio is greater than 1%,


increase the value of the SHARED_POOL_SIZE
parameter.
Executes PROC1 —> 1st pin, 1 load
Executes PROC1 —> 2nd pin, no reload Four pins
Executes PROC1 —> 3rd pin, no reload and no
Executes PROC1 —> 4th pin, no reload reloads

8-26 Copyright © 2006, Oracle. All rights reserved.


Invalidations

The number of times objects of the namespace were


marked invalid, causing reloads:

SQL> SELECT COUNT(*) FROM hr.employees;


SQL> SELECT namespace,pins,reloads,
2 invalidations
3 FROM V$LIBRARYCACHE;
SQL> execute DBMS_STATS.GATHER_TABLE_STATS -
> ('HR','EMPLOYEES');
SQL> SELECT COUNT(*) FROM hr.employees;
SQL> SELECT namespace,pins,reloads,
2 invalidations
3 FROM V$LIBRARYCACHE;

8-27 Copyright © 2006, Oracle. All rights reserved.


Avoid Hard Parses

In an OLTP system, reduce misses by keeping hard


parsing to a minimum:
• Make sure that users can share statements.
• Prevent frequently used statements from being
aged out by allocating enough space.
• Avoid invalidations that induce reparsing.

8-29 Copyright © 2006, Oracle. All rights reserved.


Are Cursors Being Shared?

• Check GETHITRATIO in V$LIBRARYCACHE:


SQL> SELECT gethitratio
2 FROM V$LIBRARYCACHE
3 WHERE namespace = 'SQL AREA';

• Determine which statements could be shared:


SQL> SELECT plan_hash_value, count(*)
2 FROM V$SQL
3 GROUP BY plan_hash_value ORDER BY 2 DESC

SQL> SELECT sql_text, executions


2 FROM V$SQLAREA
3 WHERE plan_hash_value = NNNNNNNNN

8-30 Copyright © 2006, Oracle. All rights reserved.


Sharing Cursors

Values for CURSOR_SHARING are:


• EXACT
• SIMILAR
• FORCE

8-32 Copyright © 2006, Oracle. All rights reserved.


Avoiding Soft Parses

• Reducing soft parses reduces library cache latch


contention.
• Keep soft parsing to a minimum by:
– Setting SESSION_CACHED_CURSORS
– Setting HOLD_CURSOR in the application precompiler
– Setting CURSOR_SPACE_FOR_TIME

8-33 Copyright © 2006, Oracle. All rights reserved.


Avoiding Fragmentation

Avoid fragmentation by:


• Upgrading to 10.2.0.x
• Keeping frequently required large objects
• Reserving space for large objects
• Eliminating large anonymous PL/SQL blocks
• Enabling the use of large pool

8-34 Copyright © 2006, Oracle. All rights reserved.


Sizing the Shared Pool

• Use Automatic Shared Memory Management.


• Use the Shared Pool Advisor and confirm using
other diagnostics when data has operational
history.
• Use 40 percent of the SGA size to start, when there
is no history. Monitor and adjust as needed.
• Do not increase the size when free memory is
available.
SQL> SELECT * FROM V$SGASTAT
2 WHERE NAME = 'free memory'
3 AND POOL = 'shared pool';

8-35 Copyright © 2006, Oracle. All rights reserved.


Shared Pool Advisory

SQL> SELECT shared_pool_size_for_estimate AS


2 pool_size, estd_lc_size,
3 estd_lc_time_saved
4 FROM V$SHARED_POOL_ADVICE;

POOL_SIZE ESTD_LC_SIZE ESTD_LC_TIME_SAVED


---------- ------------ ------------------
32 8 7868
40 15 7868
48 17 7868
56 17 7868
64 17 7868
72 17 7868
80 17 7868
88 17 7868

8-36 Copyright © 2006, Oracle. All rights reserved.


Shared Pool Advisor

8-38 Copyright © 2006, Oracle. All rights reserved.


Large Memory Requirements

• Satisfy requests for large contiguous memory.


• Reserve contiguous memory within the
shared pool.
Shared pool
V$SHARED_POOL_RESERVED
Library cache
Shared SQL
and PL/SQL

Reserved area

SHARED_POOL_SIZE Data dictionary


SHARED_POOL_RESERVED_SIZE cache

8-39 Copyright © 2006, Oracle. All rights reserved.


Tuning the Shared Pool
Reserved Space

IF Action
REQUEST_FAILURES

>0 and increasing AND Request_misses > 0 Increase


SHARED_POOL_
RESERVED_SIZE

>0 and increasing AND Free_memory => 50% of Increase


SHARED_POOL_RESERVE SHARED_POOL_
D_SIZE SIZE

=0 OR Free_memory => 50% of Decrease


SHARED_POOL_RESERVE SHARED_POOL_
D_SIZE RESERVED_SIZE

8-41 Copyright © 2006, Oracle. All rights reserved.


Keeping Large Objects

• Find those PL/SQL objects that are not kept in the


library cache:

SQL> SELECT * FROM V$DB_OBJECT_CACHE


2 WHERE sharable_mem > 10000
3 AND (type='PACKAGE' OR type='PACKAGE BODY' OR
4 type='FUNCTION' OR type='PROCEDURE')
5 AND kept='NO';

• Pin large packages in the library cache:


SQL> EXECUTE DBMS_SHARED_POOL.KEEP(‘package_name’);

8-43 Copyright © 2006, Oracle. All rights reserved.


Data Dictionary Cache

The data dictionary cache holds row images of data


dictionary rows.

Data dictionary cache

Data dictionary

8-45 Copyright © 2006, Oracle. All rights reserved.


Dictionary Cache Misses

Statspack/AWR report output:


Get Pct Final
Cache Requests Miss Usage
---------------- -------- ------ -------
dc_histogram_data 5,587 26.8 411
dc_histogram_defs 92,501 3.7 899
dc_object_grants 240 55.0 26
dc_object_ids 959,293 0.1 289
dc_objects 19,385 5.7 314

If there are too many cache misses, increase the


SHARED_POOL_SIZE parameter.

8-46 Copyright © 2006, Oracle. All rights reserved.


UGA and Oracle Shared Server
Dedicated server configuration PGA

UGA
Shared pool Stack User Cursor
space session state
data

Shared server configuration


PGA
Shared pool UGA
or User Cursor Stack
Large pool session state space
data

V$STATNAME OPEN_CURSORS
V$SESSTAT SESSION_CACHED_CURSORS
V$MYSTAT

8-47 Copyright © 2006, Oracle. All rights reserved.


Large Pool
• Can be configured as a separate memory area in
the SGA, used for memory with:
– I/O server processes: DBWR_IO_SLAVES
– Backup and restore operations
– Session memory for the shared servers
– Parallel query messaging
• Is used to avoid performance overhead caused by
shrinking the shared SQL cache
• Is sized by the LARGE_POOL_SIZE parameter
Database Redo
buffer cache log Shared Large pool
buffer pool
Library cache
Data dictionary UGA
cache

8-48 Copyright © 2006, Oracle. All rights reserved.


Tuning the Large Pool

• The large pool has one parameter,


LARGE_POOL_SIZE.
• V$SGASTAT shows used and free memory.

SELECT * FROM V$SGASTAT


WHERE pool = 'large pool';

POOL NAME BYTES


------------ -------------------------- ----------
large pool free memory 2814112
large pool session heap 1380192

8-49 Copyright © 2006, Oracle. All rights reserved.


Practice Overview:
Tune the Shared Pool

This practice covers the following topics:


• Tune a hard parse workload
• Tune a soft parse workload
• Keep objects in the shared pool

8-50 Copyright © 2006, Oracle. All rights reserved.


Summary

In this lesson, you should have learned how to:


• Diagnose shared pool problems
• Size the shared pool
• Size the reserved area
• Keep objects in the shared pool

8-51 Copyright © 2006, Oracle. All rights reserved.

Potrebbero piacerti anche