Inserts fail with "Too many parts" after a switch to one row per INSERT — why, and what is the fix?
A service writing to ClickHouse 25.8 LTS was changed to send every event as its own one-row INSERT — about 400 inserts per second into analytics.events (MergeTree, PARTITION BY toYYYYMM(ts)). Within an hour inserts slow down, then start failing. Constraints: server settings are defaults, async_insert is not set anywhere, and every acknowledged event must be kept.
<Information> analytics.events: Delaying inserting block by 10 ms. because there are 1004 parts and their average size is 1.31 KiB
...
Code: 252. DB::Exception: Too many parts (3001 with average size of 1.18 KiB) in table 'analytics.events'. Merges are processing significantly slower than inserts. (TOO_MANY_PARTS)Diagnose the cause and name the fix.
Each one-row INSERT makes a part, faster than merges combine them. Past 1000 active parts in a partition inserts are delayed, past 3000 (300 before 23.6) they fail. Batch on the client or enable async_insert (on since 26.2); a higher limit only hides it.
- Raising parts_to_throw_insert instead of reducing the number of parts being created
- Quoting the old 300-part threshold that changed in 23.6
- Running OPTIMIZE … FINAL on a schedule to keep up with tiny inserts
- What does
wait_for_async_inserttrade off whenasync_insertis on? - How would you count active parts per partition in
system.parts?
Cause. Every INSERT creates at least one new part. 400 one-row inserts a second means 400 tiny parts a second in one (the current monthly) partition; merges cannot keep up. The parts_to_delay_insert threshold (1000) starts throttling inserts, parts_to_throw_insert (3000; it was 300 before 23.6) raises TOO_MANY_PARTS. Both count active parts in a single partition.
Fix. Cut the number of inserts instead of raising the limit:
-- 1. Client-side batches: thousands of rows per INSERT, about once a second
INSERT INTO analytics.events (ts, user_id, event_type) VALUES
('2026-11-08 10:00:00', 1, 'view'),
('2026-11-08 10:00:00', 2, 'click');
-- … the rest of the batch
-- 2. If the client cannot change: the server buffers rows and writes them as one part.
-- On 25.8 LTS this must be enabled explicitly; since 26.2 async_insert is on by default.
SET async_insert = 1, wait_for_async_insert = 1;wait_for_async_insert = 1 acknowledges an insert only after the buffer is flushed to disk, so acknowledged events are not lost. Raising parts_to_throw_insert only postpones the error and slows reads, since queries open thousands of parts.