Introduction

Your application sends many INSERT queries, and each query contains only a few rows. Sometimes, it contains just one row. For example, a web service might write one event for every incoming request.

At first, everything works. The table is small, and background merges keep up. But as traffic grows, new parts arrive faster than ClickHouse can combine them. The number of active parts begins to increase.

Before the error appears, inserts may become slower. ClickHouse delays INSERT queries when a partition contains too many active parts. This delay is an early warning sign.

If the problem continues, INSERT queries may fail with an error such as:

Code: 252. DB::Exception: Too many parts (3000). Merges are processing significantly slower than inserts. (TOO_MANY_PARTS) 

The error may occur even when the server has sufficient CPU, memory, and disk capacity. The issue can be that one partition of one table has reached its part limit.

This guide explains how to identify excessive part creation, monitor the problem, and reduce the number of parts through client-side batching or asynchronous inserts.

Why Does TOO_MANY_PARTS Happen?

A MergeTree table stores data in parts. Each part is a directory on disk, and parts are immutable. ClickHouse does not add new rows to an existing part.

Each INSERT creates at least one new part. If a table is partitioned, a single INSERT can create one part for every partition it touches.

This means a one-row INSERT can create an entire part containing just one row.

ClickHouse uses background merges to combine smaller parts into larger ones. These merges consume CPU and disk resources and can process only a limited amount of work at a time.

When new parts arrive faster than background merges can combine them, the active part count grows.

The two important part limits

ClickHouse protects the server using two MergeTree settings:

  • parts_to_delay_insert: Delays INSERT queries when a partition has more active parts than the configured threshold. The default is 1,000.
  • parts_to_throw_insert: Rejects INSERT queries with TOO_MANY_PARTS when a partition exceeds the configured threshold. The default is 3,000.

Check the values on your server:

SELECT name, value, changed FROM system.merge_tree_settings WHERE name IN ( 'parts_to_delay_insert', 'parts_to_throw_insert' ); 

These are MergeTree settings, not session settings.

Do not increase these limits as your first response to the error. Higher limits can hide the underlying problem while allowing more active parts to accumulate, potentially slowing SELECT queries.

The root cause is often straightforward: the application sends inserts that are too small for the ingestion rate.

How to Confirm the Problem

Run the following queries on the affected ClickHouse server to determine whether small inserts are creating excessive parts.

Step 1: Count New Parts per Minute

Use system.part_log to inspect newly created parts. Each row with event_type = 'NewPart' represents a new part created through an INSERT.

SELECT toStartOfMinute(event_time) AS minute, database, `table`, count() AS new_parts, sum(rows) AS total_rows, round(sum(rows) / count()) AS avg_rows_per_part FROM system.part_log WHERE event_type = 'NewPart' AND event_time > now() - INTERVAL 1 HOUR GROUP BY minute, database, `table` ORDER BY minute DESC, new_parts DESC LIMIT 50; 

Pay attention to two values:

  • new_parts: A high value indicates that ClickHouse must process many newly created parts.
  • avg_rows_per_part: A low value suggests that inserts are creating small parts. An average between 1 and 100 rows per part is a clear warning sign.

If system.part_log does not exist, the part log may be disabled. Enable it in the server configuration before using this query.

Step 2: Count Active Parts in Each Partition

The part limits apply to individual partitions, so inspecting the total number of parts across a table is not enough.

Use this query to identify partitions with the highest active part counts:

SELECT database, `table`, partition, count() AS active_parts FROM system.parts WHERE active GROUP BY database, `table`, partition ORDER BY active_parts DESC LIMIT 20; 

Compare active_parts with the configured values of parts_to_delay_insert and parts_to_throw_insert.

This helps you identify which table and partition are approaching the limit.

Step 3: Check the Server-Wide Maximum

The MaxPartCountForPartition metric reports the highest number of parts in any partition.

SELECT metric, value FROM system.asynchronous_metrics WHERE metric = 'MaxPartCountForPartition'; 

Track this metric over time to determine whether the maximum part count continues to increase.

Step 4: Check Whether the Server Threw the Error

Use system.errors to check whether ClickHouse has recorded the error since the last server restart.

SELECT name, code, value, last_error_time FROM system.errors WHERE name = 'TOO_MANY_PARTS'; 

If value is greater than zero, the server has thrown this error since its last restart.

Interpreting the Results

Small inserts are likely responsible when both conditions are true:

  1. avg_rows_per_part is low.
  2. The number of active parts continues to grow.

If the average number of rows per part is already high but the part count still grows, background merges may be the bottleneck.

This distinction helps determine whether the primary solution should focus on reducing part creation or investigating merge performance.

Understanding the Relevant Settings

The following session settings can influence asynchronous inserts and block formation. Their defaults can vary between ClickHouse releases.

