Skip to content

Command Line Client

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

Command Line Client

kingres-cli is the command-line client of the KingresDB REST API. It is part of release 0.2.0 (2026-11-30); it is not in 0.1.0 or 0.1.1. From 0.2.0 it is in the Debian package as /usr/bin/kingres-cli (with the man page kingres-cli(1)), in the container image, and in the RPM, and it builds for Windows and macOS with go build ./cmd/kingres-cli in kingres/control-plane (no package is made for them). Until then, use the REST API (REST API Reference) or the console (Web Console).

It calls only the REST API that the console uses. Everything it does is subject to the cluster roles of the signed-in PostgreSQL role and is written to the audit log (Security Model, Control Plane and REST API). It is one static binary with the standard library only (plus golang.org/x/term for the password prompt). The reference is the README of kingres-cli; the operator guide, section 2a, shows it in use.

First steps

kingres-cli login --url https://db1.example.com:8091 --ca-file /etc/kingres/ca.pem --user root_admin
kingres-cli cluster status
kingres-cli server list
kingres-cli database create sales --sharded --buckets 64 --wait
kingres-cli table distribute sales/public.orders --column customer_id --wait

kingres-cli help lists the groups of commands (session, cluster, servers, databases, schemas and tables, rebalance and buckets, failover, tasks, alerts and audit, configuration, ledger, transfers, roles, this server, query), and kingres-cli help COMMAND gives the arguments and flags of one. A table is written DATABASE/SCHEMA.TABLE.

What it does

  • Login with profiles and TLS trust. login asks for the password on the terminal, or reads it from --password-file (- is standard input) or KINGRES_PASSWORD. The answer is a bearer token kept in a per-user config file (kingres/cli.json in the user config directory), never the password. The file is written atomically and is private to the user (mode 0600 on Linux and macOS, an access list for the current user on Windows). --profile NAME keeps several clusters side by side. A session belongs to the server that issued it; if that server is down, sign in again with --url of another server.
  • TLS. --ca-file adds the CA of the cluster to the system roots, --server-name names the certificate to check. There is no flag that turns the check off. Plain http:// works only for a loopback address; for any other address every command refuses before it sends anything.
  • No secrets on the command line. A password, a setup token or any other secret is never taken from an argument, so it is not in the process list or the shell history: use a prompt, a file, an environment variable or @file and @- for a request body.
  • Tables or --json. The default is a table (a list) or a list of fields (one object); a value the server does not know is shown as -, never as 0. --json prints the answer as it came and nothing else on standard output, so kingres-cli server list --json | jq works. Progress and warnings go to standard error. Lists with pages take --limit, --cursor and --all.
  • --wait and --retry. An operation that cannot finish within a request answers with a task. --wait follows the task until it is done, failed or paused (--wait-timeout, default 30 minutes; it never cancels the task); task wait ID does the same later. --retry N repeats a call that got 503 or 429 with Retry-After, for example while a map group fails over. Commands that destroy data (database drop, server remove, table undistribute, failover abandon) ask [y/N] on a terminal and refuse without one; --yes answers for you.
  • Transfers with resume and SHA-256 checks. table export --out FILE starts the export, waits, downloads the file and compares its SHA-256 with the one the server recorded; the file appears under its name only after the check and never replaces an existing file. A download that breaks continues when you run the command again. An upload (table import, database import, database validate-archive) hashes the file, sends it in chunks of 64 MiB, repeats a broken chunk from the offset the server reports, and continues with --resume-upload ID. Transfers need HTTPS and the cluster setting dataTransfer.enabled (Backup Restore and PITR).
  • Extensions and the preload list (since 0.2.0): extension catalog, extension show, extension packages; database extension list, install, update, remove and plan-switch; database extension-catalogue and database feature-set; preload show, plan, check and set. See Extensions.
  • Paused preload tasks and the instances of a preload change (since 0.2.1; not in 0.2.0): task resume resumes a paused task of the preload change (POST /tasks/{taskId}/resume), and preload servers shows the instances of each server and whether each runs the cluster list. See Extensions.
  • Ledger checks and the audit of the publication (since 0.2.1; not in 0.2.0): ledger check-reports and ledger check-report list and show the stored reports of the ledger checks; ledger verify --checks anchors starts a verification with the check anchors; ledger audit shows the settings and state of the scheduled audit of the publication, ledger audit-set changes them, ledger audit-now runs an audit at once, and ledger audit-ack acknowledges an altered finding (per log with --shard-group). See Ledger Anchoring.
  • api call for the rest. kingres-cli api list [FILTER] lists every operation of the contract the binary was built from, with the command that calls it. kingres-cli api call OPERATION --path NAME=VALUE --query NAME=VALUE --data JSON|@file calls any of them, including the first-run setup of a node and the operations that have no command of their own.

Exit codes

Code Meaning
0 success
1 other failure
2 usage error
3 cannot connect, or the TLS certificate is not trusted
4 not signed in, bad credentials, expired session (401)
5 not allowed for the role (403)
6 not found (404, 410)
7 conflict with the current state (409)
8 request rejected as wrong or impossible (400, 413, 416, 422)
9 server unavailable or rate limited (429, 503, 5xx)
10 the task ended failed, or is paused and waits for an operator (--wait)
11 --wait-timeout ran out; the task goes on
12 interrupted (Ctrl-C), or "continue?" was answered no

The codes are stable: a value is never reused for another meaning.

Keeping it in step with the REST API (for whoever changes the API)

The rule of the project is that every change of the REST API goes through the contract and also gets its command in the CLI. The code is kingres/control-plane/internal/cli and cmd/kingres-cli, in the module of the control plane. The CLI names an operation by its operationId and builds the request from the generated operation table internal/contract, so it never copies a method or a path. When an operation is added, renamed or changed in kingres/api/openapi.yaml:

  1. Bump the contract version and run go generate ./internal/contract.
  2. Run go test ./internal/cli. The coverage test TestEveryOperationIsCoveredOrListed fails for every new operation until it has a command (a Spec in internal/cli/commands.go) or is listed in notCovered in internal/cli/coverage.go with a reason (it is then reached with api call).
  3. TestSpecsMatchTheContract checks every command against the contract: that its arguments fill exactly the path parameters, and that the query parameters, request members and table columns exist in the schemas.
  4. Add the case to TestBodiesAndQueries and, for a new table, a golden file. A secret member is a Secret and is read from a file, the environment or a prompt, never from a flag.
  5. A change of an exit code is a change of the interface: it needs a new value.

The tests run against a fake server; TestCLIEndToEnd in internal/clustertest runs the main commands against a real three-server cluster over HTTPS.

Limits

A session belongs to the server that issued it, no package is made for Windows or macOS (the binary builds there), and there is no shell completion yet (Limitations and Known Issues).

Clone this wiki locally