Kill sessions¶
The KILL SESSION
command is to terminate running sessions.
Note
- Only the NebulaGraph
root
user can terminate sessions. - After executing the
KILL SESSION
command, all Graph services synchronize the latest session information after2* session_reclaim_interval_secs
seconds (120
seconds 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}
:SESSION
orSESSIONS
, 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} $-.sid
Note
The
KILL SESSION
command supports the pipeline operation, combining theSHOW SESSIONS
command with theKILL SESSION
command to terminate multiple sessions.[WHERE <filter_clause>]
:- Optional, the
WHERE
clause is used to filter sessions.<filter_expression>
specifies a session filtering expression, for example,WHERE $-.CreateTime < datetime("2022-12-14T18:00:00")
. If theWHERE
clause is not specified, all sessions are terminated. - Filtering conditions in a
WHERE
clause 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}
:SESSION
orSESSIONS
, 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 $-.SessionId
Caution
When you terminate all sessions, the current session is terminated. Please use it with caution.
-