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.