Find Blocked Sessions

1. find blocked sessions and blocking session

select l1.sid “blocking session”, l2.sid “blocked session”
from v$lock l1, v$lock l2
where l1.sid != l2.sid and l1.id1 = l2.id1 and l1.id2 = l2.id2 and
l2.request > 0 and l1.block = 1;

2. find how long the blocked session is waiting:

blocking_session “blocking_session”,
sid “blocked_session”,
serial# “blocked_serial#”,
seconds_in_wait/60 “wait_time(min)”
from v$session
where blocking_session is not null
order by blocking_session;

3. find which SQL command is waiting

select s.sid, s.serial# ser#, s.process os_id, s.status, sql.sql_fulltext
from v$session s, v$sql sql, v$process p
s.sql_id=sql.sql_id and
s.sql_hash_value=sql.hash_value and
s.paddr=p.addr and

4. resolving locks
If the Blocking session do not issue COMMIT, ROLLBACK or disconnects from the database,
Then you can kill that session — After having the approval from the owner of the sql such application team if is involved user/app schema, DBA/Oracle Support if the sql is database internal).

alter system kill session ‘SID,Serial#’;

[mai mult...]