SRS Library Cache Locks Report: Service Response Guide
SRS Library Cache Locks Report: Service Response Guide
..
..
..
..
OHSMON
Prepared by Akhlaq Qureshi Reference Note :417122.1
Library Cache Contains objects of various types required to parse and execute SQL
statements which includes tables, indexes, Pl/Sql packages and cursors. Library cache
pins and the associated row cache enqueue locks protect object definitions for the
duration of parse and execute calls.
Description
When a database object (table, view, procedure, function, package, package body, trigger,
index, cluster, synonym) is referenced during parsing or compiling of a SQL
(DML/DDL) or PL/SQL statement, the process parsing or compiling the statement
acquires the library cache lock in the correct mode. In Oracle8 the lock is held only until
the parse or compilation completes (for the duration of the parse call).
The session tries to find the load lock for the database object so that it can load the object.
The load lock is always obtained in Exclusive mode, so that no other process can load the
same object. If the load lock is busy the session will wait on this event until the lock
becomes available.
Library cache lock
This event controls the concurrency between clients of the library cache. Library cache
locks are heavily used, in particular by applications using PL/SQL or Advanced
2
..
..
..
.
Queuing. In ..many applications executing SQL units such as cursors, triggers, packages -
a good example of which is the Oracle E-Business Suite - a lot of time may be spent
waiting for library cache locks, mainly on tables and procedures, e.g. a package or
procedure has to be recompiled. For instance, recompiling a package body will acquire
several LB locks in share mode, but an LC lock in exclusive mode; recompiling the
whole package will also acquire LB locks in exclusive mode. Share mode library cache
locks are needed mainly during parse calls, to protect the objects on which the cursor
being parsed depends.
Library cache pin
This event manages library cache concurrency. Pinning an object causes the heaps to be
loaded into memory. If a client wants to modify or examine the object, the client must
acquire a pin after the lock.
Cause
"Gather Schema Statistics" concurrent request causing "library cache load" and
"library cache pin" events
Database EVENT 10235 level>2 can cause contention/waits for the Library
Cache (which is used to get a dump of the system stack for debugging
When a materialized view is compiled causing a DDL for the underlying object
Purge obsolete workflow runtime data
Explicit DDL on the database objects by concurrent requests
Step 1: L1 Run the libcache.pl Script to gather initial diagnostics.
Perl libcache.pl
Step 2 : L1 Refer the queries listed in appendix A in case the script doesn’t work
Step 3 : L1 Decides or takes the call based upon the result of the above two steps else
XFR the Tar to L2.
Step 4 : L2 Use the below queries for further analysis. The output of these queries can
be combined with traditional session details, sqltext, and wait event queries if required
for further analysis.
Run the Identifying the Waiting and the Holding sessions.
i)
select /*+ ordered */ w1.sid waiting_session,
3
h1.sid holding_session,
w.kgllktype lock_or_pin,
w.kgllkhdl address,
decode(h.kgllkmod, 0, 'None', 1, 'Null', 2, 'Share', 3, 'Exclusive',
'Unknown') mode_held,
decode(w.kgllkreq, 0, 'None', 1, 'Null', 2, 'Share', 3, 'Exclusive',
'Unknown') mode_requested
from sys.dba_kgllock w, sys.dba_kgllock h, v$session w1, v$session h1
where
(((h.kgllkmod != 0) and (h.kgllkmod != 1)
and ((h.kgllkreq = 0) or (h.kgllkreq = 1)))
and
(((w.kgllkmod = 0) or (w.kgllkmod= 1))
and ((w.kgllkreq != 0) and (w.kgllkreq != 1))))
and w.kgllktype = h.kgllktype
and w.kgllkhdl = h.kgllkhdl
and w.kgllkuse = w1.saddr
and h.kgllkuse = h1.saddr
/
Finding the Details about the Holding session.
ii)
col kgllkmod heading "lockmode"
col kgllkreq heading "reqmode"
col kglnaobj heading "objname"
select ses.sid, ses.serial#,lck.* from x$kgllk lck , v$session ses
where kgllkhdl in
(select kgllkhdl from x$kgllk where kgllkreq >0)
and lck.KGLLKUSE = ses.saddr
4
..
..
..
..
.
Order by lck.KGLNAOBJ
/
Sample output of the above query:
SID SERIAL# ADDR INDX INST_ID KGLLKADR KGLLKUSE KGLLKSES
---------- ---------- -------- ---------- ---------- -------- -------- --------
KGLLKSNM KGLLKHDL KGLLKPNC KGLLKPNS KGLLKCNT lockmode reqmode
---------- -------- -------- -------- ---------- ---------- ----------
KGLLKFLG KGLLKSPN KGLLKHTB KGLNAHSH KGLHDPAR KGLHDNSP
---------- ---------- -------- ---------- -------- ----------
USER_NAME
------------------------------
objname
------------------------------------------------------------
211 4481 0CA118F0 67778 1 7F104E18 57CC0128 57CC0128
211 68FB7DCC 00 00 0 0 3
0 722124 6CDDDF58 803564214 68FB7DCC 10
We thus have the SID, SERIAL# and the Instance number along with the object name
which is being locked.
Depending upon the criticality of the object in use we can take the decision either by
asking for the CRT or involving the L3.
Alter system kill session '211,4481';
The above query would give us all the required information in resolving the Library
Cache Lock.
5
Login into Oracle Applications as SYSADMIN user click on the Responsibility
select System Administrator Requests Views select Specific Requests in
the “Name” column enter “%Gather%” click on Find button.
In SQLPLUS, login as sysdba and type “show parameter event” for the EVENT
10235. If the event is not required, comment the “EVENT 10235” entry in init<SID>.ora
file.
Repeat the above Explicit DDL search by replacing “%Compile%” with the following
ones: “%Create%”, “%Alter%”, and “%Drop%”
From the tar statistics the alert is believed to exist for about 10 – 15 minutes and tar being
auto closed.
Note: Entry on the alert log file -- "WAITING FOR ROWCACHE ENQUEUE
LOCK!!!" has shown signs to cause disruption to application response.
Appendix A
1. Script shows the Library cache resource types
6
..
..
..
..
select
. substr(e.event, 1, 40) event,
e.time_waited,
e.time_waited / decode(
e.event,
'latch free', e.total_waits,
decode(e.total_waits - e.total_timeouts,0, 1,e.total_waits - e.total_timeouts)
) average_wait
from sys.v$system_event e,
sys.v$instance i
where e.event like 'library cache%';
3. Script shows Objects locked by Library Cache based on sessions detected above
4. Script shows Library Cache holders that sessions are waiting for
select sid,substr(event,1,30),wait_time
from v$session_wait
where sid in (select sid from x$kglpn , v$session
where KGLPNHDL in (select p1raw from v$session_wait
where wait_time=0 and event like 'library cache%')
and KGLPNMOD <> 0
and v$session.saddr=x$kglpn.kglpnuse );
7
-- end --