Wednesday, June 22, 2011

Check Blocking Sessions

The script below is used to show the blocking sessions in your database.
This query is valid for 10g and higher.

SELECT TO_CHAR (SYSDATE, 'DD-MON-YYYY HH24:MI:SS'),
s1.username blocker_user,
s1.machine blocker_machine,
s1.sid blocker_sid,
sqlt2.sql_text blocker_sql,
s2.username blocked_user,
s2.machine blocked_machine,
s2.sid blocked_sid,
sqlt1.sql_text blocked_sql
FROM v$lock l1,
v$session s1,
v$lock l2,
v$session s2,
v$sql sqlt1,
v$sql sqlt2
WHERE s1.sid = l1.sid
AND s2.sid = l2.sid
AND sqlt1.sql_id = s2.sql_id
AND sqlt2.sql_id = s1.prev_sql_id
AND l1.BLOCK = 1
AND l2.request > 0
AND l1.id1 = l2.id1
AND l2.id2 = l2.id2

No comments: