Kill sessions¶
The KILL SESSION command is to terminate running sessions.
Note
- Only the NebulaGraph
rootuser can terminate sessions. - After executing the
KILL SESSIONcommand, all Graph services synchronize the latest session information after2* session_reclaim_interval_secsseconds (120seconds by default).
Syntax¶
You can run the KILL SESSION command to terminate one or multiple sessions. The syntax is as follows:
-
To terminate one session
KILL {SESSION|SESSIONS} <SessionId>{SESSION|SESSIONS}:SESSIONorSESSIONS, both are supported.<SessionId>: Specifies the ID of one session. You can run the SHOW SESSIONS command to view the IDs of sessions.
-
To terminate multiple sessions
SHOW SESSIONS | YIELD $-.SessionId AS sid [WHERE <filter_clause>] | KILL {SESSION|SESSIONS} $-.sidNote
The
KILL SESSIONcommand supports the pipeline operation, combining theSHOW SESSIONScommand with theKILL SESSIONcommand to terminate multiple sessions.[WHERE <filter_clause>]:- Optional, the
WHEREclause is used to filter sessions.<filter_expression>specifies a session filtering expression, for example,WHERE $-.CreateTime < datetime("2022-12-14T18:00:00"). If theWHEREclause is not specified, all sessions are terminated. - Filtering conditions in a
WHEREclause include:SessionId,UserName,SpaceName,CreateTime,UpdateTime,GraphAddr,Timezone, andClientIp. You can run the SHOW SESSIONS command to view descriptions of these conditions.
- Optional, the
{SESSION|SESSIONS}:SESSIONorSESSIONS, both are supported.
Caution
Please use filtering conditions with caution to avoid deleting sessions by mistake.
Examples¶
-
To terminate one session
nebula> KILL SESSION 1672887983842984
-
To terminate multiple sessions
-
Terminate all sessions whose creation time is less than
2023-01-05T18:00:00.nebula> SHOW SESSIONS | YIELD $-.SessionId AS sid WHERE $-.CreateTime < datetime("2023-01-05T18:00:00") | KILL SESSIONS $-.sid
-
Terminates the two sessions with the earliest creation times.
nebula> SHOW SESSIONS | YIELD $-.SessionId AS sid, $-.CreateTime as CreateTime | ORDER BY $-.CreateTime ASC | LIMIT 2 | KILL SESSIONS $-.sid
-
Terminates all sessions created by the username
session_user1.nebula> SHOW SESSIONS | YIELD $-.SessionId as sid WHERE $-.UserName == "session_user1" | KILL SESSIONS $-.sid
-
Terminate all sessions.
nebula> SHOW SESSIONS | YIELD $-.SessionId as sid | KILL SESSION $-.sid // Or nebula> SHOW SESSIONS | KILL SESSIONS $-.SessionIdCaution
When you terminate all sessions, the current session is terminated. Please use it with caution.
-