Shared Pool Waits
#.2 Copyright 2006 Kyle Hailey Shared Pool Waits Library Cache Latch Shared Pool Latch Library Cache Pin Library Cache Lock Library Cache Load Lock Row Cache Lock
#.3 Copyright 2006 Kyle Hailey Hash Table handle Shared Pool Structure
#.4 Copyright 2006 Kyle Hailey Shared Pool Latch Protects Space Allocation in the Shared Pool Make sure two users don’t get same chunk of memory
#.5 Copyright 2006 Kyle Hailey Bucket sizes 0 < 80 bytes 1 < < < < < < < < < bigger Shared Pool Latch Shared Pool pre Memory Chunk Buckets
#.6 Copyright 2006 Kyle Hailey Shared Pool Free Space Shared Pool Latch covers changes in the lists of free memory chunks Shared Pool Latch
#.7 Copyright 2006 Kyle Hailey Get library cache latch Get shared pool latch Search right bucket Find best fit => If lists get long, search gets long Shared Pool Latch
#.8 Copyright 2006 Kyle Hailey Shared Pool Free Space Shared Pool Latch
#.9 Copyright 2006 Kyle Hailey Shared Pool Memory Chunk Buckets and up 0 16 bytes 1 20 bytes … ( only have one chunk size in bucket ) bytes to 872 …. ( only have 16 possible chunk sizes per bucket ) bigger Shared Pool Latch
#.10 Copyright 2006 Kyle Hailey library cache pin and locks Locks control access, protects handle Pins guarentees coherency, protects heaps To Access to a cursor Lock handle Locking is the way of locating Pin Pinning loads any necessary heaps Guarenteed to stay in memory until pin is released handle pin lock Heap 1 Child cursor 1 Heap 6 Heap 0
#.11 Copyright 2006 Kyle Hailey library cache lock and pins Contention when Sessions try to load/compile same SQL at same time Locks and Pins are usually in share mode unless modifications are being made
#.12 Copyright 2006 Kyle Hailey library cache lock handle pin lock #20 P1 = address of object P2 = address of lock P3 = mode | namespace See x$kgllk
#.13 Copyright 2006 Kyle Hailey library cache pin #13 P1 = address of object P2 = address of lock P3 = Mode | Namespace See x$kglpn handle pin lock
#.14 Copyright 2006 Kyle Hailey Solutions Have only one Session compile a the same cursor at a time Waits – find “competing” Sessions
#.15 Copyright 2006 Kyle Hailey SQL: Lib Cache Lock Find the waiters and who blocks them column wevent format a20 column bevent format a20 select waiter.sid waiter, waiter.p1raw wlockp1, waiter.event wevent, blocker_event.sid blocker, blocker_event.event bevent from x$kglpn p, gv$session blocker_session, gv$session_wait waiter, gv$session_wait blocker_event where p.kglpnuse=blocker_session.saddr and p.kglpnhdl=waiter.p1raw and (waiter.event like 'library cache lock' ) and blocker_event.sid=blocker_session.sid order by waiter.p1raw,waiter.sid /
#.16 Copyright 2006 Kyle Hailey library cache load lock #23 Waiting For a Reload by another Session
#.17 Copyright 2006 Kyle Hailey Library Cache Latch Protects changes in Library Cache Library Locks are not atomic Thus need library cache latch Broken out into library cache pin allocation library cache lock allocation library cache lock library cache library cache pin library cache load lock
#.18 Copyright 2006 Kyle Hailey Hash Table handle pin lock Library Cache handle Find and Lock Pin (and Load)
#.19 Copyright 2006 Kyle Hailey Child cursor 3 Hash Table handle Cursor (0) pin lock Heap 1 Child cursor 1 Child cursor 2 Heap 6 pin lock Heap 0 pin lock waiters holders Handle Cursor(0) flags Library Cache Structures Library Cache Latch
#.20 Copyright 2006 Kyle Hailey Library Cache Latch Contention Excesive Hard Parsing Not Sharing SQL – use of Literal Values Shared Pool too small Too many invalidations Excessive Soft Parsing
#.21 Copyright 2006 Kyle Hailey Sharing SQL & Literals PLAN_HASH_VALUE CNT SQL_TEXT SELECT * FROM dual WHERE dummy= SELECT * FROM dual WHERE dummy= SELECT * FROM dual WHERE dummy= SELECT * FROM dual WHERE dummy= SELECT * FROM dual WHERE dummy= SELECT * FROM dual WHERE dummy= SELECT * FROM dual WHERE dummy= SELECT * FROM dual WHERE dummy= SELECT * FROM dual WHERE dummy= select plan_hash_value, plan_hash_value,count(plan_hash_value)fromv$sql group by plan_hash_value, order by count(plan_hash_value) select plan_hash_value, plan_hash_value,count(plan_hash_value)fromv$sql group by plan_hash_value, order by count(plan_hash_value) select sql_text from v$sql where plan_hash_value = and rownum < 10; select sql_text from v$sql where plan_hash_value = and rownum < 10;
#.22 Copyright 2006 Kyle Hailey Cursor Sharing Bind Variables Select * from dual where dummy = :var; Cursor_Sharing Cursor_sharing = Force Oracle replaces variables with bind variables Defaults to Exact
#.23 Copyright 2006 Kyle Hailey Shared Pool too Small Reloads means Cursor heaps were kicked out implying shared_pool too small SQL> select namespace, reloads from v$librarycache; from v$librarycache; NAMESPACE RELOADS SQL AREA 367 TABLE/PROCEDURE 592 SQL> select namespace, reloads from v$librarycache; from v$librarycache; NAMESPACE RELOADS SQL AREA 367 TABLE/PROCEDURE 592
#.24 Copyright 2006 Kyle Hailey Invalidations Changes in dependent objects invalidate cursor FOR i IN LOOP l_cursor:=dbms_sql.open_cursor; dbms_sql.parse(l_cursor, 'SELECT * FROM toto',dbms_sql.native); execute immediate 'analyze table toto compute statistics'; dbms_sql.close_cursor(l_cursor); END LOOP; SQL> select namespace, invalidations invalidations from v$librarycache; from v$librarycache; NAMESPACE INVALIDATIONS SQL AREA 6065 SQL> select namespace, invalidations invalidations from v$librarycache; from v$librarycache; NAMESPACE INVALIDATIONS SQL AREA 6065
#.25 Copyright 2006 Kyle Hailey Re-Executing a Cursor 1.Libray Cache latch 2.Locks 3.Pins pin lock Execute 1Execute 2Execute 3Execute 4Execute 5 Cursor Memory lock = Latch Soft Parsing
#.26 Copyright 2006 Kyle Hailey Session Cached Cursors Execute 1Execute 2Execute 3Execute 4Execute 5 Cursor Memory lock = Latch pin Session_cached_cursor: If Opening/Closing keeps locked in Memory
#.27 Copyright 2006 Kyle Hailey Session Cached Cursors FOR i IN LOOP FOR i IN LOOP l_cursor:=dbms_sql.open_cursor; l_cursor:=dbms_sql.open_cursor; dbms_sql.parse(l_cursor,'SELECT * FROM dual’,dbms_sql.native); dbms_sql.parse(l_cursor,'SELECT * FROM dual’,dbms_sql.native); dbms_sql.close_cursor(l_cursor); dbms_sql.close_cursor(l_cursor); END LOOP; END LOOP; FOR i IN LOOP FOR i IN LOOP l_cursor:=dbms_sql.open_cursor; l_cursor:=dbms_sql.open_cursor; dbms_sql.parse(l_cursor,'SELECT * FROM dual’,dbms_sql.native); dbms_sql.parse(l_cursor,'SELECT * FROM dual’,dbms_sql.native); dbms_sql.close_cursor(l_cursor); dbms_sql.close_cursor(l_cursor); END LOOP; END LOOP; Session_cached_cursors=0 Latch Gets library cache lock 120,028 library cache 180,074 library cache pin 60,048 Session_cached_cursors=20 library cache lock 4 library cache 60,061 library cache pin 60,048
#.28 Copyright 2006 Kyle Hailey Cursor Space for Time Execute 1Execute 2Execute 3Execute 4Execute 5 Cursor Memory Cursor_space_for_time=true : if open and re-executing – keeps cursor pinned (Cursor already locked because cursor is kept open) = Latch pin lock OpenCursor CloseCursor
#.29 Copyright 2006 Kyle Hailey Cursor Space For Time FOR i IN LOOP rc:=dbms_sql.execute(l_cursor); rc:=dbms_sql.execute(l_cursor); IF DBMS_SQL.FETCH_ROWS (l_cursor) < 0 THEN IF DBMS_SQL.FETCH_ROWS (l_cursor) < 0 THEN DBMS_SQL.COLUMN_VALUE (l_cursor, 1, cnt); DBMS_SQL.COLUMN_VALUE (l_cursor, 1, cnt); end if; end if; FOR i IN LOOP rc:=dbms_sql.execute(l_cursor); rc:=dbms_sql.execute(l_cursor); IF DBMS_SQL.FETCH_ROWS (l_cursor) < 0 THEN IF DBMS_SQL.FETCH_ROWS (l_cursor) < 0 THEN DBMS_SQL.COLUMN_VALUE (l_cursor, 1, cnt); DBMS_SQL.COLUMN_VALUE (l_cursor, 1, cnt); end if; end if; Cursor_space_for_time=false Latch Gets library cache lock 35 library cache 60,096 library cache pin 60,044 Cursor_space_for_time=true library cache lock 30 library cache 85 library cache pin 42
#.30 Copyright 2006 Kyle Hailey Efficient Lock and Pinning Reduce use of latches Improve throughput Improve Concurrency ***
#.31 Copyright 2006 Kyle Hailey row cache lock : args P1 = cache# P2 = Lock Mode Held P3 = Lock Mode Requested select parameter as “name” from v$rowcache where cache# = P1; select parameter as “name” from v$rowcache where cache# = P1;
#.32 Copyright 2006 Kyle Hailey Summary Shared Pool Latch Shard pool too small or too much hard pasing Loading Same Cursor Library Cache Pin Library Cache Lock Library Cache Load Lock Library Cache Latch Too much hard or soft parsing Row Cache Lock
#.33 Copyright 2006 Kyle Hailey Library Cache Latch Solutions Share Cursors Use bind variables User cursor_sharing=force Avoid invalidations and reloads Size shared_pool large enough Avoid changing dependent objects Soft Parsing Session_cached_cursors =20 : keep across open/close Cursor_space_for_time=true : keep pinned across executes hold_cursor=true : used in precompilers