Monday, July 6, 2015

How to find and kill sessions what are locking the tables

Normal Tables

Find the locking sessions from following 

select s1.username || '@' || s1.machine
|| ' ( SID=' || s1.sid || ' ) is blocking '
|| s2.username || '@' || s2.machine || ' ( SID=' || s2.sid || ' ) ' AS blocking_status
from v$lock l1, v$session s1, v$lock l2, v$session s2
where s1.sid=l1.sid and s2.sid=l2.sid
and l1.BLOCK=1 and l2.request > 0
and l1.id1 = l2.id1
and l2.id2 = l2.id2 ;


Get Session details from this sql  
example : if session id = 421select * from V$Session where sid = 421; 

Kill Sessions from following
alter system kill session '421,7951';



Temporary Tables

Geth the out put from following sql and run the out put.

SELECT 'ALTER SYSTEM KILL SESSION '''||SID||','||SERIAL#||''';' FROM V$SESSION WHERE SID IN (
SELECT SID FROM V$LOCK
WHERE id1 = (SELECT object_id FROM all_objects WHERE owner ='CMDC' AND object_name ='TMP_EQUIPSTATUS'));




Lock Objects 


select C.OWNER,
  C.OBJECT_NAME,
  C.OBJECT_TYPE,
  B.sid,
  B.SERIAL#,
  B.STATUS,
  B.OSUSER,
  B.MACHINE
from V$LOCKED_OBJECT a ,
  V$SESSION B,
  DBA_OBJECTS C
where B.sid     = a.SESSION_ID
and a.OBJECT_ID = C.OBJECT_ID;

No comments:

Post a Comment