Skip to content

Runbooks

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

Runbooks

Procedures for the situations an operator meets. Every step comes from the operator guide, the README of the control plane or the REST contract, and uses operations that exist in the contract (kingres/api/openapi.yaml, 0.34.0) and pages of the console. Where the sources document no procedure, the runbook says so and does not fill the gap. Failover is new in the first release, 0.1.0 (2026-11-28): test your recovery procedure on your own cluster before you rely on it (High Availability). Alerts named here are described in Monitoring and Alerts; error texts in Troubleshooting.

All REST calls need a signed-in session with the role named in the contract; changing operations are audited (REST API Reference). The console pages named below are the ones of the console router: Dashboard, Servers, Server, Databases, Database, Table, Shards, Replication, Rebalance, Security, Ledger, Workbench, Tasks, Alerts, Logs, Settings, Configuration and This server (Web Console).

A server is lost

State: built (High Availability); test it on your own cluster first. The console has it on the Servers page (fail a server over) and the Replication page.

  1. The manager leader raises serverSuspect after suspect-timeout (default 5s) without heartbeats, then serverDown after failure-timeout (default 10s). The leader is the server that runs the primary of the map group; if that server is the lost one, see the map group case below.
  2. Decide whether the server is lost or only unreachable. Nothing in the sources says how long to wait; automatic failover (off by default) waits for max(timeoutSeconds, 3 x failure-timeout), a strict majority of servers reporting it not live, and no failover in the last 5 minutes.
  3. Look at the plan without changing anything: POST /api/v1/servers/{serverId}/failover with mode: hard and dryRun: true answers 200 with the plan.
  4. Fail over for real with mode: hard. A request that could lose asynchronously replicated writes is refused with 409 failover_needs_decision (and the alert of that name) until the request says allowDataLoss. That is a decision of the operator, not a retry. One group at a time, the map group last; one failover at a time in the whole cluster. Servers that run different versions of kingresd (alert versionMismatch) refuse it with version_mismatch; finish the upgrade first (Upgrades).
  5. Follow the task (GET /api/v1/tasks/{taskId}, GET /api/v1/failover) and read the report (GET /api/v1/failover/reports). Check the alerts failoverDataLoss, splitPromotion, oldPrimaryRunning.
  6. When the server returns, its old primary is made a standby of the new primary by itself: pg_rewind, or a new base backup when the WAL it needs is gone; only a directory proved to be a former primary is touched. Watch oldPrimaryNotRebuilt (after ten minutes or half of standby-replace-after, default 30m).
  7. If the server never returns, after standby-replace-after its standby records are marked for removal and replacements are made on other servers (a dead server gets no new standby). Removing the server itself (removeServer) is refused for a dead server (422 node_state_invalid: fail it over first), for the last server, for a server that holds an instance of the map group and for a server that still owns buckets (409 server_owns_buckets). The sources do not describe removing a lost server that still appears in the bucket map; check GET /api/v1/replication/topology after the failover. A server that owns buckets cannot be removed (rebalance first, or drain it: POST /api/v1/servers/{serverId}/drain). Right after a rebalance emptied the server, removeServer forces the cleanup of the moves of its groups that are still in the cleaning phase and waits for about two minutes while one of them is still cleaning (the task says what it waits for); it no longer fails with SQLSTATE 55006 when another cleanup holds a move at that moment. If it still fails, repeat the request.
  8. To give groups back to their home servers once the failed server returned: POST /api/v1/replication/restore-preferred-primaries (also with dryRun).

The map group. A failover of the server that runs the primary of the map group is started in mode hard and run by a standby of group 0 from a journal that survives a restart of kingresd. If the escrow of the certificate authority key was switched on beforehand (the Certificate authority tab of the Security page; it is off until an administrator switches it on), the new leader opens its own copy and goes on. Without it the new leader holds no key of the certificate authority and raises certificateAuthorityUnavailable until the operator restores pki/ca.key and pki/revoked.json of the old leader from its backup into the pki directory of the new leader and restarts kingresd, so a backup of the key must exist. Until then no certificate can be issued, renewed or revoked, addServer, joinCluster, removeServer and leaveCluster answer 503 certificate_authority_unavailable, and the cluster keeps running on its certificates until they expire.

