#Shell Script for kill the inactive sessions of the specified schema

#Single Instance Database
SELECT
‘ALTER SYSTEM KILL SESSION  ‘ ||chr(39) ||s.sid||chr(44)||s.serial#||chr(39)||’;’
FROM
V$SESSION s,V$PROCESS p
WHERE s.paddr = p.addr
AND s.username IS NOT NULL
AND s.type != ‘BACKGROUND’
AND s.username = ‘SCOTT’
AND s.module <> ‘JDBC Thin Client’
AND s.last_call_et/3600 > 1
and s.status=’INACTIVE’ order by logon_time;

#RAC Database
SET PAGESIZE 1000
SET HEAD OFF;
SELECT  ‘ALTER SYSTEM KILL SESSION  ‘ ||chr(39) ||s.sid||chr(44)||s.serial#||chr(39)||’;’
FROM   gv$session s
JOIN gv$process p ON p.addr = s.paddr AND p.inst_id = s.inst_id
WHERE  s.type != ‘BACKGROUND’
AND STATUS<>’ACTIVE’
AND s.username = ‘SCOTT’;

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s