kingres_shard
kingres · KingresDB hash sharding, distributed routing and two-phase commit.
Overview
| ID | Extension | Package | Version | Category | License | Language |
|---|---|---|---|---|---|---|
| 102352 | kingres_shard | kingres | 0.10 | FEAT | AGPL-3.0-only | C |
PostgreSQL · 18, 19
Usage
Sources:
- README.md
- kingres_shard.control
- kingres_shard–0.10.sql
- upgrade.md
- limitations.md
- kingres_shard–0.8–0.9.sql
- Release 0.2.1
- kingres_shard–0.9–0.10.sql
- CHANGELOG.md
kingres_shard 0.10 provides hash-bucket distribution, reference tables, distributed schemas, statement routing and two-phase commit for KingresDB. It requires the KingresDB kernel hooks and cannot be built against stock PostgreSQL. The reviewed release supports PostgreSQL 18.7 and 19.0; its distribution version 0.2.1 is separate from this extension version.
Configure a Cluster
Preload on every node and restart. All nodes need one PostgreSQL major and extension version, libpq connectivity and matching roles/databases. Size prepared-transaction capacity for concurrent distributed work; bucket moves require logical WAL. Administrative APIs require superuser access.
Routing and Maintenance
kingres.create_reference_table replicates a small table; kingres.move_bucket and kingres.rebalance_plan manage placement, and kingres.recover_prepared_transactions resolves recorded decisions. DDL is coordinated through the map-group primary. Table lifecycle operations now include distributing populated tables, changing distribution and returning to ordinary tables; inspect the operation-specific restrictions before running them.
The release adds distributed schemas, query pushdown, repartitioned joins and distributed columnar tables. Columnar distribution needs kingres_columnar 0.2, and does not support every online table operation or bucket splitting. Reference tables remain row storage. The shared kingres schema can coexist with the other family extensions.
Upgrade and Correctness Boundaries
Distribution 0.1.1 fixes wrong answers when an outer-join arm contains multiple distributed tables and outer ON equalities incorrectly pair their buckets. Version 0.1.0 can hit this through default pushdown. Until every server is updated, use SET kingres_shard.enable_pushdown = off; disabling only a join-specific switch is insufficient. Replace the matching same-major binaries on every server and restart. The 0.1.0-to-0.1.1 distribution update keeps SQL version 0.9 and requires no ALTER EXTENSION step.
For an upgrade from an older extension SQL version, update matching libraries on every node, restart, then promptly apply the supplied SQL chain in each database on every node. Distributed scans/fan-out writes can fail while SQL objects lag behind libraries; bucket moves require the current version on all active primaries. During a mixed-version upgrade disable kingres_shard.enable_pushdown, kingres_shard.enable_bulk_routing, kingres_shard.enable_copy_routing and kingres_shard.enable_colocated_insert_select, restoring them only after all nodes match. Early development 0.5 scripts changed in place; inspect their documented catalog repair before relying on the ordinary update chain.
Two-phase commit does not provide a global snapshot. Groups, and even scans within one statement, can see different snapshots; SERIALIZABLE applies per node. The control plane now implements failover and switchover, but automatic failover defaults off, and simultaneous failures or failure during rebalance lack cluster-level testing. Test recovery and possible data loss on the intended topology. Cross-major rolling upgrades and downgrade rollback are unsupported.
0.10: Extension Registry and Feature Locks
kingres.supported_extensions exposes the registry compiled into the library. Managed extension CREATE, UPDATE and DROP operations are coordinated across nodes, which must agree on versions, libraries, preload and schema trust. kingres.extension_registry records installation state and kingres.feature_set reports features in use or locked. Query the actual registry rather than inferring today’s allowlist from an older abbreviated README list.
Unlisted or explicitly refused extensions fail. A superuser enabling kingres_shard.allow_unlisted_extensions permits only an unlisted extension installed as unmanaged on this node; it neither bypasses an explicit refusal nor supplies distributed support. Locked sharding, moves, partitioning and other operations are refused. Class KE errors require changed configuration or state, not unchanged retries.
Distribution 0.2.0 also extends repartitioned joins and UPDATE FROM/DELETE USING on shard groups. After installing new libraries, apply the 0.9-to-0.10 SQL upgrade on every node. Disable kingres_shard.enable_repartition_join and kingres_shard.enable_write_from while versions differ, together with the existing routing-switch and traffic-stop requirements. Two-phase commit still does not provide a cross-group atomic snapshot.
Distribution 0.2.1
SQL version remains 0.10. The distribution fixes losing a changed preload list while copying a standby and restores bundled pg_cron. Upgrade every server before enabling that scheduler; its managed configuration, target database and required restart sequence are checked by the extension registry. A library cannot be removed while one of its settings remains stored. This does not remove the existing mixed-version or global-snapshot limits.