MergeTree tables more space on a self-managed server, declare the new disk in storage_configuration and add it to the volume of the storage policy that the tables use. ClickHouse applies the change when it reloads its configuration, without a restart, and starts writing new data parts to both disks. Parts that already exist stay where they are.
Starting point
A server without any storage configuration has one disk, nameddefault, which is the directory from the path server setting, and one storage policy, also named default, with a single volume named default:
storage_policy setting uses this policy:
Add the disk
First, mount the new device and create a directory on it that the user of the ClickHouse server (usuallyclickhouse) can write to, for example /mnt/disk2/clickhouse/.
Then create a file in the config.d directory of the server, for example /etc/clickhouse-server/config.d/storage.xml. It declares the new disk and redefines the default policy so that its default volume contains both disks:
path of a disk must end with /. The disk default does not have to be declared.
Finally, wait for the server to reload its configuration (it checks the files every two seconds by default), or run SYSTEM RELOAD CONFIG.
If your tables use a policy of your own, add one more <disk> line to the volume of that policy instead of redefining default.
Check the result
system.disks also shows path, free_space and total_space of every disk. If the policy did not change, look in the server log for the message An error has occurred while reloading storage policies, storage policies were not applied, followed by the reason.
New parts are now written to both disks:
Move existing data
ClickHouse does not rebalance existing parts when a disk is added. The old disk stays as full as it was, and only new parts (from inserts and merges) are spread over the disks. To free space on the old disk, move parts or whole partitions yourself:system.parts from above now returns:
Things to know
- Disks of one volume are used in turn (
round_robin, the default). Add<load_balancing>least_used</load_balancing>to the volume to write each new part to the disk that has the most free space. - A changed policy must keep all volumes and disks it had before. Otherwise the reload is rejected and the old policy stays in effect. Removing a disk from the configuration takes effect only after a restart.
- Several disks in one volume work like JBOD: there is no redundancy, and a failed disk takes the parts stored on it with it. Use replication if you need to survive a disk failure.
- The storage configuration belongs to one server. On a cluster, repeat the change on every server that gets a new disk.
- To use the new disk as a separate tier instead (for example, slower storage for old data), put it in a second volume. See the reference below.