Administration
Watching and running a sharded cluster: the gateway's counters and metrics endpoint, health checks, its configuration API, logs, upgrades without downtime, and cluster backups.
SHOW GATEWAY
Any client connection to the gateway can ask for its state:
SHOW GATEWAY; name | value
----------------------------+----------------------------------
gateway | rasterizeddb_gateway
version | 1.0.0
cluster_id | 0123456789abcdef0123456789abcdef
map_epoch | 1
map_digest | 5f0c...
shards | 3
home_shard | 0
...The first rows describe the gateway:
| Row | Meaning |
|---|---|
gateway | Its gateway_name. |
version | The gateway's version. |
cluster_id, map_epoch, map_digest, shards | The map it routes with. |
home_shard | The home shard. |
schema_epoch | The highest schema epoch it has heard from the shards. |
workers | Worker threads. |
sessions | Client sessions open now. |
draining | true while it shuts down. |
unrouted | Its unrouted setting. |
fanout_built, user_routing_built | Whether this build has fan-out and per-user shards. |
shard_compression | off, or the zstd level and threshold. |
Then the counters, summed over all workers since the gateway started:
| Counter | Counts |
|---|---|
statements | Statements and extended-protocol batches received. |
routed | Statements sent to one shard by their key. |
fan_outs | Statements run on several shards (fan-outs, gathers, split writes). |
broadcasts, broadcasts_too_large | Joins answered by copying plain tables to every shard, and those whose tables were too large to copy and were gathered instead. |
role_statements | Role and privilege statements applied on every shard. |
template_hits, template_misses | Statement shapes whose routing was already known, and those classified by the home shard. |
route_template_refuted | Remembered routings a shard contradicted, which were dropped. |
classify_errors | Statement shapes the home shard could not classify. |
retries | Statements sent again after a refusal before any effect. |
lost_08007 | Statements whose shard connection was lost after sending. |
shard_down_08006 | Statements refused because a shard could not be reached. |
refused_no_route_key, refused_cross_shard, refusals_other | Statements refused for want of a key, for reaching another shard than their transaction's, and for other shard refusals. |
bytes_in, bytes_out | Client bytes received and sent. |
sessions_opened, sessions_open | Client sessions since start, and open now. |
virtual_sessions_opened, virtual_sessions_reused | Sessions opened on shards, and taken from the session_pool instead. |
auth_failures | Failed logins. |
session_panics | Sessions ended by an internal error (each ends only that session). |
map_refreshes | Newer maps fetched from shards. |
shard_frames_compressed_out, shard_frames_compressed_in, shard_compression_saved_bytes | Compressed frames to and from shards, and the bytes saved. |
hop_p50_us, hop_p99_us | The median and 99th percentile time of a request to a shard, in microseconds (rounded up to a power of two). |
Each worker publishes its counters about once a second, so they can be a second old.
The metrics endpoint
Set admin to open a small HTTP endpoint:
admin = 127.0.0.1:9187curl -s http://127.0.0.1:9187/metricsrdb_gateway_map_epoch 1
rdb_gateway_shards 3
rdb_gateway_home_shard 0
rdb_gateway_schema_epoch 1
rdb_gateway_workers 8
rdb_gateway_sessions 12
rdb_gateway_statements 48211
rdb_gateway_routed 47002
rdb_gateway_fan_outs 1180
...
rdb_gateway_hop_p99_us 512GET /metricsreturns everySHOW GATEWAYrow whose value is a number, asrdb_gateway_<name> <value>, in the Prometheus text format.- Any other path returns every row as
name<TAB>valuetext. - The endpoint has no authentication and no TLS. Bind it to a loopback or private address.
A Prometheus scrape job:
scrape_configs:
- job_name: rasterizeddb-gateway
static_configs:
- targets: ["10.0.0.20:9187", "10.0.0.21:9187"]Things worth alerting on: shard_down_08006 and lost_08007 rising (a shard is unreachable), auth_failures rising, retries staying high (a move is stuck or the map is stale), sessions near max_sessions, and hop_p99_us growing.
Each shard is also an ordinary server with its own statistics: see Monitoring. Connect to a shard directly for SHOW SHARDS (the map it serves, its ranges and epoch) and SHOW SHARD LOAD (each partition's block range and size). Through the gateway, SHOW SHARD LOAD answers for every shard.
Health checks
- The gateway is up and can reach the home shard:
SELECT 1through the gateway (it runs on the home shard). - The process is up: a TCP connect to
listen, orGET /metricsonadmin. - The configuration API's own check:
GET /v1/health(below), which answers{"ok": true}without contacting any shard. - A shard: connect to it directly and run
SELECT 1. A shard whose rshard listener fails to open exits, so a running shard process has it.
The configuration API
The gateway can serve an HTTP API to read its state and store settings. Settings are kept in a small embedded database in config_dir, and applied at the next start, over the configuration file and the command line.
mkdir -p /var/lib/rasterizeddb-gateway
openssl rand -hex 32 > /etc/rasterizeddb/api.token
chmod 600 /etc/rasterizeddb/api.tokenapi_listen = 127.0.0.1:9190
api_token_file = /etc/rasterizeddb/api.token
config_dir = /var/lib/rasterizeddb-gateway- Every request needs
Authorization: Bearer <token>. The token is the first line ofapi_token_file, at least 16 characters, read at start; only its hash is kept. - There is no TLS: keep the port on the operator's own network.
- Request bodies are JSON, at most 1 MiB.
| Method | Path | What it does |
|---|---|---|
GET | /v1/health | {"ok": true}. |
GET | /v1/gateway | The SHOW GATEWAY rows as one JSON object. |
GET | /v1/map | The map: epoch, cluster_id, shards (each id, address, standbys, ranges), and text (the map file). |
GET | /v1/settings | The settings stored here. |
PUT | /v1/settings/{key} | Body {"value": "..."}. Checked as a configuration line would be (400 if it does not parse), stored, and applied at the next start. |
DELETE | /v1/settings/{key} | Forgets a stored setting (404 if there is none). |
GET | /v1/audit?limit=N | The latest changes, newest first (limit 100 by default, at most 10000): each with at (Unix seconds), method, path, status and detail. Refused changes are recorded too. |
TOKEN=$(head -n1 /etc/rasterizeddb/api.token)
curl -s -H "Authorization: Bearer $TOKEN" http://127.0.0.1:9190/v1/map
curl -s -X PUT -H "Authorization: Bearer $TOKEN" -H "Content-Type: application/json" \
-d '{"value": "fan_out"}' http://127.0.0.1:9190/v1/settings/unrouted
curl -s -H "Authorization: Bearer $TOKEN" "http://127.0.0.1:9190/v1/audit?limit=20"{"applied":"at the next start","name":"unrouted","value":"fan_out"}A request without the right token gets 401; an unknown path gets 404. The enterprise gateway adds its own paths: see Per-user shards.
Logs
The gateway logs to standard error, at info by default; set RUST_LOG=debug (or warn, ...) to change it. Lines worth knowing:
| Line | Meaning |
|---|---|
cluster <id>, map epoch N, M shards, digest <hex> | Start: the map it loaded. |
N setting(s) applied from the configuration store in <dir> | Start: settings from the configuration API. |
draining: no new connections; ... | SIGTERM or SIGINT received. |
drain deadline passed with N sessions open; they are closed | Sessions still open after drain_secs. |
map epoch N reported by shard S could not be fetched: ... | A newer map exists but could not be read; the old one is kept. |
shard S at <addr> does not compress its link | shard_compression is on, but that shard cannot. |
deadlock across shards: ending <id> | A transaction ended to break a deadlock. |
transaction <id> is decided commit but shard S did not finish it ... | Run rdb-shard resolve. |
rebalance started: ..., rebalance finished with exit code N | A REBALANCE CLUSTER run. |
a session panicked; it alone was ended | An internal error ended one session. |
Shards log as any server does (--log-level).
Upgrading the gateway without downtime
On Linux, two gateway processes can listen on the same port at once (SO_REUSEPORT):
- Start the new gateway with the same configuration. Both now accept connections.
- Send the old one SIGTERM. It stops accepting connections. Each idle session closes at once with
57P01, and each session inside a transaction closes when its transaction ends. Whatever is still open afterdrain_secs(30 s) is closed.
Clients that reconnect on 57P01 land on the new process. Upgrade shards one at a time; while a shard restarts, its keys are unavailable (see High availability).
Backing up a cluster
Each shard archives itself to S3 like any server (see Backup and restore): start every shard with its own prefix.
export AWS_ACCESS_KEY_ID=... AWS_SECRET_ACCESS_KEY=... AWS_REGION=us-east-1
./rasterizeddb --location ./shard0 ... --s3-bucket rdb-backups --s3-prefix cluster/shard0/g1rdb-shard backup then takes a backup of the whole cluster at one consistent point. It holds commit decisions on the home shard for a few seconds while it flushes every shard's log, so no two-phase transaction is committed at one shard's point and not at another's.
export RDB_PASSWORD='change-me'
./rdb-shard backup --map cluster.map --out backup-2026-11-27.manifest --snapshot \
--user rasterized --database postgres \
--native 0=127.0.0.1:61180 --native 1=127.0.0.1:61181 --native 2=127.0.0.1:61182shard 0: snapshot taken
shard 1: snapshot taken
shard 2: snapshot taken
shard 0: point 2026-11-27T10:15:02Z (lsn 48211)
shard 1: point 2026-11-27T10:15:02Z (lsn 39004)
shard 2: point 2026-11-27T10:15:03Z (lsn 41877)
cluster backup written to backup-2026-11-27.manifest--snapshottakes a full snapshot of every shard first. Without it, the backup relies on each shard's existing snapshots and log archive.- The manifest names each shard's restore point. A copy of the map is written beside it (
<manifest>.map). - Transactions on a single shard are not held: each shard's point is exact for that shard, so two independent transactions on two shards are not ordered by the cut.
Restoring a cluster
./rdb-shard restore --manifest backup-2026-11-27.manifest \
--user rasterized --database postgres \
--native 0=127.0.0.1:61180 --native 1=127.0.0.1:61181 --native 2=127.0.0.1:61182It checks that every shard's archive still holds its point and a snapshot before it, then prints the steps:
Every shard's archive holds its point. To restore the cluster to it:
1. Stop every gateway, then every shard.
2. Restore each shard into a new directory, with its usual --s3-* flags (its current prefix) and:
shard 0: --restore-to <new dir> --restore-at-time '2026-11-27T10:15:02Z'
...
3. Start each shard on its new directory (--location) with a NEW --s3-prefix: the restore is a new
timeline, and the old prefix also holds what came after the point.
4. Roll back what was prepared and undecided at the cut: rdb-shard resolve --map cluster.map --grace 0
5. Start the gateways.Step 2 for shard 0, for example:
./rasterizeddb --s3-bucket rdb-backups --s3-prefix cluster/shard0/g1 \
--restore-to ./shard0.restored --restore-at-time '2026-11-27T10:15:02Z'Then start shard 0 with --location ./shard0.restored and --s3-prefix cluster/shard0/g2, and the same for every shard. rdb-shard cannot stop or start the processes itself.
A backup belongs to the map the cluster had when it was taken. Restoring to a point before a move between shards is not covered here.
Limits
- The metrics endpoint and the configuration API have no TLS, and the metrics endpoint no authentication.
- Settings stored through the API take effect only at the next start.
- Counters are per gateway process and start from zero at each start.
- Zero-downtime gateway upgrades rely on
SO_REUSEPORT, which this page describes for Linux. - A cluster restore is a manual procedure the tool prints; it cannot restore across a move.