There are two kinds of kill statements: to kill a query and to kill a mutation.
Attempts to forcibly terminate the currently running queries. The queries to terminate are selected from the system.processes table using the criteria defined in the
WHERE clause of the
-- Forcibly terminates all queries with the specified query_id: KILL QUERY WHERE query_id='2-857d-4a57-9ee0-327da5d60a90' -- Synchronously terminates all queries run by 'username': KILL QUERY WHERE user='username' SYNC
Read-only users can only stop their own queries.
By default, the asynchronous version of queries is used (
ASYNC), which does not wait for confirmation that queries have stopped.
The synchronous version (
SYNC) waits for all queries to stop and displays information about each process as it stops. The response contains the
kill_status column, which can take the following values:
finished– The query was terminated successfully.
waiting– Waiting for the query to end after sending it a signal to terminate.
- The other values explain why the query can’t be stopped.
Unfortunately, not all queries can be killed. KILL QUERY only sets a flag that must be checked by the query. A query pipeline is checking this flag before switching to the next block. If the pipeline has stuck somewhere in the middle, it cannot be killed. If a query does not stop, the only way to get rid of it is to restart ClickHouse.
ClickHouse queries can’t be killed during sleep.
If you are using a recent CH release (21.12+), then the KILL flag will be checked after each block is processed (on older releases, it might never be checked). Since the default block is 65536, the query will be slept for 65536 * 3 seconds ~= 54 hours before checking anything.
In future releases of ClickHouse it will be impossible to sleep for more than 3 seconds (which right now is a limit of sleep but not for sleepEachRow). In the meantime, you can either wait or restart the server.
-- Cancel and remove all mutations of the single table: KILL MUTATION WHERE database = 'default' AND table = 'table' -- Cancel the specific mutation: KILL MUTATION WHERE database = 'default' AND table = 'table' AND mutation_id = 'mutation_3.txt'
The query is useful when a mutation is stuck and cannot finish.
Changes already made by the mutation are not rolled back.