Thursday, March 6, 2014

Auto Kill Bloking Session on Oracle Database with SQL

DECLARE   
  CURSOR c1 IS select process,sid,serial#, blocking_session from v$session where blocking_session is not null;  
  i NUMBER:= 0;
BEGIN
  FOR e_rec IN c1 LOOP
  i:= i+1;
    EXECUTE immediate 'ALTER SYSTEM KILL SESSION ' ||''''|| e_rec.sid ||','|| e_rec.serial# ||''' ';
  END LOOP;
END;
/  

1 comment:

  1. This kills the BLOCKED sessions, not the blocking session!

    ReplyDelete