The map group while its server is alive. mode: hard for the server that runs the primary of the map group also works while that server answers (a failing disk, a postmaster that hangs): the leader judges the loss, fences its own primary and hands the lease to a standby's server. Ask for dryRun first. Accepting a loss of data (allowDataLoss) in this request needs kingres_admin.

The candidate of the map group dies. If the standby that was handed the map group dies, the bootstrap cannot finish and the old leader stays held back. Declare it lost: POST /api/v1/failover/map/abandon (kingres_admin) with reason and lostServerId (the failover dialog of the map group in the console has a field for it). The lost server must have been silent for the failure timeout, and the old leader must hold a current cache of the administrators' keys (younger than admin-keys-max-age, 72 hours by default). With only one standby of the map group every REST call answers 503 and the declaration cannot work; the way out is the local command on the server of the old leader, with kingresd stopped: kingresd -release-map-hold -lost <serverId> -accept-data-loss (plus the settings of the server, at least -data-dir and -server-host). It is your word that what the lost server may have promoted is given up and that it never starts again with its old data directory; remove it from the cluster afterwards. The operator guide (section 6) has the details. If the abandon answers 503 with Retry-After, a promotion, a create, a remove or a rebuild of a standby is running on the server that holds the bootstrap (the abandon waits at most 25 seconds for it); wait for the time in Retry-After and repeat the call. The same 503 comes back when you call another server and it forwarded the call. When the bootstrap that you gave up was asking for the fence or holder lease, it lets the lease go, so the old leader wins it again and a drain that waited for it goes on.

A planned switchover

State: built (High Availability).

  1. POST /api/v1/servers/{serverId}/failover with mode: graceful, first with dryRun: true. For the server that runs the primary of the map group it is a planned switchover too, with the map group last; read the task from the new leader. Do not run a planned switchover, and do not restore preferred primaries, while servers of two versions run (Upgrades).
  2. For each group the task pauses the writes, lets distributed transactions end, stops the old primary cleanly, proves that the standby replayed everything, then promotes it. The pause of writes is not kept across a restart of kingresd.
  3. A failure before the promotion rolls back (the old primary takes the writes again) and the task ends failed with standby_behind, switchover_unproven, cannot_quiesce or prepared_transactions_pending. Read the code, fix the cause (a lagging standby, open prepared transactions), start again. The task can be cancelled (POST /api/v1/tasks/{taskId}/cancel) until the promotion begins.
  4. If a switchover task fails, check the old primary (is it writable, did the writes resume) before you continue. A stop that takes longer than the call allows (90 seconds) is rolled back and the task ends switchover_unproven; this is more likely under heavy machine load, so repeat the request when the load is lower. A task that is paused after the promotion with the critical alert failoverBlocked and a message that a step "cannot read" a catalog is waiting for an instance that was starting or stopping: check that the instance named runs, then repeat the request to run the step again. If the map group is stuck, POST /api/v1/failover/map/abandon gives up the bootstrap (for a planned switchover the old leader rolls back).

A disk is full or filling

The monitor raises diskSpaceLow at 90% (warning) and 95% (critical) of the data disk. The sources document no procedure for a full disk; the contract reserves a problem code insufficient_disk for a later increment, and the README of the control plane says the free-disk check of a rebalance is not verified on real servers. What the sources do say:

  • A standby whose replication slot holds more WAL than the warning limit raises replicationLagHigh; the slot is dropped at the retention limit and the standby is then rebuilt.
  • The instance log is under /var/lib/kingres/instances/1/pgdata/log/ in a package install and is rotated by weekday.
  • The audit log rotates at 64 MiB and its segments are never deleted.
  • A rebalance can plan by disk size (byDiskSize) and a server can be emptied with a drain (POST /api/v1/servers/{serverId}/drain, preview with .../drain-preview), then removed (Rebalancing). The contract names the code insufficient_disk for a bucket move or split and for an export or import that does not find room.
  • A drain handing over the map group, an import and an export need free space on every server; the import compares the expanded archive with the free space of every server before it starts.

Anything beyond that (adding a disk, moving data) is ordinary PostgreSQL administration that this documentation does not cover.

A rebalance stops or fails

