# Oracle SQL - Kill Sessions

{% hint style="info" %}
The <mark style="color:orange;">`KILL SESSION`</mark> command doesn't actually kill the session. It merely asks the session to kill itself. In some situations, like waiting for a reply from a remote database or rolling back transactions, the session will not kill itself immediately and will wait for the current operation to complete. In these cases the session will have a status of "marked for kill". It will then be killed as soon as possible.
{% endhint %}

* Check the status to confirm

```sql
SELECT sid, serial#, status, username FROM v$session;
```

* You can also use the <mark style="color:orange;">`IMMEDIATE`</mark> clause:

```sql
ALTER SYSTEM KILL SESSION 'sid,serial#' IMMEDIATE;
```

{% hint style="info" %}
The <mark style="color:orange;">`IMMEDIATE`</mark> clause does not affect the work performed by the command, but it returns control back to the current session immediately, rather than waiting for confirmation of the kill. Have a look at Killing Oracle Sessions.
{% endhint %}

* Update If you want to kill all the sessions, you could just prepare a small script:

```sql
SELECT 'ALTER SYSTEM KILL SESSION '''||sid||','||serial#||''' IMMEDIATE;' FROM v$session;
```

{% hint style="info" %}
Spool the above to a .sql file and execute it, or, copy paste the output and run it.
{% endhint %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.arkannis.net/database/oracle-sql-pl-sql/oracle-sql-kill-sessions.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
