1、通常kill session是由DBA手动处理的,要非常谨慎2、BACKGROUD sessions不能kill,否则会引起不可预知的错误3、ACTIVE sessions不能kill4、即使session是inactive的,也不表示就可以随便killSQL> select sid,serial#, username, status, type 2 FROM v$session; SID SERIAL# USERNAME STATUS TYPE---------- ---------- ------------------------------ -------- ---------- 1 1 ACTIVE BACKGROUND 2 1 ACTIVE BACKGROUND 3 1 ACTIVE BACKGROUND 4 1 ACTIVE BACKGROUND 5 1 ACTIVE BACKGROUND 6 1 ACTIVE BACKGROUND 7 21 KNUT INACTIVE USER 8 33 SYSTEM ACTIVE USER8 rows selected.如果你一定要的话,可以试试这样(kill 所有inactive sessions,太霸道了吧!):SQL> connect system/managerConnected.SQL> select sid,serial#, username, status, type 2 from v$session; SID SERIAL# USERNAME STATUS TYPE---------- ---------- ------------------------------ -------- ---------- 1 1 ACTIVE BACKGROUND 2 1 ACTIVE BACKGROUND 3 1 ACTIVE BACKGROUND 4 1 ACTIVE BACKGROUND 5 1 ACTIVE BACKGROUND 6 1 ACTIVE BACKGROUND 7 26 KNUT INACTIVE USER 8 35 SYSTEM ACTIVE USER 9 19 WMS INACTIVE USER9 rows selected.SQL> declare 2 cursor cur_sess is 3 select sid, serial# 4 from v$session 5 where status = 'INACTIVE' 6 and type != 'BACKGROUD'; 7 w_sid number; 8 w_serial number; 9 begin 10 open cur_sess; 11 loop 12 fetch cur_sess into w_sid,w_serial; 13 if cur_sess%notfound then 14 exit; 15 end if; 16 execute immediate 'alter system kill session '''||w_sid||','||w_serial||''''; 17 end loop; 18 end; 19 /PL/SQL procedure successfully completed.SQL> select sid,serial#, username, status, type 2 from v$session; SID SERIAL# USERNAME STATUS TYPE---------- ---------- ------------------------------ -------- ---------- 1 1 ACTIVE BACKGROUND 2 1 ACTIVE BACKGROUND 3 1 ACTIVE BACKGROUND 4 1 ACTIVE BACKGROUND 5 1 ACTIVE BACKGROUND 6 1 ACTIVE BACKGROUND 7 26 KNUT KILLED USER 8 35 SYSTEM ACTIVE USER 9 19 WMS KILLED USER9 rows selected.
标签:sql,kill,session