10 Libc-1
10 Libc-1
Kyle Hailey
http://perfvision.com
[email protected]
Shared Pool Waits
1. Latch: Library Cache
2. Latch: Shared Pool Latch
3. Mutexes
4. Library Cache Pin
5. Library Cache Lock
6. Library Cache Load Lock
7. Row Cache Lock
Lib
Cache
handle handle
handle
handle
Bucket sizes
0 < 80 bytes
1 < 144
2 < 272
3 < 528 Shared Pool pre 8.1.6
4 < 1040 Memory Chunk Buckets
5 < 2064
6 < 4112
7 < 8208
8 < 16400
9 < 32784
10 bigger
pin lock
pin lock
handle handle
waiters
pin lock
pin lock
Library Cache Latch
pin lock
holders
pin lock
handle
Handle handle handle
Cursor(0)
flags
Cursor (0)
Heap 1
pin lock
Heap 0
Heap 6
pin lock
Child cursor 1
Child cursor
2
Child cursor 3
Copyright 2006 Kyle Hailey
Library Cache Latch Contention
Excessive Hard Parsing
Not Sharing SQL – use of Literal Values
Shared Pool too small
Too many invalidations
select
select
plan_hash_value,
plan_hash_value,
count(plan_hash_value)
count(plan_hash_value)
from
from
v$sql
v$sql
group
groupby
by plan_hash_value,
plan_hash_value,
order
orderby
bycount(plan_hash_value)
count(plan_hash_value)
SQL>
SQL> @dups
@dups
PLAN_HASH_VALUE
PLAN_HASH_VALUE CNT
CNT
---------------
--------------- ----------
----------
272002086
272002086 520
520
Copyright 2006 Kyle Hailey
Sharing SQL & Literals
SQL>
SQL> @dups
select sql_text
select sql_text @dups
from
from v$sql
v$sql PLAN_HASH_VALUE
PLAN_HASH_VALUE CNT
CNT
where
where ---------------
--------------- ----
----
plan_hash_value = 272002086 272002086
272002086 520
520
plan_hash_value = 272002086
and
andrownum
rownum<< 10;
10;
SQL_TEXT
SQL_TEXT
-----------------------------------------------
-----------------------------------------------
SELECT
SELECT ** FROM
FROM dual
dual WHERE
WHERE dummy=-634891633
dummy=-634891633
SELECT
SELECT ** FROM
FROM dual
dual WHERE
WHERE dummy=1987751014
dummy=1987751014
SELECT
SELECT ** FROM
FROM dual
dual WHERE
WHERE dummy=25965276
dummy=25965276
SELECT
SELECT ** FROM
FROM dual
dual WHERE
WHERE dummy=32449789
dummy=32449789
SELECT
SELECT ** FROM
FROM dual
dual WHERE
WHERE dummy=-364632215
dummy=-364632215
SELECT
SELECT ** FROM
FROM dual
dual WHERE
WHERE dummy=-34273351
dummy=-34273351
SELECT
SELECT ** FROM
FROM dual
dual WHERE
WHERE dummy=-699712683
dummy=-699712683
SELECT
SELECT ** FROM
FROM dual
dual WHERE
WHERE dummy=1752437199
dummy=1752437199
SELECT
SELECT ** FROM
FROM dual
dual WHERE
WHERE
Copyright dummy=-1081512404
2006 Kyledummy=-1081512404
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
SQL>
SQL> select
select namespace,
namespace, reloads
reloads
from
from v$librarycache;
v$librarycache;
NAMESPACE
NAMESPACE RELOADS
RELOADS
---------------
--------------- ----------
----------
SQL
SQL AREA
AREA 367
367
TABLE/PROCEDURE
TABLE/PROCEDURE 592
592
Re-Executing a Cursor
1. Libray Cache latch
2. Locks
3. Pins
Copyright 2006 Kyle Hailey
Session Cached Cursors
lock
Session_cached_cursor:
If Opening/Closing keeps locked in Memory
Copyright 2006 Kyle Hailey
Session Cached Cursors
FOR
FORi iIN
IN1..30000
1..30000LOOP
LOOP
l_cursor:=dbms_sql.open_cursor;
l_cursor:=dbms_sql.open_cursor;
dbms_sql.parse(l_cursor,'SELECT
dbms_sql.parse(l_cursor,'SELECT**FROM
FROMdual’,dbms_sql.native);
dual’,dbms_sql.native);
dbms_sql.close_cursor(l_cursor);
dbms_sql.close_cursor(l_cursor);
END
ENDLOOP;
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
Open
lock
Close
Cursor pin
Cursor
Cursor_space_for_time=true :
if open and re-executing – keeps cursor pinned
(Cursor already locked because cursor is kept open)
Copyright 2006 Kyle Hailey
Cursor Space For Time
FOR
FORi iININ1..30000
1..30000LOOP
LOOP
rc:=dbms_sql.execute(l_cursor);
rc:=dbms_sql.execute(l_cursor);
IFIFDBMS_SQL.FETCH_ROWS
DBMS_SQL.FETCH_ROWS(l_cursor)
(l_cursor)<<00THEN
THEN
DBMS_SQL.COLUMN_VALUE
DBMS_SQL.COLUMN_VALUE(l_cursor,(l_cursor,1,
1,cnt);
cnt);
end
endif;if;
End
Endloop;
loop;
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
Heap 1
Child cursor 2 Heap 0
Heap 6
Heap 1
Child cursor 3 Heap 0
Heap 6
Heap 1
Child cursor 4 Heap 0
Heap 6
http://www.juliandyke.com/Presentations/Presentations.html#LibraryCacheInternals
Mutex
Mutual exclusion object
Similar to a latch, prevents
Deallocation while someone is using it
Read/write while someone else is modifying
Object dependency
lock in Null
Cursor execution
lock in null
Pin in Share
Cursor compilation
Lock exclusive
Pin exclusive
P1 = address of object
P2 = address of lock
P3 = mode | namespace
See
x$kgllk
pin lock
dba_kgllock
pin lock
P1 = address of object
P2 = address of lock
P3 = Mode | Namespace
See
dba_kgllock
x$kglpn
pin lock
pin lock
select
select
w.sid,
w.sid,
kglob.
kglob. kglnaown
kglnaown cursor_owner
cursor_owner,,
kglob.KGLNAOBJ
kglob.KGLNAOBJcursor_object
cursor_object
from
from
x$kglob
x$kglobkglob,
kglob,
v$session_wait
v$session_waitww
where
where
kglob.KGLHDADR=
kglob.KGLHDADR=w.P1RAW
w.P1RAW and
and
event
eventlike
like'%library%';
'%library%';
select
select
waiter.sid
waiter.sid waiter,
waiter,
waiter.event
waiter.eventwevent,
wevent,
to_char(blocker_event.sid)||','||to_char(blocker_session.serial#)
to_char(blocker_event.sid)||','||to_char(blocker_session.serial#)blocker, blocker,
substr(decode(blocker_event.wait_time,
substr(decode(blocker_event.wait_time,
0,0,blocker_event.event,
blocker_event.event,
'ON
'ONCPU'),1,30)
CPU'),1,30)beventbevent
from
from
x$kglpn
x$kglpnp,p, WAITER WLOCKP1
WAITER WLOCKP1
WEVENT
WEVENT
BLOCKER BEVENT
BLOCKER BEVENT
gv$session blocker_session, ------- ---------------- ----------------- --------- -----------------
gv$session blocker_session, ------- ---------------- ----------------- --------- -----------------
gv$session_wait 129
12900000003B76AB620
00000003B76AB620library librarycache
cachepin pin135,15534
135,15534PL/SQL
PL/SQLlock
gv$session_waitwaiter,
waiter, timer
timer
lock
gv$session_wait
gv$session_waitblocker_event
blocker_event
where
where
p.kglpnuse=blocker_session.saddr
p.kglpnuse=blocker_session.saddr
and p.kglpnhdl=waiter.p1raw
and p.kglpnhdl=waiter.p1raw
and
and(waiter.event
(waiter.eventinin( ('library
'librarycache
cachepin'
pin', ,
'library
'librarycache
cachelock'
lock', ,
'library
'librarycache
cacheload
loadlock')
lock')
and blocker_event.sid=blocker_session.sid
and blocker_event.sid=blocker_session.sid
and
andwaiter.sid
waiter.sid!=!=blocker_event.sid
blocker_event.sid
order by
order by
waiter.p1raw,waiter.sid;
waiter.p1raw,waiter.sid;
Copyright 2006 Kyle Hailey
library cache load lock
select
selectparameter
parameteras
as“name”
“name”
from
fromv$rowcache
v$rowcache
where
wherecache#
cache#==P1;
P1;
Top
Top 55 Timed
Timed Events
Events Avg
Avg %Total
%Total
~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~ wait
wait Call
Call
Event
Event Waits
Waits Time
Time (s)
(s) (ms)
(ms) Time
Time
----------------------------------
---------------------------------- -----------
----------- ------
------ ------
------
row cache lock
row cache lock 11,925
11,925 57
57 55 53.8
53.8
CPU
CPU time
time 26
26 24.1
24.1
log file parallel write
log file parallel write 1,828
1,828 20
20 11
11 18.7
18.7
log
log file
file sequential
sequential read
read 15
15 11 66
66 .9
.9
control
control file
file parallel
parallel write
write 31
31 11 24
24 .7
.7
Dictionary
Dictionary Cache
Cache Stats
Stats DB/Inst:
DB/Inst: linux3
linux3 Snaps:
Snaps: 68-69
68-69
->"Pct
->"Pct Misses"
Misses" should
should be
be very
very low
low (<2%
(<2% in
in most
most cases)
cases)
->"Final
->"Final Usage"
Usage" is
is the
the number
number of
of cache
cache entries
entries being
being
Get
Get Pct
Pct Scan
Scan Pct
Pct Mod
Mod Final
Final
Cache
Cache Requests
Requests Miss Miss Reqs
Reqs Miss
Miss Reqs
Reqs Usage
Usage
-------------
------------- --------
-------- ------
------ ----
---- ----
---- ------
------ -----
-----
dc_awr_control
dc_awr_control 11 0.0
0.0 00 00 11
dc_object_ids
dc_object_ids 10
10 0.0
0.0 00 00 650650
dc_objects
dc_objects 28
28 0.0
0.0 00 33 960960
dc_profiles
dc_profiles 66 0.0
0.0 00 00 11
dc_sequences
dc_sequences 12,002
12,002 0.0
0.0 00 12,002
12,002 44
dc_tablespaces
dc_tablespaces 31
31 0.0
0.0 00 00 10
10
dc_usernames
dc_usernames 14
14 0.0
0.0 00 00 11
11
dc_users
dc_users 262
262 0.0
0.0 00 00 22
22
Copyright 2006 Kyle Hailey
Row Cache Lock - ASH
select
ash.session_id sid,
ash.blocking_session bsid,
nvl(o.object_name,to_char(CURRENT_OBJ#)) obj,
o.object_type otype,
CURRENT_FILE# filen,
CURRENT_BLOCK# blockn,
ash.SQL_ID,
nvl(rc.name,to_char(ash.p3)) row_cache
from v$active_session_history ash,
( select cache#, parameter name from v$rowcache ) rc,
all_objects o
SID BSID OBJ OTYPE FILEN BLOCKN SQL_ID ROW_CACHE
where event='row cache lock'
143 131 -1
and rc.cache#(+)=ash.p1 0 0 41y8w0sfqb61m dc_sequences
134 131(+)= ash.CURRENT_OBJ#
and o.object_id -1 0 0 dc_sequences
151 -1
and ash.session_state='WAITING' 0 0 dc_sequences
134 151
and ash.sample_time >-1 0
sysdate - &minutes/(60*24) 0 dc_sequences
131 151
Order by sample_time
-1 0 0 dc_sequences
151 -1 0 0 dc_sequences
Row 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
Share Cursors
Use bind variables
User cursor_sharing=force
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