State: built (Rebalancing). A run makes one move at a time. The Rebalance page of the console shows it.

  1. POST /api/v1/rebalance/stop stops it: the move in flight is cancelled (undone before the switch; a move that is switching is waited for), the run is recorded stopped and the task is paused. POST /api/v1/rebalance (startRebalance) goes on with the same task. A stopped rebalance does not block updateServer and removeServer.
  2. A failed move is retried after 30 s times its failures, up to three tries; a bucket given up ends the run failed, the report is written first and the alert taskFailed carries the task. Read the report (GET /api/v1/rebalance/reports/{reportId}).
  3. Moves skipped because a lease was lost, a required synchronous standby was not in sync or the target disk was low are in the report and are not failures.
  4. A rebalance cannot run while a server.add, server.remove, server.leave or server.failover task is unfinished, and the reverse; a start is then refused with 409. It is also refused while a database import is unfinished, while servers run different versions (version_mismatch), and (without force: true) while a standby lags by more than maxStandbyLagBytes (group_degraded). A failed automatic run raises rebalanceFailed and suspends the automatic mode until an operator starts a rebalance.
  5. After a restart of kingresd or a change of leader the new leader takes the task over and settles a move left running through the extension (resume_bucket_moves()). The cancel of a task (cancelTask) stops a rebalance like a stop and records the run cancelled without a taskFailed alert.
  6. An instance created before wal_level = logical was written needs a restart; the check says so.

A certificate expires or a renewal fails

State: built; the CA itself is not rotated.

  1. The renewal job of each server renews its certificate when less than certificate-renew-fraction (default 0.3333) of its lifetime is left. After three failures in a row certificateRenewalFailed is raised.
  2. To renew by hand: renewServerCertificates (POST /api/v1/servers/{serverId}/certificates/renewals, role kingres_admin, task certificate.renew). It is the way for a server whose own job cannot (an expired certificate cannot call the leader; the leader can still call it). It is 409 certificate_revoked for a revoked server.
  3. If the alert is certificateAuthorityUnavailable or the renewals answer 503 certificate_authority_unavailable, the leader does not hold pki/ca.key: restore it as in the map group case above.
  4. The certificate of the cluster CA itself is not rotated. certificateExpiring with the aspect ca warns one year before the end and is critical 30 days before. The sources document no procedure for replacing the CA.
  5. The public certificate of the panel (tls-cert-file) is the operator's own and is not touched by the renewal job.

To lock a server out: revokeServerCertificates (.../certificates/revocations, task certificate.revoke). The internal API of every server and the PostgreSQL instances then refuse it; open connections run until they end. It never gets a new certificate. A server that owns no bucket is removed with removeServer and added again with a new setup token. Revoking a server that owns data is a one-way door in that version. The certificates of the leader cannot be revoked.

Restore of the system database

The system database kingres_system (schema kingres_cp) is on the map group (Data Model System Database). There is no automated backup: you take the backup (Backup Restore and PITR). What the sources state about a restore:

  • After restoring it, restart every kingresd of the cluster. The manager leader raises the term of the ledger when it takes over; writes of the ledger key set from the old term fail until it has.
  • The tiles, checkpoints and anchor records for the chains are public data derived from the chains and from keys the host still has. The aggregate log and the events cannot be derived again.
  • Each holder of the key files keeps published.json, the highest size and root of every log. A database that is behind it signs nothing and raises the critical alert ledgerSignerUnavailable with the subject published-state, which says what was published, what the database holds, and a confirmation of sixteen hexadecimal digits. An operator accepts the loss (ADR 0025): 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 keeps the old record as published.json.before-restore-<generation>, replaces it by what the database holds, and publishes the signed event restore-acknowledged before it signs anything else. There is no REST operation for this. The logs fork against a mirror that holds the old checkpoints; the event is the public statement of that.
  • Put the key directory (ledger/keys, default <data-dir>/ledger/keys) and the passphrase file back from backup before kingresd starts. A started kingresd that finds no key for an active key row raises ledgerSignerUnavailable and signs nothing.
  • The CA key and pki/revoked.json are files in the data directory, not in the database; they need their own backup.
  • A restore to an earlier state of a chain is a fork of the ledger: see the next runbook.

