Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

kill sessions #1874

Merged
merged 2 commits into from
Jan 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
86 changes: 86 additions & 0 deletions docs-2.0/3.ngql-guide/17.query-tuning-statements/2.kill-session.md
Original file line number Diff line number Diff line change
@@ -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} <SessionId>
```

- `{SESSION|SESSIONS}`: `SESSION` or `SESSIONS`, both are supported.
- `<SessionId>`: 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 <filter_clause>]
| 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 <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 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.
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
1 change: 1 addition & 0 deletions mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down