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/ 

About Mehmet Salih Deveci

I am Founder of SysDBASoft IT and IT Tutorial and Certified Expert about Oracle & SQL Server database, Goldengate, Exadata Machine, Oracle Database Appliance administrator with 10+years experience.I have OCA, OCP, OCE RAC Expert Certificates I have worked 100+ Banking, Insurance, Finance, Telco and etc. clients as a Consultant, Insource or Outsource.I have done 200+ Operations in this clients such as Exadata Installation & PoC & Migration & Upgrade, Oracle & SQL Server Database Upgrade, Oracle RAC Installation, SQL Server AlwaysOn Installation, Database Migration, Disaster Recovery, Backup Restore, Performance Tuning, Periodic Healthchecks.I have done 2000+ Table replication with Goldengate or SQL Server Replication tool for DWH Databases in many clients.If you need Oracle DBA, SQL Server DBA, APPS DBA,  Exadata, Goldengate, EBS Consultancy and Training you can send my email adress [email protected].-                                                                                                                                                                                                                                                 -Oracle DBA, SQL Server DBA, APPS DBA,  Exadata, Goldengate, EBS ve linux Danışmanlık ve Eğitim için  [email protected] a mail atabilirsiniz.

Leave a Reply

Your email address will not be published. Required fields are marked *