Skip to content

Instantly share code, notes, and snippets.

@dotmaik1
Created October 6, 2016 17:18
Show Gist options
  • Select an option

  • Save dotmaik1/e8e980012ba6ff78bf103fca217da901 to your computer and use it in GitHub Desktop.

Select an option

Save dotmaik1/e8e980012ba6ff78bf103fca217da901 to your computer and use it in GitHub Desktop.
Tablas y objetos bloqueados
--Para obtener una lista con los objetos bloqueados ejecucutados:
set lines 200
select substr(a.os_user_name,1,8) "OS User"
, substr(b.object_name,1,30) "Object Name"
, substr(b.object_type,1,8) "Type"
, e.process "PROCESS"
, e.sid
, e.serial#
, e.username
, e.osuser
, e.program
from v$locked_object a
, dba_objects b
, dba_rollback_segs c
, v$transaction d
, v$session e
, v$process p
where a.object_id = b.object_id
and a.xidusn = c.segment_id
and a.xidusn = d.xidusn
and a.xidslot = d.xidslot
and d.addr = e.taddr
and p.addr = e.paddr;
--otra forma de obtener los bloqueos
select 'SID ' || l1.sid ||' is blocking ' || l2.sid blocking
from v$lock l1, v$lock l2
where l1.block =1 and l2.request > 0
and l1.id1=l2.id1
and l1.id2=l2.id2;
--Para desbloquear uno de los objetos usamos alguna de las siguientes sentencias
ALTER SYSTEM DISCONNECT SESSION 'SID, SERIAL' IMMEDIATE;
--o bien
ALTER SYSTEM KILL SESSION '382,51891' IMMEDIATE;
--En el caso de que no finalice el proceso podemos matarlo desde el SO. Para ello utilizaremos lo siguiente desde un entorno linux:
kill -9 SPID
--Donde el SPID lo podemos obtener en la consulta escrita anteriormente.
SELECT decode(L.TYPE,'TM','TABLE','TX','Record(s)') TIPO_BLOQUEO,
decode(L.REQUEST,0,'NO','YES') ESPERA,
S.SECONDS_IN_WAIT SEGUNDOS_EN_ESPERA,
decode(l.LMODE,0,'none',1,'null (NULL)',2,'row-S (SS)',3,'row-X (SX)',4,'share (S)',5,'S/Row-X (SSX)',6,'exclusive (X)') MODO_BLOQUEO,
S.OSUSER USUARIO_SIST_OPERAT,
S.USERNAME USUARIO_BD,
S.PROCESS PROCESS_LOCKER,
S.MACHINE MAQUINA,
O.OBJECT_NAME OBJETO_BLOQUEADO,
O.OBJECT_TYPE OBJETO_TIPO,
concat(' ',s.PROGRAM) PROGRAMA,
O.OWNER PROPIETARIO,
S.SID,
S.SERIAL#,
(s.last_call_et /60) mins
FROM v$lock L,
dba_objects O,
v$session S
WHERE L.ID1 = O.OBJECT_ID
AND S.SID = L.SID
AND L.TYPE in ('TM','TX') ;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment