DB/Query

Lock 걸린 Object 찾는 sql

시처럼 음악처럼 2007. 12. 7. 12:24
SELECT a.SID
     , a.serial#
     , a.process
     , b.owner
     , b.object_name
     , DECODE (c.TYPE, 'TM', 'TABLE LOCK', 'TX', 'ROW LOCK', NULL) "LOCK LEVEL"
     , DECODE (c.lmode, 2, 'RS', 3, 'RX', 4, 'S', 5, 'SRX', 8, 'X', 'NO') "LOCK MODE"
     , DECODE (a.command, 2, 'INSERT', 3, 'SELECT', 6, 'UPDATE', 7, 'DELETE', 12, 'DROP TABLE', 26, 'LOCK TABLE', 'Unknown') "SQL"
     , a.state
     ,    TRIM (TO_CHAR (TRUNC (c.ctime / 3600, 0), '00')) || ':'
       || TRIM (TO_CHAR (TRUNC (MOD (c.ctime, 3600) / 60), '00')) || ':'
       || TRIM (TO_CHAR (ROUND (MOD (MOD (c.ctime, 3600), 60), 0), '00')) ctime
     , a.logon_time
     , a.program
     , a.osuser
     , a.terminal
  FROM v$session a
     , dba_objects b
     , v$lock c
     , v$locked_object l
 WHERE a.SID = c.SID
   AND b.object_id = c.id1
   AND b.object_id = l.object_id
;

select * from v$open_cursor
where sid = :sid  -- HOLDING세션
;

이렇게 찾은 세션을  kill 하는 방법 : http://blog.empas.com/garamsarang/16768578