Kill all sessions of a user logged from a particular machine in Oracle
spool KILL.SQL
SET HEAD ON
SET LINES 1000
COLUMN DATETIME FORMAT A12
COLUMN USR FORMAT A10
COL KILLSTMT FORMAT A48
COL MACHINE FORMAT A30
COL STAT FORMAT A8
col inst_id format 99
col oskill format a35
DEFINE machine='&machine';
SELECT
--A.SID,
--A.SERIAL#,
A.USERNAME USR,A.INST_ID,
LTRIM(RTRIM(TO_CHAR(A.LOGON_TIME,'DD/MM HH:MI'))) DATETIME,
-- B.SPID,
A.STATUS STAT,
'exec rc('''||'/bin/kill -9 '||b.spid||''')' oskill,
-- A.SERVER,
'alter system kill session'''||A.SID||','||A.SERIAL#||''' immediate;' KILLSTMT,
MACHINE,
'kill -9 '||b.spid,A.program
FROM GV$SESSION A,
GV$PROCESS B
WHERE A.MACHINE='&&MACHINE'
AND A.PADDR=B.ADDR
ORDER BY A.USERNAME,A.LOGON_TIME;
SPOOL KILL.OUT
SELECT
'alter system kill session'''||A.SID||','||A.SERIAL#||''' immediate;' KILLSTMT
FROM GV$SESSION A,
GV$PROCESS B
WHERE A.MACHINE='&&MACHINE'
AND A.PADDR=B.ADDR
ORDER BY A.USERNAME,A.LOGON_TIME;
SPOOL OFF
UNDEFINE MACHINE
After running the above script just execute
SQL>@KILL.SQL
SET HEAD ON
SET LINES 1000
COLUMN DATETIME FORMAT A12
COLUMN USR FORMAT A10
COL KILLSTMT FORMAT A48
COL MACHINE FORMAT A30
COL STAT FORMAT A8
col inst_id format 99
col oskill format a35
DEFINE machine='&machine';
SELECT
--A.SID,
--A.SERIAL#,
A.USERNAME USR,A.INST_ID,
LTRIM(RTRIM(TO_CHAR(A.LOGON_TIME,'DD/MM HH:MI'))) DATETIME,
-- B.SPID,
A.STATUS STAT,
'exec rc('''||'/bin/kill -9 '||b.spid||''')' oskill,
-- A.SERVER,
'alter system kill session'''||A.SID||','||A.SERIAL#||''' immediate;' KILLSTMT,
MACHINE,
'kill -9 '||b.spid,A.program
FROM GV$SESSION A,
GV$PROCESS B
WHERE A.MACHINE='&&MACHINE'
AND A.PADDR=B.ADDR
ORDER BY A.USERNAME,A.LOGON_TIME;
SPOOL KILL.OUT
SELECT
'alter system kill session'''||A.SID||','||A.SERIAL#||''' immediate;' KILLSTMT
FROM GV$SESSION A,
GV$PROCESS B
WHERE A.MACHINE='&&MACHINE'
AND A.PADDR=B.ADDR
ORDER BY A.USERNAME,A.LOGON_TIME;
SPOOL OFF
UNDEFINE MACHINE
After running the above script just execute
SQL>@KILL.SQL
Tags:
Oracle