Create a snapshot
Snapshot backup uses the standardBACKUP command with experimental_lightweight_snapshot = true. The id setting is required — it names the snapshot and is used to reference it in unlock and observability commands:
id and status, and the id can be used to track the operation in system.backups.
Backup a single table to S3:
Restore to the same service
Because a snapshot stores references to object storage files rather than copies of the data, restoring to a new or different ClickHouse service requires access to the original object storage. For that reason, cross-service restore is not supported via SQL — it is only available through the UI. By SQL, you can restore a snapshot to the same service from an external backup bucket usingsnapshot_from_current_service = 1. This reads objects directly via the destination disk instead of going through a remote snapshot reader:
AS clause restores into a new table name, leaving the original table intact. To overwrite the original table, drop it first:
Unlock a snapshot
Each snapshot holds locks in ClickHouse Keeper that prevent the referenced object storage files from being garbage collected. After a restore completes — or when a snapshot is no longer needed — unlock it to release those locks. There are two forms: a system-level unlock that removes all locks for the snapshot at once, and a per-table unlock that removes the lock for a single table while leaving the rest of the snapshot intact. System-level unlock — removes all locks for the snapshot:FROM clause is optional when the snapshot destination was stored in Keeper at creation time (visible in the info column of system.snapshot_locks):
system.snapshot_locks, and parts no longer referenced by other snapshots drop out of system.snapshot_parts.
Observability
system.backups
All snapshot operations appear insystem.backups alongside regular backup and restore operations. Query it with the id you set (or the UUID returned by the command):
system.snapshot_locks
system.snapshot_locks shows the committed snapshots currently registered in Keeper. When a snapshot is committed, a Keeper node is created at /clickhouse/snapshot/committed/{snapshot_id}. Before deleting any data part, the server checks whether a committed snapshot holds a lock on that part. If one does, deletion is skipped. The lock persists until you explicitly unlock the snapshot.
| Column | Type | Description |
|---|---|---|
id | String | Snapshot ID |
info | String | Snapshot destination, e.g. S3('...') |
ctime | DateTime | When this lock was created in Keeper |
lock_path | String | Keeper path for this lock |
SYSTEM UNLOCK SNAPSHOT to clean them up.
To check whether a specific snapshot lock is present:
system.snapshot_parts
system.snapshot_parts shows the data parts currently pinned by at least one snapshot lock. For each locked part, a Keeper node exists at /clickhouse/snapshot/{table_uuid}/{part_name} containing the part’s compressed and uncompressed size. This table reads those nodes to show which parts are currently protected from deletion.
| Column | Type | Description |
|---|---|---|
name | String | Data part name |
table_id | String | UUID of the table this part belongs to |
data_compressed_bytes | UInt64 | Compressed size of this part |
data_uncompressed_bytes | UInt64 | Uncompressed size of this part |
snapshots_size | UInt64 | Number of snapshots currently holding a lock on this part |
snapshots_size > 1 are referenced by multiple snapshots and won’t be removed from object storage until all holding snapshots are unlocked.
To check total pinned storage:
Server settings
The following server configuration parameters control snapshot behavior. They are set in the server configuration file, not in SQL.| Setting | Type | Default | Changeable without restart | Description |
|---|---|---|---|---|
max_held_snapshots | UInt64 | 0 | No | Maximum number of lightweight snapshots that can be held at the same time. 0 means unlimited. If the limit is reached, creating a new snapshot throws an exception. |
max_snapshot_commit_thread_pool_size | UInt64 | 64 | Yes | Number of threads used to commit snapshot lock nodes into Keeper. Increase this if snapshot creation is slow on large tables with many parts. |
max_snapshot_commit_thread_pool_free_size | UInt64 | 0 | Yes | If the number of idle threads in the snapshot commit pool exceeds this value, ClickHouse releases those threads and shrinks the pool. Threads are created again on demand. 0 means idle threads are never released. |
snapshot_cleaner_period | UInt64 | 120 | No | How often (in seconds) the snapshot cleaner runs to remove parts that are no longer referenced by any snapshot lock. ClickHouse Cloud only. |
snapshot_cleaner_pool_size | UInt64 | 128 | No | Number of threads in the snapshot cleaner thread pool. ClickHouse Cloud only. |