Skip to content

Servers Databases and Roles

Mohammad Rasoul Kazemi edited this page Dec 1, 2026 · 4 revisions

Servers Databases and Roles

Day-to-day administration through the REST API or the console: servers and server groups, databases and tables, roles, grants, network access and cluster settings. Operations are named by their operationId in openapi.yaml; the minimum role of each is in REST API Reference. Adding and removing servers is in Cluster Setup.

Servers

  • GET /servers, GET /servers/{serverId} (kingres_readonly). A server is a machine; its id is the host it registered under, an opaque string that clients compare for equality only.
  • Status values include pendingRebalance (a server that owns no buckets yet) and draining (it should hold none), besides decommissioning while it is added, removed or left, and dead/suspect states reported by the heartbeat (High Availability).
  • PATCH /servers/{serverId} (kingres_ops) changes only serverGroup, shouldHaveShards and weight (a larger weight gets more buckets at the next rebalance). Setting shouldHaveShards: false makes the server draining; setting it to true makes a server without buckets pendingRebalance. Nothing moves by itself: run a rebalance (Rebalancing). It is refused with 409 while a rebalance runs or while the server is being added or removed; a stopped rebalance does not block it. A change of shouldHaveShards or weight is also refused (409 operation_in_progress) while a database import is unfinished.
  • Server groups (a rack or a zone, not a shard group): GET/POST /server-groups, DELETE /server-groups/{serverGroupName}. A name matches ^[A-Za-z0-9][A-Za-z0-9_.-]{0,62}$, case-sensitive; a group that has servers cannot be deleted (409 server_group_not_empty). Standbys are placed on servers outside the primary's server group where possible.
  • Certificates: POST /servers/{serverId}/certificates/renewals and .../revocations (kingres_admin). The escrow of the certificate authority key is GET/PUT /certificate-authority/escrow and POST /certificate-authority/escrow/rotations (off until switched on; see High Availability).
  • Emptying a server for removal: POST /servers/{serverId}/drain (preview: .../drain-preview); failing a server over or switching its primaries over: POST /servers/{serverId}/failover (High Availability, Rebalancing).
  • This server (local scope, never forwarded): instances (start, stop, restart), resources, logs, and PATCH /this-server/settings for the memory quota, the log level and the log directory. The log level takes effect at once; the memory quota and the log directory need an instance restart (restartRequired: true). Data paths and client ports cannot be changed.

Databases

POST /databases (kingres_admin) starts a task that creates the database on every shard group, installs kingres_shard and kingres_ledger as selected, records the settings and applies the durability level. The body has name, general (encoding, collation), sharding (enabled, mode: rows, schemas or both, bucket count), replication and ledger. Immutable after creation: name, general.encoding, general.lcCollate, general.lcCtype and sharding.bucketCount (the default bucket count is 128, range 1 to 4096). The task cleans up a partial database on failure and waits for a server that is down.

  • PATCH /databases/{databaseName}: owner, connection limit and durability apply at once; enabling sharding or the ledger is a task. Sharding and the ledger can be turned on but never off (422). The sharding mode can be changed while no schema or table of the other kind exists (409 sharding_mode_in_use otherwise). The replica count is a cluster setting, not a database one.
  • DELETE /databases/{databaseName}?confirm=<name> drops it on every group; irreversible, the name must be repeated. Ledger tables do not protect a database from being dropped; the audit log keeps the record.
  • Durability per database: async = synchronous_commit = local, sync = on (default, waits for a quorum of synchronous standbys to flush), syncApply = remote_apply.
  • Tables: GET /databases/{db}/tables, PUT .../tables/{table}/distribution (hash or reference table; a task) and PUT .../tables/{table}/ledger. The contract text states what the extension refuses (a ledger table cannot be distributed, and a table with a key, trigger or other feature the extension does not support is refused with the condition named). A table that already holds rows can be distributed, turned back into an ordinary table, altered and partitioned as tasks with a preview (Sharding Table Lifecycle); the SQL route is in Sharding.
  • Schemas: GET /databases/{db}/schemas, PUT/DELETE .../schemas/{schema}/distribution and POST .../schemas/{schema}/moves for databases sharded by schemas.
  • Moving data in and out: CSV export and import of a table and export and import of a whole database (/data-exports, /data-uploads, /database-imports, /databases/{db}/export); both are described in the operator guide (sections 12 and 13) and, for the database form, in Backup Restore and PITR.
  • Bucket views: colocation-groups, colocation-groups/{id}/buckets, bucket-distribution.

Roles and grants

Panel accounts are PostgreSQL roles (ADR 0015). A role signs in with POST /auth/login when it has LOGIN and belongs to at least one of four built-in cluster roles. They form a hierarchy: kingres_admin includes kingres_ops, which includes kingres_readonly, which includes kingres_stats (metrics and the session only).

  • GET /cluster-roles lists the four roles. POST /roles creates a role on every shard group; the password travels as a verifier, never as plaintext. PATCH, DELETE /roles/{roleName}, PUT /roles/{roleName}/memberships and PUT /roles/{roleName}/cluster-roles (the complete list; an empty list removes panel access). All need kingres_admin.
  • Refusals: the last kingres_admin cannot be removed or dropped (409 last_admin), a role that owns objects or is the caller cannot be dropped (409 role_in_use).
  • Since 0.2.1 a role that is handed out is judged by every membership, ADMIN OPTION included, and is refused with 400 if it reaches a role that is a superuser, REPLICATION, BYPASSRLS or one of pg_execute_server_program, pg_read_server_files, pg_write_server_files; the signed-in role of the query workbench and the imports is judged only by the memberships it can use (SET or INHERIT), so an administrator is not refused because of a role it manages.
  • A server that cannot be reached during a role or grant change gets a task replicate.apply that waits for it.
  • Grants: GET/POST /grants, POST /grants/revocations, and POST /grants/template-applications with three templates on a database: readOnly (CONNECT, USAGE on all schemas, SELECT on all current and future tables), readWrite (adds INSERT, UPDATE, DELETE, not on append-only ledger tables) and owner. Table and schema grants are replayed by the control plane only for databases without kingres_shard, whose extension propagates them itself.
  • Connect over TCP with a role (kingres-psql -h 127.0.0.1 -p 5432 -U <administrator> postgres); peer authentication over the Unix socket maps to the service user only.

Network access

GET/PUT /settings/network-access (kingres_admin) holds the ordered rule list that kingresd renders into pg_hba.conf on every server. PUT replaces the whole list and needs the current revision (409 otherwise). Rules between cluster members are added by the system and cannot be removed. A rule set that would lock out the caller's own address is refused with 422; dryRun=true checks without changing anything. Replication connections for kingres-pg_basebackup need a replication rule here.

Cluster settings

GET/PATCH /settings/cluster: defaultReplicaCount (0 to 3; a change starts the task standby.reconcile), defaultDurability, autoFailover (enabled, timeoutSeconds 30 to 3600, maxCount, eventsSinceReset; reset with POST /settings/cluster/auto-failover/reset), rebalance (strategy, threshold, automatic mode and more), features (sharding and the ledger can be enabled, never disabled again), clock.maxDifferenceMs (default 1000), analytics.allowNonSuperuserOwners (default false), dataTransfer (CSV table transfer; off by default) and restart. See High Availability and Configuration.

Console

All of this is in the Servers, Databases, Security and Settings pages of the Web Console. A rule the role may not use is disabled with its reason.

Sources

Clone this wiki locally