diff --git a/docs-2.0/3.ngql-guide/17.query-tuning-statements/2.kill-session.md b/docs-2.0/3.ngql-guide/17.query-tuning-statements/2.kill-session.md new file mode 100644 index 00000000000..4235ce35359 --- /dev/null +++ b/docs-2.0/3.ngql-guide/17.query-tuning-statements/2.kill-session.md @@ -0,0 +1,86 @@ +# 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 after `2* session_reclaim_interval_secs` seconds. + +## 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} + ``` + + - `{SESSION|SESSIONS}`: `SESSION` or `SESSIONS`, both are supported. + - ``: Specifies the ID of one session. You can run the [SHOW SESSIONS command](../../3.ngql-guide/7.general-query-statements/6.show/17.show-sessions.md) to view the IDs of sessions. + + +- To terminate multiple sessions + + ``` + SHOW SESSIONS + | YIELD $-.SessionId AS sid [WHERE ] + | KILL {SESSION|SESSIONS} $.sid + ``` + + !!! note + + The `KILL SESSION` command supports the pipeline operation, combining the `SHOW SESSIONS` command with the `KILL SESSION` command to terminate multiple sessions. + + - `[WHERE ]`: + - Optional, the `WHERE` clause is used to filter sessions. `` specifies a session filtering expression, for example, `WHERE $-.CreateTime < datetime("2022-12-14T18:00:00")`. If the `WHERE` clause is not specified, all sessions are terminated. + - Filtering conditions in a `WHERE` clause include: `SessionId`, `UserName`, `SpaceName`, `CreateTime`, `UpdateTime`, `GraphAddr`, `Timezone`, and `ClientIp`. You can run the [SHOW SESSIONS command](../../3.ngql-guide/7.general-query-statements/6.show/17.show-sessions.md) to view descriptions of these conditions. + + - `{SESSION|SESSIONS}`: `SESSION` or `SESSIONS`, 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. diff --git a/docs-2.0/3.ngql-guide/7.general-query-statements/6.show/17.show-sessions.md b/docs-2.0/3.ngql-guide/7.general-query-statements/6.show/17.show-sessions.md index 5617a805d2f..60a56bf2cdb 100644 --- a/docs-2.0/3.ngql-guide/7.general-query-statements/6.show/17.show-sessions.md +++ b/docs-2.0/3.ngql-guide/7.general-query-statements/6.show/17.show-sessions.md @@ -6,7 +6,7 @@ The `SHOW SESSIONS` statement shows the information of all the sessions. It can ## Precautions -- The client will call the API `release` to release the session and clear the session information when you run `exit` after the operation ends. If you exit the database in an unexpected way and the session timeout duration is not set via `session_idle_timeout_secs` in [nebula-graphd.conf](../../../5.configurations-and-logs/1.configurations/3.graph-config.md), the session will not be released automatically. For those sessions that are not automatically released, you need to delete them manually (TODO: coding). +- The client will call the API `release` to release the session and clear the session information when you run `exit` after the operation ends. If you exit the database in an unexpected way and the session timeout duration is not set via `session_idle_timeout_secs` in [nebula-graphd.conf](../../../5.configurations-and-logs/1.configurations/3.graph-config.md), the session will not be released automatically. For those sessions that are not automatically released, you need to delete them manually. For details, see [KILL SESSIONS](../../17.query-tuning-statements/2.kill-session.md). - `SHOW SESSIONS` queries the session information of all the Graph services. diff --git a/mkdocs.yml b/mkdocs.yml index f4e39b39f72..234e825cb4c 100644 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -435,6 +435,7 @@ nav: - Query tuning and terminating statements: - EXPLAIN and PROFILE: 3.ngql-guide/17.query-tuning-statements/1.explain-and-profile.md - Kill queries: 3.ngql-guide/17.query-tuning-statements/6.kill-query.md + - Kill sessions: 3.ngql-guide/17.query-tuning-statements/2.kill-session.md - Job statements: 3.ngql-guide/4.job-statements.md