Setting Default in the referenced master branch Purpose
async_insert true on current master; false on older releases Buffers INSERT data on the server before writing parts
wait_for_async_insert true Makes the client wait until the buffered data has been written
async_insert_busy_timeout_max_ms 200 Sets the maximum buffer waiting time before flushing
async_insert_max_data_size 10485760 (10 MiB) Sets the buffer size that triggers a flush
min_insert_block_size_rows 1048449 Sets the minimum rows in a block when the server forms blocks
min_insert_block_size_bytes 268402944 Sets the minimum bytes in a block when the server forms blocks

These values are taken from the ClickHouse master branch at commit 9f79cc1, dated October 30, 2026. They are not guaranteed to match your installed release.

Check your actual values:

SELECT name, value, changed FROM system.settings WHERE name IN ( 'async_insert', 'wait_for_async_insert', 'async_insert_busy_timeout_max_ms', 'async_insert_max_data_size', 'min_insert_block_size_rows', 'min_insert_block_size_bytes' ); 

The changed column indicates whether a setting has been changed from its default.

Keep the following points in mind:

  • Check async_insert first. Older releases may have it disabled by default.
  • Older releases may use a different name for the asynchronous insert timeout setting.
  • The min_insert_block_size_rows and min_insert_block_size_bytes settings do not combine separate INSERT queries. They apply when the server forms blocks, such as during INSERT ... SELECT. They do not solve a client that sends one row per INSERT.

How to Fix TOO_MANY_PARTS

There are two main options. Client-side batching is preferable when you can change the application. Asynchronous inserts are useful when changing the client is difficult or impractical.

Option 1: Batch Inserts on the Client

Collect rows in your application and send them in a single INSERT rather than sending a separate query for every row.

A practical starting target is:

  • Batch size: 10,000–100,000 rows per INSERT.
  • Insert frequency: Approximately one INSERT per second for each table.

These values are starting points, not universal requirements. The appropriate batch size depends on row size, ingestion volume, latency requirements, and your workload.

Why does batching help?

A part containing thousands of rows generally has less overhead per row than many tiny parts. Sending approximately one INSERT per second also limits the rate of new part creation, assuming each INSERT touches a single partition.

For a workload that writes to one partition per INSERT, one INSERT per second means approximately 60 new parts per minute for that table and partition before merges are considered.

This reduces the work required from background merges and gives you greater control over batch size, retries, and error handling.

Whenever possible, client-side batching should be your first choice.

Option 2: Use Asynchronous Inserts

Sometimes, changing the application is not practical. Multiple clients may send small INSERT queries, or an application may be designed to write individual events.

Asynchronous inserts move the batching process to the ClickHouse server.

Instead of immediately creating a part for every incoming INSERT, ClickHouse collects incoming data in a server-side buffer. When the buffer flushes, the server writes the accumulated data.

This can significantly reduce part creation when many compatible inserts are received.

Enable Asynchronous Inserts

Turn on async_insert and keep wait_for_async_insert enabled.

There are several ways to configure these settings.

A. Configure a settings profile in users.xml

Use this approach when you want to configure a user or role through the server's settings profiles.

<clickhouse> <profiles> <default> <async_insert>1</async_insert> <wait_for_async_insert>1</wait_for_async_insert> </default> </profiles> </clickhouse> 

If your ingestion user uses a separate profile, configure that profile instead of changing the default profile.

B. Create a settings profile through SQL

For deployments where users and profiles are managed through SQL:

CREATE SETTINGS PROFILE IF NOT EXISTS ingest_profile SETTINGS async_insert = 1, wait_for_async_insert = 1 TO ingest_user; 

C. Configure a test session

To test the behavior in a single connection:

SET async_insert = 1; SET wait_for_async_insert = 1; 

D. Configure a single INSERT query

If only one writer needs asynchronous inserts, use the SETTINGS clause:

INSERT INTO events SETTINGS async_insert = 1, wait_for_async_insert = 1 VALUES (now(), 'login', 42); 

Choosing Asynchronous Insert Settings

Start with the following configuration principles:

async_insert = 1

Enables the asynchronous insert buffer. This is the main setting for server-side batching.

wait_for_async_insert = 1

Makes the client wait until the buffered data has been written successfully. The client receives success only after the write completes, making it easier to detect insert failures.

async_insert_busy_timeout_max_ms = 1000

Consider testing a timeout of 1,000 milliseconds instead of 200 milliseconds.

A longer timeout gives the server more time to accumulate incoming data, which can produce larger parts. The trade-off is increased insert latency: an INSERT may wait up to approximately one second for the buffer to flush, subject to other flush conditions.

Test this setting in a session:

SET async_insert_busy_timeout_max_ms = 1000; 

async_insert_max_data_size

Start with the existing 10 MiB value. Increase it only if parts remain small and the buffer is flushing because it reaches its size limit. Larger buffers consume more memory.

An Important Detail: Query Shape

ClickHouse maintains separate asynchronous insert buffers for different query texts and settings.

If clients send many differently formatted INSERT statements, the server may still create too many small parts because those inserts are accumulated in separate buffers.

