Skip to main content
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 (default 1,048,449 rows) or 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.
Look at the parts that the insert created (level = 0 selects parts that have not been merged yet):
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:
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):

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 (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 (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 or 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 and 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.