Skip to content

Docs: document BACKUP, RESTORE and ALTER TABLE ... UNLOCK SNAPSHOT - #131672

Draft
groeneai wants to merge 9 commits into
ClickHouse:masterfrom
groeneai:docs-backup-restore-statements
Draft

groeneai wants to merge 9 commits into
ClickHouse:masterfrom
groeneai:docs-backup-restore-statements

Conversation

@groeneai

@groeneai groeneai commented Nov 14, 2026 •

Copy link
Copy Markdown
Collaborator

Related: #131085

Changelog category (leave one):

  • Documentation (changelog entry is not required)

Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):

Document the BACKUP, RESTORE and ALTER TABLE ... UNLOCK SNAPSHOT statements in the SQL reference.

Description

One of the PRs for the statements without reference documentation that @ Blargian asked for in #131085. BACKUP and RESTORE were described only in the backup and restore guides, and ALTER TABLE ... UNLOCK SNAPSHOT only in the snapshot backup guide.

ParserBackupQuery gets documentation entries for BACKUP and RESTORE and is registered, and the ALTER documentation gains an ALTER TABLE ... UNLOCK SNAPSHOT entry and a row in the ALTER overview. The new backup.mdx, restore.mdx and alter/unlock-snapshot.mdx pages are committed with their generated content. The pages cover elements, destinations, archives, ON CLUSTER, ASYNC, the result, privileges and every BACKUP/RESTORE specific setting with its default, taken from system.backups.settings. The guide overview links the two pages.

Each page and section states the version it was introduced in, checked on the release tags. BACKUP and RESTORE are not behind any setting. BACKUP FROM SNAPSHOT, ALTER TABLE ... UNLOCK SNAPSHOT and the experimental_lightweight_snapshot setting are marked experimental and ClickHouse Cloud only; their Cloud behaviour comes from the snapshot guide and the source, so the docs team may want to check that wording. In open-source builds ALTER TABLE ... UNLOCK SNAPSHOT returns without an error and BACKUP FROM SNAPSHOT fails with BACKUP_IS_EMPTY; not changed here.

Validation: I checked the open-source behaviour the pages describe on a server built from this branch (File, Disk, S3 on MinIO, Memory, Null, archives, ON CLUSTER, privileges), and the examples are copied from those runs. I regenerated the pages with autogenerate_docs.py --write --only 'statement:' and ran lychee_check.py (links and redirects, 0 errors; a corrupted anchor is reported), navigation_check.py and mint validate (no error in these pages). The committed regions match master's generator run against this branch's binary (--check). 04926_system_statements fails without the three new reference lines and passes with them.

🤖 Generated with Claude Code


Workflow [PR]
Sync PR [sync-upstream/pr/131672]

groeneai and others added 4 commits November 14, 2026 16:21
`BACKUP` and `RESTORE` were documented only in the backup and restore
guides, and `ALTER TABLE ... UNLOCK SNAPSHOT` only in the snapshot backup
guide, although the parsers accept all of them.

`ParserBackupQuery` gets documentation entries for `BACKUP` and `RESTORE`
and is registered, and the `ALTER` documentation gains an `ALTER TABLE
... UNLOCK SNAPSHOT` entry and a row in the `ALTER` overview, so
`system.statements` exposes them and the docs autogeneration fills the
new `backup.mdx`, `restore.mdx` and `alter/unlock-snapshot.mdx` pages.
The pages cover the full grammar: elements, destinations, archives,
`ON CLUSTER`, `ASYNC`, the result, every BACKUP and RESTORE specific
setting with its default (taken from `system.backups.settings`), the
privileges, and `BACKUP FROM SNAPSHOT`.

Each page and section states the version it was introduced in, measured
on the release tags through the GitHub API. `BACKUP FROM SNAPSHOT`,
`ALTER TABLE ... UNLOCK SNAPSHOT` and the `experimental_lightweight_snapshot`
setting are marked experimental and ClickHouse Cloud only; `BACKUP` and
`RESTORE` themselves are not behind any setting.

