Skip to main content
The error means that a single file of a data part became too large to be uploaded to S3 with the configured multipart upload settings. The word “part” in the message is a part of an S3 multipart upload, not a ClickHouse data part. To fix it, keep the data parts smaller (do not run OPTIMIZE ... FINAL on very large partitions, keep max_bytes_to_merge_at_max_space_in_pool at its default), or change the upload settings of the disk so that upload parts can grow.

The error

The message has this form (code 318, INVALID_CONFIG_PARAMETER). The placeholders stand for the number of bytes written so far and for the effective settings:
It appears when a background merge or an OPTIMIZE writes its result to a disk backed by S3. A background merge that fails is retried and fails again, so the parts it was supposed to merge stay unmerged. How to find failed merges and mutations shows where to look for such failures.

Why it happens

On an S3 disk, every file of a data part is stored as a separate object. In a Wide part each column has its own data file, so the largest objects are the data files of the largest columns. A file larger than max_single_part_upload_size is sent as a multipart upload, and a multipart upload may have at most max_part_number parts. The default of 10000 is the limit of AWS S3 itself. The size of the upload parts is chosen as follows:
  • The first part has the size max_single_part_upload_size (32 MiB by default).
  • The following parts start at min_upload_part_size (16 MiB by default). After every upload_part_size_multiply_parts_count_threshold parts (500 by default), the size is multiplied by upload_part_size_multiply_factor (2 by default), up to max_upload_part_size (5 GiB by default).
  • If strict_upload_part_size is set, every part has exactly that size and nothing grows.
The largest file that fits is the sum of these part sizes. You can compute it for your settings. The values below are the defaults:
With the defaults the limit is far above the size of any reasonable data part. It becomes reachable when the upload parts do not grow. With upload_part_size_multiply_factor = 1 the same query returns 156.27 GiB, and with strict_upload_part_size the limit is max_part_number multiplied by that size, which is 156.25 GiB for 16 MiB. So the error needs two things at once: upload settings that keep the upload parts small, and a data part with a very large column file. Background merges limit the total size of the parts they merge by max_bytes_to_merge_at_max_space_in_pool (150 GiB by default), which is roughly the largest part they can produce. Very large files come from raising that setting, or from OPTIMIZE ... FINAL, which ignores it and merges a whole partition into one part.

Find the large parts and columns

Compare the settings printed in the error message with the size of the largest column files of the table. This query lists them, with the name of your database and table in place of db and events:
A merge fails when the column file of its result would exceed the limit, that is, roughly when the sizes of that column in the source parts add up to more than the limit.

Keep the data parts smaller

  • Do not run OPTIMIZE TABLE ... FINAL on partitions of this size. See Avoid OPTIMIZE FINAL.
  • If max_bytes_to_merge_at_max_space_in_pool was raised for the table, return it to the default, or lower it further so that the failing merge is no longer selected:
  • If you do need one part per partition, choose a partitioning key that keeps partitions smaller than the limit.

Or allow larger objects

On a self-managed server, change the upload settings. For data written by merges they are taken from the configuration of the S3 disk, where each setting has the prefix s3_:
The values shown are the defaults. Look in your disk configuration for other values of these settings and for s3_strict_upload_part_size. If the storage requires parts of equal size and you use s3_strict_upload_part_size, raise it until s3_max_part_number multiplied by it is larger than your largest column file. Larger upload parts need more memory for every file that is being written, see s3_max_inflight_parts_for_one_file. The same error can come from a query that writes one very large file to S3, for example INSERT INTO FUNCTION s3(...). There the query-level settings apply: increase s3_max_upload_part_size or s3_upload_part_size_multiply_factor, as described for s3_max_part_number.

ClickHouse Cloud

In ClickHouse Cloud the server configuration is managed for you and system settings are not configurable, so keep the data parts smaller as described above. If background merges keep failing with this error, contact ClickHouse support.