单实例无脑批量kill session场景:测试或预生产产生大量死锁时,采取无脑批量kill session操作脚本。备注:小工具备录一下
单实例无脑批量kill session declare cursor mycur is select b.username,b.sid,b.serial#,logon_time from v$locked_object a,v$session b where a.session_id = b.sid order by b.logon_time; newcount number; begin for cur in mycur loop select count(1) into newcount from v$locked_object a,v$session b where a.session_id = b.sid and b.sid=cur.sid and b.serial#=cur.SERIAL# order by b.logon_time; if newcount>=1 then execute immediate ( 'alter system kill session '''||cur.sid || ','|| cur.SERIAL# ||''' '); end if; end loop; end;
