Tuesday, January 4, 2011

Find locks in Oracle Tables

A lot of time we as developers see Oracle tables being locked. As we all share one dev database, the reason might be some long running query or service on some other workstation.

An easy way to find it out is through a query:


SELECT s1.username
'.'
s1.program
'@'
s1.machine
' ( SID='
s1.sid
' ) is blocking '
s2.username
'.'
s2.program
'@'
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: