How to kill Inactive sessions in ORACLE?
step 1. Find total session details.
SQL> select status,count(*) from v$session group by status;
Step 2. Find sid & serial# for inactive sessions.
SQL> SELECT sid, serial#, status, username FROM v$session where status='INACTIVE';
Step 3. Kill the session using the below command.
SQL> ALTER SYSTEM KILL SESSION 'sid,serial#' IMMEDIATE;
If you have multiple sessions for killing, you must prepare the script.
Script for all sessions:
SQL> SELECT 'ALTER SYSTEM KILL SESSION '''||sid||','||serial#||''' IMMEDIATE;' FROM v$session;
The script is only for Inactive sessions:
SQL> SELECT 'ALTER SYSTEM KILL SESSION '''||sid||','||serial#||''' IMMEDIATE;' FROM v$session
where status='INACTIVE';
The above queries will write the queries for you to kill Inactive sessions. It makes your task very easy.
Tags:
session