// ClickHouse error reference

252: TOO_MANY_PARTS (code 252)

Each INSERT makes a data part and merges cannot keep up, so the table hit parts_to_throw_insert or max_parts_in_total.

Fehlercode
252
Name
TOO_MANY_PARTS
Kategorie
Resource limits
Fehlermeldung
Too many parts ({parts}). Merges are processing significantly slower than inserts

Was es bedeutet

TOO_MANY_PARTS (252) is rejected at INSERT time when active parts in one partition pass parts_to_throw_insert (300 before 23.6, 3000 since) or the whole table passes max_parts_in_total (100,000). Inserts are outrunning background merges, and raising the limit only trades SELECT speed for delay.

Häufige Ursachen

  • Rows arrive as many small INSERTs, each writing its own part.
  • The partition key is high cardinality, so parts land in thousands of partitions that never merge together.
  • Merges fall behind because the disk is slow or full, or many materialized views feed off the table.

Find the cause

`system.parts` counts active parts per partition, `system.merges` shows merges in flight, `system.query_log` grouped by user shows who inserts tiny rows, and the server log records merge failures.

Wie du es behebst

  1. See which partition is over the limit and by how much.

    SELECT partition, count() AS active_parts FROM system.parts WHERE active AND database = 'my_db' AND table = 'my_table' GROUP BY partition ORDER BY active_parts DESC;
  2. Batch on the client, or use asynchronous inserts so the server merges concurrent single-row inserts into a few parts. On ClickHouse 26.9, async_insert already defaults to 1.

    INSERT INTO my_table SETTINGS async_insert = 1, wait_for_async_insert = 1 VALUES (1, 'a');
  3. For a one-off migration INSERT ... SELECT, form bigger blocks so fewer parts are created.

    INSERT INTO my_table SELECT * FROM old_table SETTINGS min_insert_block_size_bytes = 500000000;

Other ways to handle it

SYSTEM STOP MERGES my_table halts merge reservations while you re-plan, but it also freezes the table's maintenance. Raising parts_to_throw_insert delays the error and slows SELECTs.

Sicher reproduzieren

parts_to_throw_insert counts per partition, so the scratch table trips on the third INSERT while the rest of the server is untouched.

CREATE TABLE scratch_e (id UInt32) ENGINE = MergeTree ORDER BY id SETTINGS parts_to_throw_insert = 2; then run three single-row INSERTs back to back and one gets code 252.

Fragen

Should I raise parts_to_throw_insert?

Only as a stopgap. The official guidance is fewer, larger inserts: around one INSERT query per second, with at least 1,000 rows per INSERT and ideally 10,000 to 100,000; a higher limit trades SELECT performance for delay.

Do asynchronous inserts fix it?

They move batching to the server, so concurrent single-row inserts share a few parts instead of one part each. A high-cardinality partition key can still exceed the limit. A high-cardinality partition key can still exceed the limit.

Zugehörige Fehler

More resource limits errors

Der Code und der Meldungstext stammen aus der ClickHouse documentation (system.errors). Durchstöbere die vollständige ClickHouse error list oder Jeden Datenbankfehler durchsuchen.

// weniger Fehler, schnellere Korrekturen

Work on ClickHouse in SQLly

A native SQL client for macOS, Windows and Linux with schema-aware IntelliSense, guardrails for risky statements and clear error messages, for ClickHouse and the other databases you use.

Text und Daten auf dieser Seite: CC BY 4.0, Quelle: SQLly (sqlly.app). Code und SQL-Snippets: MIT. Lizenzdetails Zitierte Fehlermeldungstexte gehören dem jeweiligen Datenbankhersteller.