Skip to content

Data Architecture

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

Data Architecture

This page is the entry to the data documentation of KingresDB. It shows where data lives, how it moves, and which page describes each part. Everything is taken from the SQL scripts of the extensions, the migrations of the system database and the READMEs. The first release, 0.1.0, was published on 2026-11-28; the install scripts of the default versions (kingres_shard 0.9, kingres_ledger 0.3, kingres_columnar 0.2, kingres_timepart 0.3, kingres_sketch 1.0) and the migrations 0001 to 0045 of the system database are the sources of the data model pages.

Conceptual model

KingresDB keeps five kinds of data. They have different owners and different trust.

Kind Where it lives Who writes it Page
User data ordinary tables, hash-partitioned into buckets across shard groups; reference tables copied whole to every node the application Data Model Sharding
Sharding catalog schema kingres in every database of every node: nodes, colocation groups, bucket map, distributed schemas, user partitions, moves, splits, table operations kingres_shard (the map group primary is the authority, the other nodes hold copies) Data Model Sharding
Ledger data schema kingres, tables ledger_*, inside each shard group's database; a history table per updatable ledger table the extension kingres_ledger only (a guard refuses every other writer) Data Model Ledger
Cluster state database kingres_system, schema kingres_cp, on the map group: tasks, servers, alerts, settings, standbys, failover and rebalance records, ledger keys, tiles, checkpoints, anchors, records of staged transfer files kingresd (the manager leader) Data Model System Database
Analytics storage columnar files, the time-partitioning catalog, sketch values in ordinary columns kingres_columnar, kingres_timepart, kingres_sketch Data Model Analytics

Outside PostgreSQL, kingresd also keeps files: the certificate authority and server keys, the service credentials, the ledger signing key files, anchor credentials, the staged transfer files and their master key, the audit log and the record of what was published (published.json). See Data Security.

flowchart LR
  app["Application"] --> pg["PostgreSQL node: user tables and kingres catalog"]
  pg --> led["ledger tables"]
  cp["kingresd"] --> sys["kingres_system database, schema kingres_cp"]
  cp --> files["files: keys, audit log, published.json"]
  cp --> pg
  sys --> pub["Publication: tiles and checkpoints"]
  pub --> anc["Anchor targets"]
  pub --> ver["Verifier"]
Loading

Data flows

Writes. A write to a distributed table can be sent to any node. The node routes each row by the hash of the distribution column (bucket = hash modulo the bucket count of the colocation group) to the shard group that owns the bucket. A statement that touches several groups commits with two-phase commit (PREPARE TRANSACTION on each participant, a durable commit decision on the origin, then COMMIT PREPARED). Reference tables are written on every node. See Architecture Runtime Views Sharding and Sharding.

Reads. A read is answered by the row-moving scan, which stays as the fallback for every query shape, or by a faster path (pushdown) that sends the statement or a partial aggregate to the groups. Each group is read at its own snapshot; there is no global snapshot (phase 8 is in design, not built). See Sharding Query Pushdown.

Replication. A shard group is a primary and optional standbys on streaming physical replication, created by kingresd with pg_basebackup. A synchronous standby makes the outcome of a distributed transaction atomic across a failover. Catalog changes are made on the map group primary and pushed to the other nodes (sync_catalog), carrying a term so that a node refuses a push of an older term. See High Availability.

Moves. A bucket move copies the bucket's partitions to the target group with logical replication (a publication, a slot and a subscription), catches up, switches in the catalog, and keeps the old copy as kingres.orphan_* until move_cleanup_delay has passed. A bucket can also be split in 2, 4, 8 or 16 parts. See Rebalancing and Data Lifecycle.

Distributed schemas. In the schema mode of a database a whole schema is one unit of placement: its tables live on one shard group (a colocation group of kind schema with one bucket) and are empty shells on the others. A schema is moved with the same replication path as a bucket. See Sharding.

Export and import. A table is exported as CSV and a database as one zip archive, both as a sealed staged file on the manager leader, kept for a limited time and downloaded by the role that made it. An import reads an uploaded file as the importing role; a database import builds a private database and gives it its final name at the end. See Data Lifecycle and Data Security.

Table rebuilds. The online variants of distributing, undistributing and altering a table build a shadow table, copy, catch up with a captured log, swap, verify and keep the old copy for table_cleanup_delay. See Sharding Table Lifecycle.

Ledger publication and anchoring. A capture trigger writes one entry per row version; a background worker builds blocks; kingresd reads each group's chain through read functions, extends a transparency log per chain and an aggregate log per database in kingres_cp, signs checkpoints, and serves tiles on a listener. Anchoring sends the latest aggregate checkpoint to targets (WORM store, RFC 3161 authority, OpenTimestamps). An auditor checks it all with the verifier. See Ledger, Ledger Signing and Publication, Ledger Anchoring and The Verifier.

flowchart LR
  w["Row write"] --> e["ledger_entry and ledger_pending"]
  e --> b["ledger_tx and ledger_blocks"]
  b --> t["chain log in kingres_cp: tiles and checkpoints"]
  t --> a["aggregate log"]
  a --> p["publication listener"]
  a --> x["anchor targets"]
  p --> v["kingres-verify"]
  x --> v
Loading

Where to read next

Sources

Clone this wiki locally