Skip to content

Backup Restore and PITR

Mohammad Rasoul Kazemi edited this page Nov 30, 2026 · 4 revisions

Backup Restore and PITR

The first release, 0.1.0, ships no automated backup and no point-in-time-recovery (PITR) archive configuration (limitations.md, "Packaging and distribution"). There is no schedule, no backup catalog and no WAL archiving set up by the product. What exists is the set of PostgreSQL tools under a kingres- prefix that you run by hand, one restore-point function in kingres_shard, the export and import of a database and of a table, and documented procedures and limits. This page collects them without promising more. The operator steps are in Runbooks and Operations; the guide text is section 7 of the operator guide.

Planned: phase 22 of the roadmap plans backups made by the product with PostgreSQL native incremental backup, decided on 2026-11-30 (incremental physical backups, a WAL archive, repositories on S3-compatible storage and directories, a cluster restored to a coordinated restore point, one database or one table restored through a scratch restore), and phase 23 plans clones and snapshots. Neither is built; this page describes what can be done today. See Status and Roadmap.

What must be backed up

Item Where Notes
Every shard group's data each primary's instance directory under /var/lib/kingres A group is the unit of a physical backup; there is no cluster-wide backup command.
The system database kingres_system (schema kingres_cp) on the map group Cluster state. It is also inside the map group's physical backup.
The whole node state /var/lib/kingres Stop the service for a cold copy. It includes the CA key and the service credentials, so treat the copy as a secret.
Ledger key files and the passphrase <ledger-keys-dir> (default <data-dir>/ledger/keys) Back up the directory and the passphrase file separately and off the cluster, whenever a key is created or rotated or an anchor credential changes. getLedgerSigning reports backupAdvised until the operator says a backup was made.
The record of what was published <ledger-keys-dir>/published.json Mode 0600, no secrets. See "Restoring the system database" below.
The CA key and revocation list <data-dir>/pki/ca.key and revoked.json on the server that holds the CA Back them up off the cluster. The escrow of the key to the servers that host standbys of the map group is off until an administrator switches it on. Without a current copy, after a failover of the map group the new leader raises certificateAuthorityUnavailable until you restore pki/ca.key and pki/revoked.json from the old leader's backup.
The key of the data transfer <data-dir>/transfer.key (transfer-key-file) It seals the staged files of the CSV transfer and of database export; it is part of file-level backups of the data directory.
The ledger digests held by auditors outside the cluster These are the root of trust; a backup of the database does not replace them.

Logical backup

  • kingres-pg_dump, kingres-pg_dumpall and kingres-pg_restore are installed with the package. A dump of a node holds that node's bucket partitions and the reference tables in full, and CREATE EXTENSION IF NOT EXISTS kingres_shard; it holds nothing of the cluster catalog and nothing of kingres.cluster_secret. It also holds the tables kingres.orphan_* that finished moves left (leave them out with -T 'kingres.orphan_*').
  • Restoring a dump of one node. t/059_restore_node.pl runs these cases: (1) a dump restored into an empty database elsewhere gives plain tables, nothing belongs to a cluster; (2) a node that lost its database is put back by creating an empty database with the same name on the server at the node's old address, restoring the dump, then running SELECT kingres.sync_catalog() on the map group primary, which gives the node the catalog, the secret and its node id; the restored data is as old as the dump; (3) partitions of a node still in the cluster can be repaired from a dump with kingres_shard.enable_routing = off in the restoring session, dumping only the partitions (pg_dump --data-only --disable-triggers -t 'public.d_b*') and emptying the damaged ones first; (4) not supported: add_node() of a node that already holds the tables of the cluster. A dump of a node that took part in a bucket move after the dump was made no longer fits the cluster.
  • kingres_timepart policies and history are carried by pg_dump (the tables are extension configuration). The restore needs a superuser, and the policies come back with stale OIDs; the next run re-identifies tables by name (timepart_adopt).
  • kingres_columnar: pg_dump writes CREATE TABLE ... USING columnar and the rows as COPY; the options of a table live in its metapage, so a restored table takes the settings of the restoring session.
  • kingres_ledger: pg_dump does not dump the ledger tables. A restored database has a new, empty ledger with a new chain identity, does not verify as the old one, and inserts into a restored ledger table fail (the entry refers to a table id that is not registered). Use physical backups, standbys or pg_upgrade.

