Shared Pool Waits Kyle Hailey [email protected].

38
Shared Pool Waits Shared Pool Waits Kyle Hailey http://perfvision.com/ftp/ emea2010 [email protected]

Transcript of Shared Pool Waits Kyle Hailey [email protected].

Page 1: Shared Pool Waits Kyle Hailey  Kyle.hailey@embarcadero.com.

Shared Pool WaitsShared Pool Waits

Kyle Hailey

http://perfvision.com/ftp/emea2010

[email protected]

Page 2: Shared Pool Waits Kyle Hailey  Kyle.hailey@embarcadero.com.

Copyright 2006 Kyle Hailey

Shared Pool WaitsShared Pool Waits

1. Latches Latch: Library Cache Latch: Shared Pool Latch

2. Mutexes

3. Library Cache locks and pins

4. Row Cache Lock

Page 3: Shared Pool Waits Kyle Hailey  Kyle.hailey@embarcadero.com.

Copyright 2006 Kyle Hailey

Library CacheLibrary Cache

Lib Lib CacheCache

Page 4: Shared Pool Waits Kyle Hailey  Kyle.hailey@embarcadero.com.

Copyright 2006 Kyle Hailey

Hash Table

handlehandle

handle handlehandle

handle handlehandle

handle

handlehandle

handle

handle

Shared Pool StructureShared Pool Structure

SQL statements are hashedSQL statements are hashed

On their text. The resultingOn their text. The resulting

Hash is used to find the appropriateHash is used to find the appropriate

bucket, which is searched for thebucket, which is searched for the

Compiled SQL. If it’s not there, Compiled SQL. If it’s not there,

then we parse it.then we parse it.

Page 5: Shared Pool Waits Kyle Hailey  Kyle.hailey@embarcadero.com.

Copyright 2006 Kyle Hailey

Shared Pool LatchShared Pool Latch

Cause: Hard Parses by Concurrent SessionsContention can arise when too many sessions are hard

parsing and looking for space in the shared pool.

Protects Space Allocation in the Shared PoolProtects the structure containing memory chunks

Ensures two users don’t get same chunk of memory

Page 6: Shared Pool Waits Kyle Hailey  Kyle.hailey@embarcadero.com.

Copyright 2006 Kyle Hailey

Shared Pool Free Space

Shared Pool Latch covers changes in the lists of free memory chunks

Shared Pool LatchShared Pool Latch

Page 7: Shared Pool Waits Kyle Hailey  Kyle.hailey@embarcadero.com.

Copyright 2006 Kyle Hailey

Bucket sizes 0 < 80 bytes1 < 1442 < 2723 < 5284 < 10405 < 20646 < 41127 < 82088 < 164009 < 3278410 bigger

Shared Pool Latch 8.1.6Shared Pool Latch 8.1.6

Shared Pool pre 8.1.6Memory Chunk Buckets

Page 8: Shared Pool Waits Kyle Hailey  Kyle.hailey@embarcadero.com.

Copyright 2006 Kyle Hailey

Shared Pool Free Space 8.1.6+

Before 8.1.6, oversizing the shared pool could be a problem, after 8.1.6 should be fine

Shared Pool Latch

Shared Pool LatchShared Pool Latch

Page 9: Shared Pool Waits Kyle Hailey  Kyle.hailey@embarcadero.com.

Copyright 2006 Kyle Hailey

Shared Pool

Memory Chunk Buckets 8.1.6 and up0 16 bytes1 20 bytes … (0-198 only have one chunk size in bucket)198 808 bytes199 812 to 872…. (199-248 only have 16 possible chunk sizes per

bucket)248 3948 - 4008249 4012 - 4104250 4108 - 8204251 8204 - 16392252 16396 - 32776253 32780 - 65544254 bigger

Shared Pool LatchShared Pool Latch

Page 10: Shared Pool Waits Kyle Hailey  Kyle.hailey@embarcadero.com.

Copyright 2006 Kyle Hailey

Library Cache LatchesLibrary Cache Latches 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

