Skip to content

Data Lifecycle

Mohammad Rasoul Kazemi edited this page Nov 26, 2026 · 2 revisions

Data Lifecycle

This page follows data from its creation to its removal, component by component. Every duration below is a default stated in a README or a script; set it where the README says it can be set. Where nothing is designed, the page says so.

User data in distributed tables

Stage What happens Source of the rule
Creation create_distributed_table splits a table into hash buckets (partitions named like <table>_b0001) and places them on shard groups. The table may hold rows. Sharding
Growth New nodes join through add_node(); a rebalance moves buckets (one move at a time by default; strategies by bucket count or by disk size, weights per server, draining a server). A bucket can be split in 2, 4, 8 or 16 parts with split_bucket; the bucket count of a colocation group is otherwise changed by alter_distributed_table (a rebuild). Rebalancing, Sharding Table Lifecycle
Move One bucket per move. The target gets a copy through logical replication, catches up, and the catalog switches. The old copy stays readable as kingres.orphan_<move>_<n> until move_cleanup_delay has passed and the worker or cleanup_moved_buckets() dropped it. For an erasure that must be final at once, run cleanup_moved_buckets(true) after the move. An old copy that objects of its owner depend on (a view, a foreign key) is not dropped; check_cluster() reports orphan_blocked until the dependent is dropped. A split leaves its old copies the same way and cleanup_bucket_splits() drops them. kingres_shard README
Distributed schema A schema is placed and moved as one unit (distribute_schema, move_schema, undistribute_schema); a move leaves the old copy under the same cleanup rule. Sharding
Rebuild undistribute_table and alter_distributed_table (blocking, or online) copy into a shadow table, swap, verify, and keep the old copy until table_cleanup_delay; kingres.cleanup_table_operations() drops overdue copies. check_cluster() reports old_table for a copy overdue by an hour. Sharding Table Lifecycle
Removal DROP TABLE as for any table. A table under ledger control cannot be dropped (see below). Ledger

Two-phase commit leaves bookkeeping that ages out by itself: the commit decisions in kingres.dtx_log are kept for kingres_shard.decision_retention seconds (default 300) after the participant's synchronous standbys confirm, and without limit until then; the marks in kingres.dtx_applied are kept as long and a minute; incidents in kingres.dtx_incident are shown by check_cluster() for 30 days.

Time-partitioned tables

kingres_timepart runs a cycle for each policy (default every hour, run_every):

  1. Create ahead. Partitions are created for the cells up to as_of + create_ahead (default 7 days) on a fixed grid, in one transaction each (CREATE TABLE ... (LIKE parent ...) then ATTACH PARTITION).
  2. Convert. Partitions of the grid that end at or before as_of - columnar_after are converted, oldest first, to the access method columnar with the policy's sort and options. Converting back to heap is the same call; a columnar partition accepts no UPDATE or DELETE, so it is converted to heap, changed and converted again.
  3. Retire. Partitions whose upper bound is at or before as_of - retention are detached and, for retention_action = 'drop' (the default), dropped. With detach the table stays with its rows and its name. A partition that spans the boundary stays until its upper bound passes, so data can be kept up to one partition_every longer than retention. Nothing deletes rows; the default partition and partitions off the grid are never retired.

columnar_after must not exceed retention. The history of runs and actions is kept for 90 days after the newest run and at most 1000 runs per table (timepart_prune_runs, called at the end of every run). Dropping the extension removes the policies and the whole history without a warning.

kingresd runs the policies on a scheduler and exposes them through the REST API and the console (policies, plans, runs; each run is a task, partition.maintain). A policy can also be run by SQL (timepart_run). On a user-partitioned distributed table the partitions are created, converted and retired on every server that holds a bucket.

