{"id":4802,"date":"2025-09-02T05:40:30","date_gmt":"2025-09-02T05:40:30","guid":{"rendered":"https:\/\/w3buddy.com\/?post_type=cposts&#038;p=4802"},"modified":"2025-09-02T05:40:31","modified_gmt":"2025-09-02T05:40:31","slug":"oracle-kill-session-alter-system-kill-session","status":"publish","type":"cposts","link":"https:\/\/w3buddy.com\/blog\/notes\/oracle-dba-d2d-tasks\/oracle-kill-session-alter-system-kill-session\/","title":{"rendered":"Oracle Kill Session \u2013 ALTER SYSTEM KILL Session"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">Database administrators often face sessions that hang, lock resources, or consume unnecessary memory. Oracle provides multiple ways to terminate or disconnect sessions, depending on the scenario. In this guide, we\u2019ll cover <strong><code>ALTER SYSTEM KILL SESSION<\/code><\/strong> and <strong><code>ALTER SYSTEM DISCONNECT SESSION<\/code><\/strong>, explain the syntax in detail, and provide examples for both single-instance and RAC (Real Application Clusters) environments.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Understanding the Syntax<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Oracle uses the following syntax to end sessions:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>ALTER SYSTEM { \n    DISCONNECT SESSION 'integer1, integer2' &#91; POST_TRANSACTION ] \n    | KILL SESSION 'integer1, integer2 &#91;,@integer3]' \n} &#91; IMMEDIATE | NOREPLAY ];<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Explanation of Each Component<\/h3>\n\n\n\n<figure class=\"wp-block-table has-small-font-size\"><table><thead><tr><th>Component<\/th><th>Description<\/th><\/tr><\/thead><tbody><tr><td><code>ALTER SYSTEM<\/code><\/td><td>A system-level command used to modify database behavior, here for terminating or disconnecting sessions.<\/td><\/tr><tr><td><code>KILL SESSION 'SID, SERIAL# [, @INST_ID]'<\/code><\/td><td>Marks a session for termination, rolls back uncommitted transactions, and releases locks.<\/td><\/tr><tr><td><code>DISCONNECT SESSION 'SID, SERIAL#'<\/code><\/td><td>Disconnects a session by killing the server process or virtual circuit.<\/td><\/tr><tr><td><code>POST_TRANSACTION<\/code><\/td><td>Optional for DISCONNECT; disconnects after the current transaction completes (graceful).<\/td><\/tr><tr><td><code>IMMEDIATE<\/code><\/td><td>Forces rollback and resource release instantly.<\/td><\/tr><tr><td><code>NOREPLAY<\/code><\/td><td>Prevents session recovery under Application Continuity (AC).<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\">Placeholders Explained<\/h3>\n\n\n\n<figure class=\"wp-block-table has-small-font-size\"><table><thead><tr><th>Placeholder<\/th><th>Meaning<\/th><\/tr><\/thead><tbody><tr><td><code>SID<\/code> (<code>integer1<\/code>)<\/td><td>Session ID, unique per session in the instance.<\/td><\/tr><tr><td><code>SERIAL#<\/code> (<code>integer2<\/code>)<\/td><td>Serial number of the session, used with SID to uniquely identify a session.<\/td><\/tr><tr><td><code>@INST_ID<\/code> (<code>integer3<\/code>)<\/td><td>Optional instance ID for RAC; specifies which instance the session belongs to.<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">Kill Session vs Disconnect Session<\/h2>\n\n\n\n<figure class=\"wp-block-table has-small-font-size\"><table><thead><tr><th>Command<\/th><th>Behavior<\/th><\/tr><\/thead><tbody><tr><td><code>KILL SESSION<\/code><\/td><td>Marks session for termination, waits for ongoing transactions unless <code>IMMEDIATE<\/code> is specified.<\/td><\/tr><tr><td><code>DISCONNECT SESSION<\/code><\/td><td>Terminates the server process or virtual circuit; can be immediate or post-transaction.<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>KILL SESSION<\/strong> \u2192 Less aggressive, preferred for normal terminations.<\/li>\n\n\n\n<li><strong>DISCONNECT SESSION<\/strong> \u2192 More forceful, use carefully.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Practical Examples with Randomized Placeholders<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">1. Normally Kill a Session in the Current Instance<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Retrieve session identifiers from <code>V$SESSION<\/code>:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>SELECT sid, serial# \nFROM v$session \nWHERE username = 'HR_APP01' \n  AND lower(machine) = lower('LAPTOP-XY12AB') \n  AND lower(program) LIKE lower('%sqlplus%');<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Example output:<\/p>\n\n\n\n<figure class=\"wp-block-table has-small-font-size\"><table><thead><tr><th>SID<\/th><th>SERIAL#<\/th><\/tr><\/thead><tbody><tr><td>301<\/td><td>45211<\/td><\/tr><tr><td>402<\/td><td>87452<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">Kill sessions:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>ALTER SYSTEM KILL SESSION '301, 45211';\nALTER SYSTEM KILL SESSION '402, 87452';<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">2. Kill a Session in RAC (Specify Instance)<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Use <code>GV$SESSION<\/code> for RAC:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>SELECT 'ALTER SYSTEM KILL SESSION ''' || sid || ', ' || serial# || ', @' || inst_id || ''';' AS stmt\nFROM gv$session\nWHERE username = 'HR_APP01'\n  AND lower(machine) = lower('LAPTOP-XY12AB')\n  AND lower(program) LIKE lower('%sqlplus%');<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Example output:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>ALTER SYSTEM KILL SESSION '1203, 3345, @2';\nALTER SYSTEM KILL SESSION '1804, 7721, @3';<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">3. Immediately Kill a Session<\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Current instance:<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>ALTER SYSTEM KILL SESSION '301, 45211' IMMEDIATE;<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li>RAC instance:<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>ALTER SYSTEM KILL SESSION '1203, 3345, @2' IMMEDIATE;<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">4. Kill Session Without Application Continuity Recovery<\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Current instance:<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>ALTER SYSTEM KILL SESSION '301, 45211' NOREPLAY;\n<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li>RAC instance:<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>ALTER SYSTEM KILL SESSION '1203, 3345, @2' NOREPLAY;<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">5. Disconnect a Session<\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Normally (after transaction completes):<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>ALTER SYSTEM DISCONNECT SESSION '301, 45211' POST_TRANSACTION;<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Immediately (forceful termination):<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>ALTER SYSTEM DISCONNECT SESSION '301, 45211' IMMEDIATE;<\/code><\/pre>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p class=\"wp-block-paragraph\"><strong>Important:<\/strong> Always specify <code>POST_TRANSACTION<\/code> or <code>IMMEDIATE<\/code> with <code>DISCONNECT SESSION<\/code>, otherwise the command fails.<\/p>\n<\/blockquote>\n\n\n\n<h2 class=\"wp-block-heading\">Quick Reference Table<\/h2>\n\n\n\n<figure class=\"wp-block-table has-small-font-size\"><table><thead><tr><th>Scenario<\/th><th>Command Example<\/th><\/tr><\/thead><tbody><tr><td>Normal kill (current instance)<\/td><td><code>ALTER SYSTEM KILL SESSION 'SID, SERIAL#';<\/code><\/td><\/tr><tr><td>Normal kill (RAC instance)<\/td><td><code>ALTER SYSTEM KILL SESSION 'SID, SERIAL#, @INST_ID';<\/code><\/td><\/tr><tr><td>Immediate kill (current instance)<\/td><td><code>ALTER SYSTEM KILL SESSION 'SID, SERIAL#' IMMEDIATE;<\/code><\/td><\/tr><tr><td>Immediate kill (RAC instance)<\/td><td><code>ALTER SYSTEM KILL SESSION 'SID, SERIAL#, @INST_ID' IMMEDIATE;<\/code><\/td><\/tr><tr><td>Kill without AC recovery<\/td><td><code>ALTER SYSTEM KILL SESSION 'SID, SERIAL#' NOREPLAY;<\/code><\/td><\/tr><tr><td>Normal disconnect<\/td><td><code>ALTER SYSTEM DISCONNECT SESSION 'SID, SERIAL#' POST_TRANSACTION;<\/code><\/td><\/tr><tr><td>Immediate disconnect<\/td><td><code>ALTER SYSTEM DISCONNECT SESSION 'SID, SERIAL#' IMMEDIATE;<\/code><\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">Conclusion<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Oracle provides flexible ways to manage sessions in both single-instance and RAC environments. By understanding the syntax, placeholders (<code>SID<\/code>, <code>SERIAL#<\/code>, <code>INST_ID<\/code>), and the different scenarios, DBAs can safely terminate or disconnect sessions without impacting database stability. This guide ensures you have <strong>all scenarios covered<\/strong>, from normal termination to immediate disconnection, with RAC support and Application Continuity considerations.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Database administrators often face sessions that hang, lock resources, or consume unnecessary memory. Oracle provides multiple ways to terminate or disconnect sessions, depending on the scenario. In this guide, we\u2019ll cover ALTER SYSTEM KILL SESSION and ALTER SYSTEM DISCONNECT SESSION, explain the syntax in detail, and provide examples for both single-instance and RAC (Real Application [&hellip;]<\/p>\n","protected":false},"template":"","meta":{"googlesitekit_rrm_CAowu461DA:productID":""},"categories":[952,984],"class_list":["post-4802","cposts","type-cposts","status-publish","hentry","category-notes","category-oracle-dba-d2d-tasks"],"_links":{"self":[{"href":"https:\/\/w3buddy.com\/blog\/wp-json\/wp\/v2\/cposts\/4802","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/w3buddy.com\/blog\/wp-json\/wp\/v2\/cposts"}],"about":[{"href":"https:\/\/w3buddy.com\/blog\/wp-json\/wp\/v2\/types\/cposts"}],"wp:attachment":[{"href":"https:\/\/w3buddy.com\/blog\/wp-json\/wp\/v2\/media?parent=4802"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/w3buddy.com\/blog\/wp-json\/wp\/v2\/categories?post=4802"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}