ClickHouse too many parts error: causes and fixes
Why ClickHouse rejects inserts with "Merges are processing significantly slower than inserts", how to find the cause in system tables, and six fixes ordered by effort.
The ClickHouse “Too many parts” error (code 252, TOO_MANY_PARTS) means a MergeTree table has a partition with more active data parts than parts_to_throw_insert allows, so ClickHouse refuses the insert until background merges catch up. Every synchronous INSERT writes at least one new part per partition it touches, and merges combine parts only within a partition, so the error almost always comes from one of two habits: sending many small inserts, or partitioning so finely that each insert lands in many partitions. In current releases the default limit is 3,000 active parts per partition (it was 300 before 23.6), and inserts are slowed down from 1,000, according to the MergeTree settings reference. ClickHouse’s own knowledge-base article on the error is blunt that raising the limit is not the fix. Below: how to confirm which cause you have, and six fixes ordered by effort. Every query was run against ClickHouse 26.9.
What does the “Too many parts” error mean?
Here is the error as ClickHouse 26.9 prints it, reproduced on a test table with the thresholds lowered to 5 and 10 and merges stopped:
Code: 252. DB::Exception: Too many parts (10 with average size of 970.00 B)
in table 'default.events (...)'. Merges are processing significantly slower
than inserts. (TOO_MANY_PARTS)
A MergeTree table stores data as immutable parts. An INSERT writes a new part; a background thread later merges small parts into bigger ones. That design is what makes ClickHouse inserts and scans fast, and it has one rule that matters here: a merge only combines parts that share the same partition value. The custom partitioning key guide states this directly.
Four MergeTree settings decide when the error fires:
| Setting | Default (26.9) | What it does |
|---|---|---|
parts_to_delay_insert | 1000 | Above this many active parts in one partition, inserts are slowed down |
parts_to_throw_insert | 3000 | Above this, inserts fail with TOO_MANY_PARTS (was 300 before 23.6) |
max_parts_in_total | 100000 | Same error when the whole table, all partitions together, crosses this |
max_avg_part_size_for_too_many_parts | 1 GiB | The per-partition check only applies while the average part is smaller than this |
The last row explains why a table with thousands of large, healthy parts never sees the error: the check targets partitions full of small parts, which is the signature of merges losing the race.
Two details are easy to miss. First, the error does not arrive without warning. Between 1,000 and 3,000 parts, ClickHouse adds a sleep to every insert, growing linearly from 10 ms (min_delay_to_insert_ms) to 1 second (max_delay_to_insert). At 2,000 parts that is about 500 ms per insert. If your insert latency crept up in the hours before the failure, this is why. Second, in our test the check looked at the busiest partition in the table, not the one being written: once one daily partition crossed the limit, an insert into a different, empty partition was rejected with the same error. One bad partition blocks the whole table.
A related message shares the same code: Too many partitions for single INSERT block (more than 100). That one is max_partitions_per_insert_block, and it fires when a single insert would touch more than 100 partitions. It is the same root cause, a partition key that is too granular, caught earlier.
How to diagnose too many parts in ClickHouse
Work through four questions: which partition is overloaded, how fast parts are being created, whether merges are running, and what the inserts look like.
1. Which tables and partitions have the most parts?
SELECT
database,
table,
partition,
count() AS active_parts,
sum(rows) AS rows,
formatReadableSize(sum(bytes_on_disk)) AS size,
formatReadableSize(avg(bytes_on_disk)) AS avg_part_size
FROM system.parts
WHERE active
GROUP BY database, table, partition
ORDER BY active_parts DESC
LIMIT 10;
Hundreds of parts averaging a few kilobytes point at small inserts. A table with a few parts per partition but thousands of partitions points at the partition key. For a single number to alert on, system.asynchronous_metrics exposes MaxPartCountForPartition, the worst partition on the server.
2. How fast are new parts arriving, and how big are they?
system.part_log, when it is enabled in the server config, records every part created and every merge. This shows the insert pattern from the storage side:
SELECT
database,
table,
toStartOfMinute(event_time) AS minute,
countIf(event_type = 'NewPart') AS new_parts,
countIf(event_type = 'MergeParts') AS merges,
round(avgIf(rows, event_type = 'NewPart')) AS avg_rows_per_new_part
FROM system.part_log
WHERE event_time > now() - INTERVAL 1 HOUR
AND database != 'system'
GROUP BY database, table, minute
ORDER BY new_parts DESC
LIMIT 20;
Dozens of new parts per minute with a handful of rows each is the classic picture.
3. Are merges actually running?
SELECT database, table, round(elapsed) AS elapsed_s, round(progress, 2) AS progress,
num_parts, formatReadableSize(total_size_bytes_compressed) AS size, is_mutation
FROM system.merges
ORDER BY elapsed DESC;
SELECT metric, value
FROM system.metrics
WHERE metric IN ('BackgroundMergesAndMutationsPoolTask',
'BackgroundMergesAndMutationsPoolSize', 'DelayedInserts');
If the pool task count sits at the pool size, merges are saturated. If system.merges is empty while parts pile up, merges are blocked: check free space in system.disks, look for heavy mutations sharing the pool, and on replicated tables read last_exception and postpone_reason in system.replication_queue. Someone may also have run SYSTEM STOP MERGES during maintenance and forgotten to start them again. system.events keeps running totals of DelayedInserts and RejectedInserts since server start.
4. What do the inserts look like?
SELECT
arrayStringConcat(tables, ', ') AS tables,
count() AS inserts,
round(avg(written_rows)) AS avg_rows,
countIf(ProfileEvents['AsyncInsertQuery'] > 0) AS async_inserts,
countIf(exception_code = 252) AS too_many_parts_errors
FROM system.query_log
WHERE event_time > now() - INTERVAL 1 DAY
AND query_kind = 'Insert'
AND type IN ('QueryFinish', 'ExceptionWhileProcessing')
GROUP BY tables
ORDER BY inserts DESC
LIMIT 20;
Thousands of inserts a day averaging single-digit rows, with async_inserts at zero, tells you exactly which client to fix. If you are new to sizing the merge pool against your workload, ClickHouse sizing for a data team of 20 covers how CPU and disk budget translate into background capacity.
Fix 1: Make sure merges can run at all
The cheapest fix is the one that removes a blocker. If diagnosis question 3 showed merges stopped or stuck, deal with that first:
SYSTEM START MERGES events; -- if merges were stopped for maintenance
Free up disk if it is nearly full, since merges need room to write the merged part before deleting the inputs. Kill or reschedule a large mutation that is hogging the background pool. In our test, starting merges again on a table at the limit brought it from 10 parts to 1 within seconds, and the next insert succeeded. If merges were fine, move on: the problem is the shape of the writes.
Fix 2: Batch inserts on the client
This is the fix ClickHouse recommends first. Its insert strategy guide says to insert “in batches of at least 1,000 rows, and ideally between 10,000-100,000 rows”, and to keep the rate “around one insert query per second” regardless of batch size.
In practice that means buffering in the producer: collect rows in memory or in a queue, and flush every N rows or every T seconds, whichever comes first. Two ways teams accidentally defeat batching:
- One insert per event from a web handler or worker, often hidden behind an ORM or a logging library.
- Many parallel writers each batching a little. Twenty workers each sending 500 rows a second is twenty parts a second. Batch per destination table, not per worker, or route writers through a queue.
For backfills, avoid row-at-a-time loops; an INSERT ... SELECT from a table function or file moves millions of rows as a few large blocks. The batched backfill in our Postgres to ClickHouse migration playbook is one worked example.
Fix 3: Turn on asynchronous inserts when the client cannot batch
When you do not control the producer, such as many small agents, IoT devices or a third-party tool, let the server batch for you. With async_insert = 1, ClickHouse collects incoming inserts in an in-memory buffer and flushes them as one part when a size threshold, a time threshold (adaptive between 50 and 200 ms by default since 24.2) or a count of 450 queries is reached.
-- per query
INSERT INTO events SETTINGS async_insert = 1, wait_for_async_insert = 1
VALUES (now(), 42, 'click');
-- or for a user, so every client inherits it
ALTER USER ingest_writer SETTINGS async_insert = 1, wait_for_async_insert = 1;
Keep wait_for_async_insert = 1. The asynchronous inserts guide calls the fire-and-forget mode (0) “very risky”, because the client is acknowledged before the data is written and never hears about a failed flush.
Check your version before assuming this is off. Since 26.2, async_insert defaults to 1; our 26.9 test server reported it as the default, and in one run 30 parallel single-row inserts landed in 8 parts instead of 30. If your client or user profile explicitly sets async_insert = 0, you do not get the benefit.
Async inserts have limits. Buffers are kept per node and per query shape and settings, so many distinct insert shapes batch poorly. And each flush still writes one part per partition value it contains, so they do not rescue a bad partition key.
Fix 4: Use a coarser partition key
If diagnosis showed thousands of partitions, or each insert spanning many of them, the partition key is the problem. ClickHouse’s guidance is that you rarely need a partition key “more granular than by month, unless targeting an observability use case”, and that you should not “partition your data by client identifiers or names”. Partitions are for data management (dropping or moving old data), not query speed; the sort key handles filtering.
Common offenders and replacements:
| Partition key | Problem | Usually better |
|---|---|---|
toStartOfHour(ts) | 8,760 partitions a year; backfills touch hundreds per insert | toYYYYMM(ts) |
customer_id or tenant_id | Partitions grow with your customer count | No partition, tenant_id first in ORDER BY |
(toDate(ts), event_type) | Each insert splits into days times types | toYYYYMM(ts), event_type in ORDER BY |
toDate(ts) with late data | Late events reopen old days, adding parts there | toYYYYMM(ts), or daily only if you drop days |
You cannot change the partition key in place, so rebuild and swap:
CREATE TABLE events_v2 AS events
ENGINE = MergeTree
PARTITION BY toYYYYMM(event_time)
ORDER BY (event_type, event_time);
INSERT INTO events_v2 SELECT * FROM events;
EXCHANGE TABLES events AND events_v2; -- atomic swap, Atomic database engine
Pause writers or replay the gap between the copy and the swap. For a large table, copy in slices with a WHERE on the time column. When you drop a partition column such as tenant_id, move it to the front of ORDER BY so filters on it stay fast.
Fix 5: Check what your materialized views write
A materialized view runs on every insert into its source and writes its result into a target table, so each source insert also creates parts in every target. Ten small inserts a second into a source with four views is fifty new parts a second across five tables. If the error names a view’s target table rather than the table you insert into, look here.
Two things help: batch the source inserts (Fix 2 or 3 fixes the views as well), and give each target table a partition key at least as coarse as the source. An aggregating target partitioned by hour beneath a source partitioned by month will hit the limit first. Materialized views vs projections in ClickHouse covers when a projection, which lives inside the source part and adds no extra parts, is the better tool.
Fix 6: Raise the limit, briefly and on purpose
Raising parts_to_throw_insert buys time during an incident. It is a per-table MergeTree setting:
ALTER TABLE events MODIFY SETTING parts_to_throw_insert = 6000;
Treat it as a tourniquet. The knowledge-base article warns that higher limits add filesystem and metadata overhead and slow queries, since every SELECT has to open more parts. The setting’s own documentation adds that a merge problem such as a full disk will surface later than it otherwise would. Raise it to stop rejected writes while you apply Fixes 1 to 5, then set it back with ALTER TABLE events RESET SETTING parts_to_throw_insert.
Avoid running OPTIMIZE TABLE ... FINAL in a loop as a substitute for merges. It rewrites whole partitions, competes for the same disk and CPU the background merges need, and does nothing about the inserts creating the parts.
A checklist to prevent it
- Alert on
MaxPartCountForPartitionwell belowparts_to_delay_insert, and on rising insert latency. - Watch
RejectedInsertsandDelayedInsertsinsystem.events. - Review every new table’s partition key in code review: monthly or none unless you have a retention reason.
- Batch in the producer, or confirm
async_insert = 1withwait_for_async_insert = 1for the ingest user. - Count materialized views per source table and check their targets’ partition keys.
Part pressure is easier to manage when someone watches it continuously. In Goni, the Pulse page includes a parts-pressure heatmap showing each table’s part count, its worst partition, the effective parts_to_throw_insert threshold and a projected time until inserts would be rejected at the current insert-minus-merge rate. Goni only monitors ClickHouse, so this helps only if that is your warehouse; the queries above work on any ClickHouse deployment with no extra tooling.
FAQ
What causes “Too many parts” in ClickHouse?
New parts are being created faster than background merges can combine them. Each synchronous insert writes at least one part per partition it touches, so the usual causes are many small inserts, a partition key so granular that each insert spans many partitions, or merges that are stopped or starved of disk space and background threads.
What is the default parts_to_throw_insert value?
Since ClickHouse 23.6 the default is 3,000 active parts in a single partition; before that it was 300. Inserts start being delayed earlier, at parts_to_delay_insert (default 1,000). A separate table-wide limit, max_parts_in_total, defaults to 100,000. Check your server with SELECT * FROM system.merge_tree_settings WHERE name LIKE 'parts_to%'.
Should I increase parts_to_throw_insert?
Only as a short-term measure during an incident. A higher limit stops rejected inserts but leaves the cause in place, adds filesystem overhead, slows SELECT queries that must read more parts, and hides merge failures such as a full disk for longer. Fix the insert batching or the partition key, then reset the setting.
Do async inserts fix the too many parts error?
They fix the small-insert cause: the server buffers many inserts and writes them as one part. They do not fix a partition key that is too granular, because each flush still writes one part per partition value. Since 26.2, async_insert is on by default, so check whether a client is turning it off.
How many rows should a ClickHouse insert contain?
ClickHouse recommends at least 1,000 rows per insert and ideally 10,000 to 100,000, at roughly one insert query per second per table. Fewer, larger inserts create fewer parts and less merge work. If producers cannot batch, use asynchronous inserts with wait_for_async_insert = 1 so the server does the batching.