Every behaviour on the pages was observed on a server built from this
branch, and the examples are copied from those runs. The generated
regions are left to the autogeneration workflow.

Related: ClickHouse#131085

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The five-argument form takes a storage account URL, not a connection
string (`registerBackupEngineAzureBlobStorage.cpp`).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…or limits

The pages now state that ZIP archives are also refused on a `Disk` backed
by S3 or Azure object storage and that no archive can be used with
`ON CLUSTER`; that temporary tables need no `BACKUP` privilege, that a base
backup needs the `READ` source privilege (for `RESTORE` also the base the
backup records) and that a named collection destination needs
`NAMED COLLECTION`; the `extra_credentials` argument of `S3` and the
`key = value` overrides of a named collection locator; that
`compression_level` is not supported for TAR archives; how the server
settings `backups.data_file_name_generator` and
`backups.data_file_name_prefix_length` change the defaults; the
ClickHouse Cloud settings `resumable_backup_batch_size` and
`resumable_backup_batch_size_bytes`; and that `RESTORE ... ALL` exists
since v22.7. The first example creates its database, and the
asynchronous example says the `system.backups` query runs after the
backup finished.

Each new sentence was observed on a server built from this branch.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ege limits

`ON CLUSTER` legs run outside the current session, so the pages now say
that `Memory` destinations and session temporary tables cannot be used
with it and that `ALL` leaves those temporary tables out. The
`experimental_lightweight_snapshot` row says a snapshot backup cannot be
created with `ON CLUSTER` and cannot be a `base_backup`. The
`NAMED COLLECTION` privilege covers named collections used by base backup
locators too, and overriding a stored collection parameter needs
`SHOW NAMED COLLECTIONS SECRETS`. The Cloud-only `BACKUP FROM SNAPSHOT`
and `ALTER TABLE ... UNLOCK SNAPSHOT` state the `READ` source privilege of
the snapshot destination, and the `RESTORE` page links the guide section
on engines it cannot recreate (a standalone `MaterializedPostgreSQL`
table).

The session and privilege sentences were observed on a server built from
this branch; the snapshot and `MaterializedPostgreSQL` ones follow the
code paths that reject them.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@groeneai