Export and import of a database (and of a table)

The product has its own export and import, built in phases 14a to 14c (operator guide, sections 12 and 13). They are off by default (cluster setting dataTransfer.enabled), need TLS and kingres_admin, and are a way to copy a database, not a scheduled backup:

  • POST /api/v1/databases/{db}/export writes one zip archive (structure, a catalog of what KingresDB adds, one CSV entry per table, a manifest with SHA-256 sums), staged and sealed on the manager leader (transfer-dir) for a limited time. The archive is checked (validateDatabaseArchive) and imported (POST /api/v1/database-imports) as a new database, in this cluster or another.
  • It carries no roles, grants, functions, triggers, policies or large objects. Plan to make them again by hand.
  • A ledger table is carried as data and restarts its chain: the import needs acknowledgeLedgerRestart: true, and the old blocks, digests, proofs and anchors do not verify against the new database. Keep the exported database and its digests if you must prove the earlier history.
  • Time-partition policies come back switched off.
  • The import needs free space for the expanded archive on every server, fails at its last step when a primary changed during it (do not switch over or drain during an import), and is read as hostile input (only what pg_dump writes is accepted).
  • Export and import of one table as CSV have no global snapshot (the file of a table spread over several groups is per group), take at most 2 GiB of decompressed CSV in one import and have no batches.

There is no global snapshot in these exports either; see Limitations and Known Issues.

Physical backup and standbys

kingres-pg_basebackup -h 127.0.0.1 -U <role with REPLICATION> -D DIR -X stream takes a physical copy (a replication rule in the network access page is needed). kingresd itself uses pg_basebackup -X stream over a certificate-authenticated connection to create and rebuild standbys. pg_basebackup, incremental backup, archive recovery and pg_rewind work with the columnar library preloaded. A base backup taken while writers hold reservations of row numbers restores to a clean state.

Coordinated restore points

kingres.create_restore_point(name) (map group primary, superuser) raises a barrier on every primary, waits until no distributed transaction is between its first PREPARE TRANSACTION and the end of its second phase, calls pg_create_restore_point(name) on every primary, and lowers the barrier. Restoring every server to that name (recovery_target_name = name) gives a state in which no distributed transaction is half committed (tested with three servers restored under a multi-node write load).

What it does not give:

  • Standbys. Only primaries get a restore point; a standby is rebuilt from the restored primary.
  • A bucket move in progress. A restore brings the move back as it was; resume_bucket_moves() (the recovery worker does) undoes or finishes it.
  • Sequences. Values handed out after that point are handed out again.
  • Time. The restore points of the nodes are made at slightly different moments; single-node statements that commit between the first and the last are in one node's restored state and not another's.
  • A node with wal_level = minimal refuses.
  • Transactions whose second phase failed or was deferred are in the restored state and are resolved by kingres.recover_prepared_transactions() after the restore.