Page 11: Shared Pool Waits Kyle Hailey  Kyle.hailey@embarcadero.com.

Copyright 2006 Kyle Hailey

Hash Table

handle

pin

pin

lock

lock

Library CacheLibrary Cache

handle

Find and LockFind and Lock

Pin (and Load)Pin (and Load)

Page 12: Shared Pool Waits Kyle Hailey  Kyle.hailey@embarcadero.com.

Copyright 2006 Kyle Hailey

Child cursor 3

Hash Table

handle handle handle

Cursor (0)

pin

pin

lock

lock

Heap 1

Child cursor 1

Child cursor 2

Heap 6

pin

pin

lock

lock

Heap 0

pin

pin

lock

lock

waiters

holders

Handle

Cursor(0)

flags

Library Cache StructuresLibrary Cache Structures

Library Cache Latches

Page 13: Shared Pool Waits Kyle Hailey  Kyle.hailey@embarcadero.com.

Copyright 2006 Kyle Hailey

Library Cache Latch ContentionLibrary Cache Latch Contention

Library Cache Latch Contention because of these possibilities:

Excessive Hard ParsingNot Sharing SQL – use of Literal ValuesShared Pool too smallToo many invalidations

Excessive Soft Parsing

Page 14: Shared Pool Waits Kyle Hailey  Kyle.hailey@embarcadero.com.

Copyright 2006 Kyle Hailey

Sharing SQL & LiteralsSharing SQL & Literals

select select plan_hash_value,plan_hash_value,

count(plan_hash_value)count(plan_hash_value)

from from

v$sql v$sql

group by plan_hash_valuegroup by plan_hash_value

order by count(plan_hash_value)order by count(plan_hash_value)

select select plan_hash_value,plan_hash_value,

count(plan_hash_value)count(plan_hash_value)

from from

v$sql v$sql

group by plan_hash_valuegroup by plan_hash_value

order by count(plan_hash_value)order by count(plan_hash_value)

SQL> @dups

PLAN_HASH_VALUE CNT--------------- ---------- 272002086 520

SQL> @dups

PLAN_HASH_VALUE CNT--------------- ---------- 272002086 520

Page 15: Shared Pool Waits Kyle Hailey  Kyle.hailey@embarcadero.com.

Copyright 2006 Kyle Hailey

Sharing SQL & LiteralsSharing SQL & Literals

SQL_TEXT-----------------------------------------------SELECT * FROM dual WHERE dummy=-634891633SELECT * FROM dual WHERE dummy=1987751014SELECT * FROM dual WHERE dummy=25965276SELECT * FROM dual WHERE dummy=32449789SELECT * FROM dual WHERE dummy=-364632215SELECT * FROM dual WHERE dummy=-34273351SELECT * FROM dual WHERE dummy=-699712683SELECT * FROM dual WHERE dummy=1752437199SELECT * FROM dual WHERE dummy=-1081512404

SQL_TEXT-----------------------------------------------SELECT * FROM dual WHERE dummy=-634891633SELECT * FROM dual WHERE dummy=1987751014SELECT * FROM dual WHERE dummy=25965276SELECT * FROM dual WHERE dummy=32449789SELECT * FROM dual WHERE dummy=-364632215SELECT * FROM dual WHERE dummy=-34273351SELECT * FROM dual WHERE dummy=-699712683SELECT * FROM dual WHERE dummy=1752437199SELECT * FROM dual WHERE dummy=-1081512404

select sql_text from v$sql where plan_hash_value = 272002086 and rownum < 10;

select sql_text from v$sql where plan_hash_value = 272002086 and rownum < 10;

SQL> @dups

PLAN_HASH_VALUE CNT--------------- ---- 272002086 520

SQL> @dups

PLAN_HASH_VALUE CNT--------------- ---- 272002086 520

Page 16: Shared Pool Waits Kyle Hailey  Kyle.hailey@embarcadero.com.

Copyright 2006 Kyle Hailey

Cursor SharingCursor Sharing

