Repository navigation
Data Quality and Integrity
KingresDB has several checks, each for a different layer. None of them replaces the others. This page lists what each check proves, what it does not, and how to run it. For what to do with a finding, see Runbooks and Troubleshooting.
| Layer | Check | Proves | Does not prove |
|---|---|---|---|
| Cluster structure | kingres.check_cluster() |
catalogs agree, every bucket partition exists where the map says, nothing is left behind by moves, no old prepared transactions | that the rows of a partition are right (it is structural) |
| Standbys | kingres.standby_status() |
each standby streams and is in recovery | that data is identical |
| Ledger inside the database | kingres.ledger_verify() |
the chain, blocks, trees and entries are consistent with each other and with the tables | integrity against someone who rewrites the whole chain consistently |
| Ledger against an outside copy |
ledger_verify_digest, kingres-verify
|
the chain matches a digest or checkpoint kept outside the database | transactions not yet covered by a digest |
| Columnar storage |
columnar_check(), columnar_check_clean(), columnar_check_indexes()
|
catalog rows and files agree; stripes and chunks readable; indexes have entries for visible rows | nothing about logical content beyond CRCs |
| Time partitioning | kingres.timepart_check() |
policies are suitable, partitions are ahead, nothing is misaligned or blocked | n/a |
| B-tree indexes | PostgreSQL amcheck
|
index structure | see the columnar limit below |
| Table rebuilds | built-in verification (kingres_shard.rebuild_verify) |
the old and new copy hold the same rows after the swap | writes after the swap |
SELECT * FROM kingres.check_cluster(); -- older_than defaults to 5 minutes
SELECT * FROM kingres.check_cluster(interval '1 hour'); -- age of a prepared transaction that counts as oldRun it on the map group primary as a superuser. It returns one row (check_name, node_id, object, detail) per inconsistency; no rows means consistent, in the structural sense only: it never compares the rows, indexes, constraints or replica identity of a partition with its parent, and a copy that diverged in content does not show up. After a move, compare counts or checksums of the bucket's tables yourself if you need that assurance. The checks are:
- Catalog:
catalog_differs,extension_version_differs,secret_missing,server_major_differs,node_unreachable. - Buckets:
partition_missing,partition_misplaced,stray_bucket_table,bucket_map_incomplete,group_without_primary. - Moves and splits:
orphan_table,orphan_blocked(an old copy that objects of its owner keep from being dropped),stalled_move,split_stalled,replication_slot,publication,subscription,replication_origin,bucket_moving_without_move,move_without_moving_bucket. - Transactions:
prepared_transaction(older than the argument),foreign_prepared_transaction,prepared_rolled_back_after_failover,participant_lost_committed_transaction,decision_unconfirmed. - Partitions and layout:
bucket_layout,dist_partition_mismatch,leaf_conversion_stale(a claim ofkingres_timeparton the leaves of a partition that nobody renewed). - Distributed schemas:
schema_missing,schema_table_missing,schema_structure_differs,stray_schema_rows,schema_catalog_differs. For ledger tables:ledger_distributed_table(a ledger table that the catalog also lists as a distributed or reference table) andledger_on_non_owner(a ledger table on a node that does not own its distributed schema). - Reference tables:
reference_table_differs(copies compared by their rows). - Standbys:
standby_unreachableand related problems. - Online table operations:
table_operation_stalled,shadow_table,log_table,capture_trigger,old_table,table_verification_failed.
kingresd calls check_cluster() itself inside a failover (after resolving prepared transactions, with incidents going into the report of the run) and expects it clean after a move; a general scheduled run with alerts is not described in the sources. See High Availability and Monitoring and Alerts.
Rebuild verification. In the cleaning phase of an online table operation, kingres.internal_table_digest() compares row counts and a digest of the old and new copy; a difference makes the call fail and shows as table_verification_failed. A table written after the swap can give a false failed, which only keeps the old copy.
SELECT * FROM kingres.ledger_verify(); -- from block 0 to the head; no rows when consistent
SELECT * FROM kingres.ledger_verify(1000, 2000); -- a range of heights
SELECT kingres.ledger_verify_recorded(); -- the same, recorded in kingres.ledger_verification; returns the idIt reads every ledger table and entry and returns (check_name, object, detail) per problem. It detects changed fields, wrong links or hashes, gaps, rows that point above the head, an unregistered capture trigger, an operator_removal record, and (for client signatures) duplicate attestations, unknown or malformed client keys, orphan attestations and unattested entries under policy required. It does not verify signatures and does not detect blocks removed from the end together with the rows that refer to them. A digest or signed checkpoint kept elsewhere does.
Run it on a schedule. The console's Ledger page and the REST API run it as the task ledger.verify (through ledger_verify_recorded), listing results with the kinds blockHashMismatch, prevHashMismatch, merkleRootMismatch, rowHashMismatch, missingBlock and other. Only the first 100 problems are stored. The verification of records of other shard groups and verification against a given digest are not done by this operation yet.
Against an outside copy:
SELECT kingres.ledger_generate_digest(); -- store the result OUTSIDE the database
SELECT kingres.ledger_verify_digest('{...}'); -- a digest exported earlier
SELECT kingres.ledger_inclusion_proof('accounts', kingres.ledger_row_hash(a.*)) FROM accounts a WHERE id = 1;
SELECT kingres.ledger_verify_proof(proof, digest); -- uses only its two argumentsThe standalone verifier kingres-verify re-checks digests, proofs, blocks, signed checkpoints, tile logs, consistency between checkpoints, aggregates, bundles, client signatures and anchors without trusting the database; exit status 0 means everything asked for was verified, 3 means a part could not be checked and must be treated as an alert. See The Verifier, Ledger.
If a finding shows a stray row above the head, do not remove it before comparing block B with what was published or kept outside the database: if block B was published or digested, the finding is damage, not a stray row, and the way back is a restore from a backup or a point in time that has block B, or accepting the divergence in the publication (Backup Restore and PITR).
SELECT * FROM kingres.columnar_check(); -- superuser; returns (check_name, relation, detail)
SELECT kingres.columnar_check_clean(); -- true only when every columnar table was checked and nothing was found
SELECT * FROM kingres.columnar_check_indexes('t'::regclass); -- index_entry_missing
SELECT kingres.columnar_reconcile(); -- deletes catalog rows of files no relation uses-
columnar_checkreports catalog rows of files nobody uses, stripes beyond the end of the file, stripes whose first page is not theirs, stripes over the row limit and unreadable relations. It reads the catalog as of now, never waits for a lock, and reportsnot_checkedfor a table it could not lock.columnar_check(true)deletes the first two kinds. -
columnar_check_clean()is the strict form for a monitor:falsefor any rowcolumnar_check()would return, anot_checkedtable included. A monitor tests that the result is empty, or callscolumnar_check_clean(). - Every stored chunk has a CRC-32C checked before decoding, so damage gives SQLSTATE
XX001. -
amcheck.
bt_index_check(idx),bt_index_check(idx, false, true)(withheapallindexed) andbt_index_parent_check(idx)work on a columnar B-tree index;heapallindexedreports a row that has no entry.columnar_check_indexes()finds the same without amcheck (superuser, up to 50 million entries). Indexes built withCREATE INDEX CONCURRENTLYorREINDEX CONCURRENTLYare refused on a columnar table.
SELECT * FROM kingres.timepart_check(); -- returns (schema_name, table_name, problem, detail)Reports problems such as misaligned, retire_blocked (a partition a foreign key still references), policy_unverified and an orphan policy after a schema rename. The run history (timepart_run, timepart_run_action) records every action and its outcome.
All of these checks are read-only except columnar_check(true), columnar_reconcile() and ledger_remove_stray (and the rebuild verification, which only decides whether the old copy is kept). The alerts of the control plane, including ledgerChainDiverged for a diverged chain, are listed on Monitoring and Alerts.
- https://github.com/KingresDB/Kingres/blob/kingres-18/contrib/kingres_shard/README.md
- https://github.com/KingresDB/Kingres/blob/kingres-18/contrib/kingres_shard/kingres_shard--0.9.sql
- https://github.com/KingresDB/Kingres/blob/kingres-18/contrib/kingres_ledger/README.md
- https://github.com/KingresDB/Kingres/blob/kingres-18/contrib/kingres_columnar/README.md
- https://github.com/KingresDB/Kingres/blob/kingres-18/contrib/kingres_columnar/kingres_columnar--0.2.sql
- https://github.com/KingresDB/Kingres/blob/kingres-18/contrib/kingres_timepart/README.md
- https://github.com/KingresDB/Kingres/blob/kingres-18/kingres/control-plane/README.md
- https://github.com/KingresDB/Kingres/blob/kingres-18/kingres/verifier/README.md
KingresDB's own code is licensed under AGPL-3.0-only. PostgreSQL code keeps the PostgreSQL License. Copyright of the project's own code: RooyeKhat Media Co. KingresDB is derived from PostgreSQL and is not endorsed by the PostgreSQL project. Repository | Licence | COPYRIGHT
KingresDB
1. Product
- Product Overview and Features
- Status and Roadmap
- User Guide
- Administrator Guide
- REST API Reference
- Web Console
- Command Line Client
- Extensions
- Limitations and Known Issues
- Release Notes
Features in detail
- Sharding
- Sharding Query Pushdown
- Sharding Table Lifecycle
- High Availability
- Ledger
- Ledger Signing and Publication
- Ledger Anchoring
- The Verifier
- Analytics Extensions
Administration
- Cluster Setup
- Servers Databases and Roles
- Rebalancing
- Configuration
- Memory and Warm-up
- Control Plane and REST API
- Upgrades
2. Architecture (arc42)
- Architecture
- Architecture Introduction and Goals
- Architecture Constraints
- Architecture System Context
- Architecture Containers
- Architecture Components
- Architecture Runtime Views Sharding
- Architecture Runtime Views Availability and Ledger
- Architecture Deployment
- Architecture Crosscutting Concepts
- Security Model
- Architecture Decisions
- Architecture Quality Requirements
- Architecture Risks and Technical Debt
- Enterprise Architecture
3. Data architecture
- Data Architecture
- Data Model Sharding
- Data Model Ledger
- Data Model System Database
- Data Model Analytics
- Data Lifecycle
- Backup Restore and PITR
- Data Security
- Data Quality and Integrity
4. Development
- Building from Source
- Development and Testing
- Repository Layout
- Coding Standards
- Branching and Synchronisation
- Testing Strategy
- Review Process
- Release Process
- Contributing
5. Operations