How to Find which Session is Holding a Particular Library Cache Lock

How to Find which Session is Holding a Particular Library Cache Lock (Doc ID 122793.1)

METHOD 2: EXAMINE THE X$KGLLK TABLE

The X$KGLLK table (accessible only as SYS/INTERNAL) contains all the
library object locks (both held & requested) for all sessions and is more complete than the V$LOCK view although the column names don’t always reveal their meaning.

You can examine the locks requested (and held) by the waiting session by looking up the session address (SADDR) in V$SESSION and doing the following select:

select sid,saddr from v$session where event= 'library cache lock';

SID      	 SADDR
---------- 	--------
16  		572ed244
select kgllkhdl Handle,kgllkreq Request, kglnaobj Object
from x$kgllk where kgllkses = '572ed244'
and kgllkreq > 0;

HANDLE   REQUEST   OBJECT
-------- ---------- ------------------------------------------------------------
62d064dc          2 EMPLOYEES

This will show you the library cache lock requested by this session (KGLLKREQ > 0) where KGLNAOBJ contains the first 80 characters of the name of the object.The value in KGLLKHDL corresponds with the ‘handle address’ of the object in Method 1 Systemstate Analysis as shown above.

If we now match the KGLLKHDL with the handles of other sessions in X$KGLLK, that should give us the address of the blocking session.The session holding the lock will have KGLLKMOD > 0 as it is holding the lock.

select kgllkses saddr,kgllkhdl handle,kgllkmod mod,kglnaobj object
from x$kgllk lock_a
where kgllkmod > 0
and exists (select lock_b.kgllkhdl from x$kgllk lock_b
where kgllkses = '572ed244' /* blocked session */
and lock_a.kgllkhdl = lock_b.kgllkhdl
and kgllkreq > 0);

SADDR     			HANDLE   	MOD 							OBJECT
--------  		--------	 ----------    ------------------------------------------------------------
572eac94		  62d064dc          3  	   EMPLOYEES

If we look a bit further, we can then again match KGLLKSES with SADDR in v$session to find further information on the blocking session:

select sid,username,terminal,program from v$session where saddr = '572eac94'

	SID      		  USERNAME                			  TERMINAL 							PROGRAM
---------- ------------------------------ ------------------------------ ------------------------------------------------
	12       	   UserName                       	   pts/20 			   sqlplus@xxxxxx.forgotten.realms (TNS V1-V3)

In the same way, we can also find all the blocked sessions:

select sid,username,terminal,program from v$session
where saddr in
(select kgllkses from x$kgllk lock_a
 where kgllkreq > 0
 and exists (select lock_b.kgllkhdl from x$kgllk lock_b
             where kgllkses = '572eac94' /* blocking session */
             and lock_a.kgllkhdl = lock_b.kgllkhdl
             and kgllkreq = 0)
);

	SID        USERNAME                       TERMINAL               PROGRAM
----------- -------------------  -------------------------------	----------------------------------
	13         UserName                           abc/22               sqlplus@go.there.com (TNS V1-V3)
	16         UserName                           abc/7                sqlplus@go.there.com (TNS V1-V3)
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值