Repository navigation
Control Plane and REST API
kingresd is the control-plane server of KingresDB. It runs on every server of a cluster and serves, on one port (default 127.0.0.1:8091), the management REST API and the embedded Web Console. The REST contract is kingres/api/openapi.yaml, revision 0.13.0, OpenAPI 3.1, base path /api/v1.
-
Agent. On each server it creates, configures, starts and stops the PostgreSQL instances (
initdb,postgresql.conf,pg_hba.conf,pg_ctl), holds the server's certificates, and sends heartbeats. - Manager (leader). One server is the manager leader: the server that runs the primary of the map group (ADR 0018). It runs tasks and the recurring jobs. A mutating cluster operation that reaches another server is forwarded to the leader, and the response is the leader's.
- Client router. An optional TCP entry point that forwards client connections to the current primary, or to a local standby for lag-tolerant reads (see High Availability).
kingres-cli is named in the documents as a second client of the API. This checkout has no kingres-cli command in kingres/control-plane/cmd (only kingresd and kingres-watchdog), so use the REST API or the console.
State that belongs to the control plane (tasks, cluster settings, server groups, alerts, managed network rules) lives in a system database, kingres_system, schema kingres_cp, with embedded migrations (ADR 0019). There is no bundled metrics store: kingresd samples and exports metrics itself (ADR 0020). Panel accounts are PostgreSQL roles (ADR 0015).
Phase 3 (control plane, REST API, panel, package) is done, and the control plane passes its integration suite on PostgreSQL 18 and 19. Later phases added rebalancing, high availability, the ledger operations and configuration from the console; for their review state see Status and Roadmap. The control plane and the packaging have not been checked on 19 beyond that suite.
cd kingres/control-plane
go build -o kingresd ./cmd/kingresd
./kingresd -pg-dsn "host=127.0.0.1 port=5432 dbname=postgres user=kingresd password=..." -data-dir ./data
While a node is uninitialized, kingresd writes a one-time setup token to <data-dir>/setup-token and logs only the file name. GET /api/v1/setup/state and /healthz work at once.
Start a one-server cluster by hand (from the README):
kingresd -data-dir /var/lib/kingres -pg-bin-dir /opt/kingres/bin -listen 127.0.0.1:8091
curl -s -X POST http://127.0.0.1:8091/api/v1/setup/init-cluster \
-H "X-Setup-Token: $(cat /var/lib/kingres/setup-token)" -H 'Content-Type: application/json' \
-d '{"clusterName":"prod","admin":{"username":"root_admin","password":"a-long-password"},
"dataPaths":{"dataDirectory":"/var/lib/kingres"},"memoryQuota":{"totalMegabytes":4096}}'
curl -s http://127.0.0.1:8091/api/v1/setup/state
A second server joins with POST /api/v1/setup/join-cluster (it registers with the leader at existingNodeAddress, receives the certificates, and creates a primary of a new shard group and the standby of a neighbouring group; it appears as pendingRebalance and no data moves until a rebalance is started). Joining, adding and removing servers need internal-listen, the mutual-TLS listener of the internal server-to-server API (by convention the REST port plus one). See Configuration for the settings and Installing and Packaging for the package.
A rebalance is one task of kind rebalance on the leader: check the cluster, compute the plan with kingres.rebalance_plan(), move buckets one at a time with kingres.move_bucket(...), write the report. It can be stopped and started again, is taken over after a restart or a leader change, and has a page in the console. Several moves at once, the strategy by disk size and draining a server are phase 10 and are not built. The reviews found and fixed fencing defects; the latest round's fixes have not been reviewed again (Status and Roadmap). See Sharding for bucket moves in the extension.
-
POST /auth/loginsigns in a PostgreSQL role by user name and password. The role needsLOGINand membership in at least one cluster role. The response sets thekingres_sessioncookie (HttpOnly, Secure, SameSite=Strict) and a CSRF token that browsers send asX-CSRF-Tokenon every mutating request. WithissueToken: truethe response also holds a bearer token for scripts. - A session belongs to the server that created it: the same value on another server is 401, and a restart ends the session. A client signs in once per server.
- The four cluster roles are memberships in
kingres_admin,kingres_ops,kingres_readonlyandkingres_stats, with the hierarchy admin > ops > readonly > stats. Every operation names its minimum role inx-required-role(the contract has 43 operations for admin, 21 for ops, 57 for readonly, 4 for stats and 7 without a role). - The setup operations use the one-time
X-Setup-Tokenheader, and only from loopback addresses unlessallow-remote-setupis true. - Every request passes one guard in this order: node-state gating, cross-site check, rate limit, authentication, CSRF check, role check, query-parameter validation, then the handler. Audited operations are written to an append-only audit log.
- Errors are RFC 9457
application/problem+json; long-running operations answer 202 with aTaskand aLocationheader.
See Security Model.
All paths are below /api/v1. The list is taken from openapi.yaml.
| Tag | Paths (examples) |
|---|---|
| Health |
/healthz, /readyz
|
| Auth |
/auth/login, /auth/logout, /auth/session
|
| Setup |
/setup/state, /setup/init-cluster, /setup/join-cluster, /setup/token-check
|
| This server |
/this-server, /this-server/resources, /this-server/instances, /this-server/instances/{instanceId}/start, /stop, /restart, /this-server/settings, /this-server/leave-cluster, /this-server/logs
|
| Cluster, Servers |
/cluster, /cluster/summary, /servers, /servers/{serverId}, /servers/{serverId}/failover, /servers/{serverId}/certificates/renewals, /servers/{serverId}/certificates/revocations, /server-groups
|
| Databases, Tables, Shards |
/databases, /databases/{databaseName}, /databases/{databaseName}/tables, .../tables/{tableName}/distribution, /databases/{databaseName}/colocation-groups, /databases/{databaseName}/bucket-distribution
|
| Replication, failover |
/replication/topology, /replication/restore-preferred-primaries, /failover, /failover/reports, /settings/cluster/auto-failover/reset
|
| Rebalance |
/rebalance (status and start), /rebalance/plan, /rebalance/stop, /rebalance/reports, /rebalance/reports/{reportId}
|
| Tasks |
/tasks, /tasks/{taskId}, /tasks/{taskId}/cancel
|
| Roles, Grants, Network access, Audit, Settings |
/roles, /roles/{roleName}, /cluster-roles, /grants, /settings/network-access, /audit, /settings/cluster
|
| Configuration (0.8.0) |
/config/parameters, /config/changes/preview, /config/changes, /config/servers, /config/time, /config/restarts
|
| Ledger |
/ledger/status, /databases/{databaseName}/ledger/blocks, .../digests, .../verifications, .../inclusion-proofs, /ledger/signing/keys, /ledger/publication, /ledger/anchor-targets, .../ledger/anchors, .../ledger/bundles, .../ledger/client-keys
|
| Query |
/query, /query/statements/{statementId}/cancel
|
| Alerts, Logs, Metrics |
/alerts, /logs, /metrics/query
|
Some phase-7 ledger operations in the contract are not built and answer 422 unsupported_operation. The reference is openapi.yaml itself; conventions are in kingres/api/README.md. Example calls:
POST /api/v1/auth/login {"username":"alice","password":"s3cret","issueToken":true}
GET /api/v1/rebalance
POST /api/v1/servers/{serverId}/failover (body: {"mode":"hard","dryRun":true})
go vet ./..., gofmt -l ., golangci-lint run ./... and go test ./... need no database. Integration tests run against real PostgreSQL instances when KINGRES_PG_BIN is set; scripts/run-integration.ps1 runs them in WSL2 and takes -Install to test another major. See Development and Testing.
- kingres/control-plane/README.md
- kingres/control-plane/internal-api.md
- kingres/api/openapi.yaml
- kingres/api/README.md
- kingres/docs/design/control-plane-2.md
- kingres/docs/design/control-plane-3.md
- kingres/docs/design/shard-phase4.md
- kingres/docs/design/shard-phase10.md
- kingres/docs/adr/0014-one-package-panel-on-every-node.md
- kingres/docs/adr/0015-panel-accounts-are-postgresql-roles.md
- kingres/docs/adr/0016-go-backend-react-frontend-openapi-first.md
- kingres/docs/adr/0018-manager-leader-follows-the-map-group-primary.md
- kingres/docs/adr/0019-cluster-state-in-a-system-database.md
- kingres/docs/adr/0020-no-bundled-metrics-store.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