Link to home
Create AccountLog in
Avatar of kingno1
kingno1

asked on

Killing Inactive Oracle database sessions

Hello, I have installed a database with 250 sessions specified in the init file.
I still see a lot of inactive sessions in the database once in a while.
I would like to kill/terminate any sessions that are inactive for 2 hours. How do I achieve this?
Lets say use scott has 10 sessions and only 2 of them are inactive for over 2 hours, I would like to kill only those 2.
Please suggest.
Thank you.
Avatar of Naveen Kumar
Naveen Kumar
Flag of India image

try the below. This query will generate kill session commands as the output and you need to just execute those commands generated in the output.

 select 'alter system kill session '|| sid || ',' || serial# || ';'
 from v$session
 where user ='SCOTT' -- i have used SCOTT for example , change it accordingly if you want some other user
 and status ='INACTIVE' -- to only get inactive sessions

thanks
ASKER CERTIFIED SOLUTION
Avatar of Naveen Kumar
Naveen Kumar
Flag of India image

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
SOLUTION
Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
Avatar of kingno1
kingno1

ASKER

Thank You.