Columnar tables

  • Rows are written in stripes and never changed. kingres.columnar_compact(rel, min_rows) merges stripes smaller than min_rows (by default a quarter of the stripe size). It changes nothing logically and does not block readers or writers.
  • VACUUM records counts, deletes catalog rows of dead files and returns the unreferenced tail of the file when it holds at least 1000 pages or a sixteenth of the file; it asks for the exclusive lock without waiting and gives up after 5 seconds. Since 0.2 the space that compaction and failed loads free inside the file is reused.
  • kingres.columnar_info shows unreferenced_bytes; kingres.columnar_reconcile() deletes catalog rows of files no relation uses.
  • Conversion: ALTER TABLE t SET ACCESS METHOD columnar rewrites under ACCESS EXCLUSIVE; back with SET ACCESS METHOD heap. A rewrite gives the new file the default options.
  • No UPDATE or DELETE. pg_upgrade of a columnar table is not supported in this version.

Sketches and rollups

A sketch is a column value. A rollup is rebuilt for a whole window or fed each source row exactly once; uniting a window with itself leaves an hll as it was and counts everything twice in topn and tdigest. See Data Model Analytics.

Ledger data

  • Ledger data is permanent by design. Enabling a table is permanent; DROP TABLE, TRUNCATE, DROP SCHEMA ... CASCADE of its schema, and DROP EXTENSION kingres_ledger while a ledger table exists are all rejected. No retention, compaction or archive of ledger tables is designed.
  • The one removal path is ledger_remove_stray(reason), for rows that a hand wrote and that are not part of the chain. Each removal is copied into ledger_removed and ledger_verify reports it for as long as it exists.
  • Published tiles and checkpoints are kept for ever ("Minimum index is always 0, nothing is pruned"). The publisher deletes a partial tile 24 hours after its full tile appears. A bundle is a set of files under the data directory, available for 24 hours.
  • The chain is closed, not deleted, when its database is dropped or its server is removed: a signed chain-retired event is published. After a restore or a loss at failover the old log is frozen (closed) and a new epoch starts; the old log stays served.
  • Digests in ledger_digest and verification records in ledger_verification accumulate; the sources describe no pruning for them.

Cluster state and logs

Data Lifecycle
Tasks in kingres_cp.task Not pruned; the control-plane README lists the lack of a retention as open.
Audit log (audit.jsonl) Append-only JSON lines; rotates at 64 MiB into audit.jsonl.<first id>; segments are never deleted.
Metrics No bundled store. A short in-memory history for the charts and /metrics for an external Prometheus (ADR 0020).
Standby replication slots A slot that retains slot-retention-warn-bytes (default 1 GiB) raises replicationLagHigh; above slot-retention-limit-bytes (default 4 GiB) the slot is dropped and the standby is rebuilt.
Certificates Renewed at a third of the lifetime left; the revocation list is valid 30 days and issued again after 10. The CA is not rotated.
Ledger signing keys Created, rotated, retired (bounded by max_tree_size) and revoked by tasks; a retired key's old signatures stay valid. See Ledger Signing and Publication.
Staged transfer files (kingres_cp.data_transfer) A table or database export, or an upload, is a sealed (encrypted) file in the staging directory of the manager leader. It expires after dataTransfer.retentionHours (1 to 168; 24 hours by default); a janitor deletes expired files, and an upload that received no bytes for 48 hours. An upload of a database import that is pending, running or paused is kept. Transfers are off until dataTransfer.enabled is on.

Archives

There is no long-term archive subsystem. What exists: export and import. A table can be exported as CSV and imported again (all-or-nothing, with a commit marker), and a whole database can be exported as one zip archive (exportDatabase), the archive validated without touching any database (validateDatabaseArchive) and imported as a new database (importDatabase). The archive carries structure and data but no roles, grants, functions, triggers, policies or large objects, and a ledger table restarts its chain on import (Administrator Guide). Staged files expire as described above. Other things that keep data for a time: a detached time partition (kept as an ordinary table), the old copy of a moved bucket or rebuilt table (kept for the cleanup delay), and a WORM anchor target (an object store with Object Lock, written by the anchoring, which stores signed checkpoints and not row data). Write-ahead log archiving and point-in-time recovery are not configured by KingresDB; see Backup Restore and PITR.

Sources

Clone this wiki locally