Who is locking the record ?

The following query might start you off on the right path. It tells you "who is waiting for who". This isn't quite what you are after as it is only useful if one user is blocked by another... check out the system views and maybe you'll find one that satisfies your requirement.

SELECT substr(s1.username,1,12) "WaitingUser",
substr(s1.osuser,1,8) "WaitingOSUser",
substr(to_char(w.session_id),1,5) "WaitingSid",
P1.spid "WaitingPID",
substr(s2.username,1,12) "HoldingUser",
substr(s2.osuser,1,8) "HoldingOSUser",
substr(to_char(h.session_id),1,5) "HoldingSid",
P2.spid "HoldingPID"
FROM sys.v_$process P1, sys.v_$process P2,
sys.v_$session S1, sys.v_$session S2,
sys.dba_lock w, sys.dba_lock h
WHERE h.mode_held != 'None'
AND h.mode_held != 'Null'
AND w.mode_requested != 'None'
AND w.lock_type (+) = h.lock_type
AND w.lock_id1 (+) = h.lock_id1
AND w.lock_id2 (+) = h.lock_id2
AND w.session_id = S1.sid (+)
AND h.session_id = S2.sid (+)
AND S1.paddr = P1.addr (+)
AND S2.paddr = P2.addr (+)
 
Back
Top