A ledger chain has diverged

State: built (Ledger Signing and Publication); the Ledger page of the console has the acknowledgement.

The alert ledgerChainDiverged (critical) means the head of a chain is lower than what was published, or a published block changed: a restore of an older state, a point-in-time recovery, blocks lost in an asynchronous failover, or tampering. The ledger cannot tell which. Nothing is signed over that chain, nothing repairs it, and the database keeps working; other chains keep being published.

  1. Establish what happened (a restore you made, a failover with allowDataLoss, or something you cannot explain). If you cannot explain it, treat it as an incident: the published tiles and any anchors hold the old history.
  2. If the cut was intended or unavoidable, acknowledge it: acknowledgeLedgerDivergence (POST /api/v1/databases/{databaseName}/ledger/chains/{shardGroupId}/acknowledge, role kingres_admin). The body gives a kind (restore, failoverLoss or other), a reason and the database name as confirmation. It answers 409 chain_not_diverged when there is nothing to acknowledge.
  3. The task ledger.epoch.start publishes a signed epoch-closed event (with the final size and root, the common height, the kind, the reason and who acknowledged it), freezes the old log for ever, starts a new epoch log built from block 0 of the current chain, and clears the alert. Anchors continue with the next aggregate checkpoint.
  4. A verifier compares the two epochs and reports that the history was cut, when and by whom; --accept-epoch-closed prints the finding and does not hide it (The Verifier).
  5. A pg_dump and restore is not a restore of the chain: it gives an empty ledger with a new chain identity.

Key rotation, retirement and revocation of the ledger signing key

State: built (Ledger Signing and Publication); the signing tab of the Ledger page of the console has these actions.

  • Back up first. Back up <ledger-keys-dir> and the passphrase file separately and off the cluster whenever a key is created or rotated. The console shows a reminder (backupAdvised) until the operator ticks that a backup was made; the tick proves nothing.
  • Create or rotate: createLedgerSigningKey (POST /api/v1/ledger/signing/keys). With an active key the call is a rotation; the new key is given to the servers that may become the leader (the leader and the servers that run shard group 0), a signed key-added event is published, and the latest checkpoint of every log is signed again. A holder that cannot be reached gets the key later (job ledger.key.sync). One key task runs at a time in the cluster.
  • Retire (the key is no longer used and its past signatures stay valid): retireLedgerSigningKey (.../keys/{fingerprint}/retire). The key is bound to a maximum tree size, so what it signed stays valid and anything it signs later is refused. Refused with 409 last_signing_key when no other key is active and in force.
  • Revoke (the key is compromised): revokeLedgerSigningKey (.../keys/{fingerprint}/revoke) with the date it is compromised since. It needs another active key (the control plane never makes one inside a revocation), publishes a signed key-revoked event, signs again and deletes key files no server needs.
  • After a change, give auditors a new trust file from getLedgerTrustFile through a channel outside the cluster; verifiers pin the trust file, not the database.
  • All copies of the key lost with no other active key: the chain and the published history are not harmed but nothing more can be signed. The design offers "Replace lost key" in the console: a new key signs a key-added event alone, the key ring is marked discontinuity: true, and every auditor must replace their trust file out of band.
  • A key task fails with a code such as key_set_damaged, clock (retryable; the clocks of the server and of the database differ by more than two minutes), term_over, not_leader, key_files_remain or key_file_missing. The alert ledgerSignerUnavailable shows a damaged set or a missing file.
  • Client signing keys of a database (registerLedgerClientKey, revokeLedgerClientKey) are separate and are described in Ledger.

A lease was lost

leaseLost (critical): no majority of servers renewed the lease of a group in time. With a standby the primary was stopped so that no second primary exists; the instance does not start again without a lease. Without a standby the primary keeps running and writes are not protected by a lease. The sources document no manual step beyond looking at the cluster (check_cluster() in the extension, the failover status) and, if a server is gone, the first runbook.

An old primary is still running

oldPrimaryRunning, oldPrimaryNotStopped: kingresd stops an instance whose role file says primary on a port that the catalog calls a standby (checked every 2 seconds) and the lease keeps the old primary from acting. If the alert stays, the sources document no manual command.

Sources

Clone this wiki locally