ALTER SYSTEM KILL SESSION

2025-11-19 10:08:13  Updated

Purpose

You can use this statement to terminate a session. To execute this statement, you must have the ALTER SYSTEM privilege.

Syntax

ALTER SYSTEM KILL SESSION 'session_id, serial#';

ALTER SYSTEM KILL SESSION 'session_id' [IMMEDIATE];

Parameters

Parameter Description
session_id The client session ID of the current session, which is the unique identifier of the session in the client.

Note

You can execute the SHOW PROCESSLIST; SQL statement to query session IDs in the database.

serial# This parameter is not implemented in the current version and is reserved only for syntax compatibility.
IMMEDIATE Immediately switches back to the specified session to execute the KILL statement. This parameter is optional. This parameter is not implemented in the current version and is reserved only for syntax compatibility.

Examples

Create a user named kill_user and grant privileges to the user. Log in to the database as the user, query the IDs of the connected sessions, and then terminate the target session.

obclient [SYS]> CREATE USER kill_user IDENTIFIED BY killuser123;
Query OK, 0 rows affected

obclient [SYS]> GRANT CREATE SESSION TO kill_user;
Query OK, 0 rows affected

obclient [SYS]> GRANT ALTER SYSTEM TO kill_user;
Query OK, 0 rows affected

obclient [KILL_USER]> SHOW PROCESSLIST;
+------------+-----------+----------------------+-----------+---------+------+--------+------------------+
| ID         | USER      | HOST                 | DB        | COMMAND | TIME | STATE  | INFO             |
+------------+-----------+----------------------+-----------+---------+------+--------+------------------+
| 3221487726 | KILL_USER | 100.xx.xxx.xxx:34803 | KILL_USER | Query   |    0 | ACTIVE | SHOW PROCESSLIST |
| 3221487722 | SYS       | 100.xx.xxx.xxx:40025 | SYS       | Sleep   |   93 | SLEEP  | NULL             |
+------------+-----------+----------------------+-----------+---------+------+--------+------------------+
1 row in set

obclient [KILL_USER]> ALTER SYSTEM KILL SESSION '3221487726';
Query OK, 0 rows affected

References

For more information about how to query the quantity and IDs of sessions in the current database, see View tenant sessions.

Contact Us