Kill Query
Use KILL QUERY to cancel a running SQL query while keeping its connection open. Use KILL CONNECTION to close a connection and cancel its current query.
A warehouse SQL user can cancel its own queries and connections. A SQL user with ADMIN_PRIV can also cancel work owned by other SQL users. Viewing another user's query does not by itself grant permission to cancel it.
Obtain query identifiers
KILL accepts a query ID, a user-assigned trace ID, or a numeric connection ID. Prefer a query ID or trace ID when the warehouse has multiple frontends (FEs). Numeric connection IDs identify a connection only on the frontend handling the KILL statement.
Inspect running connections
SHOW PROCESSLIST;
Inspect these fields:
| Field | Meaning |
|---|---|
CurrentConnected | Yes identifies the connection running the inspection statement. |
Id | Numeric connection ID. |
QueryId | ID of the current or most recently executed query in that connection. Check the command and SQL before canceling it. |
Info | Statement text. |
FE | Frontend hosting the connection. |
CloudCluster | Cluster associated with the connection, when available. |
By default, SHOW PROCESSLIST reports connections on the frontend to which your session is connected. To request connections across frontends:
SET show_all_fe_connection = true;
SHOW PROCESSLIST;
Alternatively, query the PROCESSLIST system table, which collects connections across frontends:
SELECT * FROM information_schema.processlist;
Result visibility depends on the SQL user's privileges. A query might complete between inspection and cancellation.
Assign a trace ID
An application can assign a trace ID before submitting a query:
SET session_context = 'trace_id:reporting_request_001';
Replace reporting_request_001 with a unique ID, such as a UUID generated by your application. The ID must not contain ;. The session maps subsequent queries to this trace ID until it is changed. Reusing one trace ID across concurrent requests can make cancellation ambiguous.
Cancel a query
Use one of these forms:
KILL QUERY 'd36417cc05ff41ab-9d3afe49be251055';
KILL QUERY 'reporting_request_001';
KILL QUERY 55;
- A quoted query ID or trace ID is looked up on the current frontend, then other available frontends if needed.
- An unquoted connection ID cancels the current query on that connection only on the frontend handling the statement. The connection remains open.
Replace the IDs with values from your warehouse. Do not use an idle connection's previous QueryId as evidence that the query is still running.
Disconnect a connection
KILL CONNECTION 55;
The CONNECTION keyword is optional:
KILL 55;
Both forms close connection 55 on the current frontend and cancel its running query. Different frontends can have the same connection ID. Check frontend ownership before using this operation.
Use trace IDs in an application
Choose one trace ID for each request and record it in the application's logs. You can set the ID before submitting SQL, or attach it to one statement with a hint.
Example 1: Set a trace ID for the session
Assign a request ID before executing a query
SET session_context = 'trace_id:reporting_request_002';
SELECT COUNT(*) FROM reporting.events;
Replace reporting.events with a table that the SQL user can query. Use another connection for cancellation:
KILL QUERY 'reporting_request_002';
Example 2: Set a trace ID for one statement
Attach a trace ID with a SET_VAR hint
SELECT /*+ SET_VAR(session_context='trace_id:reporting_request_003') */
COUNT(*)
FROM reporting.events;
Another connection can cancel the running query with:
KILL QUERY 'reporting_request_003';
Verify cancellation and resolve errors
After cancellation, inspect information_schema.processlist again and check the client that submitted the query. KILL QUERY keeps the connection available, so the connection can still appear after the query stops.
| Symptom | Action |
|---|---|
| Query or thread not found | Refresh the process list. The query might have finished, the trace ID might have changed, or a numeric connection ID might belong to another frontend. |
| Permission denied | Use the SQL identity that owns the query, or ask a warehouse SQL administrator with ADMIN_PRIV. |
| A load continues after a query is canceled | Some loads are independent jobs or backend tasks. Use the cancellation command for that load method. Canceling a SQL connection does not cancel every job it submitted. |