Skip to main content
A new or restored replica of a ReplicatedMergeTree table in self-managed ClickHouse doesn’t repeat the inserts and merges of the past. It downloads (fetches) the existing data parts from another replica. By default the fetches are not limited in bandwidth and up to 16 of them run in parallel, which can saturate the network or the disks of the replicas involved. To throttle the recovery, limit the fetch speed on the recovering replica, the send speed on the source replicas, or the number of parallel fetches.

What a recovering replica does

When a replica is created empty or restored after data loss (see Recovery after failures), it puts one GET_PART entry for every part of a source replica into its replication queue. Check the queue on the recovering server:
During recovery almost all entries are of the type GET_PART. A small number of MERGE_PARTS or MUTATE_PART entries can appear as well.

Settings that throttle the fetches

The server settings go to the top level of the server configuration, for example into a file in config.d. This example limits the fetches of the server to 50 MiB per second and to four at a time:
The server reads the two bandwidth settings at startup, and background_fetches_pool_size can’t be lowered while the server runs. Put the limits in place before you start the server that is going to recover, or restart it. The table-level settings can be given in the SETTINGS clause of CREATE TABLE, changed with ALTER TABLE, or set for all tables in the merge_tree section of the server configuration:
A table reads its limit when it is loaded, so a changed value applies after the next server restart. When both a table limit and a server limit are set, a fetch is slowed down by both. The limits are not followed with perfect accuracy.

Pause the fetches without a restart

To stop the fetches for a while, for example during peak hours, use SYSTEM STOP FETCHES on the recovering replica, for one table or for all tables. The queue entries are kept and are executed after SYSTEM START FETCHES:

Monitor the recovery

The fetches that are running now are listed in system.replicated_fetches:
Entries that wait because of a limit show the reason in the postpone_reason column of system.replication_queue, for example:
The recovery is finished when the queue is empty:
The fetch pool and the server-wide limits also apply to the regular replication of newly inserted parts. Remove the limits when the replica has caught up, or keep them high enough for the normal insert rate.