SQLMentor // articles

How to Kill a Session in Oracle

Find the stuck or blocking session in V$SESSION, then end it with ALTER SYSTEM KILL SESSION — here's the exact query, how to spot what's blocking what, and the forceful fallback for sessions that won't die cleanly.

Finding and ending a stuck or blocking session

When a session is stuck, running away with resources, or blocking other sessions, the fix is usually the same two-step process: find it in V$SESSION, then end it with ALTER SYSTEM KILL SESSION.

Step 1: find the session

SID and SERIAL# together uniquely identify a session — you need both.

SELECT sid, serial#, username, status, machine, program
FROM v$session
WHERE username IS NOT NULL
ORDER BY logon_time;

Finding what's blocking what

BLOCKING_SESSION shows the SID currently holding a lock another session is waiting on.

SELECT sid, serial#, username, blocking_session, event, seconds_in_wait
FROM v$session
WHERE blocking_session IS NOT NULL;

Step 2: kill it

Standard kill, waits for the session to notice and clean up.

ALTER SYSTEM KILL SESSION '138,29481';   -- 'sid,serial#'

When KILL SESSION doesn't seem to work

KILL SESSION marks the session for termination, but a session waiting on something outside the database — a stalled network call, for instance — may not notice immediately and can sit in a KILLED state for a while. If it's genuinely stuck, ALTER SYSTEM DISCONNECT SESSION '138,29481' IMMEDIATE; forcibly disconnects at the OS process level instead of waiting for the session to clean up on its own.

Frequently asked questions

What's the difference between KILL SESSION and DISCONNECT SESSION?
KILL SESSION marks a session to terminate at its next opportunity to notice — usually fast, but a session stuck on something outside the database might not notice right away. DISCONNECT SESSION IMMEDIATE forcibly ends the session's server process at the OS level without waiting.
Do I need a special privilege to kill a session?
Yes — ALTER SYSTEM privilege (typically held by DBA roles) is required to kill or disconnect sessions. Regular application users cannot kill arbitrary sessions.
How do I find what a blocked session is waiting for?
Join V$SESSION to V$SESSION_WAIT (or check the EVENT and SECONDS_IN_WAIT columns directly on V$SESSION in modern versions) to see the specific wait event — lock waits typically show as 'enq: TX - row lock contention' or similar.
Will killing a session roll back its uncommitted changes?
Yes. Ending a session with uncommitted work triggers a rollback of that transaction using undo, the same as if the session had issued ROLLBACK itself.