Skip to main content
Every mutation, such as ALTER TABLE ... UPDATE or ALTER TABLE ... DELETE, has a row in system.mutations that stays there with is_done = 0 until all parts are rewritten. The age of the oldest such row tells you whether mutations are keeping up, latest_fail_reason tells you why a mutation cannot finish, and KILL MUTATION removes it.

Age of the oldest unfinished mutation

How long a mutation takes depends on the amount of data it has to rewrite, so there is no universal threshold for the age. A mutation whose parts_to_do does not decrease, or that has a non-empty latest_fail_reason, needs a closer look. The number of unfinished mutations alone is covered in How do I view the number of active or queued mutations?.

Example: a mutation that can never finish

Create a table with one value that the mutation cannot process:
With mutations_sync = 1 the statement waits for the mutation, so it reports the failure (the message is shortened here; the full text also contains a stack trace):
The exception does not cancel the mutation. It stays in the queue and the server keeps retrying it. With the default mutations_sync = 0 the ALTER returns immediately and you see no error at all, only a mutation that never completes. List the unfinished mutations together with the reason of the last failure:
An empty latest_fail_reason means that the mutation has not failed: it is waiting or still running. To list only old mutations, add a condition such as AND create_time < now() - INTERVAL 1 DAY.

A stuck mutation blocks the ones behind it

Mutations of a table are applied to each part in the order of their creation, so a valid mutation submitted later cannot complete either:

Kill the stuck mutation

KILL MUTATION takes a WHERE clause over the columns of system.mutations. Select exactly the mutation you want to remove:
A few seconds later, the same query on system.mutations shows that the killed mutation is gone and the one that was waiting behind it is done:
Keep in mind:
  • KILL MUTATION does not roll back the parts that the mutation has already rewritten. If the mutation had been applied to some parts, those keep the new data.
  • Add TEST after the WHERE clause to list the mutations that the statement would kill without killing them.
  • Fix the cause before you submit the mutation again. Here, toUInt32OrZero(amount) instead of toUInt32(amount) makes the same update succeed.

Clusters and ClickHouse Cloud

On a self-managed cluster system.mutations shows the mutations known to the server that runs the query. To see all replicas, read the table through clusterAllReplicas, replacing default with the name of your cluster:
A mutation of a ReplicatedMergeTree table is stored in ClickHouse Keeper and is shared by all replicas of the table, so killing it on one replica removes it for all of them. In ClickHouse Cloud, system.mutations on each node already contains all the mutations of the service, as described in the system.mutations reference.