> ## 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.

# How to size min_insert_block_size_bytes to avoid TOO_MANY_PARTS on wide tables

> min_insert_block_size_bytes counts uncompressed bytes in memory, so parts on disk are much smaller than the setting. Measure compression and insert memory before you raise it.

`min_insert_block_size_bytes` decides how much data an `INSERT` collects before it writes a data part. It counts the bytes of the block in memory, before compression. On a wide, well-compressed table the parts on disk are therefore many times smaller than the setting, and an insert produces more parts than you would expect. When parts arrive faster than background merges combine them, inserts fail with `TOO_MANY_PARTS` (error 252).

Raising the setting gives fewer and larger parts, at the price of more memory per insert. Size it from two measurements: the compression ratio of freshly inserted parts and the peak memory of an insert.

## How blocks become parts

During an `INSERT`, ClickHouse squashes incoming data into blocks and writes one part per block (and per partition the block touches). With default settings, a block is closed as soon as it reaches either [`min_insert_block_size_rows`](https://clickhouse.com/docs/reference/settings/session-settings/min-insert#min_insert_block_size_rows) (default 1,048,449 rows) or [`min_insert_block_size_bytes`](https://clickhouse.com/docs/reference/settings/session-settings/min-insert#min_insert_block_size_bytes) (default 268,402,944 bytes, about 256 MiB).

On a table with many or large columns the byte limit is reached first. Once you raise it, the row limit becomes the next ceiling, so raise both or set `min_insert_block_size_rows = 0` to ignore the row count.

## Measured example

The table below stands for a wide log table: repetitive strings and a `Map` column that compress well.

```sql theme={null}
CREATE TABLE logs
(
    timestamp DateTime,
    service LowCardinality(String),
    level LowCardinality(String),
    host LowCardinality(String),
    trace_id UInt64,
    message String,
    attributes Map(LowCardinality(String), String)
)
ENGINE = MergeTree
ORDER BY (service, timestamp);

INSERT INTO logs
SELECT
    toDateTime('2026-01-01 00:00:00') + intDiv(number, 100),
    concat('service-', toString(number % 20)),
    ['debug', 'info', 'warning', 'error'][number % 4 + 1],
    concat('host-', toString(number % 50)),
    cityHash64(number),
    concat('Request ', toString(number), ' to /api/v1/items/', toString(number % 1000), ' finished with status 200 in ', toString(number % 300), ' ms; ', repeat('payload ', 20)),
    map('region', concat('region-', toString(number % 5)), 'version', '1.2.3', 'user', toString(number % 10000), 'path', concat('/api/v1/items/', toString(number % 1000)))
FROM numbers(4000000);

CREATE TABLE logs_copy AS logs;
SYSTEM STOP MERGES logs_copy;

INSERT INTO logs_copy SELECT * FROM logs SETTINGS max_insert_threads = 1;
```

Look at the parts that the insert created (`level = 0` selects parts that have not been merged yet):

```sql theme={null}
SELECT
    count() AS parts,
    round(avg(rows)) AS rows_per_part,
    formatReadableSize(avg(data_uncompressed_bytes)) AS uncompressed,
    formatReadableSize(avg(bytes_on_disk)) AS on_disk,
    round(sum(data_uncompressed_bytes) / sum(bytes_on_disk), 1) AS ratio,
    groupUniqArray(part_type) AS part_types
FROM system.parts
WHERE database = currentDatabase() AND table = 'logs_copy' AND active AND level = 0;
```

```text theme={null}
   ┌─parts─┬─rows_per_part─┬─uncompressed─┬─on_disk──┬─ratio─┬─part_types─┐
1. │     5 │        800000 │ 254.08 MiB   │ 8.11 MiB │  31.3 │ ['Wide']   │
   └───────┴───────────────┴──────────────┴──────────┴───────┴────────────┘
```

With the default of about 256 MiB, each part is only about 8 MiB on disk. The peak memory of the insert is in `system.query_log`:

```sql theme={null}
SELECT
    formatReadableSize(memory_usage) AS peak_memory,
    written_rows
FROM system.query_log
WHERE type = 'QueryFinish'
    AND query_kind = 'Insert'
    AND has(tables, concat(currentDatabase(), '.logs_copy'))
ORDER BY event_time_microseconds DESC
LIMIT 1;
```

```text theme={null}
   ┌─peak_memory─┬─written_rows─┐
1. │ 873.78 MiB  │      4000000 │ -- 4.00 million
   └─────────────┴──────────────┘
```

Repeating the insert into the emptied table (`TRUNCATE TABLE logs_copy`) with other settings, for example `SETTINGS max_insert_threads = 1, min_insert_block_size_bytes = 1073741824, min_insert_block_size_rows = 0`, gave these results on a test machine with version 26.12 (memory varies between runs):

| `min_insert_block_size_bytes` | `min_insert_block_size_rows` | `max_insert_threads` | Parts | Rows per part | On disk per part | Peak memory |
| - | - | - | - | - | - | - |
| 64 MiB | default | 1 | 20 | 200,000 | 3.57 MiB | 449 MiB |
| 64 MiB | default | 8 | 20 | 200,000 | 3.57 MiB | 1.58 GiB |
| default | default | 1 | 5 | 800,000 | 8.11 MiB | 874 MiB |
| default | default | 8 | 5 | 800,000 | 8.09 MiB | 2.27 GiB |
| 1 GiB | default | 1 | 4 | 1,000,000 | 10.14 MiB | 1.16 GiB |
| 1 GiB | 0 | 1 | 2 | 2,000,000 | 20.22 MiB | 1.94 GiB |

## What the numbers show

* **The setting is not the part size.** Estimate the size of a part on disk as the block size divided by the compression ratio of level-0 parts, and work backwards from the part size you want. Measure the ratio again after the change: in this example, small blocks compressed worse (17.8 at 64 MiB, 31.3 at the default).
* **Memory is a multiple of the setting, and the factor is not constant.** While one block is written, the next one is already being collected, and blocks are counted by their logical size, which is smaller than the memory allocated for them. Take the peak memory of real inserts from `system.query_log` and increase the setting in steps instead of computing a budget from the setting alone.
* **`max_insert_threads` does not change the number of parts.** The data is divided into blocks on a single stream, before it is handed to the insert threads, so the thresholds apply to the insert as a whole and not to each thread. The threads then build and write several of these blocks at the same time: the insert gets faster and uses more memory. Lowering the number of threads is a way to save memory, not to reduce parts. Since version 26.8 the default is `0`, which means the number of CPU cores; before it was `1`.
* **The row limit matters after you raise the byte limit.** With 1 GiB and the default row limit, blocks stopped at about one million rows.

## Before you raise the setting

* The server caps the effective value of `min_insert_block_size_bytes` at a fraction of its memory limit, [`insert_squashing_max_memory_ratio`](https://clickhouse.com/docs/reference/settings/session-settings/insert#insert_squashing_max_memory_ratio) (0.1125 by default). A value above the cap has no further effect: with a memory limit of 16 GiB, for example, the cap is 1.8 GiB.
* Check `part_type` with the query above after the change. With the other table settings at their defaults, a part is written in `Wide` format when the block reaches [`min_bytes_for_wide_part`](https://clickhouse.com/docs/reference/settings/merge-tree-settings/min-bytes#min_bytes_for_wide_part) (10 MiB by default in open-source ClickHouse; see `system.merge_tree_settings` for the value on your server), and in `Compact` format below it. If the table also sets [`min_rows_for_wide_part`](https://clickhouse.com/docs/reference/settings/merge-tree-settings/min-rows#min_rows_for_wide_part) or [`min_level_for_wide_part`](https://clickhouse.com/docs/reference/settings/merge-tree-settings/min-level#min_level_for_wide_part) (both `0` by default), a part is `Wide` only when it reaches all three thresholds: a block with fewer rows stays `Compact` whatever its size, and with `min_level_for_wide_part = 1` or higher every inserted part is `Compact`, because a new part has level 0. The byte comparison uses the size of the block in memory, which is not the same number as `data_uncompressed_bytes` or `bytes_on_disk` in `system.parts`. `Wide` parts store every column in separate files, which means more file operations per insert, noticeably so on object storage.
* [`parts_to_delay_insert`](https://clickhouse.com/docs/reference/settings/merge-tree-settings/parts-to#parts_to_delay_insert) and [`parts_to_throw_insert`](https://clickhouse.com/docs/reference/settings/merge-tree-settings/parts-to#parts_to_throw_insert) count active parts per partition. If one insert touches many partitions, every block is split into one part per partition, and larger blocks help less than a coarser partitioning key.

## Related pages

* [Resolving the "Too many parts" exception in ClickHouse](https://clickhouse.com/docs/resources/support-center/knowledge-base/troubleshooting/exception-too-many-parts.md)
* [How do I solve TOO MANY PARTS error during an INSERT...SELECT?](https://clickhouse.com/docs/resources/support-center/knowledge-base/performance-optimization/insert-select-settings-tuning.md)
* [Understanding part types and storage formats](https://clickhouse.com/docs/resources/support-center/knowledge-base/data-management/understanding-part-types-and-storage-formats.md)
* [`max_insert_threads`](https://clickhouse.com/docs/reference/settings/session-settings/max-insert#max_insert_threads)
