Site icon IT Tutorial

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

Hi,

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'
AND s.USERNAME <>'MSDEVECI';

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

https://ittutorial.org/oracle-kill-session-scripts-2/

https://ittutorial.org/oracle-kill-session-scripts-4/

 

 

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

https://ittutorial.org/oracle-database-performance-tuning-tutorial-12-what-is-the-automatic-sql-tuning-and-how-to-automated-sql-tuning/ 

Exit mobile version