Sunday, June 14, 2009

How to kill a not responding session in Oracle

Using SQL Plus

Sessions can be killed using 'ALTER SYSTEM KILL SESSION' command which are running within oracle.

First you need to identify the offending or not responding session using following SQL statement.
SELECT t.sid,
t.serial#,
t.username,
t.osuser,
t.program,
t.type
FROM v$session t;


After identifying the correct session it can be killed using following command. The 'SID' and 'SERIAL#' values of the relevant session should be substituted into the command:
ALTER SYSTEM KILL SESSION 'sid,serial#';

Ex:
SQL> ALTER SYSTEM KILL SESSION '140,428';

In some cases the Oracle.exe will not be able to kill the session
immediately. In such cases the session will be "marked for kill". It
will then be killed as soon as possible.

It is possible to force the kill by appending the 'IMMEDIATE' keyword,
SQL> ALTER SYSTEM KILL SESSION '140,428' IMMEDIATE;
Issuing the 'ALTER SYSTEM KILL SESSION' command is
the only safe way to kill an Oracle session. If the session which is marked
to kill persists for some time you may consider killing the process at the
operating system level. Killing OS processes
is dangerous and can lead to instant failures or unexpected results, so do this at your own will.