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

# Resolving "Previous mutation queries are not finished yet" on ALTER

> An ALTER is rejected or fails because earlier mutations of the table are not finished. Find the mutation that is stuck in system.mutations and remove it with KILL MUTATION.

The `ALTER` does not go through because earlier mutations of the same table have not finished. A common cause is a mutation that fails on every attempt: everything submitted after it queues up behind it. Find that mutation in [`system.mutations`](https://clickhouse.com/docs/reference/system-tables/mutations), read its `latest_fail_reason`, and either wait for it or remove it with [`KILL MUTATION`](https://clickhouse.com/docs/reference/statements/kill#kill-mutation).

## The error

In ClickHouse Cloud, an `ALTER` such as `DROP PROJECTION` can be rejected with a message of this form:

```text theme={null}
Previous <N> mutation queries are not finished yet. First not done mutation ID: <mutation_id>, first not done mutation query '<command>'. Last not done mutation ID: <mutation_id>, last not done mutation query: '<command>' Probably too many alters executing concurrently (highly not recommended). You can retry this error.
```

The message names the oldest and the newest unfinished mutation of the table, and it suggests a retry. A retry can only help if these mutations make progress. If one of the unfinished mutations fails on every attempt, deal with it first.

A self-managed `MergeTree` table in the same situation reports it differently, as the example below shows. The diagnosis and the fix are the same.

## Example

Create a table and a mutation that cannot succeed:

```sql theme={null}
CREATE TABLE page_views
(
    view_date Date,
    user_id UInt64,
    duration_text String,
    duration UInt32 DEFAULT 0,
    PROJECTION by_user (SELECT user_id, count() GROUP BY user_id)
)
ENGINE = MergeTree
ORDER BY (view_date, user_id);

INSERT INTO page_views (view_date, user_id, duration_text) VALUES
    ('2026-11-01', 1, '12'),
    ('2026-11-01', 2, '48'),
    ('2026-11-02', 1, 'n/a');

-- 'n/a' is not a number, so this mutation fails on every attempt.
ALTER TABLE page_views UPDATE duration = toUInt32(duration_text) WHERE 1;
```

The `UPDATE` returns without an error, because mutations run asynchronously by default. A later `ALTER` then fails:

```sql theme={null}
ALTER TABLE page_views DROP PROJECTION by_user;
```

```text theme={null}
Code: 341. DB::Exception: Exception happened during execution of mutations 'mutation_2.txt, mutation_3.txt' with part 'all_1_1_0' reason: 'Code: 6. DB::Exception: Cannot parse string 'n/a' as UInt32: syntax error at begin of string. ... (CANNOT_PARSE_TEXT)'. This error maybe retryable or not. In case of unretryable error, mutation can be killed with KILL MUTATION query. (UNFINISHED)
```

On this self-managed table, the `ALTER` is not undone. `SHOW CREATE TABLE page_views` no longer lists the projection, and `DROP PROJECTION by_user` is queued as `mutation_3.txt` behind the failing mutation. Failed mutations are retried with growing delays, so depending on the timing the statement can also wait for a long time before it returns this error.

## Find the mutation that blocks the queue

```sql theme={null}
SELECT mutation_id, command, is_done, parts_to_do, latest_fail_reason
FROM system.mutations
WHERE database = currentDatabase() AND table = 'page_views' AND NOT is_done
ORDER BY create_time
FORMAT Vertical;
```

```text theme={null}
Row 1:
──────
mutation_id:        mutation_2.txt
command:            (UPDATE duration = toUInt32(duration_text) WHERE 1)
is_done:            0
parts_to_do:        1
latest_fail_reason: Code: 6. DB::Exception: Cannot parse string 'n/a' as UInt32: syntax error at begin of string. ... (CANNOT_PARSE_TEXT)

Row 2:
──────
mutation_id:        mutation_3.txt
command:            (DROP PROJECTION by_user)
is_done:            0
parts_to_do:        1
latest_fail_reason: Code: 6. DB::Exception: Cannot parse string 'n/a' as UInt32: syntax error at begin of string. ... (CANNOT_PARSE_TEXT)
```

The long `latest_fail_reason` values are shortened here. Read the result like this:

* A failure is recorded for every mutation that was applied to the part in the same attempt, so all rows can show the same `latest_fail_reason`. The position of a row does not tell which mutation fails: a valid mutation that was submitted before the failing one, but was not applied yet, reports the same reason.
* Find the failing mutation by its `command`. The full text of the reason names the expression that failed after `while executing`, here `toUInt32(duration_text)`, and only `mutation_2.txt` contains it. If the reason does not make it clear, test the expression of every unfinished command with a `SELECT`.
* An empty `latest_fail_reason` and a `parts_to_do` value that goes down between two runs of the query mean that the mutation is working. Wait for it, then run the `ALTER` again.
* The same `latest_fail_reason` in every run means that the mutation will not finish on its own.

In ClickHouse Cloud, `system.mutations` on every node shows all mutations. In a self-managed cluster, query all replicas with `clusterAllReplicas`.

## Remove the stuck mutation

```sql theme={null}
KILL MUTATION
WHERE database = currentDatabase() AND table = 'page_views' AND mutation_id = 'mutation_2.txt';
```

```text theme={null}
   ┌─kill_status─┬─database─┬─table──────┬─mutation_id────┬─command─────────────────────────────────────────────┐
1. │ waiting     │ default  │ page_views │ mutation_2.txt │ (UPDATE duration = toUInt32(duration_text) WHERE 1) │
   └─────────────┴──────────┴────────────┴────────────────┴─────────────────────────────────────────────────────┘
```

The mutation that was queued behind it now completes:

```sql theme={null}
SELECT mutation_id, command, is_done, parts_to_do
FROM system.mutations
WHERE database = currentDatabase() AND table = 'page_views'
ORDER BY create_time;
```

```text theme={null}
   ┌─mutation_id────┬─command───────────────────┬─is_done─┬─parts_to_do─┐
1. │ mutation_3.txt │ (DROP PROJECTION by_user) │       1 │           0 │
   └────────────────┴───────────────────────────┴─────────┴─────────────┘
```

Keep in mind:

* `KILL MUTATION` does not roll back the parts that the mutation has already rewritten.
* In ClickHouse Cloud, a killed mutation can stay at `is_killed = 1` and `is_done = 0` for a while if another long-running mutation is ahead of it.
* Before you repeat the `ALTER` that failed, check `SHOW CREATE TABLE` and `system.mutations`. It may be applied or queued already, as in this example.

Then fix the cause and submit the mutation again. Here the cause is a function that throws an exception for one row:

```sql theme={null}
ALTER TABLE page_views UPDATE duration = toUInt32OrZero(duration_text) WHERE 1
SETTINGS mutations_sync = 1;

SELECT * FROM page_views ORDER BY view_date, user_id;
```

```text theme={null}
   ┌──view_date─┬─user_id─┬─duration_text─┬─duration─┐
1. │ 2026-11-01 │       1 │ 12            │       12 │
2. │ 2026-11-01 │       2 │ 48            │       48 │
3. │ 2026-11-02 │       1 │ n/a           │        0 │
   └────────────┴─────────┴───────────────┴──────────┘
```

## A related error

An `ALTER` that drops or renames a column used by an unfinished mutation is rejected right away, with the same remedy:

```text theme={null}
Code: 36. DB::Exception: Cannot drop column duration_text because it's affected by mutation with ID 'mutation_2.txt' which is not finished yet. Wait this mutation, or KILL it with command "KILL MUTATION WHERE mutation_id = 'mutation_2.txt'". (BAD_ARGUMENTS)
```

## How to avoid it

* Test the expression of an `UPDATE` or `DELETE` with a `SELECT` before you submit the mutation. In the example, `SELECT count() FROM page_views WHERE toUInt32OrNull(duration_text) IS NULL` returns `1`, the row that makes `toUInt32` fail.
* Do not send many `ALTER` statements to one table at the same time. Combine them into one statement, or run them one after another and wait for each, as described in [Concurrent `ALTER` assignment on one table](https://clickhouse.com/docs/reference/statements/alter/index#concurrent-alter-assignment-on-one-table).
* Watch the number of unfinished mutations, see [How do I view the number of active or queued mutations?](https://clickhouse.com/docs/resources/support-center/knowledge-base/monitoring-debugging/view-number-of-active-mutations.md).
