Updated on 2024-05-07 GMT+08:00

ALTER SYSTEM KILL SESSION

Description

ALTER SYSTEM KILL SESSION ends a session.

Precautions

None

Syntax

1
ALTER SYSTEM KILL SESSION 'session_sid, serial' [ IMMEDIATE ];

Parameters

  • session_sid, serial

    Specifies SID and SERIAL of a session (see examples for format). You can use the pg_stat_activity system catalog to query the current active threads (see the examples). However, when you run the ALTER SYSTEM KILL SESSION command, the threads may have ended.

    Value range: SIDs and SERIALs of all sessions that can be queried from the system catalog dv_sessions

  • IMMEDIATE

    Specifies that a session will be ended instantly after the statement is executed.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
-- Query session information.
gaussdb=# SELECT sid,serial#,username FROM dv_sessions;

       sid       | serial# | username 
-----------------+---------+----------
 140131075880720 |       0 | omm
 140131025549072 |       0 | omm
 140131073779472 |       0 | omm
 140131071678224 |       0 | omm
 140131125774096 |       0 | 
 140131127875344 |       0 | 
 140131113629456 |       0 | 
 140131094742800 |       0 | 
(8 rows)

-- End the session whose SID is 140131075880720.
gaussdb=#  ALTER SYSTEM KILL SESSION '140131075880720,0' IMMEDIATE;