Use consistent INSERT query text across clients whenever possible.

For additional configuration details, refer to the ClickHouse documentation on asynchronous inserts.

How to Verify the Fix

After changing your insert strategy, repeat the diagnostic queries from the earlier sections.

Wait approximately 10–15 minutes after making the change, then check the following:

  1. New parts per minute decrease. Fewer parts should be created for the same ingestion workload.
  2. Average rows per part increase. Each newly created part should contain more rows.
  3. Active part counts stabilize. MaxPartCountForPartition should stop growing continuously and may decrease as background merges catch up.

If these improvements do not appear, inspect the insert patterns, partitioning, asynchronous insert configuration, and merge activity again.

Inspect the Asynchronous Insert Log

If you use asynchronous inserts, the asynchronous insert log can help confirm whether buffering is working as expected.

First, check whether the log exists:

SELECT name FROM system.tables WHERE database = 'system' AND name = 'asynchronous_insert_log'; 

If the query returns no rows, the log may be disabled. Enable it in the server configuration before continuing.

Then inspect flush activity and insert results:

SELECT toStartOfMinute(event_time) AS minute, database, `table`, uniqExact(flush_query_id) AS flushes, count() AS async_inserts, sum(rows) AS total_rows, countIf(status != 'Ok') AS failed FROM system.asynchronous_insert_log WHERE event_time > now() - INTERVAL 1 HOUR GROUP BY minute, database, `table` ORDER BY minute DESC, flushes DESC LIMIT 50; 

Interpret the results as follows:

  • Many asynchronous inserts but relatively few flushes: This suggests that multiple inserts are being combined into fewer writes.
  • Flush counts: Compare these with the number of new parts reported by system.part_log. The counts should be broadly consistent, accounting for differences in logging, query types, and other part-creation paths.
  • Failed inserts: A value greater than zero in failed indicates that some asynchronous insert operations failed. Inspect the exception details for the affected records.

Monitoring these values helps verify that asynchronous inserts are reducing part creation rather than simply shifting the problem elsewhere.

Risks and Trade-Offs

Asynchronous inserts can reduce part creation, but they introduce considerations that should be understood before deployment.

1. Data Loss When wait_for_async_insert = 0

With wait_for_async_insert = 0, the server can return success while the data is still in the buffer and has not yet been written to disk.

If the server crashes before the buffer is flushed, buffered data can be lost even though the client has already received a successful response.

The client also may not receive flush errors directly. Parsing or flush errors may instead appear in the asynchronous insert log.

Use wait_for_async_insert = 0 only when you explicitly accept these risks and monitor the relevant logs. For data that cannot be rebuilt, keep wait_for_async_insert = 1.

2. Increased Insert Latency

When wait_for_async_insert = 1, a client may need to wait for the buffer to flush before receiving success.

A timeout of 1,000 milliseconds can add up to approximately one second of waiting, depending on when the buffer flushes and whether another flush condition is met.

Applications must be designed to tolerate this delay.

3. Additional Memory Usage

Asynchronous inserts hold buffered data in memory until it is flushed.

Larger values for async_insert_max_data_size, combined with many distinct query shapes, can increase memory consumption.

Monitor memory use while tuning buffer sizes and timeouts.

4. Duplicate Inserts During Retries

If a client times out while waiting for an INSERT to complete, it may retry the operation. Depending on the workload and deduplication behavior of the installed ClickHouse version, the data may be inserted more than once.

Review the applicable asynchronous insert deduplication behavior and design retry logic accordingly.

5. Client-Side Batching Is Still Preferable

When you can modify the application, batching on the client remains the preferred approach.

It reduces unnecessary server-side work and provides more direct control over batch sizes, retries, and error handling.

Asynchronous inserts are a useful alternative when client-side batching is difficult to implement.

Summary

The TOO_MANY_PARTS error usually indicates that a partition has accumulated too many active data parts. Frequent small INSERT queries are a common cause.

The most important takeaways are:

  • Diagnose the issue: Use system.part_log to count new parts and calculate average rows per part.
  • Find the affected partition: Use system.parts to identify partitions with high active part counts.
  • Monitor the error: Check system.asynchronous_metrics and system.errors.
  • Batch inserts whenever possible: Start by testing batches of 10,000–100,000 rows and approximately one INSERT per second per table, then tune to your workload.
  • Use asynchronous inserts when necessary: Enable async_insert and keep wait_for_async_insert = 1 for safer error handling.
  • Verify the outcome: Confirm that new parts per minute decrease, rows per part increase, and active part counts stabilize.
  • Avoid raising part limits as the first fix: Increasing the thresholds does not remove the underlying cause and may degrade query performance.

The goal is not simply to prevent an error. It is to create data parts at a rate that ClickHouse can manage efficiently.

References

  • ClickHouse documentation: Selecting an insert strategy
  • ClickHouse documentation: Asynchronous Inserts (async_insert)