Site icon IT Tutorial

Oracle Kill Session Scripts -3 and gv$session, gv$lock view


Sometimes application developers or client offers you to kill any session or sessions group like SQL Net Client, or JDBC Client sessions, RMAN sessions or All sessions.


gv$lock view lists the locks currently held by the Oracle Database and outstanding requests for a lock or latch.

You can list the locks running the following command.

SQL> select * from gv$lock;

Sometimes you want to kill all users sessions except Application user. You can use following query to do this task.

SELECT 'kill -9 ' || p.spid, s.username,
       'alter system kill session ''' || SID || ',' || s.serial# ||',@'||p.inst_id|| ''';'
  FROM gv$session s, gv$process p
 WHERE s.paddr = p.addr(+)
and s.TYPE ='USER'

You can execute result of above query to kill sessions.



You may want to kill some users sessions which is still executing more than 300 seconds, then you can use following useful Oracle DBA script.


SELECT 'kill -9 ' || p.spid, s.username,
       'alter system kill session ''' || SID || ',' || s.serial# || ''';'
  FROM v$session s, v$process p
 WHERE s.paddr = p.addr(+)
       AND s.SID IN (
   select sid
  from v$sql_monitor where status ='EXECUTING'  and elapsed_time/1000000> 300 
  and username in ('MEHMET','SALIH'))



You can read other Kill Session Scripts in Oracle.

Oracle Kill Session Scripts -1



Do you want to learn Oracle Database Performance Tuning detailed, then read the following articles. 

Exit mobile version