Bind VariablesSelect * from dual where dummy = :var;Select sum(money) from orders where

odate > :odate;

Cursor_SharingCursor_sharing = Force

Oracle replaces variables with bind variables

Defaults to Exact

Page 17: Shared Pool Waits Kyle Hailey  Kyle.hailey@embarcadero.com.

Copyright 2006 Kyle Hailey

Shared Pool too SmallShared Pool too Small

Reloads means Cursor heaps were kicked out implying shared_pool too small

SQL> select namespace, reloadsSQL> select namespace, reloads

from v$librarycache;from v$librarycache;

NAMESPACE RELOADS NAMESPACE RELOADS

--------------- ------------------------- ----------

SQL AREA 367SQL AREA 367

TABLE/PROCEDURE 592TABLE/PROCEDURE 592

SQL> select namespace, reloadsSQL> select namespace, reloads

from v$librarycache;from v$librarycache;

NAMESPACE RELOADS NAMESPACE RELOADS

--------------- ------------------------- ----------

SQL AREA 367SQL AREA 367

TABLE/PROCEDURE 592TABLE/PROCEDURE 592

Page 18: Shared Pool Waits Kyle Hailey  Kyle.hailey@embarcadero.com.

Copyright 2006 Kyle Hailey

InvalidationsInvalidations

Changes in dependent objects invalidate cursorFOR i IN 1..3000 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,SQL> select namespace,

invalidations invalidations

from v$librarycache;from v$librarycache;NAMESPACE INVALIDATIONSNAMESPACE INVALIDATIONS--------------- ---------------------------- -------------SQL AREA 6065SQL AREA 6065

SQL> select namespace,SQL> select namespace,

invalidations invalidations

from v$librarycache;from v$librarycache;NAMESPACE INVALIDATIONSNAMESPACE INVALIDATIONS--------------- ---------------------------- -------------SQL AREA 6065SQL AREA 6065

FOR i IN 1..3000 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;

Page 19: Shared Pool Waits Kyle Hailey  Kyle.hailey@embarcadero.com.

Copyright 2006 Kyle Hailey

Re-Executing a Cursor Re-Executing a Cursor

1.1. Libray Cache latch Libray Cache latch 2.2. LocksLocks3.3. PinsPins

pin pin pin pin pin

lock

Execute 1 Execute 2 Execute 3 Execute 4 Execute 5

Cursor MemoryCursor Memory

locklock lock lock

= Latch= Latch

Soft ParsingSoft Parsing

Page 20: Shared Pool Waits Kyle Hailey  Kyle.hailey@embarcadero.com.

Copyright 2006 Kyle Hailey

Session Cached CursorsSession Cached Cursors

Execute 1 Execute 2 Execute 3 Execute 4 Execute 5

Cursor MemoryCursor Memory

lock

= Latch= Latch

pin pin pin pin pin

Session_cached_cursor:Session_cached_cursor:

If Opening/Closing keeps locked in MemoryIf Opening/Closing keeps locked in Memory

Page 21: Shared Pool Waits Kyle Hailey  Kyle.hailey@embarcadero.com.

Copyright 2006 Kyle Hailey

Session Cached CursorsSession Cached Cursors

FOR i IN 1..30000 LOOPFOR i IN 1..30000 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 1..30000 LOOPFOR i IN 1..30000 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=0Session_cached_cursors=0

Latch Gets Latch Gets ----- ---- ----- ---- library cache lock 120,028 library cache lock 120,028 library cache 180,074 library cache 180,074 library cache pin 60,048library cache pin 60,048

Session_cached_cursors=20Session_cached_cursors=20

library cache lock 4 library cache lock 4 library cache 60,061 library cache 60,061 library cache pin 60,048library cache pin 60,048

Page 22: Shared Pool Waits Kyle Hailey  Kyle.hailey@embarcadero.com.

Copyright 2006 Kyle Hailey

Cursor Space for TimeCursor Space for Time

Execute 1 Execute 2 Execute 3 Execute 4 Execute 5

Cursor MemoryCursor Memory

