Killing Oracle Sessions
The SQL*Plus Approach
Sessions can be killed from within oracle using theALTER SYSTEM KILL SESSION syntax.First identify the offending session as follows:
SELECT s.sid,
s.serial#,
s.osuser,
s.program
FROM v$session s;
SID SERIAL# OSUSER PROGRAM
---------- ---------- ------------------------------ ---------------
1 1 SYSTEM ORACLE.EXE
2 1 SYSTEM ORACLE.EXE
3 1 SYSTEM ORACLE.EXE
4 1 SYSTEM ORACLE.EXE
5 1 SYSTEM ORACLE.EXE
6 1 SYSTEM ORACLE.EXE
20 60 SYSTEM DBSNMP.EXE
43 11215 USER1 SQLPLUSW.EXE
33 5337 USER2 SQLPLUSW.EXE
The SID and SERIAL# values of the relevant session can then be substituted into the following statement:In some situations the Oracle.exe is not able to kill the session immediately. In these cases the session will be "marked for kill". It will then be killed as soon as possible.SQL> ALTER SYSTEM KILL SESSION 'sid,serial#';
Issuing the
ALTER SYSTEM KILL SESSION command is the only safe way to kill an Oracle session. If the marked session
persists for some time you may consider killing the process at the operating system level, as explained below. Killing OS processes
is dangerous and can lead to instance failures, so do this at your own peril.It is possible to force the kill by adding the
IMMEDIATE keyword:This should prevent you ever needing to use theSQL> ALTER SYSTEM KILL SESSION 'sid,serial#' IMMEDIATE;
orakill.exe in Windows, or the kill command in UNIX/Linux.The NT Approach
To kill the session via the NT operating system, first identify the session as follows:
SELECT s.sid,
p.spid,
s.osuser,
s.program
FROM v$process p,
v$session s
WHERE p.addr = s.paddr;
SID SPID OSUSER PROGRAM
---------- --------- ------------------------------ ---------------
1 310 SYSTEM ORACLE.EXE
2 300 SYSTEM ORACLE.EXE
3 309 SYSTEM ORACLE.EXE
4 299 SYSTEM ORACLE.EXE
5 302 SYSTEM ORACLE.EXE
6 350 SYSTEM ORACLE.EXE
20 412 SYSTEM DBSNMP.EXE
43 410 USER1 SQLPLUSW.EXE
33 364 USER2 SQLPLUSW.EXE
The SID and SPID values of the relevant session can then be substituted into the following command issued from the command line:The session thread should be killed immediately and all resources released.C:> orakill ORACLE_SID spid
The UNIX Approach
To kill the session via the UNIX operating system, first identify the session in the same way as the NT approach, then substitute the relevantSPID into the following command:If in doubt check that the% kill -9 spid
SPID matches the UNIX PROCESSID shown using:The session thread should be killed immediately and all resources released.% ps -ef | grep ora
For further information see:
Hope this helps. Regards Tim...
Back to the Top.