Copy link
Copy Markdown
Collaborator Author
Internal second-model review (rounds 1-3)
Finding Verdict
⚠️ Archives are refused with ON CLUSTER, and ZIP on a Disk backed by S3/Azure; the pages did not say so AGREE, fixed
⚠️ Privileges: temporary tables need no BACKUP grant; base_backup needs READ, a named-collection destination needs NAMED COLLECTION AGREE, fixed
⚠️ Examples: missing CREATE DATABASE, the ASYNC example did not say the SELECT runs after completion AGREE, fixed
⚠️ extra_credentials(...) and named-collection key = value overrides missing from the destination forms AGREE, fixed
⚠️ Cloud-only resumable_backup_batch_size* settings missing AGREE, fixed
⚠️ Memory and session temporary tables cannot be used with ON CLUSTER AGREE, fixed
⚠️ Snapshot backups: not with ON CLUSTER, not usable as base_backup AGREE, fixed
⚠️ NAMED COLLECTION also applies to base backup locators; overriding a stored key needs SHOW NAMED COLLECTIONS SECRETS AGREE, fixed
⚠️ Source privileges of BACKUP FROM SNAPSHOT and ALTER TABLE ... UNLOCK SNAPSHOT (Cloud executor not in this repository; written from the backup factory's access checks) AGREE, fixed
⚠️ RESTORE cannot recreate some engines (MaterializedPostgreSQL) AGREE, fixed
💡 compression_level on TAR, data file name defaults from the server config, RESTORE ALL version AGREE, fixed
💡 Snapshot guide link and legacy redirect could point at the new page noted, not changed
💡 RESTORE ALL ... ON CLUSTER of a backup that holds session temporary tables fails instead of skipping them noted, not changed
💡 replica_num_in_backup = 0 falls back to the first replica in the backup when the host's replica is missing noted, not changed

@mintlify

mintlify Bot commented Nov 14, 2026 •

Copy link
Copy Markdown
Contributor

Preview approval required

This pull request comes from a fork, so Mintlify won't build a preview until someone with write access approves commit 1235f2a.

Approve preview

@groeneai

Copy link
Copy Markdown
Collaborator Author

cc @jkartseva, could you review this? It adds SQL reference pages for BACKUP, RESTORE and ALTER TABLE ... UNLOCK SNAPSHOT (generated from ParserBackupQuery and the ALTER documentation): elements, destinations, archives, ON CLUSTER, privileges and every setting from system.backups.settings; a check of the backup semantics and the Cloud snapshot wording would help.

@groeneai

Copy link
Copy Markdown
Collaborator Author
Pre-PR validation gate (click to expand)
# Question Answer
a Deterministic repro? On master SELECT name FROM system.statements WHERE name IN ('BACKUP', 'RESTORE', 'ALTER TABLE ... UNLOCK SNAPSHOT') returns nothing, so no reference page can be generated. With this branch it returns 3 rows.
b Root cause explained? Statement pages are generated from getDocumentation() of the parsers registered in registerParsers.cpp. ParserBackupQuery had no documentation and was not registered, and the ALTER documentation had no UNLOCK SNAPSHOT entry.
c Fix matches root cause? Yes: documentation entries in the parser sources plus the registration, the #131085 mechanism. New pages carry only frontmatter and empty markers.
d Test intent preserved / new tests added? 04926_system_statements lists the three new names; the generic documentation tests (04927, 04357, 04408, 04409, 04413, 04600, 05043) cover their shape.
e Both directions demonstrated? 04926 fails with the old reference (+ALTER TABLE ... UNLOCK SNAPSHOT, +BACKUP, +RESTORE) and passes with the new one. The generator fails with RESTORE has no matching page when restore.mdx is removed, and writes all three pages with it.
f Fix is general across code paths? Both verbs of ParserBackupQuery and both snapshot unlock forms are covered; SYSTEM UNLOCK SNAPSHOT belongs to the SYSTEM page, documented separately.
g Fix generalizes across inputs (params/datatypes/wrappers)? Every element, destination (File, Disk, S3, Memory, Null), archive format, ON CLUSTER, ASYNC and setting on the pages was run on a server built from this branch, as were the archive and ON CLUSTER limits and the privileges of temporary tables, base backups and named collections; AzureBlobStorage and the Cloud-only snapshot limits are described from their code paths only.
h Backward compatible? (maintainer-approved exception only) Yes: documentation text only, no behaviour or setting change.
i Invariants and contracts preserved? Every registered name has one page with a matching title, every related name is registered, no generated region is edited (check_autogenerated_regions.py passes, and fails on a hand edit), all links and anchors resolve (lychee_check.py), every page is in navigation.

Session id: cron:clickhouse-impl-slot-6:20261114-153400

@clickhouse-gh

clickhouse-gh Bot commented Nov 14, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [1235f2a]

Summary: ❌

job_name test_name status info comment
Finish Workflow FAIL
python3 ./ci/jobs/scripts/workflow_hooks/can_be_merged.py FAIL

@clickhouse-gh clickhouse-gh Bot added pr-documentation Documentation PRs for the specific code PR can be tested Allows running workflows for external contributors comp-documentation Documentation (docs, examples, READMEs). labels Nov 14, 2026
@groeneai

Copy link
Copy Markdown
Collaborator Author

CI finish ledger - 2a59e88

Every failure below has an owner: a fixing PR (mine or external), or a full-effort fix task
whose fixing-PR link will be posted here when it opens. Only CH Inc sync is exempt.

Check / test Reason Owner / fixing PR
Build profile diff infra, not from this PR: the job stopped before any comparison, because all 8 readiness probes (SELECT 1) to the CI logs cluster hit the 3 s read timeout and it raised LogClusterNotReady: the endpoint never became ready in has_pr_data. The same error hit 11 other PRs between 20:51Z and 22:01Z #129675 (mine, open)

Session id: cron:our-pr-ci-monitor:20261114-223011

groeneai and others added 3 commits November 16, 2026 01:53
…-statements

# Conflicts:
#	tests/queries/0_stateless/04926_system_statements.reference
ClickHouse#126158 enabled clang-tidy modernize-use-nodiscard (WarningsAsErrors), so the
new override fails Build (arm_tidy), as ParserTransactionControl.h:12 does on
master. Same spelling as every other getDocumentation override in src/Parsers.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…edPostgreSQL and replica_num rules

- `structure_only` still stores the named collections the backup selects,
  with their values (observed: `data/system/named_collections/<nc>.sql`
  carries the secret; `backup_named_collections = 0` leaves it out).
- `RESTORE` of a `MaterializedPostgreSQL` database fails with
  CANNOT_RESTORE_DATABASE, also with `create_database = 'must-exist'`
  (RestorerFromBackup.cpp, observed against PostgreSQL 16).
- `replica_num` selects that replica in each shard
  (BackupSettings::Util::filterHostIDs).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@groeneai

Copy link
Copy Markdown
Collaborator Author

CI finish ledger - e92f9fa

Every failure below has an owner: a fixing PR (mine or external), or a full-effort fix task
whose fixing-PR link will be posted here when it opens. Only CH Inc sync is exempt.

Check / test Reason Owner / fixing PR
Build (arm_tidy, 2/4) not from this PR: master was red the same way since #126158 enabled modernize-use-nodiscard; the only error is src/Parsers/ParserTransactionControl.h:12:5: function 'getDocumentation' should be marked [[nodiscard]], a file this PR does not touch; this run started before the fix merged #131891 (external, merged)
Build (arm_tidy, 3/4) same error as 2/4 #131891 (external, merged)
Build (arm_tidy, 4/4) same error as 2/4; these three failures dropped the dependent jobs, which did not run on this head #131891 (external, merged)
Sync - CH Inc sync (private, not actionable by me)

Session id: cron:our-pr-ci-monitor:20261116-033010

@Blargian Blargian self-assigned this Nov 16, 2026

@clickhouse-gh clickhouse-gh Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AI review approves this commit, see the AI Review comment.

@Blargian

Copy link
Copy Markdown
Member

@groeneai if you add the stubs without the documentation we'll get a blank page deployed. Please add the content as part of this PR.

@Blargian Blargian added the pr-autogenerated-docs PR that regenerates docs artifacts from source; exempt from the autogenerated-region edit guard label Nov 18, 2026
@Blargian
Blargian marked this pull request as draft November 18, 2026 15:57
The new reference pages were empty AUTOGENERATED stubs that the nightly
docs regeneration fills, so deploying this PR before that run would
publish blank pages (asked in
ClickHouse#131672 (comment)).

Fill the generated regions of `backup.mdx`, `restore.mdx` and
`alter/unlock-snapshot.mdx`, plus the new `UNLOCK SNAPSHOT` row of the
`ALTER` overview table, with the output of master's generator
(`autogenerate_docs.py --only 'statement:'`) run against a binary built
from this branch. The PR carries the `pr-autogenerated-docs` label.

Drop the explicit badge imports from the `BACKUP` and
`ALTER TABLE ... UNLOCK SNAPSHOT` descriptions: since ClickHouse#131704 the
generator adds the imports of the badges a page renders, which is where
the committed pages get them from.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@groeneai

Copy link
Copy Markdown
Collaborator Author

Done in 1235f2a21856: the BACKUP, RESTORE and ALTER TABLE ... UNLOCK SNAPSHOT pages, and the new row of the ALTER overview, now carry their generated content. It is the output of master's generator run against a binary built from this branch, and its --check reports the pages in sync. I also dropped the explicit badge imports from the two descriptions, since the generator adds them now (#131704).

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

can be tested Allows running workflows for external contributors comp-documentation Documentation (docs, examples, READMEs). pr-autogenerated-docs PR that regenerates docs artifacts from source; exempt from the autogenerated-region edit guard pr-documentation Documentation PRs for the specific code PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants