Friday, June 19, 2009

Determine the Locks in Oracle

To list out the Locked Objects

select c.owner, c.object_name, b.sid, b.serial#, b.status, b.osuser, b.machine ,a.process
from v$locked_object a , v$session b, dba_objects c
where
b.sid = a.session_id
and a.object_id = c.object_id;

Session Blocking Other session
Query 1:

select l1.sid, ' IS BLOCKING ', l2.sid
from v$lock l1, v$lock l2
where l1.block =1 and l2.request > 0
and l1.id1=l2.id1
and l1.id2=l2.id2;

Query 2:

select s1.username || '@' || s1.machine
|| ' ( SID=' || s1.sid || ' ) is blocking '
|| s2.username || '@' || s2.machine || ' ( SID=' || s2.sid || ' ) ' AS blocking_status
from v$lock l1, v$session s1, v$lock l2, v$session s2
where s1.sid=l1.sid and s2.sid=l2.sid
and l1.BLOCK=1 and l2.request > 0
and l1.id1 = l2.id1
and l2.id2 = l2.id2

No comments:

Post a Comment