> ## 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 add a disk to a ClickHouse server

> Add a second disk to a self-managed ClickHouse server by declaring it in the storage configuration and adding it to the volume of the storage policy that your tables use.

To give existing `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, named `default`, which is the directory from the `path` server setting, and one storage policy, also named `default`, with a single volume named `default`:

```sql theme={null}
SELECT policy_name, volume_name, disks
FROM system.storage_policies;
```

```text theme={null}
   ┌─policy_name─┬─volume_name─┬─disks───────┐
1. │ default     │ default     │ ['default'] │
   └─────────────┴─────────────┴─────────────┘
```

Every table created without the `storage_policy` setting uses this policy:

```sql theme={null}
CREATE TABLE my_table
(
    id UInt64,
    value String
)
ENGINE = MergeTree
ORDER BY id;

INSERT INTO my_table SELECT number, toString(number) FROM numbers(1000);

SELECT name, disk_name, rows
FROM system.parts
WHERE table = 'my_table' AND active
ORDER BY name;
```

```text theme={null}
   ┌─name──────┬─disk_name─┬─rows─┐
1. │ all_1_1_0 │ default   │ 1000 │
   └───────────┴───────────┴──────┘
```

## Add the disk

First, mount the new device and create a directory on it that the user of the ClickHouse server (usually `clickhouse`) 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:

```xml theme={null}
<clickhouse>
    <storage_configuration>
        <disks>
            <disk_2>
                <path>/mnt/disk2/clickhouse/</path>
            </disk_2>
        </disks>
        <policies>
            <default>
                <volumes>
                    <default>
                        <disk>default</disk>
                        <disk>disk_2</disk>
                    </default>
                </volumes>
            </default>
        </policies>
    </storage_configuration>
</clickhouse>
```

The `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

```sql theme={null}
SELECT name, type
FROM system.disks
ORDER BY name;

SELECT policy_name, volume_name, disks
FROM system.storage_policies;
```

```text theme={null}
   ┌─name────┬─type──┐
1. │ default │ Local │
2. │ disk_2  │ Local │
   └─────────┴───────┘
   ┌─policy_name─┬─volume_name─┬─disks────────────────┐
1. │ default     │ default     │ ['default','disk_2'] │
   └─────────────┴─────────────┴──────────────────────┘
```

`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:

```sql theme={null}
INSERT INTO my_table SELECT number, toString(number) FROM numbers(1000, 1000);
INSERT INTO my_table SELECT number, toString(number) FROM numbers(2000, 1000);

SELECT name, disk_name, rows
FROM system.parts
WHERE table = 'my_table' AND active
ORDER BY name;
```

```text theme={null}
   ┌─name──────┬─disk_name─┬─rows─┐
1. │ all_1_1_0 │ default   │ 1000 │
2. │ all_2_2_0 │ default   │ 1000 │
3. │ all_3_3_0 │ disk_2    │ 1000 │
   └───────────┴───────────┴──────┘
```

Which part goes to which disk depends on the position of the round-robin counter, and background merges replace these parts with larger ones, so your output can differ.

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

```sql theme={null}
ALTER TABLE my_table MOVE PART 'all_1_1_0' TO DISK 'disk_2';
```

The query on `system.parts` from above now returns:

```text theme={null}
   ┌─name──────┬─disk_name─┬─rows─┐
1. │ all_1_1_0 │ disk_2    │ 1000 │
2. │ all_2_2_0 │ default   │ 1000 │
3. │ all_3_3_0 │ disk_2    │ 1000 │
   └───────────┴───────────┴──────┘
```

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

## Related pages

* [Using multiple block devices for data storage](https://clickhouse.com/docs/reference/engines/table-engines/mergetree-family/mergetree.md#table_engine-mergetree-multiple-volumes)
* [`ALTER TABLE ... MOVE PARTITION|PART`](https://clickhouse.com/docs/reference/statements/alter/partition#move-partitionpart)
* [`system.disks`](https://clickhouse.com/docs/reference/system-tables/disks) and [`system.storage_policies`](https://clickhouse.com/docs/reference/system-tables/storage_policies)
* [Configuration files](https://clickhouse.com/docs/concepts/features/configuration/server-config/configuration-files.md)
