天天看點

實作批量Kill Oracle會話程序

查詢某個使用者會話 :

select username,sid,serial# from v$session t where upper(t.username) = 'test';

查系統中表空間使用者占用的程序 :

select p.spid,s.sid,s.serial# FROM v$session s,v$process p WHERE p.addr=s.paddr and upper(s.username) = 'test';

删除單個使用者會話程序:

alter system kill session 'sid,serial#';

如果使用alter kill殺不掉使用者會話,則需要在系統執行kill -9指令将其殺掉。

批量生成KILL會話的SQL語句:

SELECT 'alter system kill session ''' || ta.sid || ',' || ta.serial# || ''';',

'alter system disconnect session ''' || ta.sid || ',' || ta.serial# || ''' immediate;',
   'host orakill ' || tc.instance_name || ' ' || tb.spid,
   'kill -9 ' || tb.spid,
   tb.spid,
   ta.osuser,
   tb.program,
   ta.terminal,
   ta.program           

FROM v$session ta, v$process tb, v$instance tc

WHERE tb.addr = ta.paddr

AND ta.sid = &yoursid;