Поиск виновника блокировки в Oracle. Скрипт.
При возникновении ошибки
from DBA_DML_LOCKS,v$session where session_id = sid
select wait.sid waitSid, hold.sid holdSid, g.Mode_Requested, obj.name from dba_waiters g, v$session wait, v$session hold, sys.obj$ obj, v$session s where g.waiting_session=wait.SID and g.holding_session=hold.SID and s.sid = wait.SID and obj.OBJ#(+) = s.ROW_WAIT_OBJ#;
Чтобы узнать какая сессия блокирует пакет:
SELECT s.*, l.lock_type, l.mode_held, l.mode_requested, l.lock_id1, 'alter system kill session '''|| s.sid|| ','|| s.serial#|| ''' immediate;' kill_sid FROM dba_lock_internal l, v$session s AND UPPER(l.lock_id1) LIKE '%ПАКЕТ%' AND l.lock_type = 'Body Definition Lock'
select nvl(S.USERNAME,'Internal') username,
nvl(S.TERMINAL,'None') terminal,
L.SID||','||S.SERIAL# Kill,
U1.NAME||'.'||substr(T1.NAME,1,20) tab,
decode(L.LMODE,1,'No Lock',
2,'Row Share',
3,'Row Exclusive',
4,'Share',
5,'Share Row Exclusive',
6,'Exclusive',null) lmode,
decode(L.REQUEST,1,'No Lock',
2,'Row Share',
3,'Row Exclusive',
4,'Share',
5,'Share Row Exclusive',
6,'Exclusive',null) request
from V$LOCK L,
V$SESSION S,
SYS.USER$ U1,
SYS.OBJ$ T1
where L.SID = S.SID
and T1.OBJ# = decode(L.ID2,0,L.ID1,L.ID2)
and U1.USER# = T1.OWNER#
and S.TYPE != 'BACKGROUND'
order by 1,2,5
select
(select username from v$session where sid=a.sid) blocker,
a.sid,
' is blocking ',
(select username from v$session where sid=b.sid) blockee,
b.sid
from v$lock a, v$lock b
where a.block = 1
and b.request > 0
and a.id1 = b.id1
and a.id2 = b.id2