Kill or Disconnect Oracle Session in Single Instance & RAC

Share:
Article Summary

Learn how to kill or disconnect an Oracle session in Single Instance and RAC environments with simple, effective steps.

Managing sessions in Oracle databases is essential for database administrators. This guide provides concise commands for both single-instance and RAC (Real Application Clusters) environments to kill or disconnect sessions forcefully or gracefully.

Single-Instance Oracle

To kill a session immediately:

ALTER SYSTEM KILL SESSION 'SID,SERIAL#' IMMEDIATE;

To disconnect a session gracefully (waiting for transactions to complete):

ALTER SYSTEM DISCONNECT SESSION 'SID,SERIAL#' POST_TRANSACTION;

To disconnect a session immediately:

ALTER SYSTEM DISCONNECT SESSION 'SID,SERIAL#' IMMEDIATE;

Oracle RAC

To kill a session in RAC, include the INST_ID for the target instance:

SELECT 'ALTER SYSTEM KILL SESSION ''' || sid || ',' || serial# || ',@' || inst_id || ''' IMMEDIATE;'
FROM gv$session
WHERE sid = &sid AND serial# = &serial;

For active sessions only:

SELECT 'ALTER SYSTEM KILL SESSION ''' || sid || ',' || serial# || ',@' || inst_id || ''' IMMEDIATE;'
FROM gv$session
WHERE sid = &sid AND serial# = &serial AND status = 'ACTIVE';

To disconnect a session in RAC:

ALTER SYSTEM DISCONNECT SESSION ‘SID,SERIAL#,@INST_ID’ IMMEDIATE;

Key Notes

  1. IMMEDIATE: Use for forceful termination or disconnection.
  2. POST_TRANSACTION: Use for graceful disconnection.
  3. RAC: Always include INST_ID to specify the instance in multi-instance environments.

These commands enable efficient management of sessions across both single-instance and RAC Oracle environments.

Was this helpful?

Written by

W3buddy
W3buddy

Explore W3Buddy for in-depth guides, breaking tech news, and expert analysis on AI, cybersecurity, databases, web development, and emerging technologies.