After the restore: a restored map primary ends on a new timeline, which the catalog reads as "promoted without it". Run SELECT kingres.promote_node(<the map primary's node id>) on the map primary (it needs the majority of the other groups, which are restored too; repeat until the answer is already).

PITR itself is PostgreSQL's: KingresDB gives the coordinated name, not the WAL archive. Archive settings (archive_command and restore_command) are refused by name in the configuration page of the console because PostgreSQL 18 shows them to every database user.

What a restore means for the ledger

The ledger cannot prevent a restore and does not try. Restoring a database to an earlier state, or losing the last blocks at an asynchronous failover, gives a chain shorter than what was already published and anchored and, once it accepts new transactions, a different history from that height on: a fork of the same chain_id.

flowchart TD
  r["Restore or loss at failover"] --> s["Chain is shorter than published"]
  s --> d["Publisher stops the log: diverged, alert ledgerChainDiverged"]
  d --> a["Operator acknowledges with a reason"]
  a --> e["Task ledger.epoch.start: epoch-closed event, old log closed, new log epoch+1 from block 0"]
  e --> v["Verifier: new epoch verifies alone; comparing with old epoch fails and says why"]
Loading
  • Detection: the publisher finds the head below the published size or a different hash at a published height, stops the log, flags its aggregate member diverged and raises the critical alert ledgerChainDiverged. The database keeps working; nothing is published for that chain until it is acknowledged.
  • Procedure (console "Acknowledge divergence", REST acknowledgeLedgerDivergence): the operator states a reason and types the database name; the task ledger.epoch.start publishes the signed event epoch-closed, freezes the old log (its tiles stay served for ever), starts epoch e+1 from block 0 of the current chain and clears the alert. Transactions above the common height exist only in the published tiles, anchors and mirrors.
  • An auditor who holds an anchored head of the old history learns that the history was cut. kingres-verify has --accept-epoch-closed <seq> to turn that failure into a printed finding for the new epoch alone; it never hides the finding.
  • A physical clone shares the chain_id until the two diverge; publishing under another originPrefix makes the logs distinguishable.

Restoring the system database

  • The tiles, checkpoints and anchor records are derived from the chains and from keys the host still has. A restore of kingres_cp from an older backup once made the publisher sign a second root for a published size; since the fix, every holder of the key files keeps published.json with the highest size and root of every log, and a round compares the database with it. A database that holds less than was published signs nothing and raises the critical alert ledgerSignerUnavailable with subject published-state; it clears itself when the database holds what was published.
  • Not covered: a restore when every copy of the record is lost or older than the publication, and a restore of both the database and the record to the same older point. Only a mirror or an auditor holding a later checkpoint shows the fork.
  • After a restore of the system database, an operator accepts the loss (ADR 0025, status Accepted). First restart every kingresd of the cluster: the manager leader raises the term of the ledger when it takes over, and writes of the ledger key set from the old term fail until it has. The critical alert ledgerSignerUnavailable (subject published-state) then says what was published, what the database holds, and a confirmation of sixteen hexadecimal digits. Check that the database really was restored and that no newer backup exists. On the host of the manager leader write the confirmation, and on a second line a reason of up to 200 printable ASCII characters, into <ledger-keys-dir>/accept-restore. The leader makes its record what the database holds, one generation higher, keeps the old record as published.json.before-restore-<generation>, removes the file and publishes the signed event restore-acknowledged before it signs anything else. The logs fork against a mirror that holds the old checkpoints, and the event is the public statement of that. There is no REST operation for this; it needs access to the host of the leader. See Ledger Signing and Publication.
  • Loss of every signing key file: the chain and published history are not harmed; no further checkpoint can be signed. The console offers "Replace lost key", which marks the key ring discontinuity: true, and every auditor must replace the trust file with one obtained out of band.
  • A restored host puts the key directory back from backup before kingresd starts; a kingresd that finds no key for an active key row raises ledgerSignerUnavailable and signs nothing.

Not designed or not built

  • Automated backup scheduling, a backup catalog, WAL archiving and PITR configuration through the console: none in 0.1.0. The parameters archive_mode and archive_command are refused by the configuration page.
  • Cluster-wide consistent physical backup other than the restore-point procedure above.
  • A backup of the certificate authority key by the product (the escrow to standbys of the map group is optional and is not a backup; keep your own copy).
  • Restoring a ledger from a logical dump (there is no supported way to load a ledger with COPY).

Sources

Clone this wiki locally