> ## Documentation Index
> Fetch the complete documentation index at: https://docs.firebolt.io/llms.txt
> Use this file to discover all available pages before exploring further.

<AgentInstructions>

## Submitting Feedback

If you encounter incorrect, outdated, or confusing documentation on this page, submit feedback:

POST https://docs.firebolt.io/feedback

```json
{
  "path": "/reference-sql/commands/queries/cancel",
  "feedback": "Description of the issue"
}
```

Only submit feedback when you have something specific and actionable to report.

</AgentInstructions>

# CANCEL QUERY

The `CANCEL QUERY` statement is used to cancel a running query within the Firebolt engine. This statement provides a mechanism to terminate the execution of a specific query identified by its unique `query_id`.
Using [query labels](/reference-sql/system-settings#query-labelingtagging) makes it easier to retrieve the query id of your query.

## Syntax

```sql theme={"theme":{"light":"github-light","dark":"github-dark"}}
CANCEL QUERY WHERE query_id = '<query_id>';
```

## Parameters

| Parameter    | Description                                                          |
| :----------- | :------------------------------------------------------------------- |
| `<query_id>` | A unique identifier assigned to the query that needs to be canceled. |

## Example

```sql theme={"theme":{"light":"github-light","dark":"github-dark"}}
CANCEL QUERY WHERE query_id = '12345';
```

## Notes

* The query\_id is typically obtained from the `information_schema.engine_running_queries` view.
* When a query is canceled, it terminates the processes of that specific query. This action both frees up resources and prevents any further execution of the query.
* This statement is designed for administrative use and may require appropriate privileges to execute. However, all users can cancel their own queries by default.

## Example Use Case

Consider a scenario where there is a long-running query that needs to be canceled to free up system resources. The following statement can be used to obtain the query\_id:

```sql theme={"theme":{"light":"github-light","dark":"github-dark"}}
SELECT status, duration_us, query_text, query_id FROM information_schema.engine_running_queries;
```

Suppose the long-running query is identified with query\_id '12345':

```sql theme={"theme":{"light":"github-light","dark":"github-dark"}}
CANCEL QUERY WHERE query_id = '12345';
```

This will initiate the cancellation process for the specified query\_id. While the query is not immediately removed from running\_queries, its status will be observed as `CANCELING` there.
After the cancellation process is completed, the query will have the `CANCELED` status in the `information_schema.engine_query_history` view:

```sql theme={"theme":{"light":"github-light","dark":"github-dark"}}
SELECT query_id, query_text FROM information_schema.engine_query_history WHERE status = 'CANCELED';
```
