At times, you end up wanting to Kill active Session in Oracle Database in order for certain reasons. Some of those could be;
- You want to Kill an active session which has been running long and is never ending.
- You want to Kill an active session which is deadlocked by another process.
- You want Kill an active session which is running longer and is occupying more space in Oracle’s temporary database
Read this if you want to check active sessions in Oracle database
To kill an active Session in Oracle Database, you must use ALTER SYSTEM KILL SESSION keywords.
ALTER SYSTEM KILL SESSION <Session ID or Serial Number>
Session ID is the sid and Serial Number is the serial# from the v$session Oracle table.
ALTER SYSTEM KILL SESSION '1203,40428';
Below is a sample data from the v$session table which shows the active sessions in Oracle:
You must be having DBA privilege to execute a KILL command in Oracle database. You would either need to get the access in order to execute or request your DBA to run this command to Kill the active session that you want to kill.
Sometimes, the KILL command does not kill the oracle session itself in scenarios where it would wait for the resources be released.
If you want to kill a session instantly, you must include IMMEDIATE keyword in your ALTER SYSTEM KILL SESSION command, like below.
ALTER SYSTEM KILL SESSION <Session ID or Serial Number> IMMEDIATE;
ALTER SYSTEM KILL SESSION '1203,40428' IMMEDIATE;
Thank you for reading.
Please visit https://www.sql-scripts.com for anything that is related SQL Queries, Scripts and How to stuffs.