0% found this document useful (0 votes)
108 views3 pages

Multiple Session Killing

This document provides instructions for killing inactive, active, and Oracle Data Integrator (ODI) sessions in an Oracle database. It describes using SQL queries to generate scripts that issue ALTER SYSTEM KILL SESSION commands to terminate sessions matching specified criteria. It also provides notes on executing these scripts on multiple Oracle instances in a Real Application Clusters (RAC) configuration.

Uploaded by

Biplab Parida
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as RTF, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
108 views3 pages

Multiple Session Killing

This document provides instructions for killing inactive, active, and Oracle Data Integrator (ODI) sessions in an Oracle database. It describes using SQL queries to generate scripts that issue ALTER SYSTEM KILL SESSION commands to terminate sessions matching specified criteria. It also provides notes on executing these scripts on multiple Oracle instances in a Real Application Clusters (RAC) configuration.

Uploaded by

Biplab Parida
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as RTF, PDF, TXT or read online on Scribd
You are on page 1/ 3

To kill all inactive session in Database

sqlplus "/as sysdba"

SQL>set heading off

SQL>spool kill12.sql

SELECT 'ALTER SYSTEM KILL SESSION '||''''||sid ||','|| serial#||''''||' immediate;'


FROM v$session
WHERE status ='INACTIVE' and type != 'BACKGROUND';

SQL>spool off

then execute the sql script

SQL> @kill12.sql

select 'alter system kill session '''||sid||','||serial#||''' immediate;' from GV$SESSION where
type='USER' and username is not null and username not in ('DBA1','DBSNMP','PUBLIC','SYS','SYSTEM')
and username='REPUSER' and machine in ('jbosschkhrtbt1.ds.indianoil.in','jws2.ds.indianoil.in') and
status='INACTIVE';

Note:For RAC Database where we have more than 1 instances,we need to follow step 2 on all the Oracle
instances.

To kill all active session in Database:

sqlplus "/as sysdba"

SQL>set heading off


SQL>spool kill_active.sql

SELECT 'ALTER SYSTEM KILL SESSION '||''''||sid ||','|| serial#||''''||' immediate;'


FROM v$session
WHERE status ='ACTIVE' and type != 'BACKGROUND';

SQL>spool off

Note:For RAC Database where we have more than 1 instances,we need to follow step 2 on all the Oracle
instances.
To kill all ODI sessions in Database:
sqlplus "/as sysdba"

SQL>set heading off


SQL>set lines 1000
SQL>set linesize 2000
SQL>spool kill_active.sql

SELECT 'ALTER SYSTEM KILL SESSION '||''''||sid ||','|| serial#||''''||' immediate;'


FROM v$session
WHERE status ='ACTIVE' AND USERNAME LIKE '%ODI%';

SQL>spool off

Note:For RAC Database where we have more than 1 instances,we need to follow step 2 on all the Oracle
instances.

How to get the list of Users and Processes running ODI sessions:

SQL> SET LINESIZE 100


COLUMN spid FORMAT A10
COLUMN username FORMAT A10
COLUMN program FORMAT A45

SELECT s.inst_id,s.sid,s.serial#,p.spid, s.username, s.program


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 S.USERNAME LIKE '%ODI%';

How to kill a particular object blocking session:

1.Find the tables(objects) which are locked:

SELECT o.owner, o.object_name, o.object_type, o.last_ddl_time, o.status, l.session_id,


l.oracle_username, l.locked_mode
FROM dba_objects o, gv$locked_object l
WHERE o.object_id = l.object_id and o.object_name='XX_OBJECT';

2.Killing the session holding the lock:

--Find the serial# for the sessions holding the lock:

SQL> select SERIAL# from v$session where SID=667;


SERIAL#
----------
21091

SQL> alter system kill session '667,21091';

Note:For RAC Database where we have more than 1 instances,we need to follow step 2 on all the Oracle
instances.

Select 'alter system kill session '''||Sid||','||Serial#||''' immediate;' From Gv$session Where
Blocking_Session Is Not Null And Inst_Id='1' ;

select 'alter system kill session '''||sid||','||serial#||''' immediate;' from GV$SESSION where
blocking_session is not null and inst_id='2' ;

--------------------------------------------------------

select 'alter system kill session '''||sid||','||SERIAL#||''' immediate;' from GV$SESSION where
USERNAME='SMS' and STATUS='INACTIVE' and INST_ID='1';

select 'alter system kill session '''||sid||','||serial#||''' immediate;' from gv$session where
username='SMS' and status='INACTIVE' And Inst_Id='2';

You might also like