Presentation is loading. Please wait.

Presentation is loading. Please wait.

8 Copyright © 2006, Oracle. All rights reserved. Tuning the Shared Pool.

Similar presentations


Presentation on theme: "8 Copyright © 2006, Oracle. All rights reserved. Tuning the Shared Pool."— Presentation transcript:

1 8 Copyright © 2006, Oracle. All rights reserved. Tuning the Shared Pool

2 8-2 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

3 8-3 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 Database buffer cache Redo log buffer Shared pool Library cache Data dictionary cache Shared areas Large pool UGA

4 8-4 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.

5 8-5 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

6 8-6 Copyright © 2006, Oracle. All rights reserved. SQLAREA SQL and PL/SQL Storage Cursor context area for SELECT statement 2 Cursor context area for SELECT statement 1 Shared pool SELECT statement 2 SELECT statement 1 SELECT statement 1

7 8-7 Copyright © 2006, Oracle. All rights reserved. Cursor Usage and Parsing 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). Open cursors Closed cursors Session memory (UGA)Shared pool (SGA) Cursor handles Hash chains 1 2 3 4

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

9 8-9 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.

10 8-10 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

11 8-11 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

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

13 8-13 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

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

15 8-15 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

16 8-16 Copyright © 2006, Oracle. All rights reserved. Statspack/AWR Indicators Statspack and AWR reports include indicators: Load Profile Instance Efficiencies Top Wait Events Time Model

17 8-17 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

18 8-18 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

19 8-19 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 -------------------------------------------------------

20 8-20 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

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

22 8-22 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

23 8-23 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

24 8-24 Copyright © 2006, Oracle. All rights reserved. V$SGASTAT V$SGAINFO V$LIBRARYCACHE V$LIBRARY_CACHE_MEMORY V$SHARED_POOL_RESERVED V$SQLSTATS V$SQL V$SQLAREA V$SQLTEXT V$DB_OBJECT_CACHE Diagnostic Tools for Tuning the Shared Pool Parameters affecting the components: SHARED_POOL_SIZE, OPEN_CURSORS SESSION_CACHED_CURSORS, CURSOR_SPACE_FOR_TIME CURSOR_SHARING, SHARED_POOL_RESERVED_SIZE sp_m_n.lst report.txt Data dictionary cache Shared pool Library cache Shared SQL and PL/SQL Views

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

26 8-26 Copyright © 2006, Oracle. All rights reserved. Library Cache Reloads Reloads should be less than 1% of the pins: If the reloads-to-pins ratio is greater than 1%, increase the value of the SHARED_POOL_SIZE parameter. SQL> SELECT SUM(pins) "Executions", 2 SUM(reloads) "Cache Misses", 3 SUM(reloads)/SUM(pins) 4 FROM V$LIBRARYCACHE; Executes PROC1 — > 1st pin, 1 load Executes PROC1 — > 2nd pin, no reload Executes PROC1 — > 3rd pin, no reload Executes PROC1 — > 4th pin, no reload Four pins and no reloads

27 8-27 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;

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

29 8-29 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.

30 8-30 Copyright © 2006, Oracle. All rights reserved. Are Cursors Being Shared? Check GETHITRATIO in V$LIBRARYCACHE : 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 SQL> SELECT gethitratio 2 FROM V$LIBRARYCACHE 3 WHERE namespace = 'SQL AREA';

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

32 8-32 Copyright © 2006, Oracle. All rights reserved. Sharing Cursors Values for CURSOR_SHARING are: EXACT SIMILAR FORCE

33 8-33 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

34 8-34 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

35 8-35 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';

36 8-36 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

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

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

39 8-39 Copyright © 2006, Oracle. All rights reserved. Large Memory Requirements Satisfy requests for large contiguous memory. Reserve contiguous memory within the shared pool. SHARED_POOL_SIZE SHARED_POOL_RESERVED_SIZE Data dictionary cache Shared pool Library cache Shared SQL and PL/SQL V$SHARED_POOL_RESERVED Reserved area

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

41 8-41 Copyright © 2006, Oracle. All rights reserved. Tuning the Shared Pool Reserved Space IF REQUEST_FAILURES Action >0 and increasingANDRequest_misses > 0 Increase SHARED_POOL_ RESERVED_SIZE >0 and increasingAND Free_memory => 50% of SHARED_POOL_RESERVE D_SIZE Increase SHARED_POOL_ SIZE =0ORFree_memory => 50% of SHARED_POOL_RESERVE D_SIZE Decrease SHARED_POOL_ RESERVED_SIZE

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

43 8-43 Copyright © 2006, Oracle. All rights reserved. Keeping Large Objects Find those PL/SQL objects that are not kept in the library cache: Pin large packages in the library cache: SQL> EXECUTE DBMS_SHARED_POOL.KEEP(‘package_name’); 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';

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

45 8-45 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

46 8-46 Copyright © 2006, Oracle. All rights reserved. Statspack/AWR report output: If there are too many cache misses, increase the SHARED_POOL_SIZE parameter. Dictionary Cache Misses 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

47 8-47 Copyright © 2006, Oracle. All rights reserved. UGA and Oracle Shared Server Shared pool PGA Shared pool or Large pool Stack space PGA Stack space User session data Cursor state UGA V$STATNAME V$SESSTAT V$MYSTAT OPEN_CURSORS SESSION_CACHED_CURSORS Cursor state User session data UGA Dedicated server configuration Shared server configuration

48 8-48 Copyright © 2006, Oracle. All rights reserved. Shared pool Library cache Data dictionary cache UGA Database buffer cache Redo log buffer Large pool 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

49 8-49 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

50 8-50 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

51 8-51 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

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


Download ppt "8 Copyright © 2006, Oracle. All rights reserved. Tuning the Shared Pool."

Similar presentations


Ads by Google