Cursor_space_for_time=true :Cursor_space_for_time=true :

if open and re-executing – keeps cursor pinnedif open and re-executing – keeps cursor pinned

(Cursor already locked because cursor is kept open)(Cursor already locked because cursor is kept open)

= Latch= Latch

pin

lock

OpenOpenCursorCursor

CloseCloseCursorCursor

Page 23: Shared Pool Waits Kyle Hailey  Kyle.hailey@embarcadero.com.

Copyright 2006 Kyle Hailey

Cursor Space For TimeCursor Space For Time

FOR i IN 1..30000 LOOPFOR i IN 1..30000 LOOP rc:=dbms_sql.execute(l_cursor);rc:=dbms_sql.execute(l_cursor); IF DBMS_SQL.FETCH_ROWS (l_cursor) < 0 THENIF 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;End loop;End loop;

FOR i IN 1..30000 LOOPFOR i IN 1..30000 LOOP rc:=dbms_sql.execute(l_cursor);rc:=dbms_sql.execute(l_cursor); IF DBMS_SQL.FETCH_ROWS (l_cursor) < 0 THENIF 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;End loop;End loop;

Cursor_space_for_time=falseCursor_space_for_time=false

Latch Gets Latch Gets ----- ---- ----- ---- library cache lock 35library cache lock 35library cache 60,096library cache 60,096library cache pin 60,044library cache pin 60,044

Cursor_space_for_time=trueCursor_space_for_time=true

library cache lock 30library cache lock 30library cache 85library cache 85library cache pin 42library cache pin 42

Page 24: Shared Pool Waits Kyle Hailey  Kyle.hailey@embarcadero.com.

Copyright 2006 Kyle Hailey

Cursor SharingCursor Sharing

handle handle handle

pin

pin

lock

lock

Child cursor 0

Child cursor 1

select * from (select * from (select sql_id, count(*) cntselect sql_id, count(*) cntfrom V$SQL_SHARED_CURSORfrom V$SQL_SHARED_CURSORgroup by sql_id )group by sql_id )where cnt > 5where cnt > 5order by cnt;order by cnt;

Child cursor 2

handle

Cursor (0)

Handle

Cursor(0)

flags

Page 25: Shared Pool Waits Kyle Hailey  Kyle.hailey@embarcadero.com.

Copyright 2006 Kyle Hailey

V$SQL_SHARED_CURSORV$SQL_SHARED_CURSOR

10gR2, 53 reasons why cursors aren’t shared If using “cursor_sharing=similar” might not

work – bugs Examples

OPTIMIZER_MODE_MISMATCH , see V$SQL_OPTIMIZER_ENV STATS_ROW_MISMATCH, could be sql trace AUTH_CHECK_MISMATCH

TRANSLATION_MISMATCH – different object in SQL stmt BIND_MISMATCH – bind variable different sizes LANGUAGE_MISMATCH – NLS Language

http://www.juliandyke.com/Presentations/Presentations.html#LibraryCacheInternals

Page 26: Shared Pool Waits Kyle Hailey  Kyle.hailey@embarcadero.com.

Copyright 2006 Kyle Hailey

V$SQL_SHARED_CURSORV$SQL_SHARED_CURSORUNBOUND_CURSORSQL_TYPE_MISMATCHOPTIMIZER_MISMATCHOUTLINE_MISMATCHSTATS_ROW_MISMATCHLITERAL_MISMATCHSEC_DEPTH_MISMATCHEXPLAIN_PLAN_CURSORBUFFERED_DML_MISMATCHPDML_ENV_MISMATCHINST_DRTLD_MISMATCHSLAVE_QC_MISMATCHTYPECHECK_MISMATCHAUTH_CHECK_MISMATCHBIND_MISMATCHDESCRIBE_MISMATCHLANGUAGE_MISMATCHTRANSLATION_MISMATCHROW_LEVEL_SEC_MISMATCHINSUFF_PRIVSINSUFF_PRIVS_REMREMOTE_TRANS_MISMATCHLOGMINER_SESSION_MISMATCHINCOMP_LTRL_MISMATCHOVERLAP_TIME_MISMATCHSQL_REDIRECT_MISMATCHMV_QUERY_GEN_MISMATCH

USER_BIND_PEEK_MISMATCH TYPCHK_DEP_MISMATCHNO_TRIGGER_MISMATCHFLASHBACK_CURSORANYDATA_TRANSFORMATIONINCOMPLETE_CURSORTOP_LEVEL_RPI_CURSORDIFFERENT_LONG_LENGTHLOGICAL_STANDBY_APPLYDIFF_CALL_DURNBIND_UACS_DIFFPLSQL_CMP_SWITCHS_DIFFCURSOR_PARTS_MISMATCHSTB_OBJECT_MISMATCHROW_SHIP_MISMATCHPQ_SLAVE_MISMATCHTOP_LEVEL_DDL_MISMATCHMULTI_PX_MISMATCHBIND_PEEKED_PQ_MISMATCHMV_REWRITE_MISMATCHROLL_INVALID_MISMATCHOPTIMIZER_MODE_MISMATCHPX_MISMATCHMV_STALEOBJ_MISMATCHFLASHBACK_TABLE_MISMATCHLITREP_COMP_MISMATCH

Page 27: Shared Pool Waits Kyle Hailey  Kyle.hailey@embarcadero.com.

Copyright 2006 Kyle Hailey

10g : Mutex10g : Mutex

A new semaphore method which can replace latches

Mutex Mutual exclusion object

Similar to a latch, prevents Deallocation while someone is using it Read/write while someone else is modifying

Different from latch Every object can have it’s own mutex A mutex can cover multiple objects Usually dynamically allocated along with structure they protect Can be stored in the structure, thus destroying structure deletes

the mutex

Page 28: Shared Pool Waits Kyle Hailey  Kyle.hailey@embarcadero.com.

Copyright 2006 Kyle Hailey

Mutex Views and StatsMutex Views and Stats

Views V$mutex_sleep V$mutex_sleep_history

Cursor:pin S Pin cursor for execute, and cursor is currently being

examined by another Session Bug 69681526968152

Cursor:pin S wait on X Pinning a cursor for execute Bug on 10.2.0.3 typically with DBMS_STATS Metalink Note:401435.1, Note:5907779.8, bug 59077795907779

Fixed 10.2.0.4 ?

Turn off with _kks_use_mutex_pin=FALSE"_kks_use_mutex_pin=FALSE"

Instead of “library cache pin”cursor_space_for_time not needed

Instead of latching for execute pin we use a shared mutexInstead of latching for execute pin we use a shared mutex

If can’t get the mutex spinIf can’t get the mutex spin

Page 29: Shared Pool Waits Kyle Hailey  Kyle.hailey@embarcadero.com.

Debugging Pin WaitsDebugging Pin Waits

Copyright 2006 Kyle Hailey

NAME P1 P2 P3NAME P1 P2 P3------------------------- ----- ------- ---------------------------------------- ----- ------- ---------------cursor: mutex X idn value where|sleepscursor: mutex X idn value where|sleepscursor: mutex S idn value where|sleepscursor: mutex S idn value where|sleepscursor: pin S wait on X idn value where|sleepscursor: pin S wait on X idn value where|sleepscursor: pin X idn value where|sleepscursor: pin X idn value where|sleepscursor: pin S idn value where|sleepscursor: pin S idn value where|sleeps

select p1, p2raw, count(*)  from v$session where event = ‘cursor: pin S wait on X’   and wait_time = 0Group by p1, p2;

        P1  P2RAW            COUNT(*)P1  P2RAW            COUNT(*)----------  ---------------- ------------------  ---------------- --------2700259466  0000139700000000        92700259466  0000139700000000        9<Mutex Id>  <   SId><RefCnt><Mutex Id>  <   SId><RefCnt>

select to_number(1397,'XXXX') from dual;

TO_NUMBER(1397,'XXXX')TO_NUMBER(1397,'XXXX')-------------------------------------------- 50155015

Alter system kill session ‘5015,82’;

Select serial# from v$session where sid=5015;SERIAL#SERIAL#---------------- 8282

Images from Images from Marcin Przepiorowski  

Page 30: Shared Pool Waits Kyle Hailey  Kyle.hailey@embarcadero.com.

Copyright 2006 Kyle Hailey

lock and pinslock and pins

1.1. Library Cache PinLibrary Cache Pin

2.2. Library Cache LockLibrary Cache Lock

3.3. Library Cache Load LockLibrary Cache Load Lock

Contention when Sessions try to load/compile same SQLCompile package others are running

Locks and Pins are usually in share mode unless modifications are being made

Page 31: Shared Pool Waits Kyle Hailey  Kyle.hailey@embarcadero.com.

Copyright 2006 Kyle Hailey

Lib Cache Lock : blockers and waiters Lib Cache Lock : blockers and waiters

select waiter.sid waiter, waiter.event wevent, to_char(blocker_event.sid)||','||to_char(blocker_session.serial#) blocker, substr(decode(blocker_event.wait_time, 0, blocker_event.event, 'ON CPU'),1,30) beventfrom x$kglpn p, gv$session blocker_session, gv$session_wait waiter, gv$session_wait blocker_eventwhere p.kglpnuse=blocker_session.saddr and p.kglpnhdl=waiter.p1raw and waiter.event in ( 'library cache pin' , 'library cache lock' , 'library cache load lock') and blocker_event.sid=blocker_session.sid and waiter.sid != blocker_event.sidorder by waiter.p1raw,waiter.sid;

select waiter.sid waiter, waiter.event wevent, to_char(blocker_event.sid)||','||to_char(blocker_session.serial#) blocker, substr(decode(blocker_event.wait_time, 0, blocker_event.event, 'ON CPU'),1,30) beventfrom x$kglpn p, gv$session blocker_session, gv$session_wait waiter, gv$session_wait blocker_eventwhere p.kglpnuse=blocker_session.saddr and p.kglpnhdl=waiter.p1raw and waiter.event in ( 'library cache pin' , 'library cache lock' , 'library cache load lock') and blocker_event.sid=blocker_session.sid and waiter.sid != blocker_event.sidorder by waiter.p1raw,waiter.sid;

WAITER WLOCKP1 WEVENT BLOCKER BEVENT------- ---------------- ----------------- --------- -----------------129 00000003B76AB620 library cache pin 135,15534 PL/SQL lock timer

WAITER WLOCKP1 WEVENT BLOCKER BEVENT------- ---------------- ----------------- --------- -----------------129 00000003B76AB620 library cache pin 135,15534 PL/SQL lock timer

Page 32: Shared Pool Waits Kyle Hailey  Kyle.hailey@embarcadero.com.

Copyright 2006 Kyle Hailey

SolutionsSolutions

1. Library Cache Pin

2. Library Cache Lock

3. Library Cache Load Lock

Have only one Session compile the same cursor at a time

Avoid compiling while executing Waits – find “competing” Sessions

Page 33: Shared Pool Waits Kyle Hailey  Kyle.hailey@embarcadero.com.

Copyright 2006 Kyle Hailey

row cache lock : argsrow 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;

Page 34: Shared Pool Waits Kyle Hailey  Kyle.hailey@embarcadero.com.

Row Cache Lock - ASHRow Cache Lock - ASHselectselect

ash.session_id sid,ash.session_id sid,

ash.blocking_session bsid,ash.blocking_session bsid,

nvl(o.object_name,to_char(CURRENT_OBJ#)) obj,nvl(o.object_name,to_char(CURRENT_OBJ#)) obj,

o.object_type otype,o.object_type otype,

CURRENT_FILE# filen,CURRENT_FILE# filen,

CURRENT_BLOCK# blockn,CURRENT_BLOCK# blockn,

ash.SQL_ID,ash.SQL_ID,

nvl(rc.name,to_char(ash.p3)) row_cachenvl(rc.name,to_char(ash.p3)) row_cache

from v$active_session_history ash,from v$active_session_history ash,

( select cache#, parameter name from v$rowcache ) rc,( select cache#, parameter name from v$rowcache ) rc,

all_objects oall_objects o

where event='row cache lock'where event='row cache lock'

and rc.cache#(+)=ash.p1and rc.cache#(+)=ash.p1

and o.object_id (+)= ash.CURRENT_OBJ#and o.object_id (+)= ash.CURRENT_OBJ#

and ash.session_state='WAITING'and ash.session_state='WAITING'

and ash.sample_time > sysdate - &minutes/(60*24)and ash.sample_time > sysdate - &minutes/(60*24)

Order by sample_timeOrder by sample_time

Page 35: Shared Pool Waits Kyle Hailey  Kyle.hailey@embarcadero.com.

Row Cache Lock - ASHRow Cache Lock - ASHselectselect

ash.session_id sid,ash.session_id sid,

ash.blocking_session bsid,ash.blocking_session bsid,

nvl(o.object_name,to_char(CURRENT_OBJ#)) obj,nvl(o.object_name,to_char(CURRENT_OBJ#)) obj,

o.object_type otype,o.object_type otype,

CURRENT_FILE# filen,CURRENT_FILE# filen,

CURRENT_BLOCK# blockn,CURRENT_BLOCK# blockn,

ash.SQL_ID,ash.SQL_ID,

nvl(rc.name,to_char(ash.p3)) row_cachenvl(rc.name,to_char(ash.p3)) row_cache

from v$active_session_history ash,from v$active_session_history ash,

( select cache#, parameter name from v$rowcache ) rc,( select cache#, parameter name from v$rowcache ) rc,

all_objects oall_objects o

where event='row cache lock'where event='row cache lock'

and rc.cache#(+)=ash.p1and rc.cache#(+)=ash.p1

and o.object_id (+)= ash.CURRENT_OBJ#and o.object_id (+)= ash.CURRENT_OBJ#

and ash.session_state='WAITING'and ash.session_state='WAITING'

and ash.sample_time > sysdate - &minutes/(60*24)and ash.sample_time > sysdate - &minutes/(60*24)

Order by sample_timeOrder by sample_time

SID BSID OBJ OTYPE FILEN BLOCKN SQL_ID ROW_CACHE

--- ---- ---- ----- ----- ------- ------------- ------------

143 131 -1 0 0 41y8w0sfqb61m dc_sequences134 131 -1 0 0 dc_sequences151 -1 0 0 dc_sequences134 151 -1 0 0 dc_sequences131 151 -1 0 0 dc_sequences151 -1 0 0 dc_sequences

Page 36: Shared Pool Waits Kyle Hailey  Kyle.hailey@embarcadero.com.

Copyright 2006 Kyle Hailey

Row Cache LockRow Cache Lock

Select seq.next_val Sequence cache set to 1 Default sequence cache is 20

SQL> @sqltext

Enter value for 1: 41y8w0sfqb61m

SQL_FULLTEXT

-----------------------------------

SELECT TOTO_SEQ.NEXTVAL FROM DUAL

Page 37: Shared Pool Waits Kyle Hailey  Kyle.hailey@embarcadero.com.

Copyright 2006 Kyle Hailey

Library Cache Latch SolutionsLibrary Cache Latch Solutions

Share CursorsUse bind variablesUser cursor_sharing=force

Avoid invalidations and reloadsSize shared_pool large enoughAvoid changing dependent objects

Soft ParsingSession_cached_cursors =20 : keep across open/closeCursor_space_for_time=true : keep pinned across executeshold_cursor=true : used in precompilers

Page 38: Shared Pool Waits Kyle Hailey  Kyle.hailey@embarcadero.com.

Copyright 2006 Kyle Hailey

SummarySummary

Shared Pool LatchShared pool too small or too much hard parsing

Loading Same CursorLibrary Cache PinLibrary Cache LockLibrary Cache Load Lock

Row Cache LockDepends on the cache