Skip to content

This is the multi-page printable view of this section. .

Return to the regular view of this page.

Addons

pgcli addon management guide

pgcli supports extending PostgreSQL capabilities through an addon system. Addons are standalone containers that provide additional functionality for PostgreSQL instances without modifying the database itself.

Supported Addons

The following addons are currently supported:

Addon Description
pgbouncer Connection pool manager with transaction-level pooling
etcd Distributed key-value store — standalone, clusterable, for HA / DCS use
pgdog Postgres proxy — connection pooling, load balancing and sharding
postgrest Expose a PostgreSQL schema as a REST API — single stateless container, local or remote (any PG endpoint)
haproxy TCP load balancer in front of a Patroni cluster — unified or read/write split, or any native proxying via your own haproxy.cfg (Linux only)
minio S3-compatible object storage with web console — standalone or distributed erasure-coded cluster across hosts (Linux and macOS)
silo S3-compatible object storage (Pigsty’s MinIO fork) — same feature surface as the minio addon, shares one port pool; ships its own mcli client (Linux and macOS)
rustfs S3-compatible object storage (Rust reimplementation) — SNSD/SNMD/MNMD erasure-coded layouts, fixed container uid handled inside pgcli’s wrapper image, shares the one port pool (Linux only)
garage S3-compatible object storage (Deuxfleurs’ Rust store) — single-node v1, rendered garage.toml, two data dirs, four ports from its own pool, plaintext HTTP only (front with nginx for TLS) (Linux; macOS code-complete, untested)
seaweedfs S3-compatible object storage (Go, volume-managed disk) — single-node weed mini or cross-host weed server cluster with filer metadata in a shared PostgreSQL, one credential pair shared by the whole cluster, native S3 TLS; own port pool (Linux; macOS code-complete, untested)
redis Standalone key-value store for cache, session, ranking and counter data — selectable majors 7/8, auto-generated requirepass, RDB persistence, read replicas, native cluster sharding via --cluster, own port pool (Linux; macOS code-complete, untested)
predixy Redis protocol proxy — turns a native cluster into one plain redis:// endpoint, so clients need no cluster awareness at all; own port pool (Linux only)
pgadmin pgAdmin 4 — the official PostgreSQL web administration UI, one container from the upstream image; web login auto-generated, optional one-time server seed via --dsn/--pg-name, persistent session store; own port pool (Linux; macOS code-complete, untested)
nginx HTTP reverse proxy fronting multiple web services — path-based routing to declared backends, optional TLS termination, rendered nginx.conf or your own --conf-file, pg addon nginx reload on config change; own port pool (Linux and macOS)
privoxy HTTP/HTTPS forward proxy — direct HTTP forwarding plus HTTPS CONNECT tunnels (no TLS interception, no CA), rendered config or your own --conf-file, client ACLs via --allow-network/--deny-network (repeatable and comma-separated, whitelist/blacklist with last-match-wins ordering), port auto-assigned from privoxy_start_port (default 8118) skipping host-listening ports; own port pool (Linux and macOS)
grafana Grafana — the open-source observability dashboard, one container from the official upstream image; web login auto-generated, Listen defaults to 0.0.0.0 (signup closed), env-only (GF_*) config with no provisioning in v1; own port pool (Linux; macOS code-complete, untested)
prometheus Prometheus — the metrics collection backend Grafana reads from, one container from the official docker.io/prom/prometheus image; rendered prometheus.yml (self job + one job per --scrape JOB, folding that job’s targets; --scrape-append merges incrementally; --alertmanager-url forwards fired alerts and adds the matching scrape job; --rule-file copies and loads alerting rules) or your own --conf-file, SIGHUP reload via pg addon prometheus reload; no web login — Listen defaults to 0.0.0.0 guarded only by the network (use --listen 127.0.0.1 for loopback); own port pool (Linux; macOS code-complete, untested)
alertmanager Alertmanager — the alert dedup/grouping/routing frontend of the Prometheus stack, one container from the official docker.io/prom/alertmanager image; rendered alertmanager.yml (a minimal route to a no-op or --webhook-url web.hook receiver) or your own --conf-file, SIGHUP reload via pg addon alertmanager reload; HA cluster gossip disabled (9094 never opens); no web login — Listen defaults to 0.0.0.0 guarded only by the network, and reaching it means anyone can create silences (mute on-call), so use --listen 127.0.0.1 for loopback; wired to Prometheus from the Prometheus side via pg addon install prometheus --alertmanager-url; own port pool (Linux; macOS code-complete, untested)
victoriametrics VictoriaMetrics — fast, Prometheus-compatible time-series database, one container from the official docker.io/victoriametrics/victoria-metrics image; no config file (everything is CLI flags: -storageDataPath / -httpListenAddr / -retentionPeriod / --extra-arg), no hot reload (changes recreate the container), image runs as root (no pre-chown); no web login — Listen defaults to 0.0.0.0 guarded only by the network (use --listen 127.0.0.1 for loopback); own port pool (Linux; macOS code-complete, untested)
nodeexporter node_exporter — the official Prometheus host-metrics exporter, one stateless container from the official docker.io/prom/node-exporter image; the one addon that must hard-wire three read-only host mounts (/proc→/host/proc, /sys→/host/sys, /→/rootfs) plus --path.* redirection or it would silently export the container’s own numbers instead of the host’s; no config file (everything is CLI flags: --web.listen-address / --path.* / --collector.filesystem.mount-points-exclude / --extra-arg), no hot reload (changes recreate the container), no data dir (remove never deletes anything); no auth, no TLS — Listen defaults to 0.0.0.0 because a Prometheus scraping it is usually on another host, so a remote-exposed instance is guarded only by the network; scrape it from a pgcli Prometheus with pg addon install prometheus --scrape node-exporter=<host>:9100; own port pool, default 9100 (Linux; macOS code-complete, untested)
pgexporter pg_exporter — Pigsty’s declarative PostgreSQL database-metrics exporter, one stateless container from the official docker.io/pgsty/pg_exporter image; the companion to node_exporter (which describes the host) that exports ~460 pg_* metrics (activity, locks, replication, bloat, WAL, per-DB stats) and its distinguishing feature is unified collection: the target is EITHER a pgcli-managed instance (--pg-name, admin DSN re-derived each start) OR any reachable PostgreSQL pgcli does not manage — given as ONE mutually-exclusive URL: --admin-dsn (an admin URL used once to create the monitor role, then discarded — only its credential-free address is stored, the exporter dials as the monitor role) or --dsn (dial-as-is: pgcli runs no SQL, the exporter uses this URL’s own credentials — for a role that already exists or a database pgcli must not touch) — the point being one exporter shape collects databases inside and outside pgcli alike; by default pgcli creates a low-privilege pg_monitor monitor role on the target so the exporter NEVER dials as admin — local admin creds are derived automatically, a remote target takes an --admin-dsn used once for the CREATE ROLE/GRANT batch and never stored, and the generated monitor password is retrievable via pg addon password pgexporter; no config file needed (the default collector set is baked into the binary, planned at runtime by version/role/extensions; an optional --config-file collector YAML mounts read-only and SIGHUP-hot-reloads via pg addon pgexporter reload); /up /primary /replica health probes double as HAProxy-style routing checks; no auth, no TLS, and admin endpoints /reload /explain /stat on the same port — Listen defaults to 0.0.0.0 guarded only by the network; scrape it from a pgcli Prometheus with pg addon install prometheus --scrape pg=<host>:9630; own port pool, default 9630 (Linux host-network is tested; macOS bridge can’t reach a local instance’s loopback DSN — use a remote URL there (--dsn or --admin-dsn))
documentdb DocumentDB gateway — the official Rust MongoDB wire-protocol gateway in front of the DocumentDB PostgreSQL extension, one container from pgcli’s own ghcr.io/mars-base/pgcli/pgcli-documentdb-gateway image; local PG 18 instances only (--pg-name; --dsn/--admin-dsn rejected) because the official .deb authenticates only over a shared Unix socket and refuses passwords; the gateway connects as the passwordless docdb_gateway superuser via local … trust, clients use a DocumentDB native user (default docdb_admin, pg addon password documentdb) — DocumentDB users are ordinary PG roles, so use a distinct --username per gateway sharing a database (that separates credentials, not data or load — every gateway adds connections and shares the instance’s CPU/I/O); rendered SetupConfiguration.json with metrics/tracing disabled (no upstream all-in-one image, no telemetry), self-signed TLS auto-generated and persisted in a named volume, --tls-mode allow|require; own port pool, default 10260; management CLI (pg addon documentdb shell plus read-only databases/collections/indexes) via an on-demand mongosh-only image — for the local add-on or any remote gateway with --dsn/DOCDB_URI — so the pgcli binary stays unchanged (Linux; macOS code-complete, untested)
victorialogs VictoriaLogs — the log database of the VictoriaMetrics family, one container from the official docker.io/victoriametrics/victoria-logs image; single HTTP port serves ingestion (JSON Lines / Elasticsearch bulk / syslog / OTLP), LogsQL queries and the built-in UI; no config file (everything is CLI flags: -storageDataPath / -httpListenAddr / -retentionPeriod / --extra-arg), --retention takes a duration (30d, 3months, …) and is omitted by default so the binary’s own default stands; no web login — Listen defaults to 0.0.0.0 guarded only by the network (use --listen 127.0.0.1 for loopback); own port pool, default 9428 (Linux; macOS code-complete, untested)
influxdb InfluxDB — the classic 1.x time-series database (TSM storage, InfluxQL), one container from pgcli’s own ghcr.io/mars-base/pgcli/pgcli-influxdb image packaging the official 1.13.1 linux/amd64 release on Alpine; authentication always on (generated admin password, pg addon password influxdb), minimal rendered influxdb.conf that only overrides paths/listen/auth, every other upstream default kept, arbitrary persistent overrides via --config-option or pg addon influxdb config set/unset; one container plus a unique loopback-only backup/restore RPC port per instance (upstream RPC has no auth); online portable backup/restore (--newdb to restore alongside), offline export via influx_inspect (stops the container, restarts unless --no-start), import with # CONTEXT-DATABASE: rewrite; top-level pg influx passthrough runs the influx CLI in a throwaway container against the local addon or any remote InfluxDB 1.x server (--host/--dsn, TLS flags, INFLUX_USERNAME/INFLUX_PASSWORD, -import -path FILE mounted into the container); no HTTPS listener (front with nginx), no HA, v1 is in maintenance mode; own port pool (Linux/amd64 only)
influx2tsdb influx2tsdb — InfluxDB 1.x HTTP API adapter (Line Protocol + InfluxQL) in front of a PostgreSQL database with TimescaleDB, one stateless container from pgcli’s own ghcr.io/mars-base/pgcli/pgcli-influx2tsdb image (upstream 1.3.2 on Debian); each InfluxDB database maps to a PostgreSQL schema and each measurement to a hypertable; target a local instance with --pg-name (DSN re-derived on every start) or any remote PostgreSQL/TimescaleDB with --dsn; no authentication and no TLS — front with nginx or isolate the port; retention and compression are applied as TimescaleDB background jobs (add_retention_policy / add_compression_policy, re-synced every 5 minutes) — no pg_cron needed, and cleanup continues while the proxy is down; data lives entirely in PostgreSQL, so remove never deletes it and backup/PITR/replication/HA are PostgreSQL’s; InfluxQL subset, nanosecond timestamps, below-native-InfluxDB performance; own port pool (Linux/amd64 only)
vlagent vlagent — the official VictoriaLogs log agent, one container from the official docker.io/victoriametrics/vlagent image; tracks host log files (each --log-path mounted read-only at the same absolute path) selected by vlagent’s native globs (--include/--exclude; no regex), and forwards to VictoriaLogs via one or more --remote-write-url values ending in /insert/native; relay-only when no paths are given; no config file, no auth; own port pool, default 9429 (Linux; macOS code-complete, untested)
vmalert vmalert — the VictoriaMetrics rule-evaluation engine, one container from the official docker.io/victoriametrics/vmalert image; evaluates alerting/recording rules against exactly one datasource (VictoriaLogs 9428 by default, or VictoriaMetrics 8428 for metrics — logs and metrics cannot be mixed) and forwards firing alerts to one or more repeatable --notifier-url Alertmanagers; host rules/templates directories are bind-mounted read-only (*.yaml / *.tpl only — *.yml is ignored), seeded once and never overwritten, with pg addon vmalert reload (GET /-/reload, asynchronous) plus pg addon vmalert status; --remote-write-url/--remote-read-url restore alert state across restarts (both required); HA via repeated instances with distinct --external-label replica=...; no auth, no TLS and Listen defaults to 0.0.0.0; own port pool, default 8880 (Linux; macOS code-complete, untested)
vmcluster VMCluster — the VictoriaMetrics cluster edition, three components (vminsert + vmselect + vmstorage) each in its own container from the official docker.io/victoriametrics/*:*-cluster images; --roles selects which components THIS host runs (default all three = converged single host) and --storage-node lists every vmstorage address for cross-host sharding/replication; only vmstorage has persistent data; no config file, no auth; 5 ports per instance from vmcluster_start_port (default 8480-8484) (Linux only)
vlcluster VLCluster — the VictoriaLogs cluster edition, three components (vlinsert + vlselect + vlstorage) all from the same docker.io/victoriametrics/victoria-logs image, distinguished only by flags; --roles selects which components THIS host runs (default all three = converged single host) and --storage-node host:storagePort lists every vlstorage address for cross-host sharding (no replication — a down vlstorage makes queries return 502); only vlstorage has persistent data; no config file, no auth; 3 ports per instance from vlcluster_start_port (default 9430-9432) (Linux only)
gitea Gitea — self-hosted Git service, one container from the official docker.io/gitea/gitea image (rootful build, runs as uid 1000); no-wizard install (INSTALL_LOCK) plus an auto-created admin whose web login is generated, printed once, and retrievable via pg addon password gitea; embedded SQLite by default or an external PostgreSQL via --dsn (Gitea creates its schema, pgcli never creates or drops the database); optional ssh:// clones via --ssh-port (own second port pool; off by default — HTTP clone only, since the image’s OpenSSH sshd runs unconditionally on every instance and --ssh-port is what promotes it from a parked listener to the live clone endpoint); crypto secrets (SECRET_KEY/INTERNAL_TOKEN) deliberately never injected — they belong to the persisted volume so reinstalls cannot silently re-key a surviving database; Listen defaults to 0.0.0.0 (signup closed by default, open it with --allow-registration; accounts via pg addon gitea user create), env-only (GITEA__*) config; own port pool (Linux; macOS code-complete, untested)
beegfs BeeGFS — parallel filesystem, pgcli’s first multi-container addon: one config entry = one converged single-host filesystem = three containers (mgmtd + meta + storage) from the official ghcr.io/thinkparq/beegfs-* images, started in dependency order and managed as a unit (cluster-granular install reuse, stop/start, autostart, pg logs addon beegfs --service); host networking only — Linux only, no port pool: the protocol ports are stock/fixed (8008/8010 movable via the two --beegfs-mgmtd-* flags, meta 8005 + storage 8003 have no 8.4 override), which is exactly why v1 is one filesystem per host (guarded); shared connection-auth secret generated on install (pg addon password beegfs), mgmtd TLS disabled (--tls-disable, so clients must match); the client is a kernel module — pgcli never installs or mounts it, pg addon beegfs mount-hint prints the exact client config; licenses never injected; pg addon beegfs check reads daemon log lines for health; v1 single-host, v2 = cross-host cluster
juicefs JuiceFS — S3-backed POSIX filesystem, pgcli’s first host-binary addon (no container): the binary is downloaded from GitHub releases with a pinned sha256 (a juicefs on PATH is reused), both sides fully explicit with no same-host auto-detection — the object store is an EXTERNAL S3 service (--s3-endpoint http(s)://host[:port] + --access-key/--secret-key, probed before format) and the metadata engine is an explicit --dsn URL (postgres:// / redis:// / sqlite3://, which pgcli never creates or drops); buckets stay manual pg mc work — pgcli prints the exact command. Mounts a plain host directory (no propagation into PG containers); `pg addon juicefs mount
zerofs ZeroFS — encrypted, self-maintaining S3 filesystem (its own LSM on the bucket, no external metadata engine) as a host-binary addon: pgcli writes config.toml and runs two host processes — a loopback-only 9P server (9P has no auth; non-loopback --listen is rejected, one port per instance) plus the FUSE client; the object store is an EXTERNAL S3 service given explicitly (--s3-endpoint + --access-key/--secret-key, optional --s3-region — no same-host addon lookup); a generated encryption password wraps the bucket’s data key (pg addon password zerofs; after remove keeps the bucket, re-attach with --encryption-password '<original>' or the server fails Invalid password or corrupted key); fencing needs conditional put — --conditional-put auto (MinIO 2022-08+ / real S3) or redis via an explicit --redis-dsn for stores lacking it, none single-writer only; `pg addon zerofs start
duckdb DuckDB — embedded OLAP database (“SQLite for analytics”) as a host-binary addon (no container, no daemon): C++ columnar engine with vectorised execution, queries Parquet/CSV/JSON/Arrow directly; downloaded from GitHub releases with a pinned sha256 (a duckdb on PATH is reused); common extensions (httpfs, parquet, json) auto-installed; --version pins the release (1.5.6 LTS default, 2.0.0 supported); `pg addon duckdb status
clickhouse ClickHouse — columnar OLAP database from the official docker.io/clickhouse/clickhouse-server image (pinned 26.8 LTS 26.8.36.3, amd64/arm64; host networking, data/log/config/backup dirs bind-mounted); authentication always on with a generated admin account (pg addon password clickhouse); HTTP 8123 and native TCP 9000 by default from separate port pools (TCP shares the S3 API pool); Listen defaults to 127.0.0.1; no TLS listener (front with nginx); runs single-node, or becomes one member of a static replicated cluster with --cluster/--shard/--replica/--peer/--keeper (ReplicatedMergeTree, Distributed, ON CLUSTER DDL; interserver 9009); pg addon clickhouse status|shell|query|database|user|grant|backup|restore|backups|config, dotted-XML-path settings via config set; Linux only
clickhouse-cluster ClickHouse cluster — the multi-host walkthrough for the ClickHouse addon: 2 shards × 2 replicas, Keeper-first install order, per-member --peer lists, rendered zz-pgcli-cluster.xml, pg addon clickhouse cluster status, ReplicatedMergeTree + Distributed tables, Keeper/ClickHouse failure drills; static membership, uniform replica counts, IP addresses only, and the production rule that Keeper runs on dedicated servers
clickhouse-keeper ClickHouse Keeper — standalone ZooKeeper-compatible coordination addon for the ClickHouse cluster, from the official docker.io/clickhouse/clickhouse-keeper image; independent config/data/log paths (never inside a ClickHouse instance); --server-id/--advertise-host/--peer form a Raft quorum (3 or 5 members, 1 failure tolerated), client 9181 + Raft 9234; pg addon clickhouse-keeper status|shell|config show; pg start starts Keeper before ClickHouse; no auth/TLS; Linux only
kafka Kafka — KRaft broker (no ZooKeeper) from the official docker.io/apache/kafka image (pinned 4.4.0, amd64/arm64; host networking, rendered server.properties, data dir bind-mounted); single-node combined broker+controller or one node of a multi-host static controller quorum installed on every host with --cluster/--node-id/--peer (derived cluster id, immutable membership); broker 9092 and controller 19093 by default (own port pools; controller avoids Alertmanager’s 9093); Listen defaults to 127.0.0.1 (clusters require 0.0.0.0); PLAINTEXT by default with an optional TLS listener (--tls, SSL port from the 9093 pool; encryption only, no client authentication; cluster clients need a concatenated CA bundle); RF=min(3, voters) / minISR=min(2, RF); pg addon kafka status|shell|topic create/list/describe/delete/retention|group list/describe|cluster status; --config-option overrides persisted in pg.yaml; Linux only
rabbitmq RabbitMQ — message broker from the official docker.io/library/rabbitmq management image (pinned 4.4.0, amd64/arm64; host networking, rendered rabbitmq.conf, data dir bind-mounted, enabled_plugins fixed to management, plus etcd discovery in cluster mode); single node or one member of a multi-host cluster formed by etcd peer discovery (--cluster, --node-name, --etcd-endpoints or --etcd, shared secrets via pg addon rabbitmq secret generate + --secrets-from-etcd, or --erlang-cookie-file/--admin-password-file); AMQP 5672 and management web UI/API 15672 by default, plus EPMD 4369 and Erlang distribution 25672 (pool-assigned and loopback-only standalone, fixed and network-reachable for cluster members, one clustered instance per host); Listen defaults to 127.0.0.1 standalone and 0.0.0.0 clustered; authentication always on with a generated admin password (pg addon password rabbitmq), reconciled on every start; optional additive TLS (--tls: AMQPS 5671 and management HTTPS 15671, generated CA or bring-your-own --tls-cert/--tls-key; encryption only, no client authentication; distribution traffic remains unencrypted); pg addon rabbitmq status|shell|queue ... — declare/info/publish/get/bind/unbind/bindings go through the management API, list/purge/delete through rabbitmqctl; cluster declare defaults to quorum queues (--type classic for non-replicated); pg addon rabbitmq cluster status|forget NODE; no Prometheus plugin; Linux only
rocketmq RocketMQ — Apache RocketMQ 5.x messaging from the official docker.io/apache/rocketmq image (host networking, rendered namesrv.conf/broker.conf/rmq-proxy.json, broker/controller stores and logs bind-mounted); three containers per instance (NameServer + broker + proxy, started namesrv → broker → proxy); standalone one async master with no replicas, or one member of a multi-host cluster with an embedded DLedger controller in every NameServer and controller-mode brokers that fail over automatically (--cluster/--controller-id/--advertise-host/--peer ID@HOST, full peer list on every host, one member per host, fixed ports 9876/9877/10911/10912/8080/8081); NameServer 9876, controller 9877, broker 10911 (HA 10912, VIP 10909), proxy remoting 8080 and gRPC 8081; no authentication, no TLS, no web UI; pg addon rocketmq status|shell|topic create/list/describe/delete|send|cluster status; --config-option broker.conf overrides persisted in pg.yaml; controller/broker stores are stateful, 3+ members for quorum, identity immutable after install; Linux only

Each addon has its own page with commands, parameters, and troubleshooting.

Patroni HA (pg ha) is not on this list — it is not installed via pg addon but is its own top-level command, and its documentation now lives in a dedicated HA Cluster section. etcd and HAProxy here are addons a pg ha cluster can use.

How It Works

Addons run as standalone containers managed through pg.yaml:

  1. pg addon install generates configuration and starts the addon container
  2. Config and data live under <base-dir>/addon/<addon-name>/
  3. Addon containers communicate over the host network
  4. Containers automatically restart when configuration is updated

Namespace isolation: Addons respect the config’s namespace setting — container names include the namespace prefix, so different config files can manage independent addons without conflicting.

Common Commands

pg addon install <addon> [flags]   # install / reconfigure (idempotent)
pg addon list                       # show all installed addons and status
pg addon remove <addon> [flags]     # remove the addon, container, and data

See each addon’s page for its specific flags and examples: Pgbouncer · etcd · PgDog · PostgREST · HAProxy · MinIO · Silo · rustfs · Garage · SeaweedFS · Redis · Predixy · pgAdmin 4 · nginx · Privoxy · Grafana · Prometheus · Alertmanager · VictoriaMetrics · node_exporter · pg_exporter · DocumentDB · VictoriaLogs · vlagent · vmalert · InfluxDB · influx2tsdb · ClickHouse · ClickHouse Cluster · ClickHouse Keeper · Kafka · RabbitMQ · RocketMQ · VMCluster · VLCluster · Gitea · BeeGFS · JuiceFS · ZeroFS · DuckDB. Patroni pages live in HA Cluster.

1 - PgBouncer

Connection pooling for PostgreSQL instances via the PgBouncer addon

PgBouncer is a lightweight connection pooler for PostgreSQL. As a pgcli addon it runs as a container in front of one or more PostgreSQL instances, reusing server connections across many short-lived client sessions — transaction-level pooling by default.

PgBouncer supports two deployment modes:

  • Local: pg addon install pgbouncer -i <instance> — stored under instances.<name>.addons
  • Remote: pg addon install pgbouncer --dsn <dsn> --pg-name <name> — stored in top-level addons.pgbouncer

Platform support

PgBouncer works on Linux (host networking, including cross-host pools) and on macOS for single-host dev/test (the container joins the pgcli-net bridge and publishes its port, the same way a PG instance does under podman machine). On macOS:

  • Local mode just works: PgBouncer reaches the managed instance by its container name automatically — no address to configure.
  • Remote mode: the --dsn host must be reachable from the Mac — do not point it at 127.0.0.1, which is the Mac itself, not the podman machine VM.
  • Client connections still target 127.0.0.1:<port>; gvproxy forwards the published port to the Mac’s loopback, exactly as for a PG instance.

How It Works

  1. pg addon install pgbouncer generates configuration files and starts the container
  2. Config files live in <base-dir>/addon/pgbouncer/<instance>/
  3. The container reaches PostgreSQL over the host network (Linux) or the pgcli-net bridge by container name (macOS)
  4. Config file updates restart the container automatically

Namespace isolation: PgBouncer respects the config’s namespace setting. Container names and auth users include the namespace prefix (e.g. pgb_<namespace>_<instance>), so different configs with different namespaces can create independent poolers for the same PostgreSQL instance without conflicting.

# Config with namespace "prod"
pg -c prod-pg.yaml addon install pgbouncer -i mypg
# → container: pgcli-pgbouncer-prod-mypg, auth user: pgb_prod_mypg

# Config with namespace "staging"
pg -c staging-pg.yaml addon install pgbouncer -i mypg
# → container: pgcli-pgbouncer-staging-mypg, auth user: pgb_staging_mypg

Commands

Install

# Local mode: pool a managed instance
pg addon install pgbouncer -i mypg

# Remote mode: pool a remote PG instance
pg addon install pgbouncer \
  --dsn "postgres://admin:pass@10.0.0.20:35432/mypg_db" \
  --pg-name my-remote-pool

# Tune pool parameters
pg addon install pgbouncer -i mypg \
  --max-client-conn 200 \
  --default-pool-size 30 \
  --min-pool-size 5 \
  --reserve-pool-size 10 \
  --max-db-connections 50 \
  --query-timeout 60 \
  --admin-users admin \
  --log-connections 1

Parameters:

Parameter Description Default
--dsn PG instance connection string (remote mode) —
--pg-name Name to identify a remote PgBouncer (required with –dsn) —
--max-client-conn Maximum client connections 100
--default-pool-size Default pool size 20
--min-pool-size Minimum pool size (warmup) 0
--reserve-pool-size Reserve pool size (burst) 0
--max-db-connections Max connections per database 50
--max-user-connections Max connections per user 0 (unlimited)
--server-idle-timeout Idle server connection timeout (seconds) 600
--server-lifetime Max server connection lifetime (seconds) 3600
--server-connect-timeout PostgreSQL connection timeout (seconds) 15
--query-timeout Query timeout (seconds) 0 (unlimited)
--query-wait-timeout Wait for connection timeout (seconds) 120
--idle-transaction-timeout Idle transaction timeout (seconds) 0
--transaction-timeout Transaction timeout (seconds) 0
--admin-users Admin users list (empty)
--stats-users Read-only stats users list (empty)
--log-connections Log connections 0
--log-disconnections Log disconnections 0

List

pg addon list

PgBouncer appears under Local add-ons / Remote add-ons:

Local add-ons:
  pgbouncer (instance: mypg)
    Status:    running
    Host:      127.0.0.1:56432
    Port:      56432
    Pool mode: transaction
    Container: pgcli-pgbouncer-default-mypg

Remote add-ons:
  pgbouncer (pg-name: my-remote-pool)
    Status:    running
    Host:      10.0.0.20:56433
    Port:      56433
    Pool mode: transaction
    Container: pgcli-pgbouncer-default-my-remote-pool

Start and stop

After a reboot or manual stop, bring the pooler back up without re-running install (config and auth users are untouched):

# Local
pg addon start pgbouncer -i mypg
pg addon stop pgbouncer -i mypg

# Remote
pg addon start pgbouncer --pg-name my-remote-pool
pg addon stop pgbouncer --pg-name my-remote-pool

start is idempotent — a running pooler is left alone. stop keeps the container and its config; use pg addon remove to tear it down.

Remove

# Remove local PgBouncer
pg addon remove pgbouncer -i mypg

# Remove remote PgBouncer
pg addon remove pgbouncer --pg-name my-remote-pool

Workflow:

  1. Stop and remove the addon container
  2. Delete the <base-dir>/addon/pgbouncer/<instance>/ directory and files
  3. Remove the addon entry from pg.yaml

Configuration

Local mode (under instances.<name>.addons):

instances:
  mypg:
    addons:
      pgbouncer:
        enabled: true
        max_client_conn: 200
        default_pool_size: 30
        min_pool_size: 5
        reserve_pool_size: 10
        max_db_connections: 50
        query_timeout: 60
        admin_users: admin
        log_connections: 1

Remote mode (under top-level addons):

addons:
  pgbouncer:
    my-remote-pool:
      container_name: pgcli-pgbouncer-default-my-remote-pool
      host_port: 56433
      pool_mode: transaction
      dsn: "postgres://admin:pass@10.0.0.20:35432/mypg_db"
      max_client_conn: 200
      default_pool_size: 30

Generated files, per instance, under <base-dir>/addon/pgbouncer/:

<base-dir>/addon/pgbouncer/
├── mypg/
│   ├── pgbouncer.ini    # PgBouncer main configuration
│   └── userlist.txt     # auth user credentials (auto-regenerated)
└── my-remote-pool/
    ├── pgbouncer.ini
    └── userlist.txt

Authentication

PgBouncer uses the auth_query method for dynamic password lookup:

  1. A per-pooler auth user is created on PostgreSQL with a random password, named pgb_<namespace>_<instance> (e.g. pgb_default_mypg, pgb_test-ns_my-remote)
  2. A shared SECURITY DEFINER function pgbouncer_lookup() is installed to query pg_authid
  3. When a client connects, PgBouncer uses its own auth user to run the auth_query and fetch the real user’s password hash
  4. The password is cached in PgBouncer’s memory for subsequent connections

userlist.txt only contains the pooler’s auth user (plaintext password). All other users are authenticated dynamically via auth_query — no password sync needed.

Each pooler gets its own PG auth user, so multiple poolers (local or cross-host) targeting the same PG instance do not conflict.

After changing a PostgreSQL user’s password, re-run pg addon install pgbouncer to reset the auth cache, or connect to the admin console and run RECONNECT.

Connecting

Clients connect through the addon port:

# Direct connection to PostgreSQL
pg exec -i mypg "SELECT version()"

# Connection through PgBouncer
pg exec --dsn "postgres://user:pass@127.0.0.1:56432/mypg_db" "SELECT version()"

Port allocation: PgBouncer defaults to port 56432; if occupied, pgcli assigns the next free port. View the current port with pg addon list.

Use Cases

High Concurrency

pg addon install pgbouncer -i mypg \
  --max-client-conn 1000 \
  --default-pool-size 50 \
  --reserve-pool-size 20 \
  --max-db-connections 100

Short-Lived Connections

pg addon install pgbouncer -i mypg \
  --pool-mode transaction \
  --server-idle-timeout 60 \
  --server-lifetime 600

Long-Lived Connections

pg addon install pgbouncer -i mypg \
  --pool-mode session \
  --server-lifetime 86400

Read Replicas

pg addon install pgbouncer -i mypg-replica \
  --pool-mode transaction \
  --max-db-connections 30 \
  --query-timeout 30

Monitoring

PgBouncer exposes an admin console for pool and runtime status.

Connecting to the Admin Console

Connect to the pgbouncer virtual database as an admin user:

pg exec --dsn "postgres://<admin-user>:<password>@127.0.0.1:<pgbouncer-port>/pgbouncer" "SHOW pools"

Example:

pg exec --dsn "postgres://admin:secret@127.0.0.1:56432/pgbouncer" "SHOW pools"

Note: Only users listed in admin_users can access the admin console.

Common SHOW Commands

Command Description
SHOW pools Connection pool status (active/waiting client and server connections)
SHOW clients All current client connections with details
SHOW servers All current server (PostgreSQL) connections with details
SHOW databases Configured databases and their connection parameters
SHOW stats Traffic statistics (transactions, queries, bytes received/sent)
SHOW config All runtime configuration parameters
SHOW sockets Low-level TCP socket information
SHOW active_sockets Active TCP sockets
SHOW mem Memory usage statistics
SHOW lists Summary of various object counts

Examples

# Check pool status
pg exec --dsn "postgres://admin:secret@127.0.0.1:56432/pgbouncer" "SHOW pools"

# View active client connections
pg exec --dsn "postgres://admin:secret@127.0.0.1:56432/pgbouncer" "SHOW clients"

# View PostgreSQL backend connections
pg exec --dsn "postgres://admin:secret@127.0.0.1:56432/pgbouncer" "SHOW servers"

# Check current configuration
pg exec --dsn "postgres://admin:secret@127.0.0.1:56432/pgbouncer" "SHOW config"

# View traffic statistics
pg exec --dsn "postgres://admin:secret@127.0.0.1:56432/pgbouncer" "SHOW stats"

Other Admin Commands

Command Description
RELOAD Reload configuration file
PAUSE Pause connection pool (wait for transactions to complete)
RESUME Resume connection pool
RECONNECT Force reconnect all server connections
SHUTDOWN Shutdown PgBouncer

Troubleshooting

Connection Pool Full

ERROR: no more connections allowed

Cause: Reached max_client_conn limit.

# Increase maximum connections
pg addon install pgbouncer -i mypg --max-client-conn 500

# Or reduce pool size
pg addon install pgbouncer -i mypg --default-pool-size 10

Authentication Failure

FATAL: password authentication failed

Cause: Auth cache contains a stale password hash.

# Re-run install to reset the auth cache
pg addon install pgbouncer -i mypg

Container Won’t Start

# View container logs
podman logs pgcli-pgbouncer-default-mypg

# Check the configuration file
cat <base-dir>/addon/pgbouncer/mypg/pgbouncer.ini

Common causes: config syntax error, malformed user list, or port already in use.

Query Timeout

ERROR: query timeout

Cause: Query exceeded query_timeout.

# Increase the timeout, or disable it
pg addon install pgbouncer -i mypg --query-timeout 300
# or
pg addon install pgbouncer -i mypg --query-timeout 0

Notes

  • Port: PgBouncer defaults to 56432; ensure firewall rules allow access
  • Passwords: After changing a PostgreSQL user password, re-run pg addon install to reset the auth cache
  • Config edits: After editing config files manually, restart to apply:
    podman restart pgcli-pgbouncer-default-mypg
  • Transaction mode: transaction mode does not support session-level features (e.g. temporary tables); use session mode instead

2 - Etcd

Run a standalone etcd cluster as a pgcli addon for HA / DCS use

etcd is a distributed key-value store. pgcli can run one or more etcd members as a standalone, top-level addon — shared infrastructure rather than a per-instance sidecar. This is useful as the DCS (Distributed Concurrent Store) backing a PostgreSQL HA stack, or as a general config/lock service.

Security: pgcli-managed etcd members run without TLS or authentication by default — any client that can reach a client port has full read/write access, so loopback binds and a trusted network are the baseline. Pass --tls to encrypt the client listener and mutually authenticate raft peers, and --auth to require a username/password. There is still no multi-user or RBAC management: --auth creates a single user with the root role. See TLS and Authentication.

Members are managed one pg addon install etcd at a time: the first member bootstraps a cluster, and later members join the same named cluster on the fly — from the same host or from another machine.

How It Works

  • Shared infrastructure: etcd lives in the top-level addons.etcd map in pg.yaml, keyed by member name — not under any single instance.
  • Host network, configurable bind: each member runs with --network host. By default its client/peer URLs bind to 127.0.0.1 — without --tls and --auth, any reachable client has full access, so loopback-only exposure is the default posture for a single-host cluster. For cross-host clusters each member advertises a reachable address (--advertise-host) while also listening on loopback, so local etcdctl and remote peers both work.
  • Optional TLS and authentication: --tls covers both interfaces (client HTTPS plus raft peer mTLS), --auth adds a root-role username/password. Both are cluster-wide and fixed at bootstrap — see TLS and Authentication.
  • Dynamic membership: the first member starts with --initial-cluster-state new; each subsequent member is registered with etcdctl member add against a running peer, then started with --initial-cluster-state existing. pgcli does this automatically — same-host via a member container, cross-host via a temporary etcdctl container.
  • Cluster identity: members sharing the same --cluster value join the same etcd cluster (it maps to etcd’s --initial-cluster-token). The default is pgcli-etcd.
  • Baked-in tuning: every member launches with periodic compaction (--auto-compaction-mode periodic, --auto-compaction-retention 24h) and an 8 GiB backend quota (--quota-backend-bytes 8589934592) — sane defaults for a small HA metadata store.

Deployment Topologies

pgcli supports two cluster shapes. Both use the same install commands — the difference is whether members share a host.

Single host — all members on one machine (testing / dev)

The classic layout for a dev box or CI: every member listens on loopback with a different auto-assigned port. No --advertise-host needed (default 127.0.0.1), no firewall changes, nothing reachable from outside the host.

pg addon install etcd --name m1              # 127.0.0.1:2379/2380
pg addon install etcd --name m2              # 127.0.0.1:2381/2382
pg addon install etcd --name m3              # 127.0.0.1:2383/2384

All three belong to cluster pgcli-etcd; m1 bootstraps, m2/m3 join on the fly. This gives you real 3-node raft semantics but zero host isolation — the whole cluster dies with one machine, which is exactly why it is a testing topology.

Cross host — one member per machine (production HA)

The production shape: spread members across machines (ideally 3 or 5, an odd count — see Topology & Quorum). Each member advertises its host’s LAN address; the first member must bootstrap with --advertise-host so remote peers can dial it. Ports may repeat on every host since each binds its own interface.

# host A (10.0.0.1) — bootstrap
pg addon install etcd --name m1 --cluster prod \
  --advertise-host 10.0.0.1 --client-port 2379 --peer-port 2380

# host B (10.0.0.2) — join
pg addon install etcd --name m2 --cluster prod \
  --advertise-host 10.0.0.2 --client-port 2379 --peer-port 2380 \
  --join http://10.0.0.1:2379

# host C (10.0.0.3) — join
pg addon install etcd --name m3 --cluster prod \
  --advertise-host 10.0.0.3 --client-port 2379 --peer-port 2380 \
  --join http://10.0.0.1:2379

Requirements: every member’s --advertise-host is a mutual-LAN-reachable address, the firewall on each host lets the other members through on every member’s client and peer ports (bidirectional peer traffic — e.g. open 2379-2386/tcp for a 4-member cluster on default ports), and all members share the same --cluster token. Each host survives losing any one member; the cluster only needs a majority of machines.

Single host Cross host
Use for dev, CI, functional testing production HA
--advertise-host omit (loopback default) required, every member
--join not used every member after the first
Ports unique per member on one host may repeat, one host each
Firewall none (loopback only) open every member’s client+peer ports, both ways
Survives machine loss no yes (with quorum)

TLS and Authentication

--tls and --auth are independent, optional, and cluster-wide properties decided at bootstrap. Every member of a cluster must agree on each:

  • --tls turns the client listener into HTTPS and the raft peer listener into mTLS. Every member presents a leaf signed by one per-cluster CA, and peers verify each other’s certificates against that CA.
  • --auth enables etcd’s auth store with a single user (default root) that holds the root role, then turns authentication on.

Without --tls, --auth still works, but the password crosses the network in clear text (pgcli prints a warning). With --tls, client traffic is encrypted and the server is authenticated; clients authenticate with the username/password.

Single host

pg addon install etcd --name m1 --tls --auth

When --password is omitted on the first install, pgcli generates one and prints it once:

  TLS:          on
  Cluster CA:   ~/.pgcli/tls/etcd/pgcli-etcd/ca.crt
  Auth:         on
  Auth user:    root
  Auth password: ********  (generated once; stored in pg.yaml)
  Retrieve later with: pg addon password etcd --name m1

Retrieve it later with pg addon password etcd --name m1. Additional members on the same host inherit both settings (and the credentials) from the local peer automatically:

pg addon install etcd --name m2

Pass --password (and optionally --root-user) to choose your own; either flag implies --auth. Re-running install with a new --password rotates the root user’s password.

Cross-host cluster

The first member generates the CA locally; joining hosts fetch it from the cluster automatically — no certificate files to copy:

# host A (10.0.0.1) — bootstrap
pg addon install etcd --name m1 --cluster prod \
  --advertise-host 10.0.0.1 --tls --auth --password '<password>'

# host B (10.0.0.2) — join over HTTPS; the CA is fetched automatically
pg addon install etcd --name m2 --cluster prod \
  --advertise-host 10.0.0.2 --join https://10.0.0.1:2379 \
  --tls --auth --password '<password>'
  • The --join scheme must match: https:// with --tls, http:// without.
  • When the remote cluster has auth enabled, --password (plus --root-user if not root) is required — the CA fetch itself authenticates with those credentials. Without them the join fails with an explicit error.
  • The CA fetch is trust-on-first-use: verification is skipped for that single exchange, then all subsequent traffic is verified against the fetched CA.

--join works on hosts with no local CA only when the cluster CA was generated by pgcli. With a manually distributed CA or BYO certificates, copy the CA to every host yourself (below).

Manual CA distribution (pg cert --ca)

Instead of letting the first member generate a CA, mint one with pg cert --ca and place it on every host before installing. The pair must live at <base_dir>/tls/etcd/<cluster>/ (<base_dir> defaults to ~/.pgcli):

# mint straight into the target directory (run this once, on any host)
mkdir -p ~/.pgcli/tls/etcd/prod
pg cert --ca --host localhost,127.0.0.1 \
  --cert-file ~/.pgcli/tls/etcd/prod/ca.crt \
  --key-file  ~/.pgcli/tls/etcd/prod/ca.key

# copy the pair to the same path on every other host
scp ~/.pgcli/tls/etcd/prod/ca.crt ~/.pgcli/tls/etcd/prod/ca.key \
  hostB:~/.pgcli/tls/etcd/prod/

The pair is read from that directory (the key kept at 0600) and reused as-is; each member then gets its own leaf signed by that CA. Use the same pair on every host, including the bootstrap host. This mode does not publish the CA into etcd — distribute it yourself.

A CA generated by a current pg cert --ca carries no extended key usage restriction, so it can sign both server and client certificates (raft peers present their certificate as a client cert). Older pgcli releases wrote a serverAuth-only CA; peer mTLS rejects those chains, and pgcli now refuses such a CA up front with a message to regenerate it.

Bring your own member certificate

--tls-cert / --tls-key use an externally issued leaf for this member (implies --tls); the optional --tls-ca is the CA clients verify against, defaulting to the leaf itself for a self-signed certificate. The leaf must carry the clientAuth EKU (or no EKU at all) because raft peers verify it as a client certificate. BYO material is never copied into etcd and the CA is not published — distribute both yourself.

What gets published, and the risk

In generated-certificate mode (plain --tls, no BYO pair) the first member writes the cluster CA pair into etcd itself, at /_pgcli/pki/etcd/ca.crt and /_pgcli/pki/etcd/ca.key, so other hosts can fetch it during --join:

  • Before --auth is enabled, anyone who can reach the client port can read the CA private key (it is published before auth is turned on, since the publish itself runs without credentials). With --auth, reading it requires the credentials.
  • Anyone holding that key can mint certificates this cluster trusts. Keep client ports on a private network and firewall 2379, or avoid publication entirely by distributing a pg cert --ca CA or BYO certificates manually.

The install summary prints this warning whenever a generated CA is published.

Consumers that are not compatible

Patroni’s DCS configuration and RabbitMQ’s etcd peer discovery still dial plain HTTP without credentials. Enabling --tls or --auth on a cluster they consume disconnects them. When pgcli finds such a consumer in the local config (a Patroni cluster whose etcd members/endpoints match this member, or a RabbitMQ instance using it for discovery), the install prints a [!] warning. Keep such etcd clusters plaintext and network-isolated until those integrations support TLS/auth.

Changing TLS/auth later

TLS is fixed for the life of a member: its advertised peer URL scheme is part of the cluster’s membership record. Switching an initialized member, or mixing TLS and non-TLS members in one cluster, is rejected — destroy and re-create the cluster instead:

pg addon remove etcd --name m1 --clean-data

Authentication is also cluster-wide. To enable it on an existing plaintext cluster, re-install the bootstrap member with --auth --password ... first, then re-install every other member with --auth so each records the credentials (same-host peers inherit them; cross-host members must pass --password). Disabling auth again requires re-creating the cluster.

Inspecting authentication

Authentication status and users/roles can be queried directly:

pg etcdctl auth status      # Authentication Status and AuthRevision
pg etcdctl user list        # cluster users (--auth creates only root)
pg etcdctl user get root    # roles of the root user
pg etcdctl role list        # roles
pg etcdctl role get root    # permissions of the root role

View the password (only present when Auth: true; it is stored in pg.yaml and can only be read on a host that has the member configured):

pg addon password etcd --name m1

pg addon list also shows Auth: enabled / Auth: disabled per member. This version has no multi-user/RBAC management commands; etcd’s native commands can be passed through pg etcdctl.

Commands

Create the first member

pg addon install etcd --name m1
-> Bootstrapping etcd cluster...
  [OK] etcd container started

✓ etcd installed: "m1"
  Container:    pgcli-etcd-m1
  Cluster:      pgcli-etcd
  Data dir:     ~/.pgcli/addon/etcd/m1/data
  Client port:  2379
  Peer port:    2380
  Advertise:    127.0.0.1

  Client URL: http://127.0.0.1:2379
  Connect (etcdctl): ETCDCTL_ENDPOINTS=http://127.0.0.1:2379

The client port starts at 2379 and the peer port takes the next free port (2380), auto-allocated from etcd_start_port.

Add members to the same cluster

With m1 running, installing another member of the same --cluster joins it:

pg addon install etcd --name m2
pg addon install etcd --name m3

pgcli finds a running peer to act as coordinator, registers m2/m3 via etcdctl member add, and starts them with --initial-cluster-state existing. Ports continue to auto-assign without collisions (m2 → 2381/2382, m3 → 2383/2384). A freshly-grown cluster briefly lacks quorum during leader re-election; pgcli retries the membership operations automatically, so you do not need to wait between installs.

Use a different --cluster to keep members in a separate etcd cluster.

Join a member on another machine

Members on different hosts form one cluster too. Each cross-host member must advertise an address the other members can reach, set with --advertise-host. On the machine that already hosts a member, bootstrap as usual, passing its LAN address:

# host A (10.0.0.1)
pg addon install etcd --name m1 --cluster prod \
  --advertise-host 10.0.0.1 --client-port 2379 --peer-port 2380

Then on the new host, point --join at any existing member’s client endpoint. pgcli registers the member through that endpoint (from a temporary etcdctl container — no local member container or image needed; the image is pulled on demand), takes the authoritative ETCD_INITIAL_CLUSTER from the response, and starts the member:

# host B (10.0.0.2)
pg addon install etcd --name m2 --cluster prod \
  --advertise-host 10.0.0.2 --client-port 2379 --peer-port 2380 \
  --join http://10.0.0.1:2379
-> Registering member with the cluster at http://10.0.0.1:2379...
-> Starting etcd container (joining cluster)...
  [OK] etcd container started

Notes for cross-host clusters:

  • Every member needs a reachable --advertise-host — including the first. Its advertised peer URL propagates into the cluster’s membership list, so a first member started on the default 127.0.0.1 can never be joined from another host. If you plan a cross-host cluster, pass the LAN address at bootstrap time.
  • --cluster is required with --join and must match the remote cluster’s token — membership is checked by that cluster, not by the local config.
  • --advertise-host is required with --join; without it the other members could register a peer URL they can’t dial.
  • Ports may repeat across hosts (2379/2380 on both) since each host binds its own interfaces.
  • A member’s client/peer ports must be reachable between hosts — open your firewall for every member’s ports, in both directions. Peers dial each other’s peer ports bidirectionally, and clients (and --join/pg etcdctl) reach the client ports, so allow both. Auto-assignment means the exact numbers vary per member — read them from the install summary or pg addon list (or pin them with --client-port/--peer-port) and open that range, e.g. 2379-2386/tcp for a 4-member cluster on default ports. Skipping this is the usual cause of a member hanging with etcdserver: no leader or a --join that times out.
  • Re-running the same --join install for an already-registered name fails with a clear error; deregister first via pg etcdctl member remove <hex-id> against the cluster.

Inspect with pg etcdctl

pg etcdctl runs etcd’s client from a short-lived container — no need to exec into a member (and it works even on a host with no member installed, pulling the image on demand). The target comes from ETCDCTL_ENDPOINTS, falling back to the first configured member:

export ETCDCTL_ENDPOINTS=http://10.0.0.2:2379
pg etcdctl member list
pg etcdctl endpoint health
pg etcdctl endpoint status -- -w table

etcdctl flags that pg’s own parser would reject (-w table, --hex, …) go after --.

List

pg addon list

etcd members appear under the Infra add-ons (etcd) section:

Infra add-ons (etcd):
  etcd (name: m1)
    Status:      running
    Cluster:     pgcli-etcd
    Client URL:  http://127.0.0.1:2379
    TLS:         off
    Auth:        off
    Client port: 2379
    Peer port:   2380
    Image:       quay.io/coreos/etcd:v3.5.30
    Container:   pgcli-etcd-m1

A TLS-enabled member also prints a CA: line with the cluster CA path used for client verification (ready to use with pg etcdctl --ca on a non-member host).

Start and stop

After a host reboot or a manual stop, bring a member back up without re-running install — no member add, the existing config and on-disk data are reused:

pg addon start etcd --name m1
pg addon stop etcd --name m1

start is safe to repeat: an already-running member is a no-op, and a member whose container was removed is recreated from its data with --initial-cluster-state existing. For a cross-host cluster, confirm the member’s peers are reachable (quorum intact) before starting it.

Remove a member

pg addon remove etcd --name m2

Removal first deregisters the member from the cluster (resolving its hex member ID — etcd v3.5 member remove takes an ID, not a name), then deletes the container and the member’s data directory. Remaining members stay healthy as long as quorum holds.

Cross-host members must be deregistered separately. The automatic deregistration above only works when another running member of the same cluster is present in the local pg.yaml — pgcli has no view of members that live on other hosts. So on a cross-host cluster, removing a member from the host that runs it deletes the container and data but leaves its entry in the cluster’s membership list (a “stale” member) — the surviving members keep trying to peer with the now-deleted host.

Remove it in two steps instead:

# 1. on the host that runs the member — stop and clean up local state
pg addon remove etcd --name m4

# 2. from any surviving host's member, deregister it from the cluster
export ETCDCTL_ENDPOINTS=http://10.0.0.1:2379   # a surviving member's client URL
pg etcdctl member list                            # find m4's hex ID
pg etcdctl member remove <hex-id>                 # e.g. 5c7048c8f7521ec7

pg etcdctl needs a reachable peer to talk to — point ETCDCTL_ENDPOINTS at a member of that cluster that is still running (on a host that still has a running member, this falls back automatically; otherwise set it explicitly), then remove by ID (see Inspect with pg etcdctl). Verify with pg etcdctl member list afterward: the removed name should be gone.

Parameters

Flag Description Default
--name Member name, and the pg.yaml config key etcd
--cluster Cluster identity (--initial-cluster-token); same value = same cluster pgcli-etcd
--client-port Client host port (0 = auto-assign from etcd_start_port) auto
--peer-port Peer host port (0 = auto-assign, next free port) auto
--image etcd image tag quay.io/coreos/etcd:v3.5.30
--data-dir Data dir root — absolute, or relative to base_dir; each member uses <root>/<name>/data <base_dir>/addon/etcd
--advertise-host Host advertised in this member’s peer/client URLs (empty = 127.0.0.1 for single-host; set a LAN IP or FQDN for cross-host) 127.0.0.1
--join Client endpoint of an existing member to join cross-host, e.g. https://10.0.0.1:2379 (implies --initial-cluster-state existing; requires --advertise-host and --cluster; scheme must match --tls) —
--tls TLS on both interfaces — client HTTPS and raft peer mTLS; certificates generated under <base_dir>/tls/etcd/<cluster>/ off
--tls-cert / --tls-key Bring-your-own member certificate and key (implies --tls; the leaf needs the clientAuth EKU or no EKU) —
--tls-ca CA clients verify against with --tls-cert/--tls-key (defaults to the certificate itself) —
--auth Enable username/password authentication with a single root-role user off
--root-user Authentication user name (implies --auth) root
--password Authentication password (implies --auth); generated on first install when omitted generated

Container name follows the namespace convention: pgcli-etcd-<namespace>-<name> (namespace omitted when unset).

Data Directory Layout

Data is always laid out as <root>/<name>/data, so multiple members on one host never share a directory:

<base_dir>/addon/etcd/
├── m1/data/     # member m1
├── m2/data/     # member m2
└── m3/data/     # member m3

--data-dir sets the root. A relative value resolves against the config’s base_dir; the resolved root is persisted, so the config stays portable:

# base_dir: /data/pgcli  →  root /data/pgcli/etcd, member d1 → /data/pgcli/etcd/d1/data
pg addon install etcd --name d1 --data-dir ./etcd

# absolute root
pg addon install etcd --name d2 --data-dir /mnt/ssd/etcd

pg addon remove deletes only that member’s <name>/data dir and leaves the shared root in place.

Connecting

Use pg etcdctl, which runs etcd’s v3 client from a short-lived container against a member’s client URL. No local member container or image is required (the image is pulled on demand). etcdctl’s native flags go after --.

From a member host (bootstrap or joined node)

Whenever the local pg.yaml configures any member of the cluster — whether it is the bootstrap member or one that joined later — pg etcdctl injects that member’s CA (ETCDCTL_CACERT) and credentials (ETCDCTL_USER; the password stays out of ps) automatically, with no extra flags:

pg etcdctl endpoint health
pg etcdctl member list
pg etcdctl put foo bar
pg etcdctl endpoint status -- -w table

Without ETCDCTL_ENDPOINTS the target falls back to the first locally configured member. To query another member of the same cluster, set it explicitly — the injected CA/credentials come from the local member, but every member shares the same cluster CA and auth user, so they work too:

ETCDCTL_ENDPOINTS=https://10.0.0.2:2379 pg etcdctl member list

Retrieve the password with pg addon password etcd --name m1 on any host that has the member configured.

From a non-member host

On a host with no configured etcd member — for example a third machine used only as a client — pg etcdctl injects nothing. Provide the endpoint, CA and credentials explicitly:

  1. Look up the node’s CA path in the CA: line of pg addon list on any member host, then copy that file to the client host (generated mode: ~/.pgcli/tls/etcd/<cluster>/ca.crt; for manual/BYO setups use your own CA):

    # Show the node's CA path on a member host
    ssh member-host 'pg addon list' | grep "CA:"
    
    # Copy the path shown above (generated-mode example)
    scp member-host:/root/.pgcli/tls/etcd/pgcli-etcd/ca.crt /tmp/etcd-ca.crt
  2. Point at a member’s client URL, pass the host CA with --ca (pg mounts it into the etcdctl container), and the credentials via --user after --:

    ETCDCTL_ENDPOINTS=https://10.0.0.1:2379 pg etcdctl \
      --ca /tmp/etcd-ca.crt endpoint health -- --user root:<password>

    The password is available from pg addon password etcd --name m1 on a member host.

An etcdctl --cacert passed after -- refers to a path inside the helper container, so a host path there does not work (use --ca instead). For a quick check without the CA, skip verification — etcdctl only honors skip-verify once it builds a TLS config, so disable its default plaintext transport too:

ETCDCTL_ENDPOINTS=https://10.0.0.1:2379 pg etcdctl \
  member list -- --insecure-transport=false --insecure-skip-tls-verify

A non-member host must be able to reach a member’s client port (allow it through the firewall, e.g. 2379/tcp).

Topology & Quorum

etcd requires a quorum (majority) of members to accept writes:

Members Quorum Tolerates failures
1 1 0
3 2 1
5 3 2
  • Use an odd number of members — 3 or 5 for production HA.
  • Removing members can drop the cluster below quorum (e.g. 3 → 1 surviving); it will then be unable to commit writes. Keep a majority running.

Configuration

After install, pg.yaml records each member under the top-level addons.etcd:

addons:
  etcd:
    m1:
      container_name: pgcli-etcd-m1
      name: m1
      cluster_name: pgcli-etcd
      image_tag: quay.io/coreos/etcd:v3.5.30
      data_dir: /home/user/.pgcli/addon/etcd
      client_port: 2379
      peer_port: 2380
      autostart: true
    m2:
      container_name: pgcli-etcd-m2
      name: m2
      cluster_name: pgcli-etcd
      client_port: 2381
      peer_port: 2382

Port base is configurable via top-level etcd_start_port (default 2379). A cross-host member records the address it advertises:

addons:
  etcd:
    m1:
      name: m1
      cluster_name: prod
      advertise_host: 10.0.0.1
      client_port: 2379
      peer_port: 2380

A TLS/authenticated member records the cluster-wide settings too:

addons:
  etcd:
    m1:
      name: m1
      cluster_name: prod
      advertise_host: 10.0.0.1
      client_port: 2379
      peer_port: 2380
      tls: true
      auth: true
      auth_user: root
      auth_password: example-password

auth_password is stored in clear text (like other addon secrets) and is what pg addon password etcd --name m1 reads back. A BYO member additionally records tls_cert_file, tls_key_file and tls_ca_file; in generated- certificate mode those stay empty and the paths are derived from the cluster name under <base_dir>/tls/etcd/<cluster>/.

Auto-start on Boot

Containers also carry a --restart unless-stopped policy, which a per-container conmon monitor enforces even without a podman daemon — it covers crashes but not host reboots. To bring members up after a reboot, enable autostart per member:

pg autostart enable --etcd --name m1
pg autostart enable --etcd --name m2
pg autostart enable --etcd --name m3

This sets autostart: true on the member in pg.yaml and installs/refreshes the boot service (see Auto-start on Boot). Boot is start-only: it starts the member’s existing container and never re-runs member add — an initialized member reloads its cluster from disk and rejoins. On a cross-host cluster, run the command on each host for that host’s member(s). pg autostart status lists every member’s state.

Notes

  • Single-node vs cluster: --name m1 alone gives a one-member cluster; install more members with the same --cluster to grow it.
  • Production-ready defaults: every member already launches with periodic compaction and an 8 GiB backend quota (see How It Works), suitable for a production DCS without further tuning.
  • Reinstall is idempotent: re-running pg addon install etcd --name <m> on a running member recreates its container with updated flags; a member already registered in the cluster is not re-added.
  • TLS/auth are bootstrap decisions: start cross-host clusters with --tls --auth from the first member; an initialized member cannot switch schemes without being destroyed and re-created.
  • Manual and BYO certificates stay out of etcd: only a CA that pgcli generated is published for --join to fetch — distribute manual or BYO material yourself.

3 - PgDog

Run PgDog — a Postgres proxy for connection pooling, load balancing and sharding — as a pgcli addon

PgDog is a high-performance Postgres proxy written in Rust (the successor to PgCat). It provides connection pooling, read/write load balancing across replicas, and horizontal sharding — in front of one or more PostgreSQL backends. pgcli can run PgDog as a standalone, top-level addon: shared infrastructure rather than a per-instance sidecar.

Security caveat: PgDog authenticates clients against plaintext passwords stored in users.toml. pgcli writes that file mode 0600 and mounts it read-only into the container, but the passwords still sit in clear text on disk and in pg.yaml. Keep the listen port on loopback (the default) or inside a trusted network, and treat the config file as a secret.

PgDog is configured with two TOML files — pgdog.toml (the proxy, its backends, and sharding rules) and users.toml (the client credentials). pgcli generates both entirely from the install flags: there is no config file to hand-edit, so pg addon install pgdog is the source of truth and is idempotent — re-running it re-renders the files from the flags given.

Platform support

PgDog runs on Linux (host networking) and on macOS for single-host dev/test, joining the same pgcli-net bridge a PG instance uses under podman machine and publishing its client + openmetrics ports. On macOS:

  • The listen bind is widened to 0.0.0.0 inside the container so the published port is reachable (a loopback-only bind can’t be forwarded to); the client address you connect to is still 127.0.0.1:<port>.
  • Backends must be reachable from the bridge. PgDog has no automatic name-resolution for --backend, so a 127.0.0.1 backend would point at the Mac, not the podman machine VM. Give each --backend either the target instance’s container name (run pg status -i <instance> and read the Container: line, e.g. app=pgcli-pg-mypg:5432:...) or an address the Mac can route to — never 127.0.0.1 for a managed instance.

How It Works

  • Shared infrastructure: PgDog lives in the top-level addons.pgdog map in pg.yaml, keyed by proxy name — not under any single instance.
  • Host network (Linux) / bridge (macOS): the proxy listens on its client port (auto-assigned from pgdog_start_port, default 7432) plus a Prometheus-style openmetrics port on the next free number. On Linux it runs with --network host; on macOS it joins pgcli-net and publishes both ports.
  • Generated config: pgdog.toml + users.toml are written under <base-dir>/addon/pgdog/<name>/ and bind-mounted into the container at /pgdog.
  • Image pinned: ghcr.io/pgdogdev/pgdog:v0.1.57 by default; override with --image.

Install

A minimal single-backend proxy (pooling only — see the note below):

pg addon install pgdog \
  --backend "app=127.0.0.1:35432:default_db" \
  --user "appuser:secret:app" \
  --sharded-table "app:users:id:bigint"

Declare a --sharded-table so the example is a complete, self-consistent config (it mirrors the sharding example below). Be aware that with a single --backend there is nothing to shard across — every row lands on that one backend regardless of the declaration, so this minimal example only demonstrates connection pooling. For real sharding you need two or more --backends with distinct shard numbers (see Sharding and replicas).

  • --backend NAME=HOST:PORT:DBNAME[:SHARD[:ROLE]] — one [[databases]] entry. NAME is the logical database clients connect to; DBNAME is the real database on the backend. SHARD defaults to 0; ROLE to PgDog’s default (primary, or set replica for read routing). Repeatable.
  • --user NAME:PASSWORD[:DBNAME] — one [[users]] entry. The DBNAME is the logical database (a --backend name) the user may reach; it defaults to the first backend’s name. Repeatable.
  • At least one --backend and one --user are required.

Other flags:

Flag Meaning Default
--name proxy / addon key pgdog
--port client host port (openmetrics takes the next free) auto-assign
--host listen address 127.0.0.1
--pool-mode transaction or session transaction
--workers worker threads 2
--default-pool-size server connections per user/db pair 10
--image PgDog image tag ghcr.io/pgdogdev/pgdog:v0.1.57

Sharding and replicas

Repeat --backend across shards and roles, and declare the shard key with --sharded-table DBNAME:TABLE:COLUMN:DATA_TYPE:

pg addon install pgdog \
  --backend "app=10.0.0.1:5432:shard0:0" \
  --backend "app=10.0.0.2:5432:shard1:1" \
  --backend "app=10.0.0.1:5433:shard0:0:replica" \
  --backend "app=10.0.0.2:5433:shard1:1:replica" \
  --user "appuser:secret:app" \
  --sharded-table "app:users:id:bigint"

This puts two shards (each with a primary + replica) behind the logical database app and routes the users table by its id column.

Provisioning the backends

PgDog routes to databases, tables, and roles that must already exist on the backends — installing the proxy does not create them. For a local pgcli instance, use pg exec to create each shard database, its sharded table, and the login role. With the default instance on a single host (shards as separate databases on one port), the example below provisions the backends (steps 1–4), installs the proxy (step 5), and writes through it to show the routing (steps 6–7):

# 1. create the shard databases
pg exec -i default -- psql -U admin -d default_db -c "CREATE DATABASE shard0;"
pg exec -i default -- psql -U admin -d default_db -c "CREATE DATABASE shard1;"

# 2. create the sharded table (same schema) in each shard
for db in shard0 shard1; do
  pg exec -i default -- psql -U admin -d "$db" \
    -c "CREATE TABLE users (id bigint PRIMARY KEY, name text, email text);"
done

# 3. create the login role PgDog uses to reach the backends — its name must
#    match a --user, and its password must match that user's users.toml entry
pg exec -i default -- psql -U admin -d default_db \
  -c "CREATE ROLE appuser LOGIN PASSWORD 'secret';"

# 4. grant that role access to the sharded table in every shard
for db in shard0 shard1; do
  pg exec -i default -- psql -U admin -d "$db" \
    -c "GRANT SELECT, INSERT, UPDATE, DELETE ON TABLE users TO appuser;"
done

# 5. install the proxy over both shards (see "Sharding and replicas" above)
pg addon install pgdog \
  --backend "app=127.0.0.1:35432:shard0:0" \
  --backend "app=127.0.0.1:35432:shard1:1" \
  --user "appuser:secret:app" \
  --sharded-table "app:users:id:bigint"

# 6. write rows through the proxy with pgcli (pg exec --dsn), ONE row per
#    statement so PgDog routes each by its id (a multi-row INSERT is broadcast
#    to every shard instead)
for id in 1 2 3 4 5 6; do
  pg exec --dsn "postgres://appuser:secret@127.0.0.1:7432/app" \
    "INSERT INTO users (id, name, email) VALUES ($id, 'n$id', 'e$id@x');"
done

# 7. read each shard directly to confirm the rows landed where PgDog routed
#    them — pg psql -- -d <db> targets one database
pg psql -i default -- -d shard0 -tAc "SELECT id, name FROM users ORDER BY id;"
pg psql -i default -- -d shard1 -tAc "SELECT id, name FROM users ORDER BY id;"

pg exec -i default -- psql -d <db> runs a command against a specific database in the named instance’s container. The id bigint column matches the --sharded-table "app:users:id:bigint" declaration above, so PgDog can route users rows by id. Steps 6–7 make that routing visible: the two shard queries return different, non-overlapping subsets of the ids you inserted (the exact split depends on PgDog’s hash), and together they account for every row — no row lands in both shards. For remote backends, run the equivalent SQL against each host directly.

The backend role is not optional. By default PgDog authenticates to the backends using the client’s --user name and its users.toml password. So every backend must have a login role named appuser (etc.), or connections fail with password for user "..." is wrong, or the database does not exist, even on a loopback trust setup where the password is ignored but the role must still exist. Under password auth (the default for non-loopback scram-sha-256), the users.toml password must match the role’s.

Decoupling client and backend users. PgDog itself supports connecting to the backends with a different user than the client uses: a [[users]] entry can carry server_user / server_password, and a [[databases]] entry can carry user / password (which take priority). pgcli’s install flags do not currently emit these fields, so through pg addon install pgdog the backend role name is always the --user name. If you need a shared backend role (a common postgres superuser, or a name that differs from every client user), hand-edit the generated users.toml/pgdog.toml and restart the container — but note a re-install regenerates both files from the flags and will discard those edits.

Connecting

The install summary prints the endpoint. Clients connect through the proxy’s client port, using the logical database name and a --user credential — with pgcli, that’s a --dsn pointing at the proxy:

# interactive psql through the proxy
pg psql --dsn "postgres://appuser:secret@127.0.0.1:7432/app"

# one-shot SQL
pg exec --dsn "postgres://appuser:secret@127.0.0.1:7432/app" "SELECT version();"

Prometheus metrics are served on the openmetrics port:

curl -s http://127.0.0.1:7433/metrics

Writing to shards

How a write lands on the shards depends on the form of the statement. Observed with PgDog v0.1.57:

Single-row INSERT — routed by the shard key. One VALUES tuple per statement; PgDog hashes the id and sends that row to exactly one shard:

pg exec --dsn "postgres://appuser:secret@127.0.0.1:7432/app" \
  "INSERT INTO users (id, name, email) VALUES (4, 'n4', 'e4@x');"

Inserting ids 1–6 as six single-row statements split them across the two shards (in one run: shard0 got 1,2, shard1 got 3,4,5,6 — the exact split is PgDog’s hash, not something to rely on). No row lands in both shards.

Multi-row INSERT — broadcast, not split. A single statement carrying several VALUES tuples is sent verbatim to every shard, so each shard ends up with every row:

pg exec --dsn "postgres://appuser:secret@127.0.0.1:7432/app" \
  "INSERT INTO users (id, name, email) VALUES (1,'a','a@x'),(2,'b','b@x'),(3,'c','c@x'),(4,'d','d@x');"

This reported INSERT 0 8 — 4 rows in each shard. The per-shard PRIMARY KEY still holds (the duplicate ids live in different shards, never colliding), and there is no error or warning: every shard silently grows a full copy of the batch. Reads through the proxy will then see each id multiple times.

Bulk-loading correctly: loop one statement per row through the proxy (each routed individually), or skip the proxy and run the load against each shard directly (COPY via pg exec -i <inst> -- psql -d <shard>).

Configuration

After install, pg.yaml records each proxy under the top-level addons.pgdog:

addons:
  pgdog:
    pgdog:
      container_name: pgcli-pgdog-pgdog
      name: pgdog
      image_tag: ghcr.io/pgdogdev/pgdog:v0.1.57
      host: 127.0.0.1
      host_port: 7432
      openmetrics_port: 7433
      pooler_mode: transaction
      workers: 2
      default_pool_size: 10
      backends:
        - name: app
          host: 127.0.0.1
          port: 35432
          database_name: default_db
          shard: 0
      users:
        - name: appuser
          password: secret
          database: app
      autostart: false

Port base is configurable via the top-level pgdog_start_port (default 7432); the openmetrics port is always allocated just above it.

List

pg addon list

Every PgDog proxy appears under the Infra add-ons (pgdog) section with its runtime status, ports, backend/user counts, image, and container name:

Infra add-ons (pgdog):
  pgdog (name: pgdog)
    Status:      running
    Listen:      127.0.0.1:7432
    Client port: 7432
    Metrics:     http://127.0.0.1:7433/metrics
    Pool mode:   transaction
    Backends:    2
    Users:       1
    Image:       ghcr.io/pgdogdev/pgdog:v0.1.57
    Container:   pgcli-pgdog-pgdog

Backends / Users are the counts from pgdog.toml / users.toml; Status reflects the live container (a stopped proxy shows stopped).

Start and stop

After a reboot or a manual stop, bring the proxy up without re-running install (config and users are untouched):

pg addon start pgdog            # default name "pgdog"
pg addon start pgdog --name proxy
pg addon stop pgdog --name proxy

start is idempotent — a running proxy is left alone; a proxy whose container was removed is recreated from its config directory.

Auto-start on Boot

Containers carry a --restart unless-stopped policy (crashes, not reboots). To bring a proxy up after a host reboot:

pg autostart enable --pgdog --name pgdog

This sets autostart: true and installs/refreshes the boot service (see Auto-start on Boot). Boot is start-only: it starts the existing container reading the pgdog.toml/users.toml already on disk, and never re-generates config or auth. Install the proxy first. pg autostart status lists every target’s state.

Logs

pg logs addon pgdog --name pgdog       # last 50 lines
pg logs addon pgdog --name pgdog -f    # follow

PgDog logs connection-pool events (new server connections, auth, client connect/disconnect) as structured INFO lines. A repeatedly failing pool with password for user "..." is wrong, or the database does not exist means step 3 or 4 above was skipped — the backend has no such login role, or its password does not match users.toml.

Notes

  • Reinstall is idempotent: re-running pg addon install pgdog --name <p> re-renders the config from the given flags and recreates the container. The backend/user/shard lists are fully replaced by this command’s flags — an omitted --backend is removed, not kept.
  • Plaintext credentials: passwords live in users.toml and pg.yaml. Prefer a dedicated low-privilege role for proxy users and restrict network access to the client port.
  • Write forms differ: single-row INSERT is routed by the shard key; a multi-row INSERT VALUES is broadcast to every shard. See Writing to shards.
  • Not a per-instance sidecar: unlike PgBouncer, PgDog frontends backends by address in --backend — it does not have to point at a pgcli-managed instance, and one proxy can span many databases/shards.

4 - Garage

Run Garage (the Rust S3-compatible object store from Deuxfleurs) as a pgcli addon — single-node or multi-node cross-host cluster, plaintext HTTP, TLS terminated by fronting it with the nginx addon

Garage is a Rust, AGPLv3 reimplementation of S3-compatible object storage, built by Deuxfleurs for small self-hosted and geo-distributed clusters. pgcli runs it as a standalone, top-level addon with the same CLI surface as minio, silo and rustfs (install, list, logs, autostart, password), but its runtime model diverges from all three in four ways that shape this page:

  1. A rendered TOML config file, not argv/env. Garage reads /etc/garage.toml. pgcli renders it under the instance directory and bind-mounts it read-only; the MinIO/silo/rustfs addons pass argv or env.
  2. Two kinds of directory — and multi-disk is native since Garage v0.9.0. metadata_dir (LMDB) and data_dir (blocks) are separate bind mounts, and metadata_dir is always exactly one. data_dir takes either a single path or, natively upstream, a list of { path = …, capacity = … } entries — one per disk, so a node spreads its blocks across several drives itself rather than needing host LVM/RAID under one big filesystem. pgcli exposes that list as --drive (repeatable); MinIO, silo, rustfs, seaweedfs and garage all take a per-node drive list now — see Multi-disk data dirs and Capacity and sizing.
  3. Four ports, from their own pool. S3 API, node-to-node RPC, the s3_web static site, and the admin/metrics API — allocated together per instance from garage_start_port (default 3900), a separate cursor from the shared minio/silo/rustfs pool.
  4. No native TLS — plaintext HTTP only. pgBackRest’s S3 repository forces HTTPS, so a Garage store meant to receive archive-push must be fronted by the nginx addon — see TLS by fronting with nginx.

Like rustfs, Garage is a good successor route now that the open-source MinIO repository is archived. pgcli runs it single-node by default (replication_factor = 1, garage server --single-node) and, with a handful of cluster flags, as a multi-node cross-host cluster — see Multi-node cluster.

Platform support: tested on Linux (host networking). The macOS bridge path publishes all four ports and is code-complete, following the same shape as the other object stores, but has not been exercised on a Mac yet.

How It Works

One container per instance. pgcli pulls the upstream docker.io/dxflrs/garage image directly (pull-only) — unlike rustfs there is no wrapper image to build, because Garage runs as root inside its own container and ships no uid-drop, so there is no host-side ownership dance to absorb.

The data lives in bind-mounted host directories that outlive the container:

  • <base-dir>/addon/garage/<name>/data → /var/lib/garage/data (blocks),
  • <base-dir>/addon/garage/<name>/meta → /var/lib/garage/meta (LMDB),

plus the rendered <base-dir>/addon/garage/<name>/garage.toml → /etc/garage.toml, mounted read-only (Garage never rewrites its own config). With --drive (multi-disk), the single data dir is replaced by one host dir per drive, each mounted at its own numbered container slot /var/lib/garage/data1..N — the meta dir and the rendered config stay exactly one apiece; see Multi-disk data dirs.

Credentials are handled like the other stores, but Garage’s are an access key / secret key pair rather than a root user / password:

  • root_user is the access key id, generated on first install with Garage’s own GK-prefixed shape (GK + 32 hex chars, what openssl rand -hex 16 yields in the quick-start), or supplied via --root-user.
  • root_password is the secret key, generated on first install (64 hex chars), or supplied via --root-password.
  • A third secret, rpc_secret (the cluster’s RPC signing key), is generated the same way and stored alongside. On a single-node instance it never surfaces in the CLI; on a cluster bootstrap it is printed once — together with the join command — for the operator to carry to the next host (pgcli never executes anything remotely).

All three land in pg.yaml (addons.garage.<name>.*) so a recreate is stable. On a single-node first boot the container is passed --single-node --default-bucket plus the GARAGE_DEFAULT_ACCESS_KEY / GARAGE_DEFAULT_SECRET_KEY / GARAGE_DEFAULT_BUCKET env, so Garage itself creates the access key and one bucket (named after the instance, owned by that key) — no post-install exec needed. The key and bucket live in metadata_dir, so they survive container recreation. A cluster member starts bare (no --single-node/--default-bucket, no GARAGE_DEFAULT_* env); its key and bucket are seeded explicitly by the install that completes quorum — see Multi-node cluster.

Install

# default instance name "garage", four ports from the garage pool, loopback bind
pg addon install garage

# a named instance with an explicit data directory
pg addon install garage --name store --data-dir /srv/garage

# spread this node's blocks over several disks (see Multi-disk data dirs below)
pg addon install garage --name store --drive /mnt/d1/garage --drive /mnt/d2/garage

# a fixed S3 API port (RPC/web/admin take the next three free ports)
pg addon install garage --name store --api-port 3900

# expose the store on the network instead of loopback only
pg addon install garage --name store --listen 0.0.0.0

# supply your own access key / secret key instead of generating them
#   Garage's own limits apply: access key >= 8 chars, secret key >= 16 chars
pg addon install garage --name store --root-user GK<...> --root-password <secret>

# join a cross-host cluster (see Multi-node cluster below)
pg addon install garage --name store --cluster c1 --advertise-host 10.0.0.11 \
  --zone z1 --capacity 15 --replication-factor 3 \
  [--peer <id@addr> --rpc-secret <64hex>]   # a joiner carries both

Supplying your own keys: these two flags only take effect on a single-node install — a cluster member never reads them, because its key comes from garage key create at the quorum-completing install. The values go to Garage verbatim and Garage is what enforces them: an access key id shorter than 8 characters, or a secret key shorter than 16, is rejected when the container first boots (Invalid default access key: … should be at least N characters long) — and because the container starts detached, install itself reports success while the node crash-loops behind --restart unless-stopped. Check podman logs (or just let pg mc alias set fail) if a custom-key install comes up unable to serve. The generated shapes (GK + 32 hex / 64 hex) clear both bounds with room; mc additionally requires an access key of [A-Za-z0-9], so stay alphanumeric.

The output reports endpoints and the seeded credentials:

✓ garage installed: "store"
  Container:     pgcli-garage-default-store
  Image:         docker.io/dxflrs/garage:v2.4.1
  Data:          ~/pg/addon/garage/store/data
  Metadata:      ~/pg/addon/garage/store/meta
  Config:        ~/pg/addon/garage/store/garage.toml
  S3 API:        http://127.0.0.1:3900
  RPC/Web/Admin: 3901/3902/3903

  Access key:    GK<generated>
  Secret key:    <generated>
  Bucket:        store (created on first boot, owned by the access key)

  NOTE: Garage serves plaintext HTTP only. pgBackRest requires HTTPS — front it
        with the nginx addon via --conf-file (template --upstream mode strips
        the port from Host and breaks S3 signing; see docs/addon/garage):
          backend 127.0.0.1:3900, listen ssl, proxy_set_header Host $http_host
  Try it:        pg mc alias set store http://127.0.0.1:3900 GK<...> <secret> && pg mc ls store

Re-running install against a live instance is a no-op: the container is not recreated (a stopped one is simply started, with a notice), the flags are merged into the stored config, and the existing credentials are kept. Pass --force to recreate the container so changed ports, listen address, or credentials take effect — without losing the data directories.

Bind address: the default 127.0.0.1 keeps the store local. --listen 0.0.0.0 (or the listen key in pg.yaml) exposes it on the network. Because Garage serves plaintext HTTP, anyone who can reach the port can sniff the credentials in transit — only bind it publicly behind a firewall, or in practice, in front of the nginx TLS front.

--tls is rejected for garage. Garage has no TLS listener to enable; passing --tls/--tls-cert/--tls-key errors out and points you at the nginx front rather than silently ignoring the flag.

TLS by fronting with nginx

Because pgcli does not couple the two addons, terminating TLS in front of a Garage store is an explicit two-step: install garage, then front it with nginx.

Use --conf-file, not the --upstream template. S3 requests are signed with SigV4 over the Host header including the port. The template mode forwards Host $host, which nginx renders without the port — Garage then re-derives a different canonical request and every write fails with Invalid signature (verified: pg mc mb through a template front is refused; through the --conf-file front below it round-trips). The custom config also lets you set client_max_body_size 0; (the 1 MiB nginx default otherwise rejects any real object upload) and long proxy timeouts.

pg addon install garage --name store

# front.conf — path-style S3 over TLS, host+port preserved for signing:
cat > front.conf <<'EOF'
worker_processes auto;
pid /tmp/nginx.pid;
events { worker_connections 1024; }
http {
    access_log /var/log/nginx/access.log;
    error_log  /var/log/nginx/error.log;
    server {
        listen 0.0.0.0:8081 ssl;          # 0.0.0.0 so remote clients can reach it; the HTTPS port pgcli assigned
        ssl_certificate     /etc/nginx/certs/public.crt;
        ssl_certificate_key /etc/nginx/certs/private.key;
        client_max_body_size 0;          # unlimited PUT
        proxy_read_timeout   3600s;
        proxy_send_timeout   3600s;
        location / {
            proxy_pass http://127.0.0.1:3900;   # the garage S3 API port
            proxy_set_header Host $http_host;   # keep the port — SigV4
            proxy_request_buffering off;
            proxy_http_version 1.1;
        }
    }
}
EOF

pg addon install nginx --name gtls --tls --conf-file front.conf --https-port 8081

--tls makes pgcli generate the self-signed CA + leaf (public.crt / private.key, mounted at /etc/nginx/certs) and stands up the HTTPS listener. Point S3 clients at https://<host>:8081 and hand consumers the front’s CA at <base-dir>/addon/nginx/gtls/tls/ca.crt.

Bind the front 0.0.0.0, leave Garage on loopback. The listen line above binds all interfaces so a remote host (e.g. a Patroni node pushing archives) can reach the TLS endpoint — TLS is terminated at nginx, so this is safe in a way that exposing Garage’s plaintext port is not. The proxy_pass still targets 127.0.0.1:<garage-api-port>: the nginx container runs on the host network, so the loopback Garage bind is reachable from it, and the plaintext leg never leaves the machine. For a front that should stay local, bind listen 127.0.0.1:<port> ssl; instead.

Why the listen and proxy_pass lines are pinned by hand. In --conf-file mode pgcli mounts your config verbatim, so the ports in it must match the ones the two addons were assigned — read the garage S3 API: port from its install output and the nginx HTTPS: port from pg addon list. (The $http_host and client_max_body_size lines are the two that a template front gets wrong for S3.)

Getting that CA onto a remote Patroni host without a manual scp is what pg backup fetch-ca is for — it dials the TLS front and pulls the root straight out of the handshake:

pg backup fetch-ca <front-host>:<https-port>
#   [OK] CA fetched from <front-host>:<https-port>
#        saved:    ~/.pgcli/backup/repo-ca/ca-<front-host>-<https-port>.crt
#        SHA-256:  c0f0…fe2e
pg backup setup --s3-ca-file ~/.pgcli/backup/repo-ca/ca-<front-host>-<https-port>.crt

The fetch is trust-on-first-use — compare the printed SHA-256 against the front host’s sha256sum ~/.pgcli/addon/nginx/gtls/tls/ca.crt before trusting it.

Fronting a cluster: one node, or the local nodes

A cluster does not need all members behind the front. S3 replication is the data layer’s job: a request to any member is complete, and that member replicates it to replication_factor nodes itself. So the single-node front above works for a cluster too — point proxy_pass at one member’s S3 port.

Front more members only to remove that member from the access single point of failure. Keep the upstream to the nodes reachable on the front’s host (typically the local site — see Geo-distributed topology), and let each site run its own front:

http {
    upstream garage_s3 {
        server 10.0.0.11:3904;   # member A, this site
        server 10.0.0.12:3900;   # member B, this site
        # no remote member: it stays a data replica, off the request path
    }
    server {
        listen 0.0.0.0:8081 ssl;
        ssl_certificate     /etc/nginx/certs/public.crt;
        ssl_certificate_key /etc/nginx/certs/private.key;
        client_max_body_size 0;
        proxy_read_timeout   3600s;
        proxy_send_timeout   3600s;
        location / {
            proxy_pass http://garage_s3;
            proxy_set_header Host $http_host;   # keep the port — SigV4
            proxy_request_buffering off;
            proxy_http_version 1.1;
        }
    }
}

Two constraints this raises that the single-backend example does not:

  • The members’ S3 API must leave loopback. Cluster mode only widens the RPC bind automatically; --listen still defaults to 127.0.0.1, so a remote front cannot reach another host’s member. Install the fronted members with --listen 0.0.0.0 (behind a firewall — the front is what speaks TLS), or accept that only same-host members are valid upstream entries.
  • Ports differ per host — same gotcha as the RPC port: each member’s S3 API port comes from its own install output / pg addon list (S3 URL:), not necessarily 3900.

This stays a --conf-file config: the --upstream template’s fault for S3 is unchanged — Host $host without the port breaks every SigV4 write, and there is no client_max_body_size 0 (see the note above). With several upstream servers the default round-robin is fine; add max_fails/fail_timeout to taste. (Verified on a 3-node cluster: pg mc round-trips through such a front, and stopping one upstream member leaves the front serving through the other.)

Wiring pgBackRest to a fronted Garage store

Once you have a TLS endpoint, a Garage-backed S3 repository is the same as a MinIO one — the S3 contract is identical (path-style, repo1-s3-uri-style=path):

pg backup setup \
  --s3-endpoint <front-host>:<https-port> \
  --s3-bucket store \
  --s3-access-key GK<...> \
  --s3-secret-key <secret> \
  --s3-ca-file <front>/addon/nginx/gtls/tls/ca.crt

See Backup → S3 object storage repository for the full flow. pg addon password garage --name store prints the secret key for scripting.

Multi-disk data dirs

A Garage node does not need one big filesystem under it. Since v0.9.0 Garage accepts a list of data directories and balances blocks across them itself; pgcli exposes that as a repeatable --drive:

pg addon install garage --name store \
  --drive /mnt/d1/garage --drive /mnt/d2/garage --drive /mnt/d3/garage

What that produces, verified on real disks (a 3-node cluster whose members each took two drives):

  • Each drive is bind-mounted at its own container slot — /var/lib/garage/data1, data2, … in --drive order — and the rendered garage.toml lists them as Garage’s array form:

    data_dir = [
      { path = "/var/lib/garage/data1", capacity = "4G" },
      { path = "/var/lib/garage/data2", capacity = "4G" },
    ]
  • The per-entry capacity is mandatory — v2.4 refuses to boot an entry that carries neither a capacity nor read_only = true (invalid data_dir config: data directories in data_dir should have a capacity value or be marked read_only). pgcli has no knob for it, so it fills in each drive’s own filesystem usable size in GiB (rounded down, floor 1) — which is what a “one dir per separately-mounted disk” layout wants, and is what makes Garage weight the spread toward the bigger disk. --capacity stays the node-level number, unchanged by this.

  • metadata_dir never joins the set — it stays the single meta dir beside the instance’s data path (LMDB is one directory by upstream design).

  • --drive and --data-dir are mutually exclusive: drives fully replace the resolved data dir. Re-running install without --drive on a multi-drive instance keeps the stored drives (they merge, like every other key).

  • A drive sitting on the host’s root device only warns and is used anyway (as with seaweedfs; MinIO/silo refuse and rustfs hard-requires a separate device) — multi-drive only buys something on separately-mounted disks.

  • pg addon list reports it as Drives: N (multi-disk data_dir) with one container-slot <- host-dir line each; the install summary prints the same mapping as Drive 1: … -> /var/lib/garage/data1 lines.

  • remove --clean-data goes through every drive dir (plus meta and the rendered config), each still refusing to delete a live mount point.

  • Blocks genuinely land on both dirs: a 48 MiB upload to a 2-drive node left data in both host directories, and a 64 MiB object round-tripped (sha256sum identical) through a 3-node rf = 3 cluster read from all three hosts. Stop/start preserves the objects; a recreated container reads the same drives.

The one thing this does not get you is drive-level redundancy on a lone node — see Capacity and sizing. Garage’s own rebalancing rules when you add a drive later (existing blocks are not reshuffled; a read-only entry drains opportunistically or via an explicit repair) are upstream Multi-HDD support territory: pgcli writes the config, Garage does the moving.

Multi-node cluster

Garage’s real strength is the cross-host cluster: nodes in different zones, CRDT-replicated layout, quorum reads/writes. pgcli drives this with the same pg addon install garage command — no new entry point — adding a handful of cluster flags. A cluster is assembled one host at a time (the Patroni model): pgcli never executes anything on a remote host. The first host bootstraps, prints a ready-made join command carrying the shared rpc_secret and this node’s id@addr, and you run that command (edited for the next host) yourself.

Roles

garageInstallRole picks the role from the flags you pass:

Role When What install does
single no --cluster the v1 path, byte-for-byte (--single-node --default-bucket)
bootstrap --cluster set, no --peer generates rpc_secret, starts a bare garage server, stages its own layout role, prints the join command
join --cluster + --peer <id@addr> carries --rpc-secret, connects to that peer, stages its own role, applies when it completes quorum

Three-host walkthrough

Host 1 — bootstrap. Give it a --zone, a --capacity, and the eventual --replication-factor. Because only one node exists so far, Garage refuses to apply the layout (it needs replication_factor nodes with positive capacity), and pgcli turns that into a warning, not an error — the staged role is cluster-replicated and survives until the last host applies it:

# on 10.0.0.11
pg addon install garage --name store --cluster c1 \
  --advertise-host 10.0.0.11 --zone z1 --capacity 15 --replication-factor 3

A cluster member is a Garage node like any other, so it can also take --drive for its own disks (see Multi-disk data dirs) — verified on a 3-host cluster where each member carried two drives.

The summary prints the secret and a copy-paste join template:

  Cluster:       c1 (role: bootstrapping cluster, replication factor 3)
  Advertise:     10.0.0.11:3905
  Zone/Capacity: z1 / 15 GiB
  Node ID:       1c0597cc…200aeb@10.0.0.11:3905
  [i] layout staged but not applied yet — Garage needs replication-factor assigned nodes to commit (later joins will).

  To add ANOTHER member, run on the next host (carrying --rpc-secret yourself;
  pgcli never executes remotely). --advertise-host is that host's own peer-
  reachable IP; pick a --zone per failure domain and keep --replication-factor:
    pg addon install garage --name store --cluster c1 \
      --advertise-host <next-host-ip> --rpc-secret <64hex> \
      --peer 1c0597cc…200aeb@10.0.0.11:3905 --zone <zone> --capacity <GiB> --replication-factor 3

Host 2 — join. Copy the printed command, change --advertise-host to this host’s IP and --zone to a distinct zone:

# on 10.0.0.12
pg addon install garage --name store --cluster c1 \
  --advertise-host 10.0.0.12 --rpc-secret <64hex> \
  --peer 1c0597cc…200aeb@10.0.0.11:3905 --zone z2 --capacity 15 --replication-factor 3

Two nodes are assigned now, still fewer than rf = 3, so it warns again. Peering is transitive: host 2 only needs one --peer (host 1); host 3 can point at either existing node.

Host 3 — the install that completes quorum. The third host sees the full staged role set (assign is cluster-replicated), so its layout apply commits version 1 — and this is the install that seeds the access key and bucket:

# on 10.0.0.14
pg addon install garage --name store --cluster c1 \
  --advertise-host 10.0.0.14 --rpc-secret <64hex> \
  --peer 5b370435…1c1c9187@10.0.0.12:3901 --zone z3 --capacity 15 --replication-factor 3
  Access key:    GKc57063…6147b0
  Secret key:    <printed once, here>
  Bucket:        store (cluster key + bucket seeded on this install)

Every install runs the seeding step idempotently, so the last host to join is naturally the one that seeds — no back-fill on host 1 needed. The key name is the instance name (store), the bucket too, and the key is granted read/write/ owner on it.

Seeding and the secret

In a cluster the single-node --default-bucket / GARAGE_DEFAULT_* fast path is unavailable, so pgcli seeds explicitly with key create + bucket create + bucket allow. Two consequences:

  • garage key create prints the secret exactly once and is not idempotent (a re-run mints a second key with the same name). pgcli checks key list first and only creates when absent. Whichever host performs the seeding writes the access/secret pair into its own pg.yaml; the other hosts hold only the public key id.
  • pg addon password garage on a non-seeding host has no secret to print and says so — the secret lives in the pg.yaml of the host whose install completed quorum. Reveal it there, or run garage key create yourself to mint a fresh key on any node.

Version conflicts and re-runs

layout apply --version N requires exactly current + 1 — Garage’s optimistic lock. If two hosts install concurrently, one apply fails; pgcli reports it as “layout changed concurrently — re-run the same install command”. assign is idempotent and re-staging is harmless, so the retry just re-reads the version and applies. A re-run against a live member is otherwise a no-op (container already running → skipping creation; peering already done → treated as success).

Zone and replication-factor advice

  • --replication-factor must be ≤ the number of nodes you will join; a cluster cannot seed until rf nodes hold a positive-capacity role.
  • Give each host a distinct --zone to survive whole-failure-domain loss; Garage keeps replica copies in different zones when it can.
  • --capacity is GiB and is what Garage carves out for blocks; a node with capacity 0 is treated as not-yet-data-bearing.
  • --advertise-host is required for every member — it becomes rpc_public_addr, the address peers dial. Without it a cluster member is unreachable. (A cluster member whose --listen is loopback still widens its RPC bind to 0.0.0.0; only the S3/web/admin ports stay on loopback.)

Capacity and sizing

Garage’s unit of redundancy is the node, not the drive — every block of a replicated object is placed on a different node (preferring a different zone), so no drive or node failure loses data as long as replication_factor copies survive. What a node does with its own disks is a separate axis, and Garage handles that natively: since v0.9.0 a node can be given several data directories and spreads its blocks across them proportionally to their declared capacities (see Multi-disk data dirs). MinIO and rustfs aggregate drives with erasure-coding inside a node and survive drive loss that way; Garage’s multi-drive mode is aggregation without redundancy — losing one of a node’s drives loses that node’s share of the blocks, and the object is then repaired from its copies on other nodes. If a store must survive a drive loss on a single node with no other nodes to repair from, put LVM/RAID under data_dir instead. MinIO/rustfs manage drives as a pool; Garage manages nodes, and uses drives only for spread.

--capacity is the number you hand that model: GiB this node may store (layout assign -c <N>GiB). Two properties worth internalising:

  • It is a placement weight, not a quota. Garage never refuses a write because capacity was reached — the real free space is what garage status reports as DataAvail. Setting --capacity 100 on a 20 GiB filesystem would just let Garage fill (and then break) the disk. Keep it at (or under) the usable size of the backing filesystem — in multi-drive mode, at the sum of the drives’ usable sizes.
  • Changing it is a layout change: re-run the same pg addon install line with the new --capacity (assign is idempotent, the apply bumps the layout version), and Garage rebalances blocks onto the enlarged space. Growing the backing filesystem first is what actually buys room.

Note there are two capacity numbers in a multi-drive node and they are not the same knob: --capacity is the node’s role in the cluster layout (how much this node is trusted to hold, shared across all its drives), while each data_dir entry’s capacity tells Garage how much that drive holds so it can weight the spread. pgcli fills the per-drive numbers automatically (see below); only the node-level --capacity is yours to choose.

Usable capacity is the sum of all node capacities divided by the replication factor — every object is kept in rf copies:

Nodes Per node (--capacity) rf Raw total Usable
3 15 GiB 3 45 GiB 15 GiB
4 15 GiB 3 60 GiB 20 GiB
5 15 GiB 3 75 GiB 25 GiB

General rule: usable = Σ capacity ÷ rf. The same math is why rf = 2 halves the storage overhead at the cost of surviving only one node loss; rf = 3 costs 3× but a write commits once 2 of 3 copies are acked, so a 3-node rf = 3 cluster tolerates 1 node down for writes, a 5-node one tolerates 2 (any 2 of the remaining members can ack). Adding a 4th or 5th node therefore buys both fault tolerance and usable space, unlike simply mirroring.

Quorum behaviour on a stopped node

Stop any one member and the other two keep serving reads and writes (2/3 quorum with rf = 3):

# on host 3
pg addon stop garage --name store
# on host 1 — still reads and writes
pg mc cat c1/store/v.txt

pg addon start rejoins the node under the same Node ID (the keypair lives in metadata_dir, not the container), and garage status shows it healthy again. Start/stop/remove/autostart/logs always manage only the local container — the Patroni semantic; there is no remote orchestration.

Geo-distributed topology: 2 local + 1 remote

The production shape Garage was designed for: two members in your own site (one per rack/zone, z1 + z2) and a third member in a remote site (z3). It fits the write-latency maths well: an rf = 3 write commits on a 2/3 quorum, so the two local replicas acknowledging is enough — the remote copy follows asynchronously and a slow (or briefly down) WAN link never slows a write. The nginx TLS front points at the two local members only (see Fronting a cluster); the remote member carries data, not request traffic, and typically runs its own front for local read repair / disaster use.

Two honest caveats about what the remote member is not:

  • It is a replica, not a backup. CRDT replication syncs everything, including deletions — a mistaken mc rb --force or a pgBackRest expire propagates to the remote site. For delete-immune copies you need Garage’s own bucket replication between separate clusters (a Garage CLI feature, manual here: garage bucket replication); the 2+1 cluster gives you node- and site-level survivability plus a manual rescue copy, nothing more.
  • A whole-site outage does not fail over automatically. If both local members die together, the lone remote node is below quorum (1 < 2) and the cluster is unwritable. The data is intact on it, and Garage documents a manual recovery (re-committing a reduced layout from surviving nodes), but pgcli does not orchestrate that — it is a garage layout operation for an operator who has decided the site is really gone.

So the accurate framing is: 2 local + 1 remote = HA with site-failure rescue, writes stay local-speed, and “backup” in the delete-immune sense remains pgBackRest’s (or replication’s) job.

Getting the cluster’s AK/SK

The seeded access key is cluster-wide (any member validates it), but its secret exists on exactly one host — whichever install completed quorum printed it once and stored it in that host’s pg.yaml:

# on the seeding host only:
pg addon password garage --name store              # print the secret key
pg addon password garage --name store --file ./ak  # mode 0600, for shipping
pg addon list --show-password                      # access key + secret together
  • Any host can show the public id (pg addon list → Access key:); on non-seeding hosts pg addon password errors and names the host that holds the secret — the message is precise, the secret is simply not there to give.

  • Lost secret, or want credentials of your own? Mint a fresh key on any member and grant it the bucket — keys are CRDT state, so the new pair works cluster-wide immediately:

    pg garage --name store key create app-key
    pg garage --name store bucket allow store \
      --key GK<new-id> --read --write --owner

    This is the recommended day-2 practice: applications and pgBackRest get their own keys (independent rotation/revocation), the seeded one stays the break-glass admin credential. pg garage is the general passthrough for Garage’s own control CLI — see Administering via pg garage.

v2.0 does not remove a node from the layout (layout remove + data migration), revert a committed layout, or orchestrate multi-zone failover. Those stay manual garage CLI operations — run them via pg garage.

Using the mc Client

pg mc runs MinIO’s own mc client from a throwaway container — no local install, no manual podman run — and speaks Garage’s S3 API like any other store. Use the access key in place of a user and the secret key in place of a password:

# pick the URL for your platform — see "Endpoints by platform" below:
pg mc alias set store http://127.0.0.1:3900 GK<...> <secret>       # Linux, local addon
pg mc alias set store http://host.containers.internal:3900 GK<...> <secret>  # macOS, local addon
pg mc alias set store http://10.0.5.7:3900 GK<...> <secret>        # either, remote store
pg mc mb store/backups
pg mc ls store                       # the seeded "store" bucket is already here
pg mc cp ./dump.pglz store/backups/

Aliases persist on the host at ~/.mc/config.json — mc’s own default path, the same on Linux and macOS — so alias set once and every later pg mc invocation (and a native mc on Linux) sees the same aliases. pg mc alias list reads them back and pg mc alias remove drops one. alias set validates the credentials against the endpoint before writing, so a wrong key leaves ~/.mc/config.json untouched. Under the hood pg mc mounts your ~/.mc into the container and runs ghcr.io/mars-base/pgcli/pgcli-mc (the static upstream binary on scratch); nothing else about it is magic.

Any mc flag that pg’s own flag parser would reject goes after --, exactly like the other stores — --recursive, --force, --all, --json and so on:

pg mc cp ./dir store/backups/ -- --recursive
pg mc rb store/scratch -- --force

Endpoints by platform: on Linux pg mc runs on the host network, so a 127.0.0.1 alias reaches a local addon instance directly. On macOS the container sits on the bridge network, where 127.0.0.1 is the container’s own loopback — point an alias at a local Mac addon via http://GK<...>:<secret>@host.containers.internal:3900, or at a remote store via its routable address. To go over TLS, set the alias to the nginx front’s https:// endpoint instead (and -- --insecure for a self-signed leaf).

Common commands

Command Purpose
pg mc ls store / pg mc ls store/backups list buckets / objects
pg mc mb store/backups create a bucket
pg mc cp ./file store/backups/ upload (for a tree: pg mc mirror ./dir store/backups/, or add -- --recursive to cp)
pg mc cp store/backups/file ./ download
pg mc find store -- --name '*.pglz' search objects by name
pg mc du store size per bucket
pg mc rm store/backups/file delete one object
pg mc rm store/prefix -- --recursive delete many objects
pg mc rb store/bucket -- --force remove a bucket, objects and all

The same access/secret key pair works for any S3 SDK — including pgBackRest against a repo1-type=s3 repository (through the nginx TLS front).

Administering via pg garage

pg garage forwards any Garage control-CLI subcommand into the instance’s running container — the replacement for hand-written podman exec pgcli-garage-<ns>-<name> /garage …. --name selects the instance (default: the first by name); everything after the subcommand word reaches /garage verbatim, so Garage’s own flags need no -- separator. It works the same on a single-node instance and on any cluster member; on a cluster, ask any running member — status, layout and keys are cluster-replicated CRDT state.

Any member answers any pg garage command — reads and writes. Every host runs its own garage node, and buckets, keys and the layout are CRDT state that does not belong to any one of them, so bucket create, key create, bucket allow, layout show — and their delete/deny counterparts — produce the same result whichever running member you point at, and the change is visible on all the others immediately. (Verified on a 3-node cluster: a bucket created on host 2 showed up in bucket list on hosts 1 and 3, and a delete issued from host 1 was gone from host 2’s list.) The one member-specific thing is secret retrieval: a seeded key’s secret exists only in the pg.yaml of the host that minted it, so pg addon password works there and errors elsewhere (see Getting the cluster’s AK/SK) — that is pgcli’s local-config boundary, not a garage limitation, and it does not stop you from minting new keys from any member.

Health and status

pg garage --name store health            # exit code 0 iff the cluster is healthy
pg garage --name store status            # per node: zone, capacity, DataAvail, version
pg garage --name store layout show       # committed roles + staged changes + layout version
pg garage --name store stats             # per-partition replication detail
curl -s http://127.0.0.1:3903/health     # the admin-port liveness line

health is the monitoring-friendly one: it prints a short summary (known / connected / storage nodes, partition quorum) and sets the exit code, so a cron or check script can use pg garage --name store health > /dev/null directly. status is the wide table — watch the DataAvail column, that is the real free space (see Capacity and sizing).

Keys and buckets

pg garage --name store key list                    # who can access the store
pg garage --name store key create app-key          # secret printed once
pg garage --name store bucket allow store --key GK... --read --write
pg garage --name store bucket deny  store --key GK... --write
pg garage --name store bucket list
pg garage --name store bucket info store           # size, object count, per-key grants
pg garage --name store key delete GK...            # revoke an app key

Mint-then-allow is the day-2 credential pattern: applications get their own key, the seeded one stays break-glass (see Getting the cluster’s AK/SK).

Creating a bucket is the same passthrough — bucket create names it and bucket allow then decides who can use it (a fresh bucket is reachable by no key until granted). Install-time seeding only makes the one bucket named after the instance; later buckets are yours to add here:

pg garage --name store bucket create backups        # global alias = "backups"
pg garage --name store bucket allow backups --key GK... --read --write --owner
pg garage --name store bucket list                  # shows the new "backups" alias
pg garage --name store bucket delete backups --yes  # --yes required; empty bucket only

The bucket’s global alias is its S3 name and is unique across the cluster; ask any running member — the create/delete works from any of them just the same (the any-member note at the top of this section).

Layout changes (cluster)

Adding a node is pg addon install (it assigns and applies automatically); the raw CLI is for auditing and the manual edge cases pgcli deliberately does not orchestrate:

pg garage --name store layout history              # which version when, by which node
pg garage --name store layout show                 # any STAGED ROLE CHANGES pending?
pg garage --name store node connect <id@addr>      # (re-)peer a node

layout remove, layout revert and multi-zone failover remain manual garage operations — the v2.0 limits blockquote at the end of Getting the cluster’s AK/SK lists them.

Maintenance

pg garage --name store bucket cleanup-incomplete-uploads   # abort stale multipart uploads
pg garage --name store key delete-expired                  # sweep expired keys
pg garage --name store bucket inspect-object store/key    # which nodes hold this object's blocks

Ports

Each instance takes four consecutive ports from Garage’s own pool, starting at garage_start_port (default 3900): the S3 API first, then RPC, s3_web, and admin/metrics. The pool is separate from the shared minio/silo/rustfs pool (that one starts at minio_start_port, default 9000), so a garage, a minio, and a rustfs instance never collide:

pg addon install garage --name store    # 3900 / 3901 / 3902 / 3903
pg addon install garage --name lake     # 3904 / 3905 / 3906 / 3907
pg addon install minio  --name archive  # 9000 / 9001  (shared pool)

Only the S3 API port is a knob (--api-port); the other three are assigned the next free ports after it. The RPC port is node-to-node traffic and, for a single-node instance, stays on loopback; the admin/metrics port (3903) serves Garage’s status API. A cluster member’s RPC port is what peers dial (rpc_public_addr), so pgcli widens its RPC bind to 0.0.0.0 even when --listen is loopback — the channel is signed with rpc_secret. Note the port number also rides inside --advertise-host/--peer, so on a host that already runs another garage instance the cluster’s RPC may land on a different port than 3901 (e.g. 10.0.0.11:3905).

No web console — administering via CLI and the admin API

Unlike MinIO (which ships a bundled web Console on a second port), Garage has no built-in web UI. Its management surface is three things:

  • The garage CLI, via pg garage — the practical way to inspect and change state. pg garage runs Garage’s own control CLI inside the instance’s running container (it talks to the local RPC port), so you never podman exec by hand:

    pg garage --name store status         # nodes, zones, capacity, DataAvail
    pg garage --name store layout show    # committed layout + version
    pg garage --name store bucket list
    pg garage --name store key list

    Everything after --name is forwarded to /garage verbatim, so Garage’s own flags (--read --write, -z, -c) need no -- separator — and they go after the subcommand word, since pgcli only reads its own flags before it. With a single instance installed, --name can be dropped; with several, omitting it targets the first by name (announced on stderr). This needs a running member — unlike pg mc/pg etcdctl, which spin up a throwaway client container, pg garage execs the node’s own CLI. See Administering via pg garage for the full operations menu.

  • The admin API on the admin port (3903) — a JSON API. From Garage v2 the endpoints are /v2/<Operation> (e.g. /v2/GetClusterHealth) and require a Bearer token in the Authorization header; a bare curl gets 403 AccessDenied. Only a few endpoints are open without a token:

    curl -s http://127.0.0.1:3903/health          # "Garage is fully operational"
    curl -s http://127.0.0.1:3903/metrics         # Prometheus exposition
    curl -s http://127.0.0.1:3903/v2/GetClusterHealth \
      -H "Authorization: Bearer <admin-token>"   # needs a token
  • s3_web on the web port (3902) — this is not a console. It only serves static-website content for buckets that have website hosting enabled (via per-bucket vhost); its root returns 404.

Community web UIs exist (e.g. dashboards built on the admin API), but they are not part of Garage and not managed by pgcli; wiring one up means minting an admin API token and pointing the third-party app at the admin port. The web_port (3902) that pgcli assigns is reserved for bucket website hosting, so a third- party console should talk to 3903 (admin API) or use pg garage for the CLI — not to 3902.

Configuration

Instances live under the top-level addons.garage map in pg.yaml:

namespace: default
garage_start_port: 3900    # garage's own pool (API/RPC/web/admin, four each)
addons:
  garage:
    store:
      container_name: pgcli-garage-default-store
      name: store
      image_tag: docker.io/dxflrs/garage:v2.4.1
      # data_dir: /srv/garage      # omit for <base-dir>/addon/garage/store/data
      #                             # (meta dir and garage.toml live beside it)
      # drives:                   # multi-disk: replaces data_dir, one dir per disk
      #   - /mnt/d1/garage        # (mutually exclusive with data_dir; each drive
      #   - /mnt/d2/garage        #  is mounted at /var/lib/garage/data<N>)
      # config_file: /etc/garage.toml   # BYO config: mounted verbatim, never rewritten
      listen: 127.0.0.1
      api_port: 3900
      rpc_port: 3901
      web_port: 3902
      admin_port: 3903
      root_user: GK<generated>        # access key id, written on first install
      root_password: <generated>      # secret key, written on first install
      rpc_secret: <generated>         # cluster RPC signing key, written on first install
      region: garage                  # s3_region
      replication_factor: 1           # single-node must be 1; a cluster sets it >1
      autostart: false                # pg autostart enable --garage --name store
      # --- multi-node cluster keys (omit for single-node) ---
      # cluster: c1                   # non-empty ⇒ cluster mode; groups members
      # advertise_host: 10.0.0.11 # rpc_public_addr host; required in cluster
      # zone: z1                      # layout assign -z (failure domain)
      # capacity: 15                  # layout assign -c, GiB; 0 ⇒ no auto-assign
      # peers:                        # known id@addr, each `garage node connect`ed
      #   - 1c0597cc…200aeb@10.0.0.11:3905
      # node_id: 1c0597cc…200aeb@10.0.0.11:3905  # read back after first boot

replication_factor defaults to 1. Setting it > 1 without a cluster is rejected at install — a lone node cannot meet a multi-node quorum. The cluster keys above are written by the cluster install path; you can also set them by hand and re-install. Zone and capacity are layout state, not TOML, so they appear only here.

Edits to listen, ports, root_user, root_password, image_tag, data_dir, drives, or config_file take effect after the next pg addon install garage --name store --force.

List

pg addon list
Infra add-ons (garage):
  garage (name: store)
    Status:      running
    Cluster:     c1 (rf 3)
    Advertise:   10.0.0.11:3905
    Zone/Cap:    z1 / 15 GiB
    Node ID:     1c0597cc…200aeb@10.0.0.11:3905
    Nodes:       3 assigned (healthy)
    Listen:      127.0.0.1
    API port:    3904
    RPC/Web/Admin: 3905/3906/3907
    S3 URL:      http://127.0.0.1:3904
    Data:        ~/pg/addon/garage/store/data
    Metadata:    ~/pg/addon/garage/store/meta
    Access key:  GK<generated>
    Bucket:      store
    Image:       docker.io/dxflrs/garage:v2.4.1
    Container:   pgcli-garage-default-store
    NOTE:        plaintext HTTP only — front with the nginx addon for TLS

Cluster members gain the Cluster / Advertise / Zone/Cap / Node ID / Nodes lines; Nodes: is a live garage status read (best-effort — it is omitted when the member is unreachable). A multi-drive instance replaces the Data: line with Drives: plus one indented container-slot/host-dir line per drive (see Multi-disk data dirs). On a cluster the Access key on the hosts that did not perform the seeding is the public id only (no secret); see Seeding and the secret.

pg addon list never prints the secret key. Reveal it deliberately with pg addon list --show-password (appends a Secret key: line), or print just the secret for scripting: pg addon password garage --name store (the secret key, paired with the Access key: above; --file <path> writes it mode 0600).

Start and stop

pg addon start garage --name store
pg addon stop  garage --name store

install skips a still-present container (starting it if stopped); start only starts an existing one (and self-heals an improper state by recreating it from the config, re-rendering garage.toml).

Auto-start on Boot

Containers carry a --restart unless-stopped policy (crashes, not reboots). To bring instances up after a host reboot:

pg autostart enable --garage --name store

garage autostart re-renders garage.toml and starts the existing container. Garage runs as root in the upstream image, so a boot-time start needs no special host privileges beyond running podman itself. Boot is start-only; garage is independent of the PostgreSQL stack, so it is started alongside the other object stores.

Remove

pg addon remove garage --name store            # container gone, data kept
pg addon remove garage --name store --clean-data   # also delete every data dir + meta dir + config

The data directories are the object storage — losing them means losing every bucket in them — so remove keeps them by default. --clean-data deletes the data dir(s) (in multi-drive mode, every drive dir), the meta dir, and the pgcli-rendered garage.toml (a config_file you supplied yourself is never touched), and prunes the now-empty default-layout parent directory. Each dir is skipped — with a refusal, not a silent pass — while it is still a live mount point. Unlike rustfs, Garage writes as root and pgcli runs podman as root on the managed hosts, so plain removal suffices — no podman unshare fallback.

Logs

pg logs addon garage --name store      # last 50 lines
pg logs addon garage --name store -f   # follow

Troubleshooting

  • pulling garage image ... : ... on install. The tag docker.io/dxflrs/garage:v2.4.1 is not reachable — check network access to Docker Hub, or pre-pull it with podman pull.
  • pg mc alias set fails with a connection error. The default --listen 127.0.0.1 binds the store loopback-only; on macOS, use host.containers.internal, not 127.0.0.1. Confirm the live API port with pg addon list.
  • Writes through the nginx front fail with Invalid signature. The front rewrote Host without the port; use proxy_set_header Host $http_host; (the conf-file recipe does) — the --upstream template mode hard-codes $host and does not fit S3.
  • PUTs through the nginx front fail at ~1 MiB. nginx defaults client_max_body_size to 1m; the conf-file recipe sets it to 0 (unlimited).
  • pgBackRest refuses the endpoint (HTTP / cert). pgBackRest forces HTTPS for S3 repos. Front Garage with the nginx addon (--tls) and point backup.repo.s3.ca_file at the front’s ca.crt.
  • replication_factor must be 1 on a single-node instance. A hand-edited replication_factor: 2 without a cluster is rejected at install — a lone node cannot meet a multi-node quorum. For multi-node, set cluster (or install with --cluster); see Multi-node cluster.

5 - PostgREST

Expose a PostgreSQL schema as a REST API via the PostgREST addon

PostgREST is a single-process, stateless web server that turns a PostgreSQL schema into a RESTful API. As a pgcli addon it runs as one container in front of any PG endpoint — no data directory, no rendered config file, everything configured through PGRST_* environment variables.

PostgREST is a proxy-type addon like PgBouncer and PgDog: it holds no state of its own. Two deployment modes mirror PgBouncer’s:

  • Local: pg addon install postgrest -i <instance> — stored as a sidecar under instances.<name>.addons.postgrest, DSN built from the instance.
  • Remote: pg addon install postgrest --dsn <dsn> --pg-name <name> — stored in top-level addons.postgrest.

The --dsn in either mode is passed verbatim into the container’s PGRST_DB_URI, so it works against any PG endpoint: a direct managed instance, a PgBouncer pool, or a Patroni cluster behind its HAProxy listener.

Platform support

PostgREST works on Linux (host networking, --network host) and macOS (container joins the pgcli-net bridge and publishes its port, the same shape as a PG instance under podman machine).

  • Local mode on macOS just works — the container reaches the managed instance over the bridge.
  • Remote mode on macOS: --dsn must be reachable from the Mac itself, not from the podman machine VM. Point it at an address the Mac can resolve (a real host IP, or host.containers.internal for a service on the VM).
  • Clients always reach the REST API at 127.0.0.1:<port> (or --listen); gvproxy forwards the published port to the Mac’s loopback.

How it works

  1. pg addon install postgrest pulls the image (if missing) and starts a container wired entirely from PGRST_* env vars.
  2. The container reaches the backend PG over the host network (Linux) or the pgcli-net bridge (macOS).
  3. PostgREST introspects the exposed schema on startup, serves REST requests, and listens on the pgrst channel for a schema-cache reload signal.

PostgREST holds no data on the host — pg addon remove postgrest only stops and removes the container.

Container name: pgcli-postgrest<ns>-<name> (local mode uses the instance name as <name>; remote mode uses --pg-name). Namespace isolation applies: two configs with different namespaces can run independent APIs without colliding.

Commands

Install

# Local mode: expose a managed instance's schema
pg addon install postgrest -i mypg --schema api --anon-role web_anon

# Remote mode: any PG endpoint (direct instance, pgbouncer, or haproxy LB)
pg addon install postgrest \
  --dsn "postgres://api:pass@127.0.0.1:5000/appdb" \
  --pg-name app-api --schema api --anon-role web_anon

# Tune the connection pool PostgREST keeps toward its backend
pg addon install postgrest -i mypg --db-pool 20

# Enable JWT auth (unauthenticated requests still fall back to --anon-role)
pg addon install postgrest -i mypg --schema api --anon-role web_anon --jwt-secret "$(openssl rand -hex 32)"

Re-running install is idempotent: an existing container is reused (a stopped one is started). Pass --force to recreate it after changing ports, listen address, DSN, db-pool, schema, anon-role, or jwt-secret.

Parameters:

Parameter Description Default
-i, --instance Managed instance (local mode) default
--dsn Backend PG URI (remote mode); → PGRST_DB_URI verbatim —
--pg-name Name to identify a remote PostgREST (required with --dsn) —
--schema Exposed schema(s), comma-separated; → PGRST_DB_SCHEMAS PostgREST default (public)
--db-pool Connections in PostgREST’s pool toward the backend; → PGRST_DB_POOL PostgREST default (10)
--anon-role Role unauthenticated requests run as; → PGRST_DB_ANON_ROLE — (anonymous access off)
--jwt-secret Secret used to verify Authorization: Bearer JWTs; → PGRST_JWT_SECRET — (JWT auth off)
--port HTTP host port auto, from postgrest_start_port (base 3500)
--listen Bind address 127.0.0.1
--image Container image docker.io/postgrest/postgrest:v16.3
--force Recreate an existing container to apply changed flags off

--db-pool and the backend’s max_connections. Total PG connections a PostgREST deployment opens is roughly number of PostgREST instances × --db-pool. If you run several replicas behind the same endpoint, budget max_connections accordingly.

List

pg addon list

PostgREST appears under Local add-ons / Remote add-ons with Status, REST URL, Backend, Schema, DB pool, Anon role, JWT auth, and Container.

Start / stop / remove / logs

pg addon start postgrest -i mypg
pg addon stop postgrest --pg-name app-api
pg addon remove postgrest -i mypg          # stateless: only the container goes away
pg addon remove postgrest --pg-name app-api
pg logs addon postgrest -i mypg            # local container logs
pg logs addon postgrest --pg-name app-api  # remote container logs

Autostart

pg autostart enable --postgrest -i mypg
pg autostart enable --postgrest --pg-name app-api
pg autostart status

Autostart is start-only: at boot the container is brought up reading the PGRST_* env already in the config (recreated from config if it was removed). Install the addon first.

Configuration

PostgREST settings live under addons.postgrest (remote) or as an instances.<name>.addons.postgrest sidecar (local):

postgrest_start_port: 3500      # base of the HTTP port pool

addons:
  postgrest:
    app-api:
      container_name: pgcli-postgrest-default-app-api
      name: app-api
      image_tag: docker.io/postgrest/postgrest:v16.3
      host_port: 3501
      listen: 127.0.0.1
      dsn: postgres://api:pass@10.0.0.20:35432/appdb
      backend_host: 10.0.0.20:35432
      db_pool: 4
      schemas: api
      anon_role: web_anon
      jwt_secret: <HS256-shared-secret>   # only present when --jwt-secret was given
      autostart: false

Ports are auto-assigned from the postgrest_start_port pool (base 3500) when --port is omitted; the pool is independent of the PgBouncer / etcd / pgdog / minio pools.

For a Patroni cluster the recommended shape is PostgREST → HAProxy rw listener → cluster leader, not PostgREST pointed straight at a member. Pass the listener as --dsn (remote mode):

# Recommended: writes always follow the leader through the LB's rw listener
pg addon install postgrest --dsn "postgres://api:pass@<lb-host>:5000/appdb" \
  --pg-name app-api --schema api --anon-role web_anon

Why the listener, not a member’s direct port: a pinned member loses writes after a failover (the old leader stops accepting them, but the DSN keeps pointing there). pgcli detects a member’s direct port at install time and warns, suggesting the HAProxy listener instead.

  • Failover self-heal, no restart. When the leader changes, PostgREST just reconnects through the LB and re-selects the new leader — service resumes without restarting the container or re-running install. Verified: after a pg ha switchover, the one in-flight write that hit the demoted connection failed 503 (SQLSTATE 57P01, connection terminated), and the very next retried request succeeded 201 against the new leader. Treat that single transient 503/57P01 during a leader change as expected and retry it.
  • HAProxy routes by health check, decoupled from who is leader. The rw listener only admits the member passing the /primary check and the ro listener only the replicas passing /replica, so a failover needs no haproxy reconfiguration — the traffic moves on its own.
  • Scale-out. Run several PostgREST replicas behind a load balancer; each adds its own --db-pool worth of backend connections.

Database-side setup (not managed by pgcli)

pgcli installs and runs the PostgREST container; it does not touch your database. Before the API serves anything, the database needs the unauthenticated role PostgREST SET ROLEs to, plus grants on the exposed schema — usually owned by your migrations, not pgcli. This block is re-runnable:

-- The exposed schema (--schema value; skip for public, which already exists):
CREATE SCHEMA IF NOT EXISTS api;

-- The NOINHERIT role unauthenticated requests run as (the --anon-role value).
DO $$ BEGIN
  IF NOT EXISTS (SELECT FROM pg_roles WHERE rolname = 'web_anon') THEN
    CREATE ROLE web_anon NOINHERIT NOLOGIN;
  END IF;
END $$;
GRANT USAGE ON SCHEMA api TO web_anon;
GRANT SELECT ON ALL TABLES IN SCHEMA api TO web_anon;
ALTER DEFAULT PRIVILEGES IN SCHEMA api GRANT SELECT ON TABLES TO web_anon;

-- SET ROLE requires the login user to be a member of the target role
-- (skip if the DSN user is a superuser):
GRANT web_anon TO <dsn-user>;

The role view’s column is rolname, not rolename — a typo fails the whole batch. ALTER DEFAULT PRIVILEGES covers only tables created after it runs; existing ones are handled by the GRANT ... ON ALL TABLES line.

PostgREST connects as the DSN user and SET ROLEs to web_anon per request, so the API carries exactly that role’s privileges: web_anon sees SELECT-only until you GRANT INSERT/UPDATE/DELETE on the tables you want writable. The connecting login role itself needs nothing beyond membership of the roles requests will assume. Then install with --anon-role web_anon. The two ways to authenticate a request — anonymous (--anon-role) and JWT (--jwt-secret) — are covered next; without either, every request is refused with 401.

PostgREST caches the schema it introspected. After a schema change, reload the cache:

NOTIFY pgrst, 'reload schema';

LISTEN and transaction pooling. PostgREST relies on a persistent LISTEN pgrst session to receive reload notifications. Behind a pooler in transaction pooling mode (PgBouncer’s default) that session-level LISTEN is broken — the notification is never delivered, and neither is NOTIFY pgrst reaching PostgREST via a pooled connection. Verified behaviour: a reload sent through a transaction-pooled PgBouncer does not refresh PostgREST’s cache (a fresh table stays 404), and even a NOTIFY sent directly to the backend is lost because PostgREST’s own listener has no stable connection. Either point PostgREST at a session-pooled or direct connection, or restart the PostgREST container (it re-introspects on boot) to pick up schema changes.

Verifying the API

The install prints the REST URL (http://127.0.0.1:<port>). Create a table in the exposed schema, then hit the API to confirm the server is live and serves its rows:

CREATE TABLE api.widgets (id integer PRIMARY KEY, name text);
INSERT INTO api.widgets VALUES (1, 'bolt'), (2, 'nut');
GRANT SELECT ON api.widgets TO web_anon;
NOTIFY pgrst, 'reload schema';   -- otherwise the new table stays 404
# The OpenAPI root — answers as soon as PostgREST has connected to the backend.
curl -s http://127.0.0.1:3500/ | head -c 120

# Which tables/relations are exposed (from the OpenAPI paths):
curl -s http://127.0.0.1:3500/ | grep -o '"/[a-z_]*"'

# Read rows from the table. The schema is implicit in the path — it is
# /widgets, NOT /api.widgets:
curl -s "http://127.0.0.1:3500/widgets"
curl -s "http://127.0.0.1:3500/widgets?id=eq.1"   # a filter

A few things to expect on a fresh install:

  • The root can take a moment to answer — schema introspection runs after boot, so the first requests may 503 until PostgREST has connected.
  • A 404 on a just-created table or a 401 on unauthenticated requests means the schema cache is stale or --anon-role is unset — see the Troubleshooting table below for the fix.

JWT authentication

--anon-role is the simplest model: every unauthenticated request runs as one fixed role. --jwt-secret turns on per-request identity. Pass it at install time (a HS256 shared secret, or a JSON Web Key for RS256); pgcli passes it to the container as PGRST_JWT_SECRET.

pg addon install postgrest -i mypg --schema api --anon-role web_anon \
  --jwt-secret "$(openssl rand -hex 32)"

The secret is not written to your shell history if you inline a command substitution as shown. It does land in pg.yaml (so pgcli can recreate the container) — treat that file as secret-bearing, and re-run install with --force after changing it.

Length: for HS256 the secret must be at least 32 characters (256-bit key material; 48 for HS384, 64 for HS512). PostgREST refuses to start with a shorter one — openssl rand -hex 32 (64 chars) is a safe default. A JWK (for RS256/ECDSA) has no such minimum; the key strength comes from the JWK itself.

With a secret set, PostgREST verifies any request that carries Authorization: Bearer <token> and runs it as the role named in the token’s role claim:

  • The token must be signed with the same secret; a tampered one is rejected 401.
  • The role claim must name a database role with grants on the exposed schema (create it like web_anon above, NOINHERIT).
  • The login role in the DSN must be a member of that role, because serving the request means SET ROLE to it. So for a JWT role like web_user you also need GRANT web_user TO <dsn-user>; — same requirement as the anon role above, and likewise skippable when the DSN user is a superuser. Without the membership, requests fail with permission denied to set role.
  • Change the claim key from role via PGRST_JWT_ROLE_CLAIM_KEY if your issuer uses another field — pgcli does not surface that flag; set it on the container directly if needed.

--anon-role and --jwt-secret compose: requests with a valid JWT run as their role claim, requests without one fall back to --anon-role. With neither flag, every request is refused (401). A typical progression is anon for public reads plus JWT roles for authenticated writes.

In production your application’s auth service signs the tokens. To hand-craft a test token with the same HS256 secret:

b64url() { openssl base64 -A | tr '+/' '-_' | tr -d '='; }
SECRET='<the --jwt-secret value>'
HEADER=$(printf '{"alg":"HS256","typ":"JWT"}' | b64url)
PAYLOAD=$(printf '{"role":"web_anon","exp":%d}' $(( $(date +%s) + 3600 )) | b64url)
SIG=$(printf '%s.%s' "$HEADER" "$PAYLOAD" | openssl dgst -sha256 -hmac "$SECRET" -binary | b64url)
curl -s -H "Authorization: Bearer $HEADER.$PAYLOAD.$SIG" http://127.0.0.1:3500/widgets

Troubleshooting

Symptom Likely cause / fix
Install fails with cannot connect to source database The DSN host:port is unreachable from the container (on macOS, remote 127.0.0.1 points at the Mac, not the VM). Verify with pg exec --dsn <dsn> "SELECT 1".
Every request returns HTTP 401 Anonymous access is disabled No --anon-role was given and the request carried no valid JWT — add --anon-role, or install with --jwt-secret and send a signed token. A JWT 401 with --jwt-secret set means the signature/role claim is wrong.
A write returns HTTP 401 whose JSON body says 42501 / permission denied for table The role the request ran as (anon or the JWT role claim) lacks that privilege — PostgREST surfaces insufficient privilege as 401 at the HTTP layer, with the real SQLSTATE only in the body. Grant the privilege to the role the request assumes.
A brand-new table/relationship still returns 404/PGRST205 after NOTIFY pgrst Reload is not reaching PostgREST (see transaction pooling above). Restart the container, or use a session/direct connection.
Writes fail right after a Patroni failover The DSN pointed at a member’s direct port, not the HAProxy rw listener — install warned about this. Re-point the DSN at the LB.
--db-pool change didn’t take effect Existing containers are reused; re-run install with --force to recreate.
  • PgBouncer — connection pooler (watch the transaction-pooling caveat above when pooling PostgREST’s backend).
  • PgDog — pooling / sharding proxy, same dual-mode shape.
  • HAProxy — the listener PostgREST’s DSN should target for a Patroni cluster.
  • HA Cluster — Patroni topology that --dsn points at.

6 - SeaweedFS

Run SeaweedFS (the Go, Apache-2.0 S3-compatible object store) as a pgcli addon — single-node “weed mini” or a cross-host “weed server” cluster with filer metadata in a shared PostgreSQL, native S3 TLS, and one shared credential pair across the cluster

SeaweedFS is a Go, Apache-2.0 S3-compatible object store whose defining trait is volume-granularity disk management: data is split into fixed-size volumes (.vol files) that the master places across volumeservers, giving O(1) reads and cheap small-file storage. pgcli runs it as a standalone, top-level addon with the same CLI surface as garage, minio, silo and rustfs (install, list, logs, autostart, password, pg mc), but its runtime model diverges in four ways that shape this page:

  1. One process, all roles. A single node runs weed mini — master, volume server, filer and S3 gateway in one process (the officially endorsed single-binary deployment). A cluster member runs weed server -filer -s3, one per host, all roles together — never four containers.
  2. Three rendered files, argv for everything else. pgcli renders s3.json (the S3 identity) and, for a cluster, filer.toml (the PostgreSQL metadata store) under the instance directory and bind-mounts them read-only; the rest of the configuration is weed command-line flags.
  3. Cluster metadata lives in a shared PostgreSQL. Every cluster node fronts filer + S3, so the filer namespace must be one database, not per-node leveldb2 — pgcli points all members at one --dsn PostgreSQL. This is the natural home ground of pgcli: the store can sit next to (or in) a pgcli-managed instance.
  4. Native S3 TLS — --tls (self-signed) or --tls-cert/--tls-key (BYO, e.g. pg cert output) — the MinIO posture, not Garage’s nginx-front one. With TLS on, the pooled S3 port serves HTTPS only; the cleartext listener is not bound at all.

Platform support: tested on Linux (host networking). The macOS bridge path is code-complete and follows the same shape as the other object stores, but has not been exercised on a Mac yet.

How It Works

One container per instance, from the upstream docker.io/chrislusf/seaweedfs:4.48_large_disk image (pull-only). pgcli overrides the image’s ENTRYPOINT and runs /usr/bin/weed -logtostderr=true <subcommand> … directly: the stock entrypoint would chown -R /data and drop to uid 1000 on every start — on a large data directory that is exactly the silent slowdown shape pgcli avoids, and without -logtostderr weed logs to files inside the container where pg logs cannot see them.

Host state lives under <base-dir>/addon/seaweedfs/<name>/:

  • data/ → /data (volumes and, single-node, the filer’s leveldb2 metadata) — replaced by one bind mount per drive (/data1…/dataN) in multi-disk mode, see Multi-disk,
  • s3.json → /etc/seaweedfs/s3.json:ro (the S3 identity; 0600 on the host),
  • filer.toml → /etc/seaweedfs/filer.toml:ro (cluster / --dsn only; the [postgres2] section rendering the metadata DSN),
  • cert.pem/key.pem → mounted under /etc/seaweedfs/ when TLS is on.

Credentials are an access key / secret key pair rendered into s3.json (SeaweedFS’s static-identity mechanism — AWS_* env is lower priority and gets overridden by the local store, so pgcli never uses it):

  • root_user is the access key id — on a single-node install it is generated on first install (SW + 28 hex chars) or supplied via --root-user.
  • root_password is the secret key (64 hex chars), generated or supplied via --root-password.
  • Under --cluster both are required and must be identical on every node — see Multi-node cluster.

The identity is rendered with the bare Admin action, which in SeaweedFS’s permission model short-circuits to full access. All values land in pg.yaml (addons.seaweedfs.<name>.*) so a recreate is stable. The install also renders one bucket — named after the instance (--bucket overrides): single-node weed mini -bucket creates it at boot; a cluster seeds it through the S3 API with mc mb --ignore-existing once the node’s health gate is green.

Install

# default instance name "seaweedfs", four ports from the seaweedfs pool, loopback bind
pg addon install seaweedfs

# a named instance with an explicit data directory
pg addon install seaweedfs --name store --data-dir /srv/seaweedfs

# spread one node's volumes across several separately-mounted disks
pg addon install seaweedfs --name store --drive /mnt/sw-disk1 --drive /mnt/sw-disk2

# a fixed master port (volume/filer/s3 take the next three; gRPC twins +10000)
pg addon install seaweedfs --name store --port 8400

# expose the store on the network instead of loopback only
pg addon install seaweedfs --name store --listen 0.0.0.0

# supply your own access key / secret key (seaweedfs limits: key >= 8, secret >= 16 chars)
pg addon install seaweedfs --name store --root-user SW<...> --root-password <secret>

# native TLS (self-signed) — the S3 port becomes HTTPS-only
pg addon install seaweedfs --name store --tls

# join a cross-host cluster (see Multi-node cluster below) — credentials are MANDATORY here
pg addon install seaweedfs --name store --cluster c1 --advertise-host 10.0.0.11 \
  --replication 001 --root-user SW<...> --root-password <secret> \
  --dsn "postgres://admin:<pw>@10.0.0.11:35432/seaweed_store" \
  --peer 10.0.0.11:8400 --peer 10.0.0.12:8400 --peer 10.0.0.14:8400

The single-node output reports endpoints and the minted credentials:

  [OK] cluster leader: 127.0.0.1:8400.18400

✓ seaweedfs installed: "store"
  Container:     pgcli-seaweedfs-default-store
  Image:         docker.io/chrislusf/seaweedfs:4.48_large_disk
  Data:          /root/.pgcli/addon/seaweedfs/store/data
  S3 endpoint:   http://127.0.0.1:8403
  Ports:         master=8400 volume=8401 filer=8402 s3=8403 (gRPC twins +10000)
  Bucket:        store

  Access key:    SW<generated>
  Secret key:    <generated>
  Try it:        pg mc alias set store http://127.0.0.1:8403 SW<...> <secret> && pg mc ls store

The install ends with a health gate: pgcli polls the master’s JSON /cluster/status API for up to 30 s before declaring success — a detached container with --restart unless-stopped would otherwise swallow a bad argv into a crash loop behind a green-looking install. Only after the gate is green does the bucket seeding run.

Re-running install against a live instance is a no-op: the container is not recreated (a stopped one is simply started, with a notice), flags are merged into the stored config, and existing credentials are kept. Pass --force to recreate the container so changed ports, listen address, or credentials take effect — without losing the data directory or the metadata database.

Bind address: the default 127.0.0.1 keeps the store local; --listen 0.0.0.0 (or the listen key in pg.yaml) exposes it on the network. A cluster member always binds 0.0.0.0 regardless of --listen — peers must reach its gRPC twin (port + 10000) for Raft — while -ip still registers the single address peers dial.

-ip is never left to auto-detection. weed registers its volumes under whatever address it guesses; the filer/S3 data path then dials that guess and uploads 500 on an otherwise healthy-looking container. pgcli passes -ip explicitly (--listen value single-node, --advertise-host in a cluster) — verified the hard way on a test host.

TLS

SeaweedFS serves HTTPS natively on the S3 port; there is no nginx front and no web-console leg to proxy. Two shapes, same as minio/rustfs:

# self-signed: pgcli generates cert+key under the instance dir (30-day leaf,
# SANs covering the bind/advertise address, 127.0.0.1 and localhost)
pg addon install seaweedfs --name store --tls

# bring your own: e.g. a `pg cert`-issued pair (a CA certificate is refused)
pg addon install seaweedfs --name store --tls-cert fullchain.pem --tls-key privkey.pem

What TLS changes under the hood (verified): the cleartext listener is off (-s3.port=0 — the pooled port simply refuses TCP connections), and the same pooled S3 port becomes -s3.port.https. So the endpoint printed at install is https://…:8403, not an extra port. Point pg mc at it as usual — the loopback alias gets --insecure automatically; for a real or generated CA, pass its ca.crt to your S3 client.

Multi-disk

A single node can use several disks: weed’s own -dir is a comma list (dir[,dir]…) that one volume server stores its volumes across, and pgcli exposes it as a repeatable --drive — one host directory per disk, each bind-mounted at its own slot:

# each --drive must be a separately mounted disk; the drives fully replace
# --data-dir (combining the two is an error)
pg addon install seaweedfs --name store \
  --drive /mnt/sw-disk1 --drive /mnt/sw-disk2 --drive /mnt/sw-disk3

The summary and pg addon list then show the mapping instead of a single Data: line:

  Drive 1:       /mnt/sw-disk1 -> /data1
  Drive 2:       /mnt/sw-disk2 -> /data2
  Drive 3:       /mnt/sw-disk3 -> /data3

and the container runs with -dir=/data1,/data2,/data3 (verified: the volume server’s /status reports each host directory as its own DiskStatuses entry with independent disk accounting, and remove --clean-data walks the drives one by one, refusing any that is still a live mount point).

Two semantics worth knowing:

  • Placement, not RAID. This is one volume server spreading .vol files across its directories — no striping or mirroring at the OS level, and no erasure coding between the drives either (the cluster replication story is orthogonal — see Multi-node cluster). A drive that disappears takes the volumes on it; whether that loses data depends on the replication code, not on the local layout.
  • Advisory device check. install warns about any drive sitting on the same device as the host root filesystem — multi-disk only pays off on separately mounted disks. Unlike MinIO (which refuses such a drive at startup), weed happily uses them, so pgcli warns and continues. Format and mount each disk first; pgcli never partitions or formats anything.

Drives are a per-node knob, and they compose with the cluster: pass --drive on each member’s install command and every node runs its own multi-disk volume server behind the shared cluster (verified on a 3-host weed server cluster where each member mounted two drives — every member’s process showed -dir=/data1,/data2 with two independent DiskStatuses entries, and the 001 replica of one 8 MB volume landed on the real disk of one node and on the other drive of the replica node, i.e. each node’s volume server picked among its own dirs while placement chose across nodes). The nodes do not need the same drive count; each account only sees its own -dir list. Stop/start and --force recreate handle the drive set like any other config change — the mounts and -dir are rebuilt from pg.yaml.

Multi-node cluster

The cluster is MinIO-MNMD shaped, not Garage’s bootstrap/join: there is no first node, no join command with a carried cluster secret, no layout to assign. You run the same install command on every host — Raft membership is the full --peer list every node passes, and a node that starts before quorum simply waits (its health gate warns instead of failing; the install that completes quorum finishes the bucket seeding).

Two things differ from a bigger single node, and both are shared by definition — every member’s command carries them identically:

  1. One credential pair for the whole cluster. Each gateway authenticates against only its own rendered s3.json; SeaweedFS has no shared-credential backend without a standalone IAM server (out of pgcli’s v1 scope), so per-node auto-generation would leave the three gateways accepting three different identities. pgcli therefore refuses to auto-generate under --cluster: pass the same --root-user and --root-password on every node. Run the first node’s install with them, copy the pair from its printed summary, and carry it verbatim to the rest (pgcli never executes anything remotely). A half pair (only one of the two) is an error; so is re-running a single-node config’s install with --cluster.
  2. The shared filer metadata database. --dsn postgres://user:pass@host:port/db is required, must be dialable from every host — so use the host-published port / LAN address, never a container-local 127.0.0.1:5432 — and the database itself must already exist: pgcli only probes reachability, it never creates (or drops) databases it does not own. The metadata tables need no setup: weed’s postgres2 store creates .system, filemeta and one table per bucket inside it on first use (verified). sslmode=disable is rendered into filer.toml, so reachability + pg_hba is all that must line up.

Three-host walkthrough

Prepare the metadata database once, anywhere all nodes can reach (here a pgcli-managed instance on host 1, host port 35432):

pg exec -i demo "CREATE DATABASE seaweed_store"

Then, on each host, the same command with that host’s own --advertise-host (keys below are placeholders — use one pair everywhere):

# on 10.0.0.11 — the printed summary hands you the command for the others
pg addon install seaweedfs --name store --cluster c1 \
  --advertise-host 10.0.0.11 --replication 001 \
  --root-user SW<...> --root-password <secret> \
  --dsn "postgres://admin:<pw>@10.0.0.11:35432/seaweed_store" \
  --peer 10.0.0.11:8400 --peer 10.0.0.12:8400 --peer 10.0.0.14:8400

# on 10.0.0.12 — identical except --advertise-host
# on 10.0.0.14 — identical except --advertise-host

Add --drive to that same command to give each member its own multi-disk volume server (--drive /mnt/sw-disk1 --drive /mnt/sw-disk2 — see Multi-disk); it is a per-node flag, so hosts may carry different drive sets. Verified on a 3-host cluster.

The summary ends with a copy-paste block for the remaining hosts with exactly that shape (credentials and DSN filled in from this node’s config).

What the first installs say while the cluster is still assembling is normal:

  • Host 1 comes up with a leader already visible (a lone weed master with an odd peer count can still win its own election here — the observed behaviour with a 3-node list is host 1 leading immediately), but the bucket seed may fail with a connection refused: the cluster’s S3 side is not serving yet. pgcli prints [!] bucket seeding incomplete … re-run this install command once the cluster has quorum and exits 0.
  • Host 2 (or 3) completes quorum; the same idempotent seed succeeds there (Bucket created successfully). Re-running host 1’s command afterwards re-checks quietly and mb --ignore-existing stays a no-op.

After all three, any member shows the whole cluster:

$ pg weed --name store --shell "cluster.status"

cluster:
	id:       topo
	status:   unlocked
	nodes:    3
	topology: 1 DC, 3 disks on 1 rack
…

Reading and writing through any node

Because credentials are shared and the filer namespace is one database, any gateway serves any object: write through host 2’s S3 port and read back through host 3’s with the same key — verified end-to-end on a 3-host test cluster, including a wrong-secret attempt coming back as The request signature we calculated does not match (it is not a per-node local trust store). --replication 001 keeps one remote copy of every volume (volume.list shows ReplicaPlacement:001 and each volume on two data nodes).

Stop one member and the cluster keeps serving (Raft quorum is a majority; with 3 masters, 2 keep electing and writing):

# on host 3
pg addon stop seaweedfs --name store
# on host 1 — reads still succeed via host 2's gateway
pg mc cat store2/store/roundtrip.bin | sha256sum

pg addon start rejoins the node; its volumes re-register under the same -ip. Changing cluster membership is not orchestrated: the --peer list is static Raft configuration — add or remove a member by rebuilding the cluster (v1 limitation, see Limitations).

Getting the cluster’s AK/SK

The pair is by design present in every node’s pg.yaml (you carried it there), so unlike garage’s CRDT key — whose secret lives on exactly one host — pg addon password seaweedfs --name store works on any member. If the printed secret is lost everywhere, pick a new pair and re-install each node with --force (the rendered s3.json is rewritten; data and metadata are untouched).

Using the mc Client

pg mc runs MinIO’s mc from a throwaway container — no local install — and speaks SeaweedFS’s S3 API like any other store. Use the access key in place of a user and the secret key in place of a password:

pg mc alias set store http://127.0.0.1:8403 SW<...> <secret>   # Linux, local
pg mc mb store/backups
pg mc cp ./dump.pglz store/backups/
pg mc ls store

Aliases persist in ~/.mc/config.json; flags pg’s parser would claim go after -- (pg mc rm store/scratch -- --force). On macOS point the alias at host.containers.internal:<s3-port> instead of 127.0.0.1. Under TLS, use the https:// endpoint (loopback aliases are auto---insecure).

Administering via pg weed

pg weed runs SeaweedFS’s own weed control tool inside a running member’s container — the replacement for hand-written podman exec pgcli-seaweedfs-<ns>-<name> …. --name selects the instance (default: the first by name); pgcli’s own flags must come before the subcommand word, and weed’s flags pass through untouched. Two shapes:

pg weed <args>...           # verbatim: /usr/bin/weed <args> in the container
pg weed --shell <line>...   # each line piped into `weed shell`, pre-wired to
                            # this instance's master and filer over loopback

The weed shell menu is the day-2 surface (command names verified against 4.48 — the shell help lists far more):

pg weed --shell "cluster.status"                     # topology, nodes, volumes
pg weed --shell "volume.list"                        # every volume, its replicas, sizes
pg weed --shell "s3.bucket.list"                     # buckets as seen by the filer
pg weed --shell "fs.ls /"                            # the filer namespace, root
pg weed --name store --shell "volume.list" "s3.bucket.list"   # several lines at once
pg weed flag.lookup 0,1,2                            # verbatim subcommand
pg weed shell                                        # interactive (needs a TTY)

weed CLIs can print their result and then linger with open gRPC channels; pgcli cuts such a command off after its output has been quiet for 3 s (10-minute overall cap), so a hang surfaces as a loud timeout instead — re-run it.

Ports

Each instance takes four consecutive ports from SeaweedFS’s own pool, starting at seaweedfs_start_port (default 8400): master, volume, filer, s3 — and every role also opens a gRPC twin at http port + 10000 (8400 → 18400, …), which pgcli reserves in the pool too. A second instance therefore lands on 8404-8407 / 18404-18407, and a seaweedfs, a garage and a minio instance never collide (separate pools: 8400 / 3900 / 9000):

pg addon install seaweedfs --name store   # 8400-8403 + 18400-18403
pg addon install seaweedfs --name lake    # 8404-8407 + 18404-18407

--port sets only the master anchor; the rest follow. Only the S3 port is a client endpoint; master 8400 also serves the /cluster/status JSON API and the operator UI pages (the admin UI and webdav are switched off in the argv, and iceberg/lance side listeners are pinned to 0 so weed opens no extra holes).

Configuration

Instances live under the top-level addons.seaweedfs map in pg.yaml:

namespace: default
seaweedfs_start_port: 8400    # seaweedfs's own pool (master/volume/filer/s3, four each, gRPC twins reserved)
addons:
  seaweedfs:
    store:
      container_name: pgcli-seaweedfs-default-store
      name: store
      image_tag: docker.io/chrislusf/seaweedfs:4.48_large_disk
      # data_dir: /srv/seaweedfs    # omit for <base-dir>/addon/seaweedfs/store/data
      # --- multi-disk (replaces data_dir; mutually exclusive with it) ---
      # drives:                      # one host dir per disk, mounted /data1../dataN,
      #   - /mnt/sw-disk1            #   and -dir lists them comma-joined
      #   - /mnt/sw-disk2
      listen: 127.0.0.1
      port: 8400                    # master anchor; volume/filer/s3 = next three
      volume_port: 8401
      filer_port: 8402
      s3_port: 8403
      root_user: SW<generated>         # s3.json access key
      root_password: <generated>       # s3.json secret key
      bucket: store                    # seeded on first boot (default = name)
      volume_size_mb: 1024             # -master.volumeSizeLimitMB (weed's own default 128 is tiny)
      autostart: false                 # pg autostart enable --seaweedfs --name store
      # --- multi-node cluster keys (omit for single-node) ---
      # cluster: c1                    # non-empty ⇒ cluster mode (weed server)
      # advertise_host: 10.0.0.11  # the -ip peers dial; required in cluster
      # replication: "001"             # placement code XYZ (X remote copies,
      #                                #   Y racks, Z data centers), immutable in-cluster
      # peers:                         # FULL Raft list, written on every node
      #   - 10.0.0.11:8400
      #   - 10.0.0.12:8400
      #   - 10.0.0.14:8400
      # filer_dsn: postgres://admin:<pw>@10.0.0.11:35432/seaweed_store  # required in cluster
      # --- TLS ---
      # tls: true                      # self-signed (or via --tls-cert/--tls-key BYO)
      # cert_file: …/cert.pem
      # key_file: …/key.pem

Edits to listen, ports, root_user, root_password, image_tag, data_dir, drives, filer_dsn, or the TLS material take effect after the next pg addon install seaweedfs --name store --force. In a cluster the force-recreate must be run on every member (each host owns its own pg.yaml and container).

List

pg addon list
Infra add-ons (seaweedfs):
  seaweedfs (name: store)
    Status:      running
    Cluster:     c1 (replication 001, 3 peers configured)
    Peers:       10.0.0.11:8400,10.0.0.12:8400,10.0.0.14:8400
    Leader:      10.0.0.11:8400.18400
    Filer store: postgres 10.0.0.11:35432/seaweed_store
    Listen:      127.0.0.1
    Ports:       master=8400 volume=8401 filer=8402 s3=8403
    S3 URL:      http://127.0.0.1:8403
    Data:        /root/.pgcli/addon/seaweedfs/store/data
    Access key:  SW<generated>
    Bucket:      store
    Image:       docker.io/chrislusf/seaweedfs:4.48_large_disk
    Container:   pgcli-seaweedfs-default-store

Cluster members gain the Cluster / Peers / Leader / Filer store lines; Leader: is a live /cluster/status read (best-effort — omitted when the member is not running, and printed as (none yet — still electing / no quorum) while a still-assembling cluster has no leader). Single-node members show none of those four lines. A multi-disk instance shows the Drives block (with one - /dataN <- host line per drive) in place of the single Data: line — see Multi-disk. With TLS on, a final TLS: native S3 HTTPS on 8403 (cleartext listener off) line is appended. pg addon list never prints the secret key; reveal it deliberately with pg addon list --show-password (appends a Secret key: line), or pg addon password seaweedfs --name store (--file <path> writes it mode 0600). The Filer store line is host:port/db with the password always hidden.

Start and stop

pg addon start seaweedfs --name store
pg addon stop  seaweedfs --name store

install skips a still-present container (starting it if stopped); start only starts an existing one — and re-renders s3.json/filer.toml first, so hand-edits to the stored config take effect on restart.

Auto-start on Boot

Containers carry a --restart unless-stopped policy (crashes, not reboots). To bring instances up after a host reboot:

pg autostart enable --seaweedfs --name store

Autostart is start-only — the rendered files and the container already exist. A cluster member that boots before its peers just waits for quorum like any other cold start. SeaweedFS runs as root in its upstream image, so a boot-time start needs no special host privileges beyond running podman itself.

Remove

pg addon remove seaweedfs --name store               # container gone, data kept
pg addon remove seaweedfs --name store --clean-data  # also delete data dir + rendered files

The data directory is the object storage — losing it means losing every volume in it — so remove keeps it by default. --clean-data deletes the data dir, s3.json, and the filer.toml / TLS directory when present (each only after a stat — absent optionals print nothing), and refuses to touch anything that is a live mountpoint. The filer metadata database is never dropped, on any host, ever: the removal prints

  [i] The filer metadata database (10.0.0.11:35432/seaweed_store) was KEPT — pgcli never drops databases; drop it yourself if the data is disposable.

so you know exactly what to DROP DATABASE if the data is truly done with (every member’s remove prints the same notice; the database outlives all of them).

Logs

pg logs addon seaweedfs --name store      # last 50 lines
pg logs addon seaweedfs --name store -f   # follow

Limitations

What v1 deliberately does not do:

  • Cluster membership changes (add/remove/replacement nodes) are not orchestrated — --peer is a static full list; changing it means rebuilding the cluster.
  • EC erasure coding, tiering, cloud-sync (replication to other S3s), FUSE mounts, and the standalone IAM server (dynamic s3.accesskey.* users) are not managed — all remain manual pg weed territory, and IAM in particular is the only way SeaweedFS itself shares credentials dynamically, out of scope here.
  • Credential rotation is a re-install with --force on every member; pgcli never edits a live s3.json in place.
  • One bucket is seeded (instance name); further buckets are plain pg mc mb away — they land in the same filer database automatically.
  • The filer.toml DSN renders sslmode=disable; if your PostgreSQL demands TLS on that leg, pgcli’s render does not fit it (BYO --dsn with TLS is not a v1 surface).

Troubleshooting

  • requires explicit shared credentials on a --cluster install. Expected by design — run the first node with an explicit --root-user/--root-password pair and carry the same values to every remaining host (the install summary prints the ready-made command with them filled in). Single-node installs may omit them and get auto-generated keys.
  • requires a shared filer metadata database: pass --dsn …. A cluster without --dsn cannot keep one namespace across gateways. Pre-create the database and pass a host-reachable URI (published port / LAN address — a container-local 127.0.0.1:5432 is not).
  • [!] no leader yet — normal while the cluster is still assembling. The health gate’s quorum warning, not a failure: finish the remaining members' installs (or re-run this one once they are up) and it goes green.
  • [!] bucket seeding incomplete … re-run this install command. Same posture one step later: the node reached a leader but its gateway was not serving yet. Re-run the identical install after the last member joins; mb --ignore-existing makes it a clean no-op if the bucket already landed.
  • Uploads 500 on a healthy-looking single node. Historically the missing -ip signature (volumes register an auto-guessed address the data path then cannot dial); pgcli always passes -ip, so if you see it, check for a hand-edited argv or a very old binary.
  • mc: … you already own it. A bare mc mb against an existing bucket; pgcli’s own seed uses --ignore-existing, so see this only from manual mc use — add the flag.
  • Wrong-secret confusion: The request signature we calculated does not match. The pair does not match the node’s rendered s3.json — in a cluster, that means the nodes were installed with different credentials; re-run the install with the same pair + --force everywhere.
  • pulling seaweedfs image … fails on install. docker.io/chrislusf/seaweedfs:4.48_large_disk unreachable — check Docker Hub access or podman pull it first.

7 - RustFS

Run rustfs (the Rust S3-compatible object store) as a pgcli addon — single-node or erasure-coded, with the fixed container uid handled inside a purpose-built image

rustfs is a Rust reimplementation of S3-compatible object storage: the same S3 API, a web console, erasure-coded multi-drive and multi-node layouts — and a completely different runtime model from MinIO/silo. pgcli runs it as a standalone, top-level addon with the same CLI surface as minio and silo (install, TLS, BYO certs, drives, logs, autostart), sharing the one port pool, but with three differences that shape this page:

  1. A fixed container user. Upstream rustfs bakes User=rustfs (uid/gid 10001) into the image. pgcli works around this entirely inside its own wrapper image — see Privileges and ownership below — so a rustfs store needs no host-side ownership dance.
  2. Three topologies, no multi-node single-drive. rustfs speaks SNSD / SNMD / MNMD only — see Deployment modes.
  3. Its own TLS filenames. rustfs reads rustfs_cert.pem / rustfs_key.pem from RUSTFS_TLS_PATH, not MinIO’s public.crt / private.key.

Pick rustfs when you want a lean, Rust-native S3 endpoint; it can coexist with minio and silo on one host (all three draw from the same port pool).

Platform support: the rustfs addon is Linux only, in practice. The runtime model (a fixed container uid, drives on distinct block devices, host networking) is a Linux container story and is only exercised on Linux; the macOS bridge path is code-complete and the wrapper image is dual-arch, but it has not been tested on a Mac yet.

How It Works

One container per instance. The data lives in a bind-mounted host directory (default <base-dir>/addon/rustfs/<name>/data, or one directory per --drive), so it outlives the container. Unlike the minio/silo addons, pgcli does not drive the rustfs binary directly — it runs the image’s own /entrypoint.sh (via the wrapper below) because that entrypoint is what expands the multi-drive brace range in RUSTFS_VOLUMES, creates the per-drive directories, and assembles the server argv.

The image pgcli pulls is not the bare upstream one — it is ghcr.io/mars-base/pgcli/pgcli-rustfs:1.0.0, a thin pgcli wrapper built on top of docker.io/rustfs/rustfs:1.0.0 (the first GA release). pg addon install rustfs just pulls the wrapper; pgcli never builds it at run time. The tag tracks the pinned upstream version.

Credentials are handled like minio/silo:

  • root_user defaults to admin (rustfs imposes no minimum key length; anything non-empty works, and admin sidesteps the rustfsadmin warning);
  • root_password is generated on first install (or supplied via --root-password), stored in pg.yaml (addons.rustfs.<name>.root_password) and printed once in the install summary.

They are rustfs’s root access key / secret key, passed via the RUSTFS_ACCESS_KEY / RUSTFS_SECRET_KEY env vars — what every S3 client (including pg mc alias set) calls the access key and secret key.

Privileges and ownership

This is the one place rustfs genuinely differs from minio/silo, and pgcli has absorbed it into the image so it is invisible in practice.

Upstream rustfs runs as a fixed, non-configurable uid/gid (10001). Under rootless podman a host user has no claim on that uid, so the naive way to make a bind-mounted data directory writable by the process is a host-side chown dance (podman unshare chown 10001:10001 …) — fragile, and it fights with the fact that the operator may not be root. pgcli sidesteps all of it:

  • The wrapper image’s entrypoint starts as container root, chowns its own bind-mounted data directories to 10001, then su-drops to the rustfs user and execs the unmodified upstream /entrypoint.sh. pgcli passes no --user flag and does no host-side ownership work at all.
  • The result is the same on both daemon modes; only the host-visible numeric uid differs, because that is a property of podman’s user namespace, not of pgcli:
    • rootful podman → the directories land on the real host uid 10001;
    • rootless podman → they land on a subordinate host uid (subuid_start + 10001, e.g. 110001), with 10001 only visible inside the container.

Neither case needs the operator to be root or to run chown by hand. The one convention still worth knowing is that when you mount drives yourself (--drive), the mount point should be owned by the user who runs pg — under rootless podman a root-owned mount point is outside the namespace’s uid range and cannot be claimed by the in-container chown, exactly as with any bind mount.

TLS is copied, never re-owned. rustfs must read its key+cert as 10001, but the cert directory pgcli generated (0700, pgcli-owned) has to stay pgcli-owned so pg cert, CA refresh and pg backup fetch-ca keep working on it. So the wrapper does not chown that directory: it mounts it read-only and, as container root, copies the two required files into a fresh container-local directory (owned by 10001) that RUSTFS_TLS_PATH points at. No host file is ever mutated, and the BYO path uses the same copy mechanism, so BYO key/cert are mounted read-only at the required names and never chowned either.

Install

# default instance name "rustfs", ports from the shared pool, loopback bind
pg addon install rustfs

# a named instance with an explicit data directory
pg addon install rustfs --name store --data-dir /srv/rustfs

# fixed ports and a different root user
pg addon install rustfs --name store --api-port 9000 --console-port 9001 --root-user admin

# expose the store on the network instead of loopback only
pg addon install rustfs --name store --listen 0.0.0.0

# HTTPS via pgcli's self-signed CA (the prerequisite for a pgBackRest S3 repo)
pg addon install rustfs --name store --tls

# HTTPS with a certificate you already have (public-CA or private-CA cert)
pg addon install rustfs --name store --tls-cert /etc/ssl/rustfs.test.crt --tls-key /etc/ssl/rustfs.test.key

The output reports endpoints and the root credentials:

✓ rustfs installed: "store"
  Container:    pgcli-rustfs-default-store
  Image:        ghcr.io/mars-base/pgcli/pgcli-rustfs:1.0.0
  Data:         ~/pg/addon/rustfs/store/data
  S3 API:       http://127.0.0.1:9000
  Console:      http://127.0.0.1:9001

  Root user:     admin
  Root password: <generated>

Sign in to the console at the Console: URL with the printed root user and password. Point S3 clients (including pgBackRest) at the S3 API: URL, or drive them from the terminal with pg mc.

Re-running install against a live instance is a no-op: the container is not recreated (a stopped one is simply started, with a notice), the flags are merged into the stored config, and the existing root password is kept. Pass --force to recreate the container so changed ports, listen address, endpoint list, or credentials take effect — without losing the data directory.

Bind address: the default 127.0.0.1 keeps the store local. --listen 0.0.0.0 (or the listen key in pg.yaml) exposes it on the network. Anyone who can reach the port can then attempt the root credentials, so only do this behind a firewall or with TLS (--tls).

TLS (--tls)

--tls makes rustfs serve HTTPS. pgcli generates a self-signed CA and a leaf cert with the stdlib — SANs cover the loopback names, localhost, and every NIC IP of the host — into <base_dir>/tls/rustfs/<name>/: rustfs_cert.pem / rustfs_key.pem (rustfs’s required names, also mirrored as public.crt / private.key for the CA-friendly tooling) and ca.crt for distribution. The cert dir is mounted read-only and copied into the container as described in Privileges and ownership; the endpoint URL becomes https://.

Why you need it: pgBackRest forces HTTPS for S3 repositories, so a rustfs meant to receive Patroni archive-push must speak TLS. Point backup.repo.s3.ca_file at ca.crt and pgBackRest connects with full certificate verification — see Backup → S3 object storage repository. Everything that page says about a MinIO repo applies to a rustfs one: the S3 contract is identical (path-style, repo1-s3-uri-style=path).

Getting the CA onto a remote host — no scp needed. The server cert is served as a leaf+CA chain, so a consumer on another machine can pull the root straight out of a TLS handshake:

pg backup fetch-ca <store-host>:9000
#   [OK] CA fetched from <store-host>:9000
#        saved:    ~/.pgcli/backup/repo-ca/ca-<store-host>-9000.crt
#        SHA-256:  c0f0…fe2e
pg backup setup --s3-ca-file ~/.pgcli/backup/repo-ca/ca-<store-host>-9000.crt

The fetch is trust-on-first-use — compare the printed SHA-256 against the store host’s sha256sum ~/.pgcli/tls/rustfs/<name>/ca.crt before trusting it.

Bring your own certificate (--tls-cert / --tls-key)

--tls only ever serves pgcli’s own self-signed pair. To serve a certificate you already hold, pass --tls-cert <leaf(+chain).pem> --tls-key <key.pem>. Together with --tls (implied), this replaces the generated certs: the two files are mounted read-only and copied into the container at the names rustfs requires (/opt/rustfs/certs/rustfs_cert.pem, …/rustfs_key.pem); pgcli never re-owns them and never writes to their source directory.

pg addon install rustfs --name store \
  --tls-cert /etc/ssl/wildcard.example.com.crt \
  --tls-key  /etc/ssl/wildcard.example.com.key

No certificate yet? pg cert mints a self-signed leaf with whatever SANs you name, and rustfs serves it as-is (verified on a real install: the leaf rustfs presents matches the pg cert output off the live handshake, and pg mc does a full put/get round-trip against it over TLS). See Self-Cert for the mint flags, client trust-anchor, and renewal.

Everything else about BYO mode — why renewal needs --force (a single-file mount pins the source inode), how clients pick their trust anchor, and pg cert as a test-cert mint — is identical to the MinIO addon; see MinIO → Bring your own certificate. Turning BYO off: remove cert_file/key_file under this addon in pg.yaml and recreate with pg addon install rustfs --name store --force.

Deployment modes

rustfs has three layouts — there is no multi-node single-drive mode:

Mode Shape Use it for
SNSD (single-node, single-drive) one node, one data directory — the default when no --endpoint or --drive is given dev, test, demos
SNMD (single-node, multi-drive) one node, several drives — --drive per drive, see SNMD surviving a disk loss on a single host
MNMD (multi-node, multi-drive) several nodes, several drives each — --drive for this node’s drives + the --endpoint list surviving a disk loss and a node loss

There is deliberately no MNSD (multi-node single-drive) in rustfs. Passing --endpoint without --drive is rejected at install time: rustfs derives its per-drive volume range itself, so a distributed node must say how many drives it has.

rustfs hard-requires distinct physical disks. Under SNMD/MNMD, every --drive must sit on its own block device. If two drives share a device (st_dev), the rustfs process [FATAL]s at startup. pgcli launches detached, so pg addon install still exits 0 and the failure surfaces as a container that never becomes healthy — check pg logs addon rustfs --name store if a multi-drive install won’t come up. (This is stricter than MinIO/silo, which only warn.)

Single-Node Multi-Drive (SNMD)

One rustfs process, several host directories, erasure-coded across them. Pass --drive once per drive instead of --data-dir:

pg addon install rustfs --name store \
  --drive /mnt/rustfs/disk1 --drive /mnt/rustfs/disk2 \
  --drive /mnt/rustfs/disk3 --drive /mnt/rustfs/disk4 --tls

Each --drive is a host directory on its own device; drive N (0-indexed) is bind-mounted at container path /data/rustfsN, and RUSTFS_VOLUMES is set to the brace range /data/rustfs{0...3} that the image’s /entrypoint.sh expands into the individual directories. --drive is mutually exclusive with --data-dir; combining --drive with --endpoint is MNMD.

pg addon remove rustfs --name store --clean-data deletes each drive directory — but refuses any drive that is still a mount point, so an accidental --clean-data can never rm -rf through a live mount into the disk below. Unmount first if the data below is really disposable.

Distributed / Cluster Mode (MNMD)

Every node runs its own pgcli with its own pg.yaml; each pg.yaml carries the same full endpoint list and the same root credentials. For rustfs the --endpoint list is one scheme://host:port per node (no path — rustfs derives the /data/rustfsN volume range from --drive), and each node passes its own drives:

# on node 1 (10.0.0.11), four dedicated data disks:
pg addon install rustfs --name store \
  --listen 0.0.0.0 \
  --root-password '<shared-secret>' \
  --drive /mnt/rustfs/d1 --drive /mnt/rustfs/d2 --drive /mnt/rustfs/d3 --drive /mnt/rustfs/d4 \
  --endpoint http://10.0.0.11:9000 --endpoint http://10.0.0.12:9000 \
  --endpoint http://10.0.0.20:9000 --endpoint http://10.0.0.21:9000

# nodes 2-4: same command, own --drive, and the SAME --endpoint list
# AND the SAME --root-password value.

Two things matter beyond the identical config: --listen must be 0.0.0.0 (or the node’s own reachable address), not the loopback default — under podman host networking the endpoints advertise each node’s real IP, and a node listening only on 127.0.0.1 can never be joined. And every node must carry the same endpoint list and root credentials: rustfs derives one shared erasure set from them, so a mismatch splits the ring into independent standalones.

--endpoint values are scheme://host:port with no path, repeated once per node (a comma-joined --endpoint a,b,c is equivalent — it is a string-slice flag). pgcli appends the per-node /data/rustfs{0...N-1} drive range and joins the four URLs with spaces into a single RUSTFS_VOLUMES. (The RUSTFS_VOLUMES value itself must be space-joined, not comma-joined: the rustfs binary mis-splits it, collapsing http:// to http:/ so a node can’t resolve its own disks — the first-listed node aborts with VolumeNotFound and the peers hang at waiting for storage_quorum, never forming a writable cluster. Space-separated literals parse exactly like the documented compact http://node{1...4}:9000/data/rustfs{0...3} brace form, but let you use plain per-node IPs with no /etc/hosts or DNS.)

Cross-host MNMD is verified on a real 4-node × 4-drive cluster (Linux, rootful podman): all four serve /health 200, and an object written once reads back byte-identical from every node — the erasure shards spread across all 16 drives.

Using the mc Client

pg mc runs MinIO’s mc client in a throwaway container and speaks rustfs’s S3 API like any other store:

pg mc alias set store http://127.0.0.1:9000 admin <password>    # Linux
pg mc mb store/backups
pg mc ls store
pg mc cp ./dump.pglz store/backups/

The S3 data plane (PUT/GET) is proven end-to-end against rustfs via pgBackRest and a basic mc round-trip, including a full PITR sequence — base backup, archive-push of the WAL, and a --time restore that replayed the archived WAL out of rustfs and stopped exactly at the target (Linux, rootless podman). Note honestly: the administrative mc surface (alias-set validation, bucket policies, admin commands) has not been exhaustively exercised against rustfs. Use it for plain object put/get with the understanding that some MinIO-specific admin commands may not map onto rustfs.

Ports

Each instance takes two consecutive ports from one pool, starting at minio_start_port (default 9000): the S3 API first, the console second. The pool is shared across minio, silo, and rustfs — all three are assigned from one cursor, so they coexist on a host without collision (minio first by name, then silo, then rustfs):

pg addon install minio  --name store   # 9000 / 9001
pg addon install silo   --name lake    # 9002 / 9003
pg addon install rustfs --name archive # 9004 / 9005

Configuration

Instances live under the top-level addons.rustfs map in pg.yaml:

namespace: default
minio_start_port: 9000       # shared pool: minio, silo AND rustfs draw from this
addons:
  rustfs:
    store:
      container_name: pgcli-rustfs-default-store
      name: store
      image_tag: ghcr.io/mars-base/pgcli/pgcli-rustfs:1.0.0
      # data_dir: /srv/rustfs    # omit for <base-dir>/addon/rustfs/store/data
      # drives:                  # multi-drive (SNMD/MNMD): one host dir per
      #   - /mnt/rustfs/d1       # drive, mounted at /data/rustfs0../rustfsN
      #   - /mnt/rustfs/d2
      listen: 127.0.0.1
      api_port: 9000
      console_port: 9001
      root_user: admin
      root_password: <generated>   # written on first install
      autostart: false             # pg autostart enable --rustfs --name store
      # tls: true                  # serve HTTPS (self-signed CA, or BYO below)
      # cert_file: /etc/ssl/rustfs.test.crt   # BYO leaf(+chain), implies tls
      # key_file:  /etc/ssl/rustfs.test.key   # BYO private key, must pair with cert_file
      # endpoints:                 # omit for single-node; one per node for MNMD:
      #   - http://10.0.0.11:9000
      #   - http://10.0.0.12:9000

Edits to listen, ports, root_user, root_password, image_tag, data_dir, tls/cert_file/key_file, or endpoints take effect after the next pg addon install rustfs --name store --force.

List

pg addon list
Infra add-ons (rustfs):
  rustfs (name: store)
    Status:      running
    Listen:      127.0.0.1
    API port:    9000
    Console port: 9001
    Console URL: http://127.0.0.1:9001/
    Data:        ~/pg/addon/rustfs/store/data
    Root user:   admin
    Image:       ghcr.io/mars-base/pgcli/pgcli-rustfs:1.0.0
    Container:   pgcli-rustfs-default-store

pg addon list never prints the password. Reveal it deliberately with pg addon list --show-password (appends a Root password: line), or print just the secret for scripting: pg addon password rustfs --name store (the access-key secret, paired with the Root user: above; --file <path> writes it mode 0600). Health is on GET /health (returns 200), unlike MinIO’s /minio/health/live.

Start and stop

pg addon start rustfs --name store
pg addon stop  rustfs --name store

install skips a still-present container (starting it if stopped); start only starts an existing one (and self-heals an improper state by recreating it from the config). In TLS generated mode start also re-validates and, if needed, re-signs the leaf.

Auto-start on Boot

Containers carry a --restart unless-stopped policy (crashes, not reboots). To bring instances up after a host reboot:

pg autostart enable --rustfs --name store

rustfs’s fixed container uid is handled inside pgcli’s wrapper image, so a boot-time start needs no special host privileges beyond running podman itself. Boot is start-only; rustfs is independent of the PostgreSQL stack, so it is started last.

Remove

pg addon remove rustfs --name store            # container gone, data kept
pg addon remove rustfs --name store --clean-data   # also delete the data directory

The data directory is the object storage — losing it means losing every bucket in it — so remove keeps it by default. --clean-data deletes it (and prunes the now-empty default-layout parent directory). Under rootless podman the objects are owned by a subordinate uid that plain rm cannot unlink, so --clean-data transparently falls back to podman unshare rm to reclaim them.

Logs

pg logs addon rustfs --name store      # last 50 lines
pg logs addon rustfs --name store -f   # follow

Troubleshooting

  • pulling rustfs image ... : ... on install. The wrapper tag ghcr.io/mars-base/pgcli/pgcli-rustfs:1.0.0 is not reachable — check network access to ghcr.io, or pre-pull it with podman pull.
  • A multi-drive install won’t become healthy. rustfs [FATAL]s when two drives share a physical device. Check pg logs addon rustfs --name store for the disk check firing, and make sure each --drive is on its own device (a separate disk or its own loop mount).
  • Rootless podman can’t write a drive. A drive’s mount point is owned by root, outside the namespace’s uid range, so the container can’t claim it. chown the mount point to the user who runs pg.
  • Port collision on manual --api-port. The pool is shared across minio/silo/rustfs; an explicit port must be dodged by the auto-assigner for all three. Each store needs a consecutive pair.
  • --clean-data leaves a directory behind. Under rootless podman a subordinate-uid tree is removed via the podman unshare rm fallback; if that path is unavailable, remove it yourself with podman unshare rm -rf <dir>.

8 - HAProxy

Run HAProxy as a pgcli addon — a TCP load balancer in front of a Patroni cluster (unified or read/write split), or your own haproxy.cfg via –conf-file for arbitrary native proxying

HAProxy is the load balancer the Patroni docs recommend putting in front of a cluster: clients connect to one stable address, HAProxy health-checks each member’s REST API, and routes writes to the current leader (and, in read/write-split mode, reads to the replicas). pgcli runs it as a standalone, top-level addon — shared routing infrastructure, not a per-instance sidecar — pinned to the official haproxy:3.2.23-alpine image.

Platform support: the HAProxy addon is Linux-only for now. It reaches Patroni members over the host network, which the macOS podman machine does not expose to containers. On macOS NewHAProxyManager fails fast with a clear message; pg addon list still shows installed instances without live status.

How It Works

Routing follows the official Patroni haproxy.cfg pattern. Each backend is a Patroni member; two ports matter per member:

  • the PostgreSQL port — the TCP port HAProxy actually forwards connections to;
  • the REST API port — where HAProxy sends its httpchk health check.

Patroni’s REST API answers these GETs (unauthenticated by design):

Endpoint Returns 200 on
GET / the leader only
GET /replica (optionally ?lag=<max>) replicas only, and only if their lag is within the limit

So the leader is the sole UP server for a write listener, and the replicas are the sole UP servers for a read listener — failover is picked up automatically as the health checks flip. pgcli renders this into <base-dir>/addon/haproxy/<name>/haproxy.cfg and bind-mounts it read-only into the container.

Two routing modes

The mode is chosen with --mode:

  • unified (default) — a single listener sends all traffic to the current leader. Simple; every connection can read and write. On leader change the write listener uses on-marked-down shutdown-sessions to drop stale connections so clients reconnect to the new leader.
  • split — read/write separation: a _<name>_rw listener routes writes to the leader, and a separate _<name>_ro listener spreads reads across the replicas (round-robin, lag-filtered). Two client ports instead of one.

Two configuration modes

Above those two routing modes sits a choice of who writes haproxy.cfg:

  • Rendered (default) — pgcli generates the config from --node/--ha plus --mode, ports and --max-lag, and rewrites it on every install. This is the Patroni read/write proxy described above.
  • Custom (--conf-file <path>) — you provide the full haproxy.cfg and pgcli runs it verbatim, for any native HAProxy proxying (plain TCP relays, HTTP frontends, extra listeners — anything HAProxy does), not just a Patroni cluster. pgcli copies the file into its config directory, mounts that copy read-only, validates it with haproxy -c before (re)starting the container, and never rewrites or deletes your original. After an edit, pg addon haproxy reload re-validates the file and hot-reloads the running instance without dropping connections (conf-file instances only — see Hot reload). All listeners come from the file; --mode, --rw-port/--ro-port/--stats-port, --max-lag, --listen and --node/--ha have no meaning there and are rejected or ignored — see Custom config file.

Stats page

Every instance also gets an HTTP stats listener so you can watch server up/down state in a browser: http://<listen>:<stats-port>/.

Install

Backend members are supplied one of two ways (mutually exclusive), or bypassed entirely with --conf-file (see Custom config file):

  • --node NAME=HOST:PGPORT:RESTPORT (repeatable) — list them explicitly;
  • --ha <scope> — auto-derive every local member of a Patroni scope that pg ha manages, using each member’s PostgreSQL and REST API ports.

What each --node field means — for node1=10.0.0.11:35532:8008:

Field Meaning
node1 member name — becomes the server name in haproxy.cfg and the label in the stats page
10.0.0.11 address where this member is reachable from this host (the member’s advertise-host, or 127.0.0.1 on the same host)
35532 the member’s PostgreSQL port that HAProxy forwards connections to
8008 the member’s Patroni REST API port, used for the health check

With --ha, all four come from pg.yaml: the Patroni member name, its advertise-host (default 127.0.0.1), and its host_port / restapi_port.

# unified: one port, everything to the leader, backends auto-derived from scope "app"
pg addon install haproxy --name lb --ha app

# split: rw + ro listeners, reads capped at 1MB replica lag
pg addon install haproxy --name lb --mode split --ha app --max-lag 1MB

# explicit backends (e.g. members on other hosts, or a scope pgcli doesn't manage)
pg addon install haproxy --name lb --mode split \
  --node node1=10.0.0.11:35532:8008 \
  --node node2=10.0.0.11:35533:8009 \
  --node node3=10.0.0.11:35534:8010

The output reports the assigned ports and a ready-to-use connect URL:

✓ haproxy installed: "lb"
  Container:    pgcli-haproxy-default-lb
  Image:        docker.io/library/haproxy:3.2.23-alpine
  Mode:         split
  Patroni:      app
  Backends:     3
  Read-write:   127.0.0.1:5000
  Read-only:    127.0.0.1:5001 (lag ≤ 1MB)
  Stats:        http://127.0.0.1:5002/
  Config:       ~/pg/addon/haproxy/lb/haproxy.cfg

  Connect via HAProxy:
    postgres://<user>@127.0.0.1:5000/<database>

Adding or removing members later

The backend list follows the scope’s local members recorded in pg.yaml, so any topology change — or removal — is picked up by re-running the same install command: it re-derives the full backend list and recreates the container.

Added with pg ha create <scope> --member <m>, the new member is not in the running HAProxy config yet:

pg ha create app --member node3 --etcd m1
pg addon install haproxy --name lb --mode split --ha app --max-lag 1MB
# Backends: 2 -> 3, and haproxy.cfg gains: server node3 127.0.0.1:35534 ... check port 8011

Symmetrically, after pg ha remove <scope> --member <m> the removed member would otherwise linger in the config as a stale backend — re-running install drops it:

pg ha remove app --member node3
pg addon install haproxy --name lb --mode split --ha app --max-lag 1MB
# Backends: 3 -> 2, and the server node3 line is gone

For an explicit --node install there is no auto-derivation: edit the --node list itself (add or drop a spec) and re-run — the target list is replaced wholesale each time, so the command always reflects the full set you want.

Cross-host clusters

--ha derives backends from this host’s pg.yaml, which lists only the members this host’s pg ha create manages. A member living on another host was never a backend here — adding or removing one there requires no re-sync on this host (and leaves nothing stale). To front the whole cluster through one HAProxy, use an explicit --node list, with each member’s advertised host:

pg addon install haproxy --name lb --mode split \
  --node node1=10.0.0.11:35532:8008 \
  --node node2=10.0.0.12:35532:8008 \
  --node node3=10.0.0.13:35532:8008
# later: add one more --node spec (or drop one) and re-run — the list replaces wholesale

Caveat: an instance installed with --ha on one host routes writes only to a local leader — if failover promotes a remote member, the rw listener has no UP server until the leader moves back. For cross-host clusters where the leader can move, prefer the explicit all-members --node list (or run one HAProxy per host and front it with a higher-level VIP/DNS).

Custom config file

The rendered mode above is pgcli’s opinion about Patroni routing. With --conf-file you skip the render entirely and run your own haproxy.cfg — arbitrary native HAProxy: plain TCP relays, HTTP frontends, any number of frontend/backend/listen sections, anything the upstream software supports. pgcli keeps only the container lifecycle (pull, create, start, stop, remove, autostart) and the config gate:

pg addon install haproxy --name custom --conf-file /root/haproxy/lb.cfg

--conf-file is mutually exclusive with --node/--ha (the install is rejected with an error), and the file must exist and be non-empty. A typical file mixes a raw TCP relay with an unrelated HTTP listener:

global
    maxconn 1000
    log stdout format raw local0 info

defaults
    log global
    mode tcp
    timeout client 30m
    timeout connect 4s
    timeout server 30m

# plain TCP relay to a PostgreSQL instance (pgcli derives nothing here)
frontend pg_relay
    bind 10.0.0.11:7000
    default_backend pg

backend pg
    server demo 127.0.0.1:35432 check

# an HTTP-mode listener for something unrelated
listen webstats
    mode http
    bind 127.0.0.1:7001
    http-request return status 200 content-type text/plain lf-string "haproxy custom proxy alive\n"

The summary then reports the custom mode instead of ports (there are none to report — they live in your file):

✓ haproxy installed: "custom"
  Container:    pgcli-haproxy-default-custom
  Image:        docker.io/library/haproxy:3.2.23-alpine
  Mode:         custom (user config — all listeners come from the file)
  Config:       /root/.pgcli/addon/haproxy/custom/haproxy.cfg (from /root/haproxy/lb.cfg)

How the mode behaves, point by point (all of this is what an install on a real host does):

  • Your file is the source of truth; pgcli’s copy is what runs. Install copies it to <base-dir>/addon/haproxy/<name>/haproxy.cfg and bind-mounts that copy read-only. Your original is never rewritten, and pg addon remove deletes only pgcli’s copy — your file stays where you put it.
  • Edits apply via reload (seamless) or re-install (lossy). Change the file, then either pg addon haproxy reload to hot-apply it to the running container without dropping connections, or re-run the same install to recreate the container. Both first re-copy your file and validate it with haproxy -c. Editing the rendered-mode knobs does nothing here — --mode, --rw-port/--ro-port/--stats-port, --max-lag and --listen describe the generator, not your file. See Hot reload.
  • Everything is validated before the container is touched. Each install runs the mounted copy through haproxy -c (check-only) in a throwaway container first. A bad file fails the install with HAProxy’s own diagnostics, exits non-zero, and restores the previous good copy — a running container and the on-disk config are left exactly as they were, so a later reboot or pg addon start cannot resurrect a rejected config. (Warnings — missing timeouts and the like — pass; only real errors are refused.)
  • Ports are yours to choose. The pool allocator skips conf-file instances; it neither assigns nor learns the ports in your file. Pick listener ports yourself and keep them clear of rendered-mode instances’ auto-assigned ports and everything else on the host — HAProxy binds fail at start with cannot bind socket if you collide.
  • The container runs with host networking, like the rendered mode. A frontend bound to 127.0.0.1 is reachable from the host itself; to let other containers/hosts in, bind the host’s address (as pg_relay above does).
  • Health of the proxies is your config’s business. pg logs <name> shows HAProxy’s own stdout (if your file logs there, as the sample does), and any stats page is whatever stats section you wrote — pgcli does not add one.
  • Switching back is just an install without --conf-file: pass --node/--ha again and the instance returns to rendered mode (the conf-file copy on disk is overwritten by the generated config).

Example: HTTP load balancer with health checks

A conf-file instance is a full HAProxy, so the Patroni pattern is not the only thing it can do — here is an HTTP round-robin balancer over several app servers with active health checks (this exact config was run and the DOWN/UP behaviour observed in pg logs):

global
    maxconn 4096
    log stdout format raw local0 info

defaults
    log global
    mode http
    retries 2
    timeout client 30m
    timeout connect 4s
    timeout server 30m
    timeout http-request 30s

frontend http_in
    bind 127.0.0.1:8180
    default_backend http_pool

backend http_pool
    # round-robin across the app servers; health-checked via GET /
    option httpchk GET /
    http-check expect status 200
    default-server inter 3s fall 3 rise 2
    server app1 127.0.0.1:8081 check
    server app2 127.0.0.1:8181 check
    # add more: server app3 127.0.0.1:<port> check

What each piece does, and what was observed live:

  • Multiple server lines — HAProxy round-robins new connections across the UP servers (add a line per backend; the list order is the starting rotation).
  • option httpchk GET / + http-check expect status 200 — the health probe is an HTTP GET / and only 200 counts as UP. Match the method and the expected code to what the app actually answers: a server that returns 405 to HEAD but 200 to GET needs the GET form, not the HEAD / default.
  • default-server inter 3s fall 3 rise 2 — probe every 3s, mark DOWN after 3 consecutive failures, return to service after 2 successes.
  • check on each server turns the probe on for that server.

When a backend is unreachable its probe fails and, after fall 3, HAProxy drops it from rotation and logs it — pg logs <name> showed:

Server http_pool/app2 is DOWN, reason: Layer4 connection problem, info: "Connection refused", check duration: 0ms. 1 active and 0 backup servers left. ...

and all frontend traffic kept returning 200 by flowing only to the surviving app1. Once app2’s port answers again it clears rise 2 and rejoins the rotation — no reload needed. To add or remove a server line, edit the file and run pg addon haproxy reload (see Hot reload): it re-validates with haproxy -c and hot-swaps the worker without dropping in-flight connections. Backend membership changes are cleanest still through the health-check path above (a server you stop is pulled from rotation with no reload at all); reload is for when you change the server list itself.

Tuning concurrency (threads)

HAProxy’s model is one process, many threads — there is no nginx-style worker_processes. In conf-file mode you tune it from the global section of your own file (the rendered mode does not set any of these):

  • nbthread N — the number of worker threads. Validated against the image: haproxy -c accepts nbthread 4.
  • default when unset — HAProxy spreads threads across the machine’s CPUs automatically on a multi-processor host (its own wording: “Threads will automatically be used on multi-processor machines if available”), so you only need nbthread to pin a specific count.
  • cpu-map auto:1-N 0-M — optionally bind thread 1…N to CPU cores 0…M (validated).
  • nbproc no longer exists. Since HAProxy 2.5 it is refused outright (haproxy -c fails with “nbproc is not supported any more since HAProxy 2.5”). Use threads, not processes.
global
    nbthread 4
    cpu-map auto:1-4 0-3
    maxconn 4096
    log stdout format raw local0 info

Changing it means editing the file and running pg addon haproxy reload — the master re-reads the config and starts a fresh worker with the new thread count (verified: nbthread 2 → 4 applied with no dropped connections), so unlike a re-install it doesn’t cut in-flight traffic. This is a config knob in your file, not a pgcli flag.

Hot reload

--conf-file instances support seamless config reload — the HAProxy equivalent of pg addon nginx reload:

pg addon haproxy reload --name custom

The official image already runs HAProxy in master-worker mode (-W): pid 1 is the master, a child is the worker. reload sends the master SIGUSR2, so it starts a new worker from the config on disk, hands the listening sockets over, and lets the old worker drain its in-flight connections before exiting — no dropped connections, unlike the lossy container recreate that install performs. (This is verified behaviour, not just theory: a running instance’s worker was swapped end-to-end while it kept serving 200s.)

Before it signals anything, reload does exactly what install’s gate does — it is not a blind signal:

  1. re-copies your --conf-file to the mounted haproxy.cfg (verbatim);
  2. runs the copy through haproxy -c (check-only) in a throwaway container;
  3. only if it validates does it send SIGUSR2. A file that fails the check aborts the reload with HAProxy’s own diagnostics (non-zero exit), restores the previous good copy on disk, and leaves the running container untouched — so a rejected edit can never be picked up by a later restart either.

Requirements and scope:

  • --conf-file instances only. A rendered instance rebuilds its config from --node/--ha on every install and takes no hand-edits, so its update path stays pg addon install haproxy. Running reload on it is refused with that advice.
  • The container must be running. reload signals the live master; if the instance is stopped, start it (pg addon start haproxy --name custom) — a fresh install also picks up the edited file.
  • reload is for changing the running config in place. Turning a backend off for maintenance still needs no reload at all — the health check pulls it from rotation; reload is for editing the server list / global knobs themselves.

The same reload is available on install via --reload: for a running conf-file instance it validates and hot-reloads instead of recreating the container, so one command both (re)configures and applies without dropped connections:

pg addon install haproxy --name custom --conf-file /root/haproxy/lb.cfg --reload

Without --reload, install keeps its default recreate-the-container behaviour (lossy). --reload on a stopped or rendered instance is a no-op warning — it just installs normally.

Read/Write Split in Practice

After installing with --mode split, two client ports are exposed:

Port Traffic Backend
write_port (default 5000) Read + write Leader only
read_port (default 5001) Read only Replicas (round-robin, lag ≤ max-lag)
stats_port (default 5002) HTTP stats page —
# Write (always hits the current leader)
psql "host=127.0.0.1 port=5000 user=postgres dbname=postgres"

# Read (load-balanced across replicas)
psql "host=127.0.0.1 port=5001 user=postgres dbname=postgres"

After a failover, HAProxy picks up the new leader automatically via health checks — no connection string change needed. A browser at http://127.0.0.1:5002/ shows real-time backend state.

Ports

Ports are auto-assigned from a per-host pool, three consecutive free ports per instance (rw, then ro if split, then stats), starting at haproxy_start_port (default 5000). Override any of them explicitly:

pg addon install haproxy --name lb --ha app \
  --rw-port 6000 --ro-port 6001 --stats-port 6002

Because the pool scans for free ports and tracks what every HAProxy instance has already taken, you can run many instances on one machine without collisions. A split instance consumes 3 ports (rw / ro / stats), a unified instance 2 (rw / stats):

pg addon install haproxy --name lb1 --mode split --ha app     # 5000 / 5001 / 5002
pg addon install haproxy --name lb2 --ha report              # 5003 / 5004

The bind address defaults to 127.0.0.1; set --listen 0.0.0.0 — or the listen key in pg.yaml — to expose the listeners on the network. Keep it on loopback unless the backends require otherwise; there is no authentication in front of PostgreSQL here.

Configuration

Everything lives under the top-level addons.haproxy map in pg.yaml, keyed by instance name:

namespace: default
haproxy_start_port: 5000
addons:
  haproxy:
    lb:
      mode: split            # unified | split
      ha_scope: app          # scope the backends came from (for --ha re-derivation)
      listen: 127.0.0.1
      write_port: 5000
      read_port: 5001
      stats_port: 5002
      replica_max_lag: 1MB   # split mode only
      autostart: false       # pg autostart enable --haproxy --name lb
      image_tag: docker.io/library/haproxy:3.2.23-alpine
      # conf_file: /root/haproxy/lb.cfg   # custom mode (see above; skips targets/mode/ports)
      targets:
        - { name: node1, host: 127.0.0.1, pg_port: 35532, rest_port: 8008 }
        - { name: node2, host: 127.0.0.1, pg_port: 35533, rest_port: 8009 }

targets is rendered from and re-derived by install; edit mode, ports, replica_max_lag, or image_tag here for fine control, then pg addon install haproxy --name lb ... to apply. The rendered haproxy.cfg carries no secrets — only hosts, ports, and health-check URIs.

List

pg addon list
Infra add-ons (haproxy):
  haproxy (name: lb)
    Status:      running
    Mode:        split
    Patroni:     app
    Read-write:  127.0.0.1:5000
    Read-only:   127.0.0.1:5001
    Stats:       http://127.0.0.1:5002/
    Backends:    3
      - node1        127.0.0.1:35532 (check :8009)
      - node2        127.0.0.1:35533 (check :8010)
      - node3        127.0.0.1:35534 (check :8011)

A conf-file instance shows its source instead of ports and backends:

  haproxy (name: custom)
    Status:      running
    Mode:        custom (user config)
    Config:      /root/haproxy/lb.cfg

Start and stop

After a host reboot, bring an instance back without re-rendering config:

pg addon start haproxy --name lb
pg addon stop  haproxy --name lb

install always recreates the container so config changes take effect; start only starts an existing one (and self-heals an improper state by recreating from the haproxy.cfg on disk). For a --conf-file instance, pg addon haproxy reload applies an edited file to a running container without that recreate — see Hot reload.

Auto-start on Boot

Containers carry a --restart unless-stopped policy (crashes, not reboots). To bring an instance up after a host reboot:

pg autostart enable --haproxy --name lb

This sets autostart: true and installs/refreshes the boot service (see Auto-start on Boot). Boot is start-only: it starts the existing container reading the haproxy.cfg already on disk, and never re-renders config — install the instance first. The boot service starts HAProxy after the Patroni members, so its backends are already coming up. pg autostart status lists every target’s state.

Remove

pg addon remove haproxy --name lb

Stops and removes the container and deletes its config directory.

Logs

pg logs addon haproxy --name lb       # last 50 lines
pg logs addon haproxy --name lb -f    # follow

The container logs to stdout (log stdout format raw local0 info), so health-check transitions and connection events show up here.

Troubleshooting

  • All backends DOWN in the stats page. The health check hits each member’s REST API port. Confirm it is reachable — curl http://<host>:<rest_port>/ returns 200 on the leader, 503 elsewhere; /replica is the mirror image. A 000 means the REST API is down or the port is wrong.
  • --ha finds no members. --ha only derives local members that pg ha manages in pg.yaml. For remote members, or a scope pgcli doesn’t manage, list them with --node.
  • Port collision on manual --rw-port. Pick a port outside the auto pool (haproxy_start_port and up) or the auto-assigner will treat it as taken.
  • A conf-file install fails haproxy -c but the old config keeps running. That is the designed behaviour: the rejected copy is rolled back and the container untouched. Fix the file (HAProxy’s error names the line) and re-install. To see why a started container died anyway (cannot bind socket, missing files your config references), check pg logs <name>.
  • reload says “container is not running”. Reload signals the live master, so the instance must be up first — pg addon start haproxy --name <name> (or a fresh pg addon install, which also picks up the edited file).
  • reload rejects the file with haproxy -c errors. Same gate as install: the reload is aborted, the previous good copy is restored, and nothing was reloaded — fix the line HAProxy names and reload again.
  • macOS. Not supported yet — HAProxy needs host networking to reach Patroni members, which the podman machine VM does not provide to containers.

9 - Silo

Run silo (Pigsty’s MinIO fork) as a pgcli addon — single-node or distributed S3-compatible object storage with web console

silo is Pigsty’s maintained fork of MinIO: S3-compatible object storage with the web console bundled in, keeping MinIO’s wire contract end to end — the S3 API, the MINIO_* environment variables, the server /data --address :9000 --console-address :9001 command line, the --certs-dir layout, and erasure-coded cluster mode. pgcli runs it as a standalone, top-level addon with exactly the same surface as the minio addon — install, TLS, BYO certs, distributed mode, logs, autostart. Pick silo over MinIO if you follow Pigsty’s releases; the two can coexist on one host (they share one port pool, assigned without collision).

Platform support: the silo addon works on both platforms. Linux serves over host networking; macOS joins the pgcli-net bridge with its two ports published, so the Mac reaches the API and console on 127.0.0.1:<port> like any other addon. The public image is dual-arch (amd64 + arm64). Both clients — pg mcli (silo’s own) and pg mc (MinIO’s) — work on both platforms and against a silo store alike.

How It Works

One container, one directory: silo server /data --address <listen>:<api-port> --console-address <listen>:<console-port>, where /data is a bind mount of the instance’s host data directory (default <base-dir>/addon/silo/<name>/data). Everything silo stores lives there, so it outlives the container.

The image is the public upstream tag docker.io/pgsty/silo:RELEASE.2026-09-16T00-00-00Z — dual-arch, console included, and it ships the mcli client too — so pg addon install silo just pulls it; pgcli never builds the image at run time (unlike pgcli-minio, which is a self-maintained tag because MinIO’s official image dropped the console). pgcli drives the silo binary directly via an explicit --entrypoint silo, bypassing the image’s entrypoint wrapper, exactly as it does for MinIO.

Credentials are handled like Patroni’s:

  • root_user defaults to admin;
  • root_password is generated on first install (or supplied explicitly via --root-password) and stored in pg.yaml (addons.silo.<name>.root_password) and printed once in the install summary for convenience.

They are silo’s root access key / secret key — passed through the MINIO_ROOT_USER / MINIO_ROOT_PASSWORD env vars silo inherits from MinIO — what every S3 client (and pg mcli alias set <name> <url> <root_user> <root_password>) calls the access key and secret key.

The container runs --ulimit nofile=1048576:1048576 and --stop-timeout 60 as MinIO’s deployment docs recommend (the contract carries over). On macOS the podman machine VM caps RLIMIT_NOFILE lower, so the value used there is 65536 — plenty for a single-host dev/test store. Root credentials passed as -e are visible in podman inspect — the same exposure as any hand-run container; fine for a rootless single-host deployment, which is what this is.

Install

# default instance name "silo", ports from the shared pool (base 9000), loopback bind
pg addon install silo

# a named instance with an explicit data directory
pg addon install silo --name store --data-dir /srv/silo

# fixed ports and a different root user
pg addon install silo --name store --api-port 9000 --console-port 9001 --root-user admin

# expose the store on the network instead of loopback only
pg addon install silo --name store --listen 0.0.0.0

# HTTPS via pgcli's self-signed CA (the prerequisite for a pgBackRest S3 repo)
pg addon install silo --name store --tls

# HTTPS with a certificate you already have (public-CA or private-CA domain cert)
pg addon install silo --name store --tls-cert /etc/ssl/silo.test.crt --tls-key /etc/ssl/silo.test.key

The output reports endpoints and the root credentials:

✓ silo installed: "store"
  Container:    pgcli-silo-default-store
  Image:        docker.io/pgsty/silo:RELEASE.2026-09-16T00-00-00Z
  Data:         ~/pg/addon/silo/store/data
  S3 API:       http://127.0.0.1:9000
  Console:      http://127.0.0.1:9001

  Root user:     admin
  Root password: <generated>

Sign in to the console at the Console: URL with the printed root user and password. Point S3 clients (including pgBackRest) at the S3 API: URL, or drive them from the terminal with pg mcli below.

Re-running install against a live instance is a no-op: the container is not recreated (a stopped one is simply started, with a notice), the flags are merged into the stored config, and the existing root password is kept. Pass --force to recreate the container so changed ports, listen address, endpoint list, or credentials take effect — without losing the data directory.

Bind address: the default 127.0.0.1 keeps the store local. --listen 0.0.0.0 (or the listen key in pg.yaml) exposes it on the network. Anyone who can reach the port can then attempt the root credentials, so only do this behind a firewall or with TLS (--tls, below).

TLS (--tls)

--tls makes silo serve HTTPS. pgcli generates a self-signed CA and a leaf cert with the stdlib — SANs cover the loopback names, localhost, and every NIC IP of the host — into <base_dir>/tls/silo/<name>/: public.crt / private.key for silo’s --certs-dir, and ca.crt for distribution. The cert dir is mounted read-only and the endpoint URL becomes https://.

Why you need it: pgBackRest forces HTTPS for S3 repositories (plaintext is an upstream-rejected option), so a silo meant to receive Patroni archive-push must speak TLS. Point backup.repo.s3.ca_file at ca.crt and pgBackRest connects with full certificate verification — see Backup → S3 object storage repository. Everything that page says about a MinIO repo applies verbatim to a silo one: the client contract is identical.

One note on pairing stores with clusters: backup.repo.s3 is a single, global repo per config file, so the first TLS store you wire up — minio or silo — receives every stanza in that environment. If you truly need two destinations, run a second config (see Backup → Shared Backup Container, and the worked Example: HA Cluster with a Self-CA MinIO).

pg mcli adds --insecure automatically when a command targets a TLS store via a loopback alias (mcli persists no CA trust per alias; same-host loopback makes this acceptable). An alias to a LAN-IP endpoint is not loopback — append -- --insecure yourself, or set up the CA properly. External https:// endpoints keep full verification. Toggling --tls on an existing instance needs --force to take effect.

Lifetimes and access from other hosts. CA and leaf are both long-lived; pgcli re-signs the leaf on --force, or whenever a host address changes (silo watches its cert files and hot-reloads a re-signed pair, which is how a deployment picks up the new chain without a recreate), so handing ca.crt to clients is a one-time act per store. A TLS client validates the address it dials against the leaf’s SANs — the client’s own address never matters. Remote hosts therefore point backup.repo.s3.endpoint at one of the store host’s IPs (loopback names and every NIC IP, virtual bridges included, are in the SAN; raw hostnames are not — unless you set MINIO_SERVER_URL, whose host is added).

Getting the CA onto a remote host — no scp needed. The server cert is served as a leaf+CA chain, so a consumer on another machine can pull the root straight out of a TLS handshake:

pg backup fetch-ca <store-host>:9002
#   [OK] CA fetched from <store-host>:9002
#        saved:    ~/.pgcli/backup/repo-ca/ca-<store-host>-9002.crt
#        SHA-256:  c0f0…fe2e
pg backup setup --s3-ca-file ~/.pgcli/backup/repo-ca/ca-<store-host>-9002.crt

The fetch is trust-on-first-use — compare the printed SHA-256 against the store host’s sha256sum ~/.pgcli/tls/silo/<name>/ca.crt before trusting it. One setup then republishes the CA into the Patroni cluster’s etcd registry, so every other cluster host gets it with no manual step at all (see Backup → S3 object storage repository).

Bring your own certificate (--tls-cert / --tls-key)

--tls only ever serves pgcli’s own self-signed pair. To serve a certificate you already hold — one signed by a public CA for a real domain, or one issued by your private CA — pass --tls-cert <leaf(+chain).pem> --tls-key <key.pem> instead. Together with --tls (which it implies, so you don’t need to also pass it), this replaces the generated certs: the two files are mounted read-only straight at the names silo’s --certs-dir requires (/opt/silo/certs/public.crt, /opt/silo/certs/private.key), and pgcli never copies or re-signs them — the private key stays in exactly the one place you put it.

pg addon install silo --name store \
  --tls-cert /etc/ssl/wildcard.example.com.crt \
  --tls-key  /etc/ssl/wildcard.example.com.key

Everything else about BYO mode — what install checks, why renewal needs --force (a single-file mount pins the source inode), how clients pick their trust anchor, and pg cert as a test-cert mint — is identical to the MinIO addon; see MinIO → Bring your own certificate. The pg cert example, adapted:

pg cert --host "silo.test,127.0.0.1,10.0.0.9" \
  --cert-file silo.crt --key-file silo.key
pg addon install silo --name store --tls-cert silo.crt --tls-key silo.key

Turning BYO off. There is no off flag — the config merge across re-runs is one-way, matching how --tls itself works. To go back to generated certs, remove cert_file/key_file under this addon in pg.yaml and recreate with pg addon install silo --name store --force.

Deployment modes

silo/MinIO classifies its layouts; the addon supports all four:

Mode Shape Use it for
SNSD (single-node, single-drive) one node, one data directory — the default when no --endpoint or --drive is given dev, test, demos
SNMD (single-node, multi-drive) one node, several drives — --drive per drive, see SNMD below surviving a disk loss on a single host without a filesystem layer
MNSD (multi-node, single-drive) several nodes, one data disk per node — the distributed mode below compact high-availability deployments
MNMD (multi-node, multi-drive) several nodes, several drives each — --drive for this node’s drives + the full --endpoint matrix surviving a disk loss and a node loss, without a filesystem layer

SNSD is what pg addon install silo gives you out of the box. To get MNSD, pass the cluster’s endpoint list (at least four nodes) — see Distributed / Cluster Mode below.

MNMD combines both flags: give this node’s drives with --drive (as under SNMD) and the whole cluster’s host×drive endpoint matrix with --endpoint (one URL per drive on every node) — see Multi-Node Multi-Drive (MNMD) below. Disk redundancy under SNSD/MNSD is also available the other way — a ZFS pool under --data-dir — which keeps the layout changeable underneath and can be more space-efficient. S3 Storage High Availability compares native MNMD with the ZFS approach for the 4-hosts-each-with-several-disks hybrid that survives both a disk and a node.

Single-Node Multi-Drive (SNMD)

One silo process, several host directories, erasure-coded across them. Pass --drive once per drive instead of --data-dir:

pg addon install silo --name store \
  --drive /mnt/minio/disk1 --drive /mnt/minio/disk2 \
  --drive /mnt/minio/disk3 --drive /mnt/minio/disk4 --tls

Each --drive is a host directory on its own device; drive N is bind-mounted at container path /dataN and the server starts as silo server /data1 /data2 ... /dataN. --drive is mutually exclusive with --data-dir — multi-drive mode takes its data locations from --drive only. Combining --drive with --endpoint is MNMD, the multi-node version of this mode — see Multi-Node Multi-Drive (MNMD) below. Like every other silo/MinIO drive, one that shares the host’s root device is rejected at startup; pgcli lists the offending drives and warns at install time.

What EC buys you (measured on a live 4-drive silo set): a 4-drive set defaults to 2 parity shards — it tolerates 2 drive failures. With 1 drive down, reads and writes both continue; with 2 down, reads still succeed and writes are refused — that is the quorum boundary, the same arithmetic MNSD uses, just over drives instead of nodes. Usable capacity is roughly half the raw total. A drive that returns is healed by silo itself; pgcli does not need to do anything. The parity default scales with drive count — only the 4-drive shape is tested here.

pg addon remove silo --name store --clean-data deletes each drive directory — but refuses any drive that is still a mount point, so an accidental --clean-data can never rm -rf through a live mount into the disk below. Unmount first if the data below is really disposable.

Distributed / Cluster Mode

silo’s erasure-coded (EC) cluster mode works exactly like MinIO’s — same command shape, same rules. It requires at least four distinct host:port endpoints and, unlike the other addons, no central coordinator: every node runs its own pgcli with its own pg.yaml, and every one of those pg.yaml files carries the same full endpoint list and the same root credentials. pgcli only ever starts the container for the node it is running on — silo itself does the handshake to form the ring across hosts.

# on node 1 (10.0.0.11), with a dedicated data disk mounted at /data:
pg addon install silo --name store \
  --listen 10.0.0.11 \
  --data-dir /data \
  --root-password '<shared-secret>' \
  --endpoint http://10.0.0.11:9000/data \
  --endpoint http://10.0.0.12:9000/data \
  --endpoint http://10.0.0.20:9000/data \
  --endpoint http://10.0.0.21:9000/data

# nodes 2-4: same command, own --listen, and the SAME --endpoint list AND the
# SAME --root-password value.

The three strict rules (routable distinct hosts, a data directory on a disk separate from root — pgcli warns when it isn’t — and no per-node MINIO_SERVER_URL in cluster mode) and the quorum arithmetic are the same as MinIO → Distributed / Cluster Mode; silo enforces the same checks because it inherited them.

Multi-Node Multi-Drive (MNMD)

MNMD works exactly like it does under MinIO: give this node’s drives with --drive and the whole cluster’s host×drive endpoint matrix with --endpoint, one URL per drive on every node. Each endpoint must address one of that node’s /data1../dataN drive slots, the matrix must be a multiple of the per-node drive count and must name at least one remote node, and a --tls node’s endpoints must all be https:// — pgcli checks all four before starting the container. See MinIO → Multi-Node Multi-Drive (MNMD) for the full walkthrough.

On a live 4-node × 4-drive silo set (16 × 2 GiB) the measured shape matches MinIO’s: 16 drives online, EC:4 in a single erasure set of stripe size 16; losing one whole node (12/16 online) keeps reads and writes working, a 64 MiB round-trip byte-identical; losing a second node (8/16 online) refuses writes (Resource requested is unwritable) and fails reads too, and the set self-heals back to 16/16 once the nodes restart. EC:4 over 16 drives keeps 12/16 of raw bytes.

For a TLS grid the same recommendation applies as under MinIO — one pg cert leaf whose SANs cover every node address, the identical --tls-cert/--tls-key pair on every node — and it was verified on silo exactly as on minio: the ring forms with no per-node CA to reconcile. See MinIO → MNMD for the setup.

Using the mcli Client

pg mcli runs silo’s own mcli client from the pgsty/silo image in a throwaway container (selected via --entrypoint mcli — the image’s default entrypoint runs the server) — no local install:

# pick the URL for your platform — see "Endpoints by platform" in the mc page:
pg mcli alias set store http://127.0.0.1:9000 admin <password>    # Linux, local addon
pg mcli alias set store http://host.containers.internal:9000 admin <password>  # macOS, local addon
pg mcli mb store/backups
pg mcli ls store
pg mcli cp ./dump.pglz store/backups/

mcli speaks the same alias contract as mc, so it interoperates freely — against a silo store, a MinIO store, or any S3 endpoint. pgcli points both clients at one file: aliases persist on the host at ~/.mc/config.json (mc’s native default path), so an alias registered with pg mc is visible to pg mcli and vice versa — set it once, not once per client. (The stateless MC_HOST_<name> form works for both too.) A native mcli install left to its own defaults reads ~/.mcli/config.json instead, so it will not see the shared file unless MC_CONFIG_DIR is pointed at it.

alias set validates the credentials against the endpoint before writing, so a wrong password leaves the config untouched. Local file operands of cp / mirror / diff are resolved and mounted at their real absolute paths, exactly as pg mc does (on macOS, keep them under your home directory). Any mcli flag that pg’s own parser would reject goes after --:

pg mcli ls store -- --all
MC_HOST_store="http://admin:<password>@127.0.0.1:9000" pg mcli ls store

Both clients share the same command table as documented on the MinIO page — Common commands — with pg mcli in place of pg mc.

Ports

Each instance takes two consecutive ports from one pool, starting at minio_start_port (default 9000): the S3 API first, the console second. The pool is shared with the minio addon — minio and silo instances are assigned from one cursor, so they coexist on a host without collision, minio instances first (by name), then silo:

pg addon install minio --name store    # 9000 / 9001
pg addon install silo  --name lake     # 9002 / 9003

Configuration

Instances live under the top-level addons.silo map in pg.yaml, keyed by instance name:

namespace: default
minio_start_port: 9000       # shared pool: minio AND silo draw from this
addons:
  silo:
    store:
      container_name: pgcli-silo-default-store
      name: store
      image_tag: docker.io/pgsty/silo:RELEASE.2026-09-16T00-00-00Z
      # data_dir: /srv/silo     # omit for <base-dir>/addon/silo/store/data
      # drives:                  # multi-drive (SNMD/MNMD): one host dir per drive,
      #   - /mnt/minio/disk1     # each mounted at its own /dataN — see SNMD/MNMD below
      #   - /mnt/minio/disk2
      listen: 127.0.0.1
      api_port: 9000
      console_port: 9001
      root_user: admin
      root_password: <generated>   # written on first install
      autostart: false             # pg autostart enable --silo --name store
      # tls: true                  # serve HTTPS (self-signed CA, or BYO below)
      # cert_file: /etc/ssl/silo.test.crt   # BYO leaf(+chain), implies tls
      # key_file:  /etc/ssl/silo.test.key   # BYO private key, must pair with cert_file
      # endpoints:                 # omit for single-node; see "Distributed / Cluster Mode"
      #   - http://10.0.0.11:9000/data
      #   - http://10.0.0.12:9000/data
      #   - http://10.0.0.20:9000/data
      #   - http://10.0.0.21:9000/data
      #   (with `drives` also set this is MNMD — one /dataN endpoint per drive on
      #    every node, and every node's list identical; see "Multi-Node Multi-Drive")

Edits to listen, ports, root_user, root_password, image_tag, data_dir, tls/cert_file/key_file, or endpoints take effect after the next pg addon install silo --name store --force — the plain install skips a still-present container, --force recreates it (the data directory is never touched).

List

pg addon list
Infra add-ons (silo):
  silo (name: store)
    Status:      running
    Listen:      127.0.0.1
    API port:    9000
    Console port: 9001
    Console URL: http://127.0.0.1:9001/
    Data:        ~/pg/addon/silo/store/data
    Root user:   admin
    Image:       docker.io/pgsty/silo:RELEASE.2026-09-16T00-00-00Z
    Container:   pgcli-silo-default-store

pg addon list never prints the password. Reveal it deliberately with pg addon list --show-password (appends a Root password: line), or print just the secret for scripting:

pg addon password silo --name store

The value is the access-key secret; pair it with the Root user: above. --file <path> writes it mode 0600 instead of to the terminal, keeping the secret out of shell history and scrollback.

Start and stop

After a host reboot, bring an instance back without re-applying config:

pg addon start silo --name store
pg addon stop  silo --name store

install skips a still-present container (starting it if stopped); start only starts an existing one (and self-heals an improper state by recreating it from the config). In TLS generated mode start also re-validates and, if needed, re-signs the leaf (silo hot-reloads its mounted cert).

Auto-start on Boot

Containers carry a --restart unless-stopped policy (crashes, not reboots). To bring instances up after a host reboot:

pg autostart enable --silo --name store

This sets autostart: true and installs/refreshes the boot service (see Auto-start on Boot). Boot is start-only. silo is independent of the PostgreSQL stack, so it is started last; there is no ordering constraint. pg autostart status lists every target’s state.

Remove

pg addon remove silo --name store            # container gone, data kept
pg addon remove silo --name store --clean-data   # also delete the data directory

The data directory is the object storage — losing it means losing every bucket in it — so remove keeps it by default and says where it is. --clean-data deletes it (and prunes the now-empty default-layout parent directory; a data_dir override and its parent are never touched).

Logs

pg logs addon silo --name store      # last 50 lines
pg logs addon silo --name store -f   # follow

silo logs to stdout: startup lines (API:/Console: addresses, Documentation:) and request errors. An API: http://... block confirms the listeners came up.

Troubleshooting

  • pulling silo image ... : ... on install. The public tag docker.io/pgsty/silo:RELEASE.2026-09-16T00-00-00Z is not reachable — check network/registry access to docker.io, or pre-pull it with podman pull.
  • Port collision on manual --api-port. Pick ports outside the auto pool (minio_start_port and up) or the auto-assigner will treat them as taken; the pool is shared with the minio addon, so a silo instance must also dodge the minio instances’ explicit ports and vice versa. Remember each store needs a consecutive pair.
  • pg addon start after host reboot does nothing / fails. Check pg logs addon silo --name store -f — most often the data directory was deleted (with --clean-data or by hand) and silo refuses to start on an empty dir it previously formatted, or the bind port moved.
  • Console reachable but S3 clients time out. The MINIO_SERVER_URL is built from listen + API port; if you serve on 127.0.0.1 but access from another host, clients get redirected to the loopback URL. Set listen to the address clients can actually reach. (Cluster mode does not set MINIO_SERVER_URL at all.)
  • An alias set with pg mc isn’t visible to pg mcli (or vice versa). They share ~/.mc/config.json by design, so this means the alias really isn’t there — check pg mc alias list (same file), or pass MC_HOST_<name> in the environment. A native mcli reads ~/.mcli instead and won’t see the shared file unless MC_CONFIG_DIR points there.
  • macOS. Supported: the addon serves on the pgcli-net bridge with both ports published, so the Mac’s 127.0.0.1:<port> reaches them (the container binds 0.0.0.0 internally and MINIO_SERVER_URL advertises the loopback the Mac uses). After changing ports or credentials, --force recreate the container. For pg mcli, the container cannot use a 127.0.0.1 alias — see the endpoint note on the MinIO mc page.

10 - MinIO

Run MinIO as a pgcli addon — single-node or distributed S3-compatible object storage with web console

MinIO is S3-compatible object storage. pgcli runs it as a standalone, top-level addon — shared infrastructure, not a per-instance sidecar — with the web console included. It defaults to single-node mode and supports a genuinely distributed cluster mode across hosts (see below). Either way it is a general-purpose object store. silo — Pigsty’s MinIO fork, kept wire-compatible — is available as a sibling addon with the identical feature surface; the two share one port pool and can coexist on a host.

Platform support: the MinIO addon works on both platforms. Linux serves over host networking; macOS joins the pgcli-net bridge with its two ports published, so the Mac reaches the API and console on 127.0.0.1:<port> like any other addon. The public image is dual-arch (amd64 + arm64), so any host architecture works. pg mc, the client, works on both platforms too.

How It Works

One container, one directory: minio server /data --address <listen>:<api-port> --console-address <listen>:<console-port>, where /data is a bind mount of the instance’s host data directory (default <base-dir>/addon/minio/<name>/data). Everything MinIO stores lives there, so it outlives the container.

The image is the public pre-built tag ghcr.io/mars-base/pgcli/pgcli-minio:20250422221226 — the upstream static binaries (dual-arch amd64 + arm64, from the minio/minio GitHub releases) on Alpine, because MinIO’s official image dropped the bundled web console. pg addon install pulls it; pgcli never builds the image at run time.

Credentials are handled like Patroni’s:

  • root_user defaults to admin;
  • root_password is generated on first install (or supplied explicitly via --root-password) and stored in pg.yaml (addons.minio.<name>.root_password) and printed once in the install summary for convenience.

They are exactly MinIO’s root access key / secret key — what every S3 client (and pg mc alias set <name> <url> <root_user> <root_password>) calls the access key and secret key.

The container runs --ulimit nofile=1048576:1048576 and --stop-timeout 60 as MinIO’s deployment docs recommend. On macOS the podman machine VM caps RLIMIT_NOFILE lower, so the value used there is 65536 — plenty for a single-host dev/test store. Note that root credentials passed as -e are visible in podman inspect — the same exposure as any hand-run container; fine for a rootless single-host deployment, which is what this is.

Install

# default instance name "minio", ports from the pool (base 9000), loopback bind
pg addon install minio

# a named instance with an explicit data directory
pg addon install minio --name store --data-dir /srv/minio

# fixed ports and a different root user
pg addon install minio --name store --api-port 9000 --console-port 9001 --root-user admin

# expose the store on the network instead of loopback only
pg addon install minio --name store --listen 0.0.0.0

# HTTPS via pgcli's self-signed CA (the prerequisite for a pgBackRest S3 repo)
pg addon install minio --name store --tls

# HTTPS with a certificate you already have (public-CA or private-CA domain cert)
pg addon install minio --name store --tls-cert /etc/ssl/minio.test.crt --tls-key /etc/ssl/minio.test.key

The output reports endpoints and the root credentials:

✓ minio installed: "store"
  Container:    pgcli-minio-default-store
  Image:        ghcr.io/mars-base/pgcli/pgcli-minio:20250422221226
  Data:         ~/pg/addon/minio/store/data
  S3 API:       http://127.0.0.1:9000
  Console:      http://127.0.0.1:9001

  Root user:     admin
  Root password: <generated>

Sign in to the console at the Console: URL with the printed root user and password. Point S3 clients (including pgBackRest) at the S3 API: URL, or drive them from the terminal with pg mc below.

Re-running install against a live instance is a no-op: the container is not recreated (a stopped one is simply started, with a notice), the flags are merged into the stored config, and the existing root password is kept. Pass --force to recreate the container so changed ports, listen address, endpoint list, or credentials take effect — without losing the data directory.

Bind address: the default 127.0.0.1 keeps the store local. --listen 0.0.0.0 (or the listen key in pg.yaml) exposes it on the network. Anyone who can reach the port can then attempt the root credentials, so only do this behind a firewall or with TLS (--tls, below).

TLS (--tls)

--tls makes MinIO serve HTTPS. pgcli generates a self-signed CA and a leaf cert with the stdlib — SANs cover the loopback names, localhost, and every NIC IP of the host — into <base_dir>/tls/minio/<name>/: public.crt / private.key for MinIO’s --certs-dir, and ca.crt for distribution. The cert dir is mounted read-only and the endpoint URL becomes https://.

Why you need it: pgBackRest forces HTTPS for S3 repositories (plaintext is an upstream-rejected option), so a MinIO meant to receive Patroni archive-push must speak TLS. Point backup.repo.s3.ca_file at ca.crt and pgBackRest connects with full certificate verification — see Backup → S3 object storage repository.

One note on pairing stores with clusters: backup.repo.s3 is a single, global repo per config file, so the first TLS MinIO you wire up receives every stanza that opts into S3 — Patroni clusters automatically, regular instances when created with pg create --backup-target s3 (Instance with S3); everything else stays on the local repo. Installing a second MinIO does not give stanzas a per-cluster store to choose. If you truly need two destinations, run a second config (see Backup → Shared Backup Container, and the worked Example: HA Cluster with a Self-CA MinIO).

pg mc adds --insecure automatically when a command targets a TLS store via a loopback alias (mc persists no CA trust per alias; same-host loopback makes this acceptable). An alias to a LAN-IP endpoint is not loopback — append -- --insecure yourself, or set up the CA properly. External https:// endpoints keep full verification. Toggling --tls on an existing instance needs --force to take effect.

Lifetimes and access from other hosts. CA and leaf are both valid for 100 years (the 825-day cap public CAs observe is a browser policy, not something Go’s verifier enforces for a private root). pgcli re-signs the leaf on --force, or whenever a host address changes, so handing ca.crt to clients is a one-time act per store. A TLS client validates the address it dials against the leaf’s SANs — the client’s own address never matters. Remote hosts (a VM’s Patroni member, another machine’s backup container) therefore point backup.repo.s3.endpoint at one of the store host’s IPs (loopback names and every NIC IP, virtual bridges included, are in the SAN; raw hostnames are not — unless you set MINIO_SERVER_URL, whose host is added).

Getting the CA onto a remote host — no scp needed. The server cert is served as a leaf+CA chain, so a consumer on another machine can pull the root straight out of a TLS handshake:

pg backup fetch-ca <store-host>:9002
#   [OK] CA fetched from <store-host>:9002
#        saved:    ~/.pgcli/backup/repo-ca/ca-<store-host>-9002.crt
#        SHA-256:  c0f0…fe2e
pg backup setup --s3-ca-file ~/.pgcli/backup/repo-ca/ca-<store-host>-9002.crt

The fetch is trust-on-first-use — the CA is the thing you cannot verify before you hold it — so compare the printed SHA-256 against the store host’s sha256sum ~/.pgcli/tls/minio/<name>/ca.crt (the way you would an SSH host key) before trusting it. One setup then republishes the CA into the Patroni cluster’s etcd registry, so every other cluster host gets it with no manual step at all (see Backup → S3 object storage repository). Copying ca.crt over by hand still works as the fallback, and is what you must do if the store host runs a pgcli from before chain distribution (the fetch-ca error says so, and re-running pg addon install minio --tls there upgrades it without a restart). A pgBackRest stanza never requires the MinIO to share its host.

Bring your own certificate (--tls-cert / --tls-key)

--tls only ever serves pgcli’s own self-signed pair. To serve a certificate you already hold — one signed by a public CA for a real domain, or one issued by your private CA — pass --tls-cert <leaf(+chain).pem> --tls-key <key.pem> instead. Together with --tls (which it implies, so you don’t need to also pass it), this replaces the generated certs: the two files are mounted read-only straight at the names MinIO’s --certs-dir requires (/opt/minio/certs/public.crt, /opt/minio/certs/private.key), and pgcli never copies or re-signs them — the private key stays in exactly the one place you put it.

pg addon install minio --name store \
  --tls-cert /etc/ssl/wildcard.hi.163.com.crt \
  --tls-key  /etc/ssl/wildcard.hi.163.com.key

What install checks, and what it does not. --tls-cert/--tls-key are paired through Go’s own TLS loader before anything starts, so a key that doesn’t match the cert, a cert that is really just a CA certificate, an expired cert, or one restricted to a use other than server auth all fail the install outright rather than surfacing later as a crash-looping container. Whether the cert’s SANs cover the configured --listen address is checked too, but only warned about — a domain cert is routinely dialed through a name behind DNS or a load balancer that has nothing to do with the host it runs on, so a mismatch here is informational, not fatal.

Renewing. Replace the cert/key files and recreate the container:

pg addon install minio --name store --tls-cert <new.crt> --tls-key <new.key> --force

Recreate is required, not optional: with the files bind-mounted read-only into the container, a running MinIO does not pick up a replaced certificate — not a new file moved over the old one (that swaps the inode a single-file mount pins), and not even an in-place rewrite of the same file. Verified: after overwriting the host file the container keeps serving the old pair until --force recreates it. pgcli never re-signs a BYO certificate — the operator owns its lifetime — so there is no automatic refresh to rely on.

pg addon start/stop re-validate the pair on every start but never regenerate it (there is nothing to regenerate — pgcli does not own your certificate’s lifetime). A start-time validation failure is reported as a warning, not a blocker, matching the existing tolerance around a cert that is very likely still fine: the fix is always to correct the files (or swap to a new pair) and recreate with --force.

Clients. With a certificate from a publicly-trusted CA, S3 clients (the mc family, aws CLI, pgBackRest via repo*-s3-ca-file) need no extra trust material at all — the chain is already rooted in a CA they trust. For any other cert you hand the client the trust anchor as backup.repo.s3.ca_file / --s3-ca-file: the issuing CA (or the full leaf+intermediate bundle) for a private-CA cert, or — since a self-signed cert is its own anchor — the served .crt itself when you minted it with pg cert. A remote host that never saw that .crt can pull it out of the TLS handshake automatically instead of an scp — fetch-ca recognizes a self-signed leaf and saves it for you:

pg backup fetch-ca <store-host>:9010
#   [OK] CA fetched from <store-host>:9010
#        saved:    ~/.pgcli/backup/repo-ca/ca-<store-host>-9010.crt
#        SHA-256:  d4df…81e2
pg backup setup --s3-ca-file ~/.pgcli/backup/repo-ca/ca-<store-host>-9010.crt

Cross-check the SHA-256 against the store host’s sha256sum of the .crt you gave --tls-cert (trust-on-first-use, same as the generated-CA fetch above). For a public-CA cert the command stays pointless — there is nothing to fetch that isn’t already trusted.

Turning BYO off. There is no --tls-cert=/off flag — the config merge across re-runs is one-way, matching how --tls itself works. To go back to generated certs, remove cert_file/key_file under this addon in pg.yaml and recreate with pg addon install minio --name store --force.

Generating a test certificate: pg cert

You don’t need a real CA to try BYO — pg cert mints a self-signed cert whose SANs cover any mix of DNS names and IPs you ask for:

# A leaf cert valid for a hostname AND two IPs, ECDSA P-256 (the default),
# 825 days (the default validity) — the shape most BYO installs want:
pg cert --host "minio.test,127.0.0.1,10.0.0.9" \
  --cert-file minio.crt --key-file minio.key

# Then serve it:
pg addon install minio --name store --tls-cert minio.crt --tls-key minio.key

Nothing it generates touches pg.yaml or a container — it just writes two PEM files wherever you point it and prints the SANs. Flags:

Flag Default Meaning
--host 127.0.0.1 Comma-separated DNS names and/or IPs to encode as SANs (repeatable). Entries are auto-detected as one or the other, so "minio.test,10.0.0.9" needs no special syntax; *.wild.test works as a wildcard DNS entry.
--cert-file cert.pem Path to write the PEM certificate.
--key-file key.pem Path to write the PEM private key (PKCS8).
--valid-duration 825 days (19800h) How long the cert stays valid, e.g. --valid-duration 8760h for a year.
--ecdsa P-256 Curve: P-224/P-256/P-384/P-521. Set to "" to disable ECDSA (and pair with --rsa).
--rsa (off) RSA key size (e.g. 2048, 4096); set only when you specifically need RSA instead of the default ECDSA key.
--ca false Make the cert its own CA (CA:TRUE, keyCertSign) — for when you want a private root to sign further certs with, not the usual case for --tls-cert.

The same generator is also built as a standalone binary for use outside pg — make gencert → bin/gencert, with the identical flag set in single-dash form (-host, -cert-file, …). Both front the one internal/certgen package, so their output is byte-for-byte the same kind of certificate.

What pg cert writes is one self-signed leaf, not a chain. The PEM in --cert-file holds exactly one CERTIFICATE block — the cert signs itself (IsCA: false, serverAuth EKU, your SANs). It is deliberately not a leaf+intermediate+root bundle: there is no issuing CA above it, so there is nothing to chain, and ValidateBYOCert only inspects the first certificate in the file and rejects one that is a CA (leaf.IsCA), which is precisely why the --ca output is not something to point --tls-cert at — it is the trust anchor itself, not a server cert.

Since the result is self-signed, treat the generated minio.crt exactly like pgcli’s own --tls-generated ca.crt on the client side — the served leaf is its own trust anchor, so point backup.repo.s3.ca_file / pg backup setup --s3-ca-file at the same file (see Backup → S3 Object Storage Repository). This is not a workaround pgBackRest merely tolerates: OpenSSL’s trust store treats whatever you hand it via -CAfile/SSL_CTX as an anchor, CA:TRUE not required, and pgBackRest’s S3 TLS path (curl over OpenSSL) is that same mechanism — verified directly: openssl verify -CAfile <pg cert's cert> <pg cert's cert> on the self-signed, CA:FALSE leaf returns OK.

Deployment modes

MinIO/silo classifies its layouts; the addon supports all four:

Mode Shape Use it for
SNSD (single-node, single-drive) one node, one data directory — the default when no --endpoint or --drive is given dev, test, demos
SNMD (single-node, multi-drive) one node, several drives — --drive per drive, see SNMD below surviving a disk loss on a single host without a filesystem layer
MNSD (multi-node, single-drive) several nodes, one data disk per node — the distributed mode below compact high-availability deployments
MNMD (multi-node, multi-drive) several nodes, several drives each — --drive for this node’s drives + the full --endpoint matrix surviving a disk loss and a node loss, without a filesystem layer

SNSD is what pg addon install minio gives you out of the box. To get MNSD, pass the cluster’s endpoint list (at least four nodes) — see Distributed / Cluster Mode below.

MNMD combines both flags: give this node’s drives with --drive (as under SNMD) and the whole cluster’s host×drive endpoint matrix with --endpoint (one URL per drive on every node) — see Multi-Node Multi-Drive (MNMD) below. Disk redundancy under SNSD/MNSD is also available the other way — a ZFS pool under --data-dir — which keeps the layout changeable underneath and can be more space-efficient. S3 Storage High Availability compares native MNMD with the ZFS approach for the 4-hosts-each-with-several-disks hybrid that survives both a disk and a node.

Single-Node Multi-Drive (SNMD)

One MinIO process, several host directories, erasure-coded across them. Pass --drive once per drive instead of --data-dir:

pg addon install minio --name store \
  --drive /mnt/minio/disk1 --drive /mnt/minio/disk2 \
  --drive /mnt/minio/disk3 --drive /mnt/minio/disk4 --tls

Each --drive is a host directory on its own device; drive N is bind-mounted at container path /dataN and the server starts as minio server /data1 /data2 ... /dataN. --drive is mutually exclusive with --data-dir — multi-drive mode takes its data locations from --drive only. Combining --drive with --endpoint is MNMD, the multi-node version of this mode — see Multi-Node Multi-Drive (MNMD) below. Like every other MinIO drive, one that shares the host’s root device is rejected by MinIO at startup; pgcli lists the offending drives and warns at install time.

What EC buys you (measured on a live 4-drive set): MinIO splits each object into data + parity shards, and a 4-drive set defaults to 2 parity shards — it tolerates 2 drive failures. With 1 drive down, reads and writes both continue; with 2 down, reads still succeed and writes are refused — that is the quorum boundary, and it is the same arithmetic MNSD uses, just over drives instead of nodes. Usable capacity is roughly half the raw total (4 × 2 GiB drives → 3.6 GiB usable reported by mc admin info, EC:2). A drive that returns is healed by MinIO itself; pgcli does not need to do anything. The parity default scales with drive count — only the 4-drive shape is tested here.

pg addon remove minio --name store --clean-data deletes each drive directory — but refuses any drive that is still a mount point, so an accidental --clean-data can never rm -rf through a live mount into the disk below. Unmount first if the data below is really disposable.

Distributed / Cluster Mode

MinIO’s erasure-coded (EC) cluster mode is available too. It requires at least four distinct host:port endpoints and, unlike the other addons, no central coordinator: every node runs its own pgcli with its own pg.yaml, and every one of those pg.yaml files carries the same full endpoint list and the same root credentials. pgcli only ever starts the container for the node it is running on — MinIO itself does the handshake to form the ring across hosts.

The endpoint list is the mode switch: an empty list is single-node (unchanged), a non-empty list starts minio server <ep1> <ep2> ... in distributed mode.

Each endpoint is http://<host>:<port><path>. The host:port is how the nodes reach each other to form the ring. The trailing <path> is not an HTTP route — clients never see it — it is the export path, the directory inside the container where that node keeps its own slice of the erasure-coded data. Under MNSD (no --drive) pgcli bind-mounts the --data-dir at /data, so the path must start at /data — the simplest choice is literally /data. Keep the same path string across all four endpoints. (Under MNMD a node also passes --drive, and each endpoint instead names one of that node’s /data1../dataN drive slots — see MNMD below.)

Note the endpoint path is a container path, independent of the host layout: if /data is a shared disk and you want to keep other things on it, point --data-dir at a subdirectory of it — --data-dir /data/minio stores this cluster’s data under the host’s /data/minio while the endpoints stay http://<host>:9000/data (the endpoint cannot name that subdirectory; it sees the mount root). Only if you deliberately extend into the volume with a path below /data (e.g. /data/mystore) does the data land one level deeper on the host: <data-dir>/mystore — avoid pairing --data-dir /data/minio with endpoint .../data/minio, which nests as /data/minio/minio.

# on node 1 (10.0.0.11), with a dedicated data disk mounted at /data:
pg addon install minio --name store \
  --listen 10.0.0.11 \
  --data-dir /data \
  --root-password '<shared-secret>' \
  --endpoint http://10.0.0.11:9000/data \
  --endpoint http://10.0.0.12:9000/data \
  --endpoint http://10.0.0.20:9000/data \
  --endpoint http://10.0.0.21:9000/data

# nodes 2-4: same command, own --listen, and the SAME --endpoint list AND the
# SAME --root-password value.

--root-password is optional: omit it and the first install generates one (printed once, stored in pg.yaml). In cluster mode, pass the same value on every node so the stored credential is identical across the cluster without any manual copy.

The install summary lists the members and reminds you of the consistency requirement:

✓ minio installed: "store"
  ...
  Distributed mode: 4 endpoints
    - http://10.0.0.11:9000/data
    - http://10.0.0.12:9000/data
    - http://10.0.0.20:9000/data
    - http://10.0.0.21:9000/data
  NOTE: every node's pg.yaml must carry the identical endpoint list AND
  identical root credentials, or the cluster will not form.

Three things are strict in cluster mode, each learned the hard way:

  • Endpoints must be routable, distinct hosts. Same-host folds into single-node-multi-drive and is rejected (use path style endpoint for single node setup); the 127.0.0.0/8 loopback range is rejected outright (resolves to localhost). Use each node’s real LAN address.
  • The data directory must be on a disk separate from the root filesystem. MinIO refuses a drive that shares the OS disk (drive is part of root drive, will not be used). pgcli detects this with a stat of the data dir versus / and warns at install time when --data-dir is on the root device — the warning is advisory; point --data-dir at a mounted data disk.
  • MINIO_SERVER_URL is not set in cluster mode. It would differ per node (each advertises its own IP), and MinIO requires every MINIO_* env var to be byte-identical across nodes, so a per-node MINIO_SERVER_URL makes each node loop on Waiting for at least 1 remote servers with valid configuration. The endpoint list defines the addresses instead. Single-node still sets MINIO_SERVER_URL from listen.

Quorum (EC): writes need ⌈N/2⌉+1 nodes up, reads need ⌈N/2⌉. A 4-node set therefore keeps serving reads with 2 nodes down but rejects writes; restart the downed nodes and the cluster self-heals. Under MNMD the members being counted are drives, not nodes — see MNMD for the measured drive-level boundary on a live 4×4 set.

Cross-host only. This is a genuinely distributed deployment — you run pgcli on each host yourself. pgcli does not SSH between nodes or register members; keeping the N pg.yaml files consistent is the operator’s job.

Multi-Node Multi-Drive (MNMD)

MNMD is MNSD with several drives per node instead of one: MinIO erasure-codes across the whole host×drive matrix, so the set survives losing individual disks and whole nodes without any filesystem layer. Give this node’s drives with --drive (exactly as under SNMD) and the entire cluster’s endpoint list with --endpoint — one URL per drive on every node, not just this one.

The one difference from MNSD is the export path. Each node bind-mounts its drives at /data1../dataN, so each endpoint must address one of those slots: http://<host>:<port>/data<k>. pgcli does not parse the URLs — it hands the matrix to minio server verbatim, the same way MinIO documents it — so every node carries the identical full list. The list must be a multiple of the per-node drive count (MinIO requires every node contribute the same number of drives) and must name at least one remote node; a matrix that folds onto a single host is rejected before the container starts, as is a --tls node whose endpoints are plaintext http://.

Serving the grid over TLS — one certificate, not a CA per node. Let each node’s bare --tls run and every host mints its own self-signed CA, so the first cross-node handshake dies with x509: certificate signed by unknown authority and you are left seeding one CA into every node’s cert store by hand. The clean path is a single certificate shared by the whole grid: pg cert writes one self-signed leaf whose SANs cover every node address, you copy that one .crt/.key pair to all nodes byte-identically, and serve it with --tls-cert / --tls-key (there is no per-node CA to reconcile). This is the recommended TLS setup — pgBackRest forces HTTPS for an S3 repo anyway, so a backup store is a TLS grid. The endpoint matrix must then be all https://, and every address a node dials must be in the leaf’s SANs. (The same shared leaf serves an MNSD grid just as well — the handshake is between the same servers.)

# once, anywhere — one leaf for the whole grid (list every node address; add any
# VIP or hostname clients will dial):
pg cert --host 10.0.0.11,10.0.0.12,10.0.0.20,10.0.0.21 \
        --cert-file grid.crt --key-file grid.key
# then copy grid.crt + grid.key to every node — identical files everywhere

# on node 1 (10.0.0.11), four data disks mounted and passed with --drive:
pg addon install minio --name store \
  --tls-cert grid.crt --tls-key grid.key \
  --listen 0.0.0.0 \
  --drive /mnt/minio/disk1 --drive /mnt/minio/disk2 \
  --drive /mnt/minio/disk3 --drive /mnt/minio/disk4 \
  --root-password '<shared-secret>' \
  --endpoint https://10.0.0.11:9000/data1 --endpoint https://10.0.0.11:9000/data2 \
  --endpoint https://10.0.0.11:9000/data3 --endpoint https://10.0.0.11:9000/data4 \
  --endpoint https://10.0.0.12:9000/data1 --endpoint https://10.0.0.12:9000/data2 \
  --endpoint https://10.0.0.12:9000/data3 --endpoint https://10.0.0.12:9000/data4 \
  --endpoint https://10.0.0.20:9000/data1 --endpoint https://10.0.0.20:9000/data2 \
  --endpoint https://10.0.0.20:9000/data3 --endpoint https://10.0.0.20:9000/data4 \
  --endpoint https://10.0.0.21:9000/data1 --endpoint https://10.0.0.21:9000/data2 \
  --endpoint https://10.0.0.21:9000/data3 --endpoint https://10.0.0.21:9000/data4

# nodes 2-4: same command, the SAME grid.crt/grid.key pair, own --drive paths,
# and the SAME 16-endpoint matrix AND the SAME --root-password value.

The --listen 0.0.0.0 is deliberate: each node must answer on the address the other 15 endpoints name. --root-password must be identical everywhere, exactly as under MNSD.

On a live 4-node × 4-drive set (16 × 2 GiB) — formed over exactly this shared-pg cert TLS setup, the ring coming up with Network: 4/4 OK and no per-node CA to reconcile — the measured shape, via mc admin info:

  • 16 drives online, EC:4 in a single erasure set of stripe size 16 — the set reports 4 parity shards, so losing 4 drives of 16 stays healthy.
  • Losing one whole node (4 drives → 12/16 online) keeps reads and writes working; a 64 MiB upload/download round-trips byte-identical.
  • Losing a second node (8/16 online): writes are refused (Resource requested is unwritable) and reads fail too — the set is no longer safe to serve. Restart the nodes and it self-heals back to 16/16.
  • Usable capacity follows the parity ratio: EC:4 over 16 drives keeps 12/16 of raw bytes. --clean-data deletes each drive dir but refuses one still mounted, and a drive that returns is healed by MinIO itself.

The pg.yaml files on all nodes carry the identical 16-line matrix and one shared root password; keeping them consistent is, as under MNSD, the operator’s job.

Using the mc Client

pg mc runs MinIO’s own mc client from a throwaway container — no local install, no manual podman run invocation:

# pick the URL for your platform — see "Endpoints by platform" below:
pg mc alias set store http://127.0.0.1:9000 admin <password>    # Linux, local addon
pg mc alias set store http://host.containers.internal:9000 admin <password>  # macOS, local addon
pg mc alias set store http://10.0.5.7:9000 admin <password>     # either, remote store
pg mc mb store/backups
pg mc ls store
pg mc cp ./dump.pglz store/backups/

Aliases persist on the host at ~/.mc/config.json — mc’s own default path, the same on Linux and macOS — so alias set once and every later pg mc invocation (and a native mc install, on Linux) sees the same aliases. pg mc alias list reads them back and pg mc alias remove drops one. alias set validates the credentials against the endpoint before writing, so a wrong password leaves ~/.mc/config.json untouched rather than storing a dead alias. Under the hood pg mc mounts your ~/.mc into the container and runs ghcr.io/mars-base/pgcli/pgcli-mc (the static upstream binary on scratch, pulled on first use); nothing else about it is magic.

Local file operands of cp / mirror / diff work too: pg mc resolves each one (like realpath) and mounts that exact absolute path into the container, so

pg mc cp ./dump.pglz store/backups/        # upload a file from the cwd
pg mc cp store/backups/dump.pglz ./        # download into the cwd
pg mc mirror ./repo store/backups/         # or mirror a whole tree

just does what it looks like. A download target that does not exist yet (a new filename, or a ./newdir/ not created) is handled too — its nearest existing parent directory is what gets mounted, so the file mc writes lands on the host. On macOS the path must live under your home directory — that is the only tree the podman machine VM shares; pg mc says so and skips any mount outside it.

Any mc flag that pg’s own flag parser would reject goes after --, exactly like pg etcdctl — this covers essentially every mc long flag, since none are registered on pg: --all, --json, --recursive, --force, --newer-than, and so on. Put them all after --:

pg mc ls store -- --all
pg mc cp ./dir store/backups/ -- --recursive
pg mc rm store/old -- --recursive --force

Passing one before -- fails in pg, not in mc, with a message like unknown flag: --recursive — a giveaway that the separator is missing.

One caveat from native mc is worth knowing, because it interacts with the local mounts above: in a file command (cp / mirror / diff) an operand whose first segment is not a known alias is treated as a local path. A typo in an alias name therefore uploads or downloads to a local directory named after the typo instead of erroring — pg mc faithfully mounts what mc decides to read, so the behaviour is native, not a pg mc quirk. Confirm the alias with pg mc alias list before a file operation.

MC_HOST_<name> environment aliases — mc’s stateless form, no config file touched — work through pg mc too, since the variable is forwarded into the container:

MC_HOST_store="http://admin:<password>@127.0.0.1:9000" pg mc ls store

Endpoints by platform: on Linux pg mc runs on the host network, so a 127.0.0.1 alias reaches a local addon instance directly. On macOS the container sits on the bridge network, where 127.0.0.1 is the container’s own loopback — point an alias at a local Mac addon via http://admin:<password>@host.containers.internal:9000, or at a remote store via its routable address. pg mc itself works identically on both.

A Mac browser reaches the console on 127.0.0.1:<console-port> (the addon publishes it); that is host-side and unrelated to what the pg mc container can address.

Common commands

Command Purpose
pg mc ls store / pg mc ls store/backups list buckets / objects
pg mc mb store/backups create a bucket
pg mc cp ./file store/backups/ upload (for a tree: pg mc mirror ./dir store/backups/, or add -- --recursive to cp)
pg mc cp store/backups/file ./ download
pg mc find store -- --name '*.pglz' search objects by name
pg mc du store size per bucket
pg mc rm store/backups/file delete one object
pg mc rm store/prefix -- --recursive delete many objects
pg mc rb store/bucket -- --force remove a bucket, objects and all

The same root credentials work for any S3 SDK — including pgBackRest against a repo1-type=s3 repository.

Ports

Each instance takes two consecutive ports from one pool, starting at minio_start_port (default 9000): the S3 API first, the console second. Like every other auto-assigned pool, it skips ports in use and the explicit ports of sibling instances:

pg addon install minio --name store    # 9000 / 9001
pg addon install minio --name archive  # 9002 / 9003

Configuration

Instances live under the top-level addons.minio map in pg.yaml, keyed by instance name:

namespace: default
minio_start_port: 9000
addons:
  minio:
    store:
      container_name: pgcli-minio-default-store
      name: store
      image_tag: ghcr.io/mars-base/pgcli/pgcli-minio:20250422221226
      # data_dir: /srv/minio     # omit for <base-dir>/addon/minio/store/data
      # drives:                  # multi-drive (SNMD/MNMD): one host dir per drive,
      #   - /mnt/minio/disk1     # each mounted at its own /dataN — see SNMD/MNMD below
      #   - /mnt/minio/disk2
      listen: 127.0.0.1
      api_port: 9000
      console_port: 9001
      root_user: admin
      root_password: <generated>   # written on first install
      autostart: false             # pg autostart enable --minio --name store
      # tls: true                  # serve HTTPS (self-signed CA, or BYO below)
      # cert_file: /etc/ssl/minio.test.crt   # BYO leaf(+chain), implies tls; see "Bring your own certificate"
      # key_file:  /etc/ssl/minio.test.key   # BYO private key, must pair with cert_file
      # endpoints:                 # omit for single-node; see "Distributed / Cluster Mode"
      #   - http://10.0.0.11:9000/data
      #   - http://10.0.0.12:9000/data
      #   - http://10.0.0.20:9000/data
      #   - http://10.0.0.21:9000/data
      #   (with `drives` also set this is MNMD — one /dataN endpoint per drive on
      #    every node, and every node's list identical; see "Multi-Node Multi-Drive")

Edits to listen, ports, root_user, root_password, image_tag, data_dir, tls/cert_file/key_file, or endpoints take effect after the next pg addon install minio --name store --force — the plain install skips a still-present container, --force recreates it (the data directory is never touched).

List

pg addon list
Infra add-ons (minio):
  minio (name: store)
    Status:      running
    Listen:      127.0.0.1
    API port:    9000
    Console port: 9001
    Console URL: http://127.0.0.1:9001/
    Data:        ~/pg/addon/minio/store/data
    Root user:   admin
    Image:       ghcr.io/mars-base/pgcli/pgcli-minio:20250422221226
    Container:   pgcli-minio-default-store

pg addon list never prints the password. Reveal it deliberately with pg addon list --show-password (appends a Root password: line), or print just the secret for scripting:

pg addon password minio --name store
mc alias set local http://127.0.0.1:9000 admin "$(pg addon password minio --name store)"

The value is the access-key secret; pair it with the Root user: above. --file <path> writes it mode 0600 instead of to the terminal, keeping the secret out of shell history and scrollback.

Start and stop

After a host reboot, bring an instance back without re-applying config:

pg addon start minio --name store
pg addon stop  minio --name store

install skips a still-present container (starting it if stopped); start only starts an existing one (and self-heals an improper state by recreating it from the config).

Auto-start on Boot

Containers carry a --restart unless-stopped policy (crashes, not reboots). To bring instances up after a host reboot:

pg autostart enable --minio --name store

This sets autostart: true and installs/refreshes the boot service (see Auto-start on Boot). Boot is start-only. MinIO is independent of the PostgreSQL stack, so it is started last; there is no ordering constraint. pg autostart status lists every target’s state.

Remove

pg addon remove minio --name store            # container gone, data kept
pg addon remove minio --name store --clean-data   # also delete the data directory

The data directory is the object storage — losing it means losing every bucket in it — so remove keeps it by default and says where it is. --clean-data deletes it (and prunes the now-empty default-layout parent directory; a data_dir override and its parent are never touched).

Logs

pg logs addon minio --name store      # last 50 lines
pg logs addon minio --name store -f   # follow

MinIO logs to stdout: startup lines (API:/Console: addresses, Documentation:) and request errors. An API: http://... block confirms the listeners came up.

Troubleshooting

  • pulling minio image ... : ... on install. The public tag ghcr.io/mars-base/pgcli/pgcli-minio:20250422221226 is not reachable — check network/registry access, or pre-pull it with podman pull.
  • Port collision on manual --api-port. Pick ports outside the auto pool (minio_start_port and up) or the auto-assigner will treat them as taken; also remember MinIO needs a consecutive pair.
  • pg addon start after host reboot does nothing / fails. Check pg logs addon minio --name store -f — most often the data directory was deleted (with --clean-data or by hand) and MinIO refuses to start on an empty dir it previously formatted, or the bind port moved.
  • Console reachable but S3 clients time out. The MINIO_SERVER_URL is built from listen + API port; if you serve on 127.0.0.1 but access from another host, clients get redirected to the loopback URL. Set listen to the address clients can actually reach. (Cluster mode does not set MINIO_SERVER_URL at all — see Distributed / Cluster Mode.)
  • Cluster stuck on Waiting for at least 1 remote servers with valid configuration. The nodes disagree. Check that every pg.yaml has the byte-identical endpoints list and root_password (podman inspect pgcli-minio-<ns>-<name> --format '{{json .Config.Env}}' on each node), and that no per-node MINIO_SERVER_URL crept back in.
  • macOS. Supported: the addon serves on the pgcli-net bridge with both ports published, so the Mac’s 127.0.0.1:<port> reaches them (the container binds 0.0.0.0 internally and MINIO_SERVER_URL advertises the loopback the Mac uses). After changing ports or credentials, --force recreate the container. For pg mc, the container cannot use a 127.0.0.1 alias — see the endpoint note above.

11 - Redis

Run Redis as a pgcli addon — a standalone key-value store for cache, session, ranking and counter data, with selectable major versions 7 and 8

Redis is the in-memory key-value store most applications reach for when they need a cache, a session backend, leaderboards (sorted sets) or atomic counters. pgcli runs it as a standalone, top-level addon with the same CLI surface as the object stores (install / start / stop / logs / autostart / remove), managed entirely through pg.yaml.

It is deliberately the simplest addon in the fleet:

  • One container, one port, one password. requirepass is generated on the first install and stored in pg.yaml — an unauthenticated Redis is not a reachable state.
  • Version selection. It is the first version-selectable addon: --version 7|8 resolves through a built-in table to a pinned docker.io/library/redis tag (7 → 7.4.11, 8 → 8.10.2, the default). --image still bypasses the table with any tag you like.
  • Persistence you can dial in. By default the dataset is an RDB snapshot in a bind-mounted host directory — it survives restarts, and survives pg addon remove (without --clean-data) so reinstalling the same name revives the data. --aof adds the write-ahead log on top for crash-safe, no-eviction stores, and --save no turns snapshots off entirely (see Parameters).

Pick Redis for cache/session/ranking/counter workloads next to your PostgreSQL instances; it is independent of the PG stack, coexists with any other addon, and several instances (even across majors) can run on one host.

Out of scope: Sentinel (automatic failover) is not managed by pgcli. Redis’s native cluster is supported — --cluster turns instances into cluster-enabled members that you assemble once yourself with pg redis-cli -- --cluster create (masters-only by default; add per-master followers with --cluster-replicas N; see Native cluster). Read replicas are too — --replica-of turns an instance into a read-only follower of another (see Read replicas and Known limitations).

Parameters

pgcli keeps Redis’s parameter surface deliberately small: one flag per knob, each mapping to a native redis-server option — argv overrides through the image’s own entrypoint, no redis.conf file is generated, and one container per instance runs the plain upstream image (no pgcli wrapper, unlike rustfs). The table lists every knob and its default:

Flag / pg.yaml key Default Redis option Meaning
--version / version 8 — (picks the image tag) major to install (see Version selection)
--image / image_tag resolved from the version table — override the tag verbatim
--port / port auto from redis_start_port (base 6379) --port host port
--listen / listen 0.0.0.0 --bind bind address (127.0.0.1 to tighten)
--password / password generated, 20 chars --requirepass auth; always required (a replica’s must equal the master’s)
--maxmemory / maxmemory unset (no cap) --maxmemory dataset cap that turns eviction on
--maxmemory-policy / maxmemory_policy allkeys-lru --maxmemory-policy eviction policy, only under a cap
--aof / aof off --appendonly yes write-ahead log on top of the snapshot
--appendfsync / appendfsync everysec (Redis’s own) --appendfsync AOF flush strength, only with --aof
--save / save Redis’s default schedule --save RDB snapshot plan; no disables snapshots
--replica-of / replica_host+replica_port unset (master) --replicaof + --masterauth read-only replica of a local master addon (its host/port/password are resolved from the config)
--replica-of-host / replica_host — --replicaof master address for a cross-host replica (pair with --replica-of-port + --password)
--replica-of-port / replica_port — --replicaof master port, paired with --replica-of-host
--cluster / cluster unset (standalone) --cluster-enabled yes + --masterauth native-cluster member: non-empty is the group name — same value means same cluster, and every member of a group shares the first member’s password (--cluster create authenticates all operands with one password, exactly like a replica’s password must equal its master’s). Every member also carries --masterauth so any node Redis later promotes to a follower can authenticate to its master. Mutually exclusive with --replica-of/--replica-of-host — an instance is either a cluster member or a read replica, never both. pgcli installs the node; you assemble the cluster yourself — see Native cluster
--cluster-replicas / cluster_replicas 0 (masters-only) — (echoed into the suggested --cluster create only) per-master followers for the assemble step: the summary counts 3*(1+N) nodes and the printed command ends with --cluster-replicas N. Which members become followers is Redis’s decision at --cluster create, not at install. A group property like the password — the first member sets it, later members inherit it, an explicit mismatch is rejected
--advertise-host / advertise_host unset (127.0.0.1, single-host) --cluster-announce-ip/-port/-bus-port the address this member announces to peers — a LAN IP, required for a cross-host cluster (Redis’s cluster bus has no NAT/port remapping)
--data-dir / data_dir <base-dir>/addon/redis/<name>/data --dir /data (host dir bind-mounted at /data) where the data lives
— autostart: false — start on boot (pg autostart enable --redis)

How the knobs combine:

  • requirepass is always on — an unauthenticated Redis is not a reachable state, even if --password is left empty by hand in pg.yaml.
  • Persistence defaults to RDB snapshots — Redis’s own save schedule, plus a final snapshot on shutdown (--stop-timeout 30 gives Redis the time to write it) and a replay from dump.rdb at start.
  • --aof adds the write-ahead log (--appendonly yes) alongside the snapshot — the durable, no-eviction shape. --appendfsync tunes its flush: always (durability) / everysec (the default) / no (throughput). The AOF lives in an appendonlydir/ under the data dir and is replayed before the snapshot, so it is the source of truth when both are on.
  • --save no disables snapshots — pair it with --aof for an AOF-only store (the summary then reads aof only); on its own it means a purely in-memory instance that loses its dataset on restart (the install warns).
  • --maxmemory implies eviction, defaulting to allkeys-lru — the cap means “cache, evict to stay under”. Pass --maxmemory-policy noeviction for a hard ceiling (writes fail past the cap instead of evicting), or omit --maxmemory entirely for no cap. The policy flag requires --maxmemory; --appendfsync requires --aof — the CLI rejects those combinations before it pulls or creates anything.
  • --replica-of makes a read replica — see Read replicas. The persistence/eviction knobs stay orthogonal: a replica may cap memory or enable AOF exactly like a master.
  • --cluster makes a cluster member, and is mutually exclusive with --replica-of/--replica-of-host — an instance is one role or the other, never both. Members of the same --cluster group share the first member’s password automatically (a later --cluster member with a different --password is rejected before anything is pulled or created), and the per-master follower count set by --cluster-replicas N is inherited the same way. See Native cluster.

Not every Redis option is a flag, by design: the multi-node control plane (Sentinel, automatic failover) is out of scope, and so is cluster orchestration — pgcli installs cluster-enabled members but never runs --cluster create, --cluster add-node, resharding, or scale-in for you; see Native cluster and Known limitations. Read replicas are supported (Read replicas); it is the orchestration (promoting a replica automatically when the master dies) that pgcli leaves to you. And --image is the escape hatch for the engine itself: pg addon install redis --image docker.io/valkey/valkey:8 runs Valkey (the Redis fork), its major reverse-parsing as 8.

Version selection

--version picks a major; the table maps each major to a pinned patch tag:

Major Default image tag Select with
7 docker.io/library/redis:7.4.11 pg addon install redis --name cache --version 7
8 docker.io/library/redis:8.10.2 pg addon install redis --name cache (8 is the default)

Resolution rules:

  • --version 7 (or 8) → the table’s tag is stored in image_tag, the major in version;
  • --image <tag> → your tag wins outright; the major is reverse-parsed from it for display (redis:7.2.4 → 7), or left empty if unparseable (the tag is then shown verbatim);
  • neither → major 8;
  • an unknown --version → error listing the available majors.

Both majors can run side by side on one host — different tags, different ports from the same pool. The tags track the latest patch of each major and are bumped together with the docs/images.md rows.

Install

# default: major 8, instance name "redis", port auto-assigned from 6379
pg addon install redis

# a named cache instance on major 7, with a memory cap (evicts at the cap)
pg addon install redis --name legacy --version 7 --maxmemory 256mb

# loopback-only instead of the all-interfaces default
pg addon install redis --name cache --listen 127.0.0.1

# pin the password (stable across reinstalls) and a fixed port
pg addon install redis --name sessions --password 'S3ssions!' --port 6379

# a read-only replica of the local "sessions" instance (borrows its password,
# major and endpoint)
pg addon install redis --name sessions-ro --replica-of sessions

The install summary prints everything a client needs:

✓ redis installed: "cache"
  Container:  pgcli-redis-default-cache
  Version:    8
  Image:      docker.io/library/redis:8.10.2
  Data:       ~/pg/addon/redis/cache/data
  Address:    0.0.0.0:6379
  Role:       master
  Persistence: rdb snapshots (default save schedule)

  Password:    <generated>

  Client:      pg redis-cli ping
  Raw DSN:     redis://:<password>@0.0.0.0:6379/0
  NOTE: listening on every interface; the password above is the only gate.
        loopback-only: pg addon install redis --name cache --listen 127.0.0.1 --force

Security model. listen defaults to 0.0.0.0 — on Linux (host networking) the port is published on every interface, and requirepass is the only gate. That is convenient for app-on-another-host setups but means the password is load-bearing: pass --listen 127.0.0.1 to keep an instance loopback-only. pg addon list and the logs never print the password; reveal it on demand with pg addon password redis --name cache or pg addon list --show-password (or read pg.yaml).

Re-running install is idempotent: a running container is left alone, a stopped one is started. To apply changed ports/listen/password/image, add --force (the container is recreated from the config; the data dir is untouched). The persistence knobs (--aof/--appendfsync/--save/ --maxmemory-policy) take effect the same way.

Using Redis

pg redis-cli

pg redis-cli runs Redis’s own client from a throwaway container of the addon’s image — no host install, no password typing:

pg redis-cli ping                              # PONG
pg redis-cli set session:42 '{"user":"alice"}' # ok — auth is injected
pg redis-cli get session:42
pg redis-cli lrange queue 0 -1                 # negative indexes pass through
pg redis-cli --name legacy zrevrange leaderboard 0 9

The local target is --name <addon> or, when omitted, the first redis addon by name (with several installed, the chosen target is announced on stderr). pgcli’s own flags are parsed only before the command word; everything after is forwarded to redis-cli verbatim — negative indexes and option flags (via --) work that way.

Reaching a remote endpoint — --host/--port override where the client connects, without registering the remote as an addon:

# reuse a local addon's image + password, but talk to a remote host (e.g. a replica)
pg redis-cli --host 10.0.0.7 ping
pg redis-cli --host 10.0.0.7 --port 6380 --name cache info

# no local addon at all: default-major image, password via REDISCLI_AUTH
REDISCLI_AUTH=s3cret pg redis-cli --host 10.0.0.7 dbsize

Use these instead of redis-cli’s own -h/-p: those sit after the command word and would be read as command arguments (ping -h 10.0.0.7 errors), while pgcli injects the connection -h/-p itself. REDISCLI_AUTH (redis-cli’s native env var), if set, overrides the stored password in every mode:

REDISCLI_AUTH=otherpass pg redis-cli dbsize

Application connections

Any Redis client works; the DSN printed at install has the shape redis://:<password>@<host>:<port>/0. For TLS you would need a stunnel or redis’ own TLS build in front — see Known limitations.

Read replicas

--replica-of turns a new instance into a read-only replica of an existing master addon: it streams the master’s writes continuously and serves reads, while writes to it are rejected with READONLY. This is read scaling and data redundancy, not high availability — pgcli does not run Sentinel, so a dead master is not promoted automatically (see Known limitations).

# master (writable)
pg addon install redis --name cache

# same-host replica: it borrows the master's major, password and endpoint
pg addon install redis --name cache-ro --replica-of cache

A local --replica-of resolves everything from the config: the replica adopts the master’s version (cross-major replication is unsupported — a mismatch is a fast error), its password, and the endpoint 127.0.0.1:<master-port>. That one password then serves both requirepass (the replica’s own clients auth with it) and --masterauth (the replica authenticating to the master), so --password/--maxmemory/--aof etc. stay exactly as on a master. The stored replica_host/replica_port mean pg addon start rebuilds the same --replicaof argv even if the master is gone from the config.

Cross-host masters use the explicit form — pgcli cannot look up a remote master’s password, so you supply it (it must equal the master’s):

pg addon install redis --name cache-r2 \
    --replica-of-host 10.0.0.7 --replica-of-port 6379 --password <master-password>

pg addon list and the install summary show a Role: line — master, or replica of <host>:<port> (read-only) — and pg redis-cli --name cache-ro info replication reports role:replica with master_link_status:up once the (initial, RDB-carrying) sync completes. Send reads to the replica and writes to the master, e.g. with the DSNs:

# read traffic -> the replica
redis://:<password>@127.0.0.1:<replica-port>/0

To promote a replica to an independent master at runtime (the manual failover pgcli deliberately leaves to you), clear its replication and then, if you want it to persist across restarts, drop its role from the config:

pg redis-cli --name cache-ro replicaof no one   # stop following the master
pg addon remove redis --name cache-ro          # keep the data, forget the role
pg addon install redis --name cache-ro         # reinstall as a plain master

Native cluster

--cluster turns instances into members of a Redis native cluster — sharding by slot (16384 of them), not a read replica of one master. This is the only multi-node topology pgcli supports; Sentinel is not.

pgcli’s role is deliberately narrow: it installs cluster-enabled nodes, it does not assemble them. That is Redis’s own two-step flow, not a pgcli invention — a cluster is cluster-enabled yes servers plus one redis-cli --cluster create command run against all of them at once. Splitting those two steps means pgcli never has to guess “is this the last member I’m waiting for, should I form the group now” (an etcd-style auto-bootstrap state machine); assembling is always your decision, made once, the same way you’d do it against bare redis-server.

# 1. install the members — one --cluster <token> turns each into a cluster-enabled
#    node; the same token means "same cluster". Minimum 3 masters (Redis's own
#    quorum rule). masters-only is the default (3 installs, --cluster-replicas 0);
#    to give each master a follower, install 3*(1+N) members and pass
#    --cluster-replicas N to the first one (the rest inherit it) — see step 2.
pg addon install redis --name n1 --cluster app --maxmemory 10mb
pg addon install redis --name n2 --cluster app --maxmemory 10mb
pg addon install redis --name n3 --cluster app --maxmemory 10mb

Members of one group share the first member’s password automatically: --cluster create authenticates every operand node with a single -a (here, via the one REDISCLI_AUTH pg redis-cli injects), so one password has to reach the whole group — the same rule that makes a read replica’s password equal its master’s. A later --cluster member installed with a different --password is rejected up front, before anything is pulled or created; omit --password and the group’s own value is inherited. Every member also emits --masterauth (the same shared password) in its argv: at --cluster create time Redis may promote any node to a follower, and a follower needs --masterauth to authenticate to its master — without it it spins forever in a reconnect storm (master_link_status:down, CPU pinned). --cluster and --replica-of/--replica-of-host are mutually exclusive on one install — an instance is either a cluster member or a read replica, never both.

# 2. assemble once, through pg redis-cli's passthrough (pgcli never runs this)
pg redis-cli --name n1 -- --cluster create 127.0.0.1:6379 127.0.0.1:6380 127.0.0.1:6381 --cluster-replicas 0

The three addr:port operands are every member’s PeerAddr:port — that’s 127.0.0.1:<port> for a single-host cluster, or each member’s --advertise-host:<port> for a cross-host one (see below). The install summary already prints this exact command, built from whatever --cluster app members are configured at that moment (pg redis-cli --name n3 -- --cluster create 127.0.0.1:6379 127.0.0.1:6380 127.0.0.1:6381 --cluster-replicas 0), so it is copy-pasteable rather than something to reconstruct by hand:

-> NOTE: native-cluster member of "app" — it comes up cluster-enabled but INCOMPLETE
   until you assemble the group once (see the "Cluster:" line below). pgcli does not
   run --cluster create for you.
...
  Cluster:     "app" — 3 masters configured. Assemble once (pgcli does not run this):
               pg redis-cli --name n3 -- --cluster create 127.0.0.1:6379 127.0.0.1:6380 127.0.0.1:6381 --cluster-replicas 0
               (bus port = client+10000; for cross-host peers open it on the firewall, and give each member --advertise-host)

--cluster-replicas 0 is masters-only — every member holds its own slice of the slots and none of them has a follower. To give each master a follower (so one master’s slot range survives that node dying), pass --cluster-replicas N on the first install and add enough members: each master needs itself plus its N followers, so the total is 3*(1+N) — for N=1 that’s 6 members:

pg addon install redis --name n1 --cluster app --cluster-replicas 1 --maxmemory 10mb
pg addon install redis --name n2 --cluster app --maxmemory 10mb   # inherits replicas=1
# …install to 6 members total, then:
pg redis-cli --name n1 -- --cluster create \
    127.0.0.1:6379 127.0.0.1:6380 127.0.0.1:6381 \
    127.0.0.1:6382 127.0.0.1:6383 127.0.0.1:6384 --cluster-replicas 1

Which members Redis elects as masters vs followers is its decision at --cluster create (it balances followers across hosts where it can), so the pgcli instance names are deliberately role-neutral, and a follower re-links from its own nodes.conf after a restart — role and masterauth pairing survive, no re-create. The install summary switches from “3 masters configured” to counting nodes (“6 nodes configured”) once followers are in play, and echoes the group’s --cluster-replicas N into the suggested command; it never calls a follower-set node a master.

After assembling

A pg redis-cli pointed at a cluster member is automatically a cluster-aware client: pgcli injects redis-cli’s own -c flag so a get/set that lands on the “wrong” node follows its MOVED redirect to the node that actually owns the slot — no -c to remember, and it doesn’t matter which --name you happen to point at:

pg redis-cli --name n1 set foo bar      # might be served by n3 via MOVED
pg redis-cli --name n2 get foo          # same key, followed the redirect again
pg redis-cli --name n1 -- --cluster check 127.0.0.1:6379   # admin subcommands, not -c's job

The last line is the exception, not a rule to remember: when the command is redis-cli’s own --cluster <subcommand> (which dials the nodes named in its operands itself), pgcli suppresses the -c injection — it’s the assembly/admin surface from step 2, not a data command.

The auto--c above depends on pgcli reading a local cluster member from pg.yaml (the --name path). When you reach the cluster remotely with --host/--port from a machine that has no such addon configured, pgcli has no way to know the endpoint is a cluster node, so it injects nothing — and an unredirected get/set that lands on the wrong node just returns MOVED .... Forward redis-cli’s -c yourself (it is redis-cli’s own flag, so it goes after the -- passthrough, before the command word):

export REDISCLI_AUTH=<the group password>
pg redis-cli --host 10.10.0.158 --port 6379 -- -c get foo   # follows MOVED for you
pg redis-cli --host 10.10.0.158 --port 6379 -- -c set foo bar

-c matters for writes as much as reads: without it a set aimed at a non-owner returns MOVED and is not applied, so the key never exists. Put -c on the write, and any single node serves the whole keyspace.

You can also skip the env var and pass the password with redis-cli’s own -a — it is a connection option too, so it goes in the same passthrough slot, before the command word:

pg redis-cli --host 10.10.0.158 --port 6379 -- -a <the group password> -c get foo

Two caveats distinguish it from REDISCLI_AUTH: redis-cli prints a security warning on every invocation (-a/-u on a command line is visible to other users via ps), and placing the flag after the command word (get foo -a …) fails with “wrong number of arguments” — it would be passed as a command argument. For anything beyond a one-off command, prefer the env var; they are otherwise equivalent for authentication.

If your clients cannot be made cluster-aware at all, put a Predixy proxy in front of the cluster: it follows the redirects itself and exposes one plain redis:// endpoint.

The cluster bus is a second port per member: always client port + 10000 (Redis’s own fixed rule, e.g. 6379→16379) — it is not drawn from redis_start_port, not stored in pg.yaml, and pg addon list shows it alongside the token:

    Role:        cluster member of "app" (127.0.0.1:6381)
    Cluster:     app (bus 16381)

Topology is self-healing: each node’s --cluster-config-file nodes.conf lives in its own --dir /data bind mount, so pg addon stop/start (or a host reboot) brings the whole cluster back with no re-create step — same start-only model as autostart for everything else here.

Two commands check the cluster’s health directly, both through the passthrough (yes, the -c one is a data-path client flag, so it goes after the --):

# one member's view of the whole cluster — look for cluster_state:ok / cluster_size:N
pg redis-cli --host <ip> --port <port> -- -c cluster info
# full group health check (slot coverage, replicas, links) — redis-cli's admin surface
pg redis-cli -- --cluster check <ip>:<port>

Cross-host members: --advertise-host

A single-host cluster dials peers at 127.0.0.1 and works with no extra flags. Redis’s cluster bus does not support NAT or port remapping, so members on different hosts must announce the address peers can actually reach:

# on 10.10.0.158 — the first member decides the group's one password; read it back:
pg addon install redis --name n1 --cluster app --advertise-host 10.10.0.158
PW=$(pg addon password redis --name n1)
# on 10.10.0.159 and 10.10.0.160 — carry that same password across:
pg addon install redis --name n2 --cluster app --advertise-host 10.10.0.159 --password "$PW"
pg addon install redis --name n3 --cluster app --advertise-host 10.10.0.160 --password "$PW"
# assemble once (from any host that reaches all three) — the operands are each
# member's advertised address + its port (one member per host here, each host's
# own pool starts at 6379, so all three are :6379):
pg redis-cli --name n1 -- --cluster create \
    10.10.0.158:6379 10.10.0.159:6379 10.10.0.160:6379 --cluster-replicas 0

--advertise-host adds --cluster-announce-ip/-port/-bus-port to the node’s argv, and PeerAddr (used to build the --cluster create operands above) switches from 127.0.0.1 to that address. Two things to get right on your side: open each member’s bus port (client+10000 — 16379 at the default 6379) on the firewall between hosts — not just the client port — and every member of the group must carry the flag, not only the ones being joined later.

The --password "$PW" on every host after the first is not decoration: the shared-password inheritance only works within one pg.yaml — on a single host, later members automatically adopt the group’s password; across hosts, each host has its own config file and generates its own secret. A cross-host cluster must therefore pin one password explicitly on every host, read from the first member with pg addon password.

(--cluster create authenticates every operand with that one password, so a mismatch surfaces as a per-node auth error.)

Status: cross-host clusters are verified end-to-end across three hosts (--advertise-host → --cluster-announce-*, cross-host --cluster create, MOVED redirects between hosts, and self-heal after a stop/start on each host). The single-host flow is additionally covered by the automated e2e (test/addon/test_redis_cluster.sh), which tests both shapes there: a three-master group and a 3-master × 1-follower group (which is how the missing---masterauth reconnect storm was caught). The multi-host case is so far a manual procedure, not yet in the suite.

Ports

Each instance takes one port from Redis’s own pool, redis_start_port (default 6379) — a separate cursor from the object stores’ shared minio_start_port pool, so a redis, a minio and a rustfs instance never collide:

pg addon install redis  --name cache    # 6379
pg addon install redis  --name sessions # 6380

--port fixes an instance to a specific port; auto-assignment skips anything already explicit or live on the host. A native-cluster member is no different here — the cluster bus port is always Redis’s own client+10000, derived, never drawn from the pool.

Configuration

Instances live under the top-level addons.redis map in pg.yaml:

namespace: default
redis_start_port: 6379     # Redis's own pool, separate from minio_start_port
addons:
  redis:
    cache:
      container_name: pgcli-redis-default-cache
      name: cache
      version: "8"                       # major as selected/stored
      image_tag: docker.io/library/redis:8.10.2
      # data_dir: /srv/redis-cache       # omit for <base-dir>/addon/redis/cache/data
      listen: 0.0.0.0                    # default (all interfaces); 127.0.0.1 to tighten
      port: 6379
      password: <generated>              # written on first install
      # maxmemory: 256mb                 # optional cap
      # maxmemory_policy: noeviction     # only with a cap; default allkeys-lru
      # aof: true                        # write-ahead log on top of snapshots
      # appendfsync: always              # only with aof; default everysec
      # save: "900 1 300 10"             # RDB schedule; "no" disables snapshots
      # replica_host: 127.0.0.1          # set by --replica-of: this is a read replica
      # replica_port: 6379               # the master's port, paired with replica_host
      # cluster: app                     # set by --cluster: this is a native-cluster member
      # cluster_replicas: 1              # set by --cluster-replicas: followers per master for --cluster create (0 = masters-only; group-shared)
      # advertise_host: 10.10.0.158      # set by --advertise-host: peer-visible address (cross-host only)
      autostart: false                   # pg autostart enable --redis --name cache

Edits to listen, port, password, maxmemory/maxmemory_policy, aof/appendfsync/save, replica_host/replica_port, cluster/cluster_replicas/advertise_host, image_tag/version, or data_dir take effect after the next pg addon install redis --name cache --force (or via the matching flags). The replica and cluster roles are normally set by the --replica-of* / --cluster (incl. --cluster-replicas) / --advertise-host flags rather than hand-edited — see Read replicas and Native cluster.

List

pg addon list
Infra add-ons (redis):
  redis (name: cache)
    Status:      running
    Version:     8
    Address:     0.0.0.0:6379
    Role:        master
    Auth:        on (requirepass)
    Maxmemory:   256mb (allkeys-lru)
    Persistence: rdb + aof (default save schedule, appendonly yes)
    Data:        ~/pg/addon/redis/cache/data
    Image:       docker.io/library/redis:8.10.2
    Container:   pgcli-redis-default-cache
    Client:      pg redis-cli --name cache ping

pg addon list never prints the password. To reveal it deliberately, add --show-password (it appends a Password: and a ready-to-paste Raw DSN: line to each Redis instance — and a Root password: line to each object store), or print just one instance’s value bare on stdout for scripting:

pg addon password redis --name cache
export REDISCLI_AUTH="$(pg addon password redis --name cache)"

pg addon password takes the same --name as the other subcommands (defaulting to the addon’s own name) and a --file that writes the value mode 0600 instead of to the terminal — prefer --file so the secret stays out of shell history and scrollback.

Start and stop

pg addon start redis --name cache
pg addon stop  redis --name cache

stop sends a graceful SIGTERM — with --stop-timeout 30 Redis writes its final RDB before exiting. start only starts an existing container (and self-heals an improper state by recreating it from the config).

Auto-start on Boot

Containers carry a --restart unless-stopped policy (crashes, not reboots). To bring instances up after a host reboot:

pg autostart enable --redis --name cache

Redis autostart is start-only (install the instance first) and replays the RDB snapshot from its data dir, so the dataset survives the reboot. Redis is independent of the PostgreSQL stack, so boot-time pg start --autostart starts it last.

Remove

pg addon remove redis --name cache            # container + config entry; data kept
pg addon remove redis --name cache --clean-data  # also delete the data dir

Without --clean-data the host data dir (and its dump.rdb) stays in place — reinstalling the same name revives the dataset. --clean-data deletes it, falling back through podman unshare when rootless podman’s subordinate uid makes Redis’s files undeletable by the host user. An empty per-instance parent directory is pruned; a custom data_dir parent is never touched.

Logs

pg logs addon redis --name cache        # last 50 lines
pg logs addon redis --name cache -f     # follow

Troubleshooting

  • NOAUTH Authentication required from a raw client — expected: every instance has a requirepass. Get it with pg addon password redis --name cache, or use pg redis-cli, which injects it.
  • maxmemory evicting more than you wanted — under a --maxmemory cap the default policy is allkeys-lru (evict any key to stay under: a cache, not a hard store). Pass --maxmemory-policy noeviction to make the cap a hard ceiling instead (writes fail past it rather than evicting), or omit --maxmemory for no cap at all.
  • AOF not replaying the newest writes — --appendfsync everysec (the default) can lose the last second of writes on a hard crash; use --appendfsync always when you cannot afford that. A graceful pg stop always flushes, so this only bites on an unclean kill.
  • Image not found at install — both majors are plain docker.io/library/redis images pulled on demand; on an air-gapped host, podman load the tar first (the catalog and export steps live in docs/images.md in the repo) and the pull is skipped.
  • A hand-edited version that is not in the table — install errors and suggests --image rather than silently rewriting your value.
  • Port already live — auto-assignment scans host listeners and skips them; pin --port when you need a stable number.
  • A replica rejects writes (READONLY) — that is the role, not a fault: send writes to the master. To make it an independent master, see Read replicas.
  • A freshly-created replica briefly shows master_link_status:down — normal during the first (RDB-carrying) full sync, and redis 8 reloads the link once more when the snapshot transfers over its rdbchannel. Watch info replication; it settles at up and role:replica.

Known limitations

  • No automatic failover — read replicas are supported (Read replicas) and native-cluster sharding is supported (Native cluster), but the HA control plane is not: Sentinel is out of scope, and so is cluster orchestration — pgcli installs cluster members but never assembles, rescales, or rebalances them. A replica gives read scaling and a redundant copy of the data, not a self-healing pair — when the master dies you promote a replica yourself (replicaof no one, above). A single instance with no replica is a single point: it can be made durable on disk with --aof, but it cannot fail over to another node.
  • Native cluster: assembly and reshaping stay manual — --cluster installs cluster-enabled nodes and --cluster-replicas N (echoed into the suggested command) lets each master have followers, so a follower auto-promotes when its master dies. What pgcli does NOT do is run --cluster create/add-node/ resharding/del-node for you, and removing a member (pg addon remove) is a plain delete with no slot reassignment — shrink or reshape the cluster at the Redis layer first (move its slots off, forget the node), then remove it. Also note a masters-only group (--cluster-replicas 0) has no follower to promote: there a dead master takes its slot range down with it until you intervene.
  • Cross-host cluster (--advertise-host) is manual, not in the e2e suite — the flag, the --cluster-announce-* argv it produces, and the firewall/bus-port rules are implemented, unit-tested, and verified by hand across three hosts (assembly, cross-host MOVED redirects, and self-heal all pass). The single-host flow (masters-only and 3-master × 1-follower) has an automated e2e; cross-host-with-followers has no automated e2e but relies on the same per-member --masterauth that makes followers link up on one host. See the status note in Native cluster.
  • No TLS — Redis 7’s native TLS exists in some builds but is not wired here; treat the network path as trusted and rely on requirepass, or keep the instance loopback-only (--listen 127.0.0.1). For a cross-host cluster that means the cluster bus traffic between members is unencrypted as well.
  • macOS is code-complete, untested — the bridge path (published ports, host.containers.internal for pg redis-cli) mirrors the object stores; it has not yet been exercised on a Mac.
  • Default persistence is RDB granularity — a crash loses writes since the last snapshot. Enable --aof when that gap matters (at everysec you still lose at most one second; always closes it); accept snapshots-only for cache/session data, or move durable data to PostgreSQL.

12 - Predixy

Run Predixy as a pgcli addon — a Redis protocol proxy that exposes a native cluster as one plain redis:// endpoint, so cluster-unaware clients need no MOVED handling

Predixy is a high-performance Redis protocol proxy. pgcli runs it as a standalone, top-level addon whose job is to take a Redis native cluster — 3+ nodes, 16384 slots, MOVED redirects — and hand it back to your applications as one plain redis:// endpoint. Clients do not need to be cluster-aware: no -c, no redirect handling, just connect and run commands.

Platform support: like HAProxy and Redis, the Predixy addon needs Linux host networking to dial its backend nodes; it is not supported on macOS.

How It Works

Predixy speaks the Redis protocol on its client port and keeps persistent connections to every cluster node listed in --backend. A client request is routed by slot: if the node it lands on does not own the key’s slot, Predixy follows the MOVED itself and re-issues the command on the right node — transparently, in-proxy. The client never sees a redirect.

pgcli renders one config file per instance, <base-dir>/addon/predixy/<name>/predixy.conf, and bind-mounts it (file-level, read-only) over the image’s baked-in /usr/local/predixy/conf/predixy.conf. The rendered file’s Include license.conf resolves relative to that directory, so the image’s signed license sibling stays visible — pgcli never ships or manages a license (see Known limitations).

One password, two sides

The proxy sits between two authenticated parties — its own clients and the cluster behind it — and pgcli uses one password for both:

  • Authority { Auth "<pw>" { Mode admin } } — clients must AUTH this password to use the proxy;
  • ClusterServerPool { Password "<pw>" } — Predixy authenticates to the cluster nodes with it.

That works because the password is the proxied cluster’s own requirepass: clients already know it, the nodes already accept it. Read it straight out of the redis addon:

PW=$(pg addon password redis --name n1)

A single cluster-member password therefore gates the proxy endpoint too — no second secret to keep in sync. (If you want a separate client-facing password, that is a different Authority design pgcli does not render; see Known limitations.)

Install

--backend and --password are both required. --backend is the cluster’s full node list — pgcli never derives it from local redis addons, because the cluster being fronted often lives on other hosts; you know its topology, so you list it. Repeat the flag or comma-separate one run; duplicates are rejected.

# single-host cluster (members on 127.0.0.1:6379/6380/6381)
PW=$(pg addon password redis --name n1)
pg addon install predixy --name proxy \
  --backend 127.0.0.1:6379,127.0.0.1:6380,127.0.0.1:6381 \
  --password "$PW"

# cross-host cluster — one member per host at the default port
pg addon install predixy --name app-proxy \
  --backend 10.10.0.158:6379,10.10.0.159:6379,10.10.0.160:6379 \
  --password "$PW" --workers 2

The summary prints the one endpoint clients should be pointed at:

✓ predixy installed: "proxy"
  Container:    pgcli-predixy-default-proxy
  Image:        ghcr.io/mars-base/pgcli/predixy:7.0.1-alpine
  Listen:       0.0.0.0:7617
  Workers:      2
  Backends:     3 (127.0.0.1:6379, 127.0.0.1:6380, 127.0.0.1:6381)
  Config:       ~/pg/addon/predixy/proxy/predixy.conf

  Password:     <the one password>
  Raw DSN:      redis://:<password>@0.0.0.0:7617/0

  Client:       redis-cli -h 0.0.0.0 -p 7617 -a '<password>' ping
  The proxy absorbs MOVED: an ordinary redis client — no -c, no
  redirect handling — reads and writes the whole cluster key space
  through this one endpoint.

Guards run before anything is pulled or created: a missing --backend, a malformed entry (no port, non-numeric or out-of-range port, empty entry), a duplicate node, a missing --password, a password containing " or a newline (Predixy’s quoted-string syntax has no escape for them), or --workers < 1 all fail fast with a clear message.

Re-running install is idempotent as elsewhere: a running container is left alone (config rewritten), a stopped one is started, and --force recreates it so a changed port/listen/password/backend set takes effect. The backend list is replaced wholesale each time, so growing the cluster (install more redis members, --cluster add-node, …) is followed by re-running the same install with the updated full list.

Workers

--workers N sets Predixy’s WorkerThreads (default 1). Each worker is a busy-poll event thread; on a multi-core host dedicated to proxying, N ≈ the number of cores you are willing to spend scales throughput roughly linearly.

Using the proxy

Any Redis client connects to the proxy’s port with the cluster’s password and behaves as if it were talking to a single standalone Redis — the whole keyspace is served through the one endpoint:

redis-cli -h 127.0.0.1 -p 7617 -a "$PW" set foo bar    # OK — no MOVED, no -c
redis-cli -h 127.0.0.1 -p 7617 -a "$PW" get foo        # "bar"

(DSN shape: redis://:<password>@<listen>:<port>/0.)

With pg redis-cli

pg redis-cli reaches the proxy through --host/--port — there is no --name path to a Predixy instance (--name resolves redis addons only):

# on the proxy's own host
pg redis-cli --host 127.0.0.1 --port 7617 set foo bar
pg redis-cli --host 127.0.0.1 --port 7617 get foo

# from a host with no local redis addon: the default-major image, password via env
REDISCLI_AUTH=$PW pg redis-cli --host 10.10.0.158 --port 7617 ping

With a local redis addon configured, its image and password are reused (see redis.md — pg redis-cli). If that addon happens to be a cluster member, pg redis-cli injects its -c as usual — harmless through the proxy, because the proxy absorbs every MOVED before the client could see one. That is the point of the proxy: the same plain-client commands work whether or not -c is in play.

Cross-host

Verified end-to-end: a proxy on one host fronting a three-host cluster (--backend 10.10.0.15x:6379,…), with plain cluster-unaware clients connecting from a different host through it — SET whose slot belongs to a remote node is absorbed and applied, and reads back from that node’s own port. The only requirement is reachability: the proxy host must be able to dial every --backend node’s client port (the cluster bus ports are between the members, not the proxy).

Ports

Each instance takes one port from Predixy’s own pool, predixy_start_port (default 7617, the port the image EXPOSEs) — separate from Redis’s redis_start_port pool, so a proxy and the cluster it fronts never collide. --port pins an instance; auto-assignment skips what is already taken.

The bind address defaults to 0.0.0.0 (the AUTH password is the only gate); --listen 127.0.0.1 tightens it to loopback.

Configuration

Instances live under the top-level addons.predixy map in pg.yaml:

namespace: default
predixy_start_port: 7617
addons:
  predixy:
    proxy:
      container_name: pgcli-predixy-default-proxy
      name: proxy
      image_tag: ghcr.io/mars-base/pgcli/predixy:7.0.1-alpine
      listen: 0.0.0.0
      port: 7617
      workers: 2
      backend:
        - 127.0.0.1:6379
        - 127.0.0.1:6380
        - 127.0.0.1:6381
      password: <the cluster requirepass>   # written by install, never generated
      autostart: false                      # pg autostart enable --predixy --name proxy

The rendered predixy.conf carries the same information in Predixy’s own syntax; hand-editing it is wiped by the next install — edit pg.yaml (or the flags) and re-install instead.

List

pg addon list
Infra add-ons (predixy):
  predixy (name: proxy)
    Status:      running
    Address:     0.0.0.0:7617
    Workers:     2
    Backends:    3 (127.0.0.1:6379, 127.0.0.1:6380, 127.0.0.1:6381)
    Client DSN:  redis://:<password>@0.0.0.0:7617/0
    Image:       ghcr.io/mars-base/pgcli/predixy:7.0.1-alpine
    Container:   pgcli-predixy-default-proxy
    Config:      ~/pg/addon/predixy/proxy/predixy.conf

pg addon list redacts the password; --show-password reveals it, and pg addon password predixy --name proxy prints just that value bare for scripting.

Start and stop

pg addon start predixy --name proxy
pg addon stop  predixy --name proxy

start only starts an existing container (self-healing an improper state by recreating it from the rendered config on disk); it errors if that file is missing — re-run install to regenerate it.

Auto-start on Boot

pg autostart enable --predixy --name proxy

Boot is start-only (install first), and the boot service starts Predixy after Redis, so the proxied members are already coming up when the proxy dials them. See Auto-start on Boot.

Remove

pg addon remove predixy --name proxy

Stops and removes the container, deletes the rendered config directory, and drops the pg.yaml entry. The proxied cluster is untouched — the proxy is merely a consumer of it.

Logs

pg logs addon predixy --name proxy      # last 50 lines
pg logs addon predixy --name proxy -f   # follow

The startup banner reports the effective build (Workers:2, …) — the place to confirm --workers landed.

Known limitations

  • One admin Authority user — the renderer emits a single Auth "<pw>" { Mode admin }: every client of the proxy shares one password with full access. Per-user auth, read-only users, and keyspace restrictions are not rendered (Predixy itself supports more; pgcli’s surface stops here).
  • Cluster pools only — ClusterServerPool is the only backend type; Sentinel or standalone pools are not configured.
  • License lives in the image — the free-edition license baked into ghcr.io/mars-base/pgcli/predixy:7.0.1-alpine caps clients at ClientLimit 128 and expires 2026-12-31; pgcli never ships or rotates it — the image build does. When it expires, rebuild the image (the Makefile target already swaps in the current license).
  • No TLS on the client side in this addon (password-only gate; keep listen loopback or a trusted network, as with Redis itself).
  • Linux only — host networking is required to dial the backends; macOS is not supported (fails fast).

Troubleshooting

  • ERR invalid password from clients — the client must AUTH the one password; check it against pg addon password predixy --name proxy (it should equal the cluster’s, pg addon password redis --name n1).
  • Container exits at once — Predixy rejects its config on the spot: a lone { on its own line, or a password with a "/newline that broke quoting. pgcli validates both before writing, so this points at a hand-edited predixy.conf — re-install.
  • Commands hang or every key errors — a backend node is unreachable from the proxy host (wrong address, firewalled). pg logs addon predixy shows the dial failures; --backend must list nodes this host can dial.
  • Stale backend list after cluster changes — install replaces the list wholesale; re-run it with the current full node set after adding or removing members.

13 - pgAdmin 4

Run pgAdmin 4 as a pgcli addon — the official PostgreSQL web administration UI, one container from the upstream dpage/pgadmin4 image, with an auto-generated web login and optional pre-seeded servers

pgAdmin 4 is PostgreSQL’s official web administration UI — the browser console for browsing schemas, running SQL, and watching servers. pgcli runs it as a standalone, top-level addon with the same CLI surface as the other web/infra addons (install / start / stop / logs / autostart / remove), managed entirely through pg.yaml.

It is the fleet’s one UI addon, which shapes its design:

  • A web app, not a database front. pgAdmin dials the servers you register in its own UI; it does not front one specific PostgreSQL instance the way PostgREST or PgBouncer do. That is why it is a top-level-only addon (addons.pgadmin.<name>) with no per-instance sidecar.
  • Its own login. The web UI needs an email + password to sign in. That is not a PostgreSQL password — it is pgAdmin’s own account, auto-generated on first install and stored in pg.yaml. Retrieve it later with pg addon password pgadmin.
  • Persistent session store. pgAdmin keeps its config, saved servers, and browse history in a sqlite DB under a bind-mounted data dir. It survives pg addon remove (without --clean-data) and is revived on reinstall.
  • Optional one-time seed. --dsn or --pg-name <instance> pre-registers one server in the UI’s servers.json at install, so the browser opens with that server already listed. It is a convenience, not a runtime coupling — pgAdmin never blocks on it, and you can add/remove servers in the UI after.

Tip: one pgAdmin per database, spin up on demand. A pgcli-managed pgAdmin is a single lightweight container that starts in seconds and consumes very little memory — cheap enough to treat as disposable. Rather than running one shared pgAdmin with every server registered in it, create a dedicated instance for the database you are working on right now, and remove it when done:

# quick look at proj01
pg addon install pgadmin --name proj01 --pg-name proj01
# ... browse, query, done
pg addon remove proj01 --clean-data

# inspect a remote production read-replica
pg addon install pgadmin --name prod-ro \
    --dsn "postgres://reader@10.0.0.7:5432/proddb"
pg addon remove prod-ro --clean-data

Each instance gets its own port (auto-assigned), its own login, and its own pgpass — no cross-contamination between databases, no stale connections lingering in a shared session store. When you need it again, reinstall in seconds.

Out of scope: pgAdmin serves plain HTTP here — no TLS termination is wired in (put a reverse proxy in front if you need HTTPS). servers.json itself cannot carry the target server’s password (pgAdmin refuses to import one), but when the seed DSN does carry one, pgcli pre-configures it through pgAdmin’s passfile support so the seeded server connects without prompting — see Seeding a server.

Parameters

One container from the upstream docker.io/dpage/pgadmin4 image (pull-only — pgcli never builds it), configured entirely through -e env vars the entrypoint reads. The table lists every knob and its default:

Flag / pg.yaml key Default Env var Meaning
--image / image_tag docker.io/dpage/pgadmin4:9.18 — override the tag verbatim
--port / host_port auto from pgadmin_start_port (base 5050) PGADMIN_LISTEN_PORT web host port
--listen / listen 127.0.0.1 PGADMIN_LISTEN_ADDRESS bind address (0.0.0.0 to expose — see Listening and exposure)
--email / email admin@pgcli.lan PGADMIN_DEFAULT_EMAIL web login account (validated — see Troubleshooting)
--password / password generated, 20 chars PGADMIN_DEFAULT_PASSWORD web login password — not a PG password
--dsn / dsn unset — (renders servers.json + pgpass) one server to pre-register, given as a URI — when it carries a password, it is pre-filled too (host is dialed from the container — see Seeded host vs. listen address)
--pg-name unset — (renders servers.json + pgpass) resolve that one server from a locally-managed instance instead
--data-dir / data_dir <base-dir>/addon/pgadmin/<name>/data (/var/lib/pgadmin) where the session store lives
— autostart: false — start on boot (pg autostart enable --pgadmin)

How the knobs combine:

  • email + password only take effect on a fresh data dir. pgAdmin reads PGADMIN_DEFAULT_* while it initialises pgadmin4.db; once that file exists the stored account is authoritative and the env vars are ignored. A reinstall that revives a kept dir therefore prints a password that is inert against it (the install says so) — to actually reset the login, remove with --clean-data first, or pin --password to the original when reviving.
  • --dsn and --pg-name are mutually exclusive — both mean “seed this one server”, one by URI and the other by resolving a local instance’s endpoint. --name is the addon’s own key and has nothing to do with --pg-name. The seed’s host is where pgAdmin connects from, not where your browser does — see Seeded host vs. listen address.
  • listen defaults to loopback — the web UI is a login gate, so it stays on 127.0.0.1 unless you pass --listen 0.0.0.0 to reach it from another host (the summary then warns that the login is the only gate). Full picture in Listening and exposure.
  • email must survive the image’s validator — the entrypoint checks it with email_validator and rejects reserved TLDs (.local, .invalid, .test) outright, crash-looping on one. The default admin@pgcli.lan is chosen to pass; pick your own on the same basis (.lan, .internal-style names you control are fine — a real, deliverable address is not required, the deliverability check is off).

Install

# default: instance name "pgadmin", port auto from 5050, loopback, admin@pgcli.lan
pg addon install pgadmin

# a named console with your own web-login email
pg addon install pgadmin --name console --email me@example.com

# pre-seed the UI with one locally-managed instance
pg addon install pgadmin --name dev --pg-name proj01

# pre-seed from an arbitrary remote DSN
pg addon install pgadmin --name remote \
    --dsn "postgres://readonly@10.0.0.7:5432/appdb"

The install summary prints the URL and the (generated) web login:

✓ pgAdmin installed: "console"
  Container:  pgcli-pgadmin-default-console
  Image:      docker.io/dpage/pgadmin4:9.18
  Data:       ~/pg/addon/pgadmin/console/data
  URL:        http://127.0.0.1:5050/
  Seeded:     proj01
  Seed auth:  password pre-configured (pgpass) — no prompt on first connect

  Login email:    me@example.com
  Login password: <generated>
  (Web login only — not a PostgreSQL password. Retrieve it later with `pg addon password pgadmin`.)

  Add servers to browse in the web UI itself, or reinstall with --dsn/--pg-name to pre-seed one.

The Seeded: / Seed auth: lines appear only when --dsn/--pg-name was passed. Seed auth: says password pre-configured (pgpass) when the DSN carries a password, and no password in the DSN — first connect will prompt when it does not. Re-running install is idempotent: a running container is left alone, a stopped one is started. To apply a changed port/listen/email/seed, add --force (the container is recreated from the config; the data dir is untouched).

Rebuilding with --force

pg addon install pgadmin without --force is a no-op on a running container — it leaves the live config alone and just makes sure the container is up. That is exactly the wrong behaviour when you meant to change something (port, listen, email, image, seed DSN, --pg-name target, data_dir): the running container is pinned to the config it was created with, so the edit looks accepted but nothing changes until the next recreate.

--force is the knob that applies such edits. It stops the running container, removes it, and creates a new one from the current config; the data dir is untouched, so saved servers and browse history come back in the new container:

# change the bind address to expose the UI on the network
pg addon install pgadmin --listen 0.0.0.0 --force

# switch the seeded server to a different instance
pg addon install pgadmin --pg-name proj02 --force

# drop the seed entirely (no --dsn / --pg-name + --force)
pg addon install pgadmin --force

# retag to a different upstream image
pg addon install pgadmin --image docker.io/dpage/pgadmin4:9.19 --force

Two caveats worth stating:

  • email / password still only re-apply to an empty data dir. pgAdmin reads PGADMIN_DEFAULT_* while it initialises pgadmin4.db; once that file exists the stored account is authoritative and the env vars are ignored. --force alone does not reset the web login — pair it with --clean-data (which removes the store first) to actually reset the account.
  • A running container is recreated, not left alone. If the UI is open in a browser, --force kills the session; the next page load re-authenticates against the new container.

Using the web UI

Point a browser at the URL from the summary (on the host that runs podman), sign in with the login email + password, and pgAdmin’s own server tree appears. Add connections in the UI, or pre-register one at install with –dsn / –pg-name.

If the host isn’t where your browser is, set --listen 0.0.0.0 (the login is then the only gate):

Listening and exposure

--listen (config key listen) is the address pgAdmin’s HTTP server binds, and it defaults to loopback. The three postures, each applied with --force since the container is recreated to pick up the change:

# loopback only (default) — reachable on the podman host itself
pg addon install pgadmin --name console --listen 127.0.0.1 --force

# every interface — reachable from other hosts; login is the ONLY gate
pg addon install pgadmin --name console --listen 0.0.0.0 --force

# back to loopback after exposing
pg addon install pgadmin --name console --listen 127.0.0.1 --force
  • On Linux the container shares the host network, so --listen 0.0.0.0 answers on <host-ip>:<port> and --listen 127.0.0.1 on 127.0.0.1:<port>. Widening to 0.0.0.0 puts pgAdmin behind nothing but its email/password login — the install summary warns so — so keep loopback unless the network is trusted.
  • On macOS the picture inverts: the bridge network always binds 0.0.0.0 inside the podman machine and pgcli publishes the port, so listen is effectively widened there regardless, and you reach the UI from the Mac at 127.0.0.1:<port> via gvproxy. See Platform.

Retrieving the web login

pg addon password pgadmin --name console          # print bare, for scripting
pg addon password pgadmin --name console --file ./pw.txt   # mode 0600 file

pg addon list shows the URL and login email but never the password unless you pass --show-password.

Seeding a server

--dsn and --pg-name both render a one-time servers.json that pgAdmin imports on first boot, so the browser opens with that server already in its tree. --pg-name resolves the endpoint from a locally-managed instance (its host/port/database/user and password, read from pg.yaml); --dsn gives it as a URI:

pg addon install pgadmin --name dev --pg-name proj01
# or
pg addon install pgadmin --name dev --dsn "postgres://app:secret@127.0.0.1:5432/appdb"

What the seed does and does not carry:

  • The target server’s password IS pre-configured when the DSN carries one. servers.json itself cannot hold a password (pgAdmin refuses to import one), so pgcli writes a libpq pgpass file beside it and points the seeded entry at it via ConnectionParameters.passfile — an absolute path pgAdmin honours natively (documented in the pgAdmin 9.18 Import/Export Servers example). Connecting from the browser skips the password prompt entirely. A DSN without a password (e.g. postgres://app@host/db) renders servers.json only, and pgAdmin prompts on first connect as before.
  • The pgpass file holds the password in plaintext on disk. It is mode 0600 under <base-dir>/addon/pgadmin/<name>/pgpass, readable only by the host user and inside the container by uid 5050 — but it is on disk, unlike a servers.json which never holds a secret. The tradeoff is the same one every .pgpass-using tool makes: password-free connects cost a file on disk. Removing the pgAdmin instance (with or without --clean-data) deletes the pgpass alongside servers.json — the plaintext secret does not outlive the instance.
  • It’s a one-time convenience, not a coupling. After install, the server lives in pgAdmin’s own pgadmin4.db; add, rename, or delete it in the UI. The addon keeps running regardless of whether the seed target is reachable.
  • PGADMIN_REPLACE_SERVERS_ON_STARTUP=True is set whenever a seed exists, so a --force reinstall that changes --dsn/--pg-name re-applies the seed declaratively instead of leaving a stale entry.

To drop the seed and stop the declarative re-load, reinstall with --force and neither --dsn nor --pg-name.

Seeded host vs. listen address

These two knobs point at different machines and are often conflated. --listen controls who may reach the pgAdmin web UI; the seed’s host controls where pgAdmin dials the database from. The dial is made server-side — by the pgAdmin container, not by your browser — so a locally-managed instance seeded with --pg-name correctly records 127.0.0.1, because pgAdmin and that PostgreSQL share the podman host’s loopback. Exposing the UI to the network does not require the seeded host to be routable from the browser:

# pgAdmin on vm01 fronting vm01's own instance, UI reachable from other hosts
pg addon install pgadmin --listen 0.0.0.0 --pg-name demo --force
# servers.json -> Host: 127.0.0.1, Port: <demo's pg port>   (dialed in-container)

# seed a server on ANOTHER host instead — the host must be reachable from the
# pgAdmin container, since it is the container that connects
pg addon install pgadmin --listen 0.0.0.0 \
    --dsn "postgres://app@10.0.0.12:35432/appdb" --force

The converse pitfall: seed a remote host with --dsn and point a browser at that same pgAdmin from elsewhere — the connection still originates inside the pgAdmin container, so that host must be reachable from the container’s network, not from the laptop.

Ports

Each instance takes one port from pgAdmin’s own pool, pgadmin_start_port (default 5050) — a separate cursor from Redis’s, Predixy’s, and the object stores’ pools, so a pgadmin, a redis, and a minio instance never collide:

pg addon install pgadmin --name console   # 5050
pg addon install pgadmin --name audit     # 5051

--port fixes an instance to a specific port; auto-assignment skips anything already explicit or live on the host.

Configuration

Instances live under the top-level addons.pgadmin map in pg.yaml:

namespace: default
pgadmin_start_port: 5050     # pgAdmin's own pool
addons:
  pgadmin:
    console:
      container_name: pgcli-pgadmin-default-console
      name: console
      image_tag: docker.io/dpage/pgadmin4:9.18
      # data_dir: /srv/pgadmin         # omit for <base-dir>/addon/pgadmin/console/data
      listen: 127.0.0.1                # default; 0.0.0.0 to expose on the network
      host_port: 5050
      email: me@example.com            # web login account (PGADMIN_DEFAULT_EMAIL)
      password: <generated>            # web login password; written on first install
      # dsn: postgres://app@127.0.0.1:5432/appdb   # set by --dsn/--pg-name: the seed
      # server_name: app               # display name of the seeded server
      autostart: false                 # pg autostart enable --pgadmin --name console

Edits to listen, host_port, email, password, image_tag, dsn/ server_name, or data_dir take effect after the next pg addon install pgadmin --name console --force (or via the matching flags). Remember: email/password only re-apply to an empty data dir, so changing them against an existing store needs --clean-data first (or accept that the running account is the original one).

List

pg addon list
Web add-ons (pgadmin):
  pgadmin (name: console)
    Status:      running
    URL:         http://127.0.0.1:5050/
    Login email: me@example.com
    Seeded:      proj01
    Data:        ~/pg/addon/pgadmin/console/data
    Image:       docker.io/dpage/pgadmin4:9.18
    Container:   pgcli-pgadmin-default-console

pg addon list never prints the password. Reveal it deliberately with pg addon list --show-password (appends a Login password: line) or bare with pg addon password pgadmin --name console — and prefer --file so the secret stays out of shell history and scrollback.

Start and stop

pg addon start pgadmin --name console
pg addon stop  pgadmin --name console

start only starts an existing container (and self-heals an improper state by recreating it from the config). The data dir is preserved across stop/start, so pgAdmin’s saved servers and browse history come back with it.

Auto-start on Boot

Containers carry a --restart unless-stopped policy (crashes, not reboots). To bring instances up after a host reboot:

pg autostart enable --pgadmin --name console

pgAdmin autostart is start-only (install the instance first). On boot the entrypoint re-chowns /var/lib/pgadmin and replays pgadmin4.db from the data dir, so the saved servers survive the reboot. pgAdmin is independent of the PostgreSQL stack — it is a browser UI that dials its servers itself — so there is no ordering constraint and boot-time pg start --autostart starts it alongside the other non-database addons.

Remove

pg addon remove pgadmin --name console               # container + config entry; data kept
pg addon remove pgadmin --name console --clean-data  # also delete the data dir

Without --clean-data the host data dir (and its pgadmin4.db) stays in place — reinstalling the same name revives the saved servers and session store (the revived login is the original one, not a freshly generated password). --clean-data deletes it, falling back through podman unshare rm when rootless podman’s mapped uid makes pgAdmin’s files undeletable by the host user. An empty per-instance parent directory is pruned; a custom data_dir parent is never touched. servers.json (if seeded) is host-owned and removed with the instance directory either way.

Logs

pg logs addon pgadmin --name console        # last 50 lines
pg logs addon pgadmin --name console -f     # follow

Troubleshooting

  • Signed in with the printed password and it’s rejected — you reinstalled over a kept data dir. The login that works is the one pgAdmin stored in pgadmin4.db on the first init; the newly generated one is inert (install warns “reviving an existing pgAdmin data dir”). Use --clean-data to start fresh, or pg addon password pgadmin to confirm what’s stored, or reinstall with --password pinned to the original.
  • “pgAdmin could not start” / container exits immediately (or crash-loops) — the entrypoint needs both PGADMIN_DEFAULT_EMAIL and PGADMIN_DEFAULT_PASSWORD on a fresh dir; a hand-edited pg.yaml with an empty password and a wiped data dir has neither. Let install generate one, or pass --password. It also validates the email and rejects reserved TLDs (.local, .invalid, .test, …) with “does not appear to be a valid email address” — the container then exits and, under the restart policy, spins. That is exactly why the default is admin@pgcli.lan and not .local.
  • Can’t reach the UI from another machine — listen defaults to 127.0.0.1. Reinstall --listen 0.0.0.0 --force and accept that the web login is then the only gate.
  • The seeded server shows but won’t connect — if the seed DSN carried no password, pgAdmin prompts for it on first connect (Seeding a server). If it did carry one and the prompt still appears, the pgpass file was invalidated — most often because the container was started without the entrypoint’s chown running (e.g. someone passed --user 5050 directly instead of --user 0, so the file is owned by the host user and libpq silently drops it). Confirm the host/port are reachable from where pgAdmin runs.
  • Image not found at install — docker.io/dpage/pgadmin4 is pulled on demand; on an air-gapped host, podman load the tar first (catalog and export steps in docs/images.md in the repo) and the pull is skipped.
  • First boot is slow to answer — pgAdmin runs its sqlite migrations before gunicorn binds; the port answers 302 (to /login) only once that finishes. On a loaded host this can take tens of seconds.

Known limitations

  • No TLS — pgAdmin serves plain HTTP here. For HTTPS put a reverse proxy (with PGADMIN_URL_SCHEME/PGADMIN_DISABLE_STATIC_FILE_SERVER tuning) in front; pgcli does not wire it. The loopback default keeps the common case on 127.0.0.1.
  • Not suitable for large data import/export — pgAdmin streams data through HTTP (query → container → browser for export; upload → container → database for import), which times out or exhausts memory on large tables. Use pg export / pg import for pgcli instances, or pg exec --dsn "..." -- pg_dump for arbitrary databases. See Data Import/Export for details.
  • Seed password lives on disk as plaintext — the pgpass file beside servers.json is mode 0600 but not encrypted; removing the instance cleans it up. There is no way to pre-configure the password without a file on disk (pgAdmin has no KMS/keyring integration).
  • Login only applies to a fresh store — pgAdmin reads PGADMIN_DEFAULT_* while it initialises pgadmin4.db; once that file exists the stored account is authoritative. There is no in-place password reset, only --clean-data + reinstall.
  • macOS is code-complete, untested — the bridge path (published ports, proxyBindHost widening loopback to 0.0.0.0 on the bridge) mirrors redis; it has not yet been exercised on a Mac.

14 - Nginx

Run nginx as a pgcli addon — an HTTP reverse proxy in front of web services, with path-based routing and optional TLS termination

nginx is the HTTP reverse proxy that fronts multiple web services — dashboards, APIs, admin panels — with path-based routing and optional TLS termination. pgcli runs it as a standalone, top-level addon with the same CLI surface as the other web/infra addons (install / start / stop / logs / autostart / remove), managed entirely through pg.yaml.

It is the fleet’s HTTP gateway, which shapes its design:

  • A reverse proxy, not a load balancer. Unlike HAProxy — a TCP load balancer in front of Patroni — nginx is an HTTP reverse proxy that routes by URL path. Each location block forwards to one upstream (web app, API service, etc.), so clients reach multiple services through a single port.
  • File-driven configuration. pgcli renders nginx.conf from the backends you declare (or accepts a custom file via --conf-file) and bind-mounts it read-only into the official nginx:1.27-alpine image. TLS is optional: when enabled without a BYO cert, pgcli generates a self-signed leaf via tlsca.
  • Independent log mounting. Each backend gets its own access and error log files (access_<name>.log, error_<name>.log) under a bind-mounted /var/log/nginx/ directory, so per-service traffic is observable without parsing a shared log.
  • Nginx-specific subcommands. Beyond the generic addon lifecycle (install/start/stop/remove), nginx exposes test (validate config syntax via nginx -t using a temporary container), reload (hot reload via nginx -s reload), and exec (run arbitrary commands inside the container).

Platform support: nginx works on both Linux (host networking) and macOS (pgcli-net bridge with published ports). The upstream image is multi-arch (amd64 + arm64), so any host architecture works.

How It Works

Routing is path-based: each location block forwards to one upstream. The config is rendered from the backends you declare (or copied from a custom file), bind-mounted read-only, and nginx runs in the foreground with nginx -g 'daemon off;'.

Two configuration modes

The mode is chosen with --conf-file (custom) or --upstream (template):

  • Template mode (default) — pgcli renders nginx.conf from --upstream specs. Each upstream becomes an upstream block and a location block; TLS adds an HTTPS server block alongside the HTTP one. The template covers the common case: path-based routing to a handful of web services.
  • Custom mode (--conf-file) — you provide the full nginx.conf path; pgcli copies it into the addon directory and manages only the container lifecycle. Use this when production configs grow beyond the template’s reach (limit_req_zone, resolver + variable proxy_pass, WebSocket, SNI, multiple locations per backend, upstream keepalive, etc.). --upstream and --conf-file are mutually exclusive.

Per-backend logs

Each backend gets its own log files in the bind-mounted /var/log/nginx/ directory:

  • access_<name>.log — access log for that backend’s location block
  • error_<name>.log — error log for that backend’s location block

The global access.log and error.log capture server-level events. The log directory is created on the host at <base-dir>/addon/nginx/<name>/log/ and persists across container restarts.

TLS termination

TLS is optional. When enabled without --tls-cert/--tls-key, pgcli generates a self-signed leaf certificate via tlsca.Generate under <base-dir>/addon/nginx/<name>/tls/. The HTTPS listener runs alongside the HTTP one, so existing plain-text clients keep working. With BYO certs, the given files are bind-mounted instead.

A BYO cert is often a pg cert leaf — that command mints a self-signed certificate with any mix of DNS and IP SANs, exactly the shape a Git/DB endpoint needs when clients you control can be handed the CA file:

pg cert --host git.example.com,10.0.0.9 \
        --cert-file /srv/gitea.crt --key-file /srv/gitea.key
pg addon install nginx --name proxy --listen 0.0.0.0 \
  --upstream name=gitea,path=/,backend=127.0.0.1:3080 \
  --tls --tls-cert /srv/gitea.crt --tls-key /srv/gitea.key \
  --http-port 80 --https-port 443

Proxying Git (and any large POST): raise client_max_body_size. The template mode sets no request-body limit, so nginx applies its built-in default of 1 MiB — a git push (or any upload) larger than that comes back as HTTP 413. The template gives you no flag for this, so front a Git service with custom mode (--conf-file); see the complete working example under “Git HTTP push with client_max_body_size” in Common custom config patterns below.

Install

Backends are supplied one of two ways (mutually exclusive):

  • --upstream name=<n>,path=<p>,backend=<h:p> (repeatable) — explicit upstream targets. Repeat backend= within the same --upstream spec to add multiple servers (nginx round-robin), or use the shorthand backends=h1:p1,h2:p2,.... backend and backends are mutually exclusive within a single --upstream spec;
  • --conf-file <path> — a custom nginx.conf file (skips template rendering entirely).

What each --upstream field means — for --upstream name=web,path=/app,backend=127.0.0.1:8000:

Field Meaning
name upstream name in nginx.conf (defaults to a sanitized path if omitted)
path location path prefix (e.g. /app → web app, /api → API service; defaults to /)
backend host:port to proxy to (e.g. 127.0.0.1:8000); repeat for multiple servers (round-robin)
backends shorthand for multiple servers: backends=h1:p1,h2:p2,... (mutually exclusive with backend within one --upstream spec)
# template mode: one upstream, explicit
pg addon install nginx --name proxy \
  --upstream name=web,path=/app,backend=127.0.0.1:8000

# template mode: multiple upstreams
pg addon install nginx --name proxy \
  --upstream name=web,path=/app,backend=127.0.0.1:8000 \
  --upstream name=api,path=/api,backend=127.0.0.1:3000

# single upstream with multiple servers (load balancing, nginx round-robin)
pg addon install nginx --name proxy \
  --upstream name=api,path=/,backends=127.0.0.1:3000,127.0.0.1:3001,127.0.0.1:3002

# template mode with TLS (self-signed cert)
pg addon install nginx --name proxy \
  --upstream name=web,path=/app,backend=127.0.0.1:8000 --tls

# custom mode: you provide the full config
pg addon install nginx --name custom \
  --conf-file /path/to/nginx.conf --http-port 8080

The install summary reports the assigned ports and the config path:

✓ nginx installed: "proxy"
  Container:  pgcli-nginx-default-proxy
  Image:      docker.io/library/nginx:1.27-alpine
  HTTP:       127.0.0.1:8080
  HTTPS:      (disabled)
  Backends:   2
    - web   /app → 127.0.0.1:8000
    - api   /api → 127.0.0.1:3000
  Config:     ~/pg/addon/nginx/proxy/nginx.conf
  Logs:       ~/pg/addon/nginx/proxy/log/

With --conf-file, the summary says Config: <path> (from <confFile>) and skips the Backends: section (pgcli does not parse the user’s config).

Rebuilding with --force

pg addon install nginx without --force on a running container now auto-reloads config changes: it writes the new nginx.conf, validates it with nginx -t, and sends nginx -s reload on success. If validation fails, the old config is restored and the reload is skipped. This means most edits (backends, --conf-file, worker_connections, TLS) apply without restarting the container.

--force is still needed when the change requires a container recreate (image tag, listen address, ports, networking mode): it stops the running container, removes it, and creates a new one from the current config:

# change the bind address to expose the proxy on the network
pg addon install nginx --listen 0.0.0.0 --force

# retag to a different upstream image
pg addon install nginx --image docker.io/library/nginx:1.28-alpine --force

Nginx subcommands

Beyond the generic addon lifecycle (install/start/stop/remove), nginx exposes three subcommands for day-to-day operations:

test — validate config syntax

pg addon nginx test --name proxy
pg addon nginx test --conf-file /path/to/nginx.conf

Runs nginx -t inside a temporary container (podman run --rm) with the same mounts as the real one. Does not require the nginx container to be running — it spins up a throwaway container, validates the config, and exits. This is the safe way to test config changes before reloading:

# edit the config file (template or custom)
vim ~/pg/addon/nginx/proxy/nginx.conf

# validate syntax without affecting the running proxy
pg addon nginx test --name proxy
# nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
# nginx: configuration file /etc/nginx/nginx.conf test is successful

# only then reload
pg addon nginx reload --name proxy

--conf-file validates a standalone config file before installing it — useful for CI pipelines or pre-deploy checks:

# validate a config you haven't installed yet
pg addon nginx test --conf-file /tmp/new-nginx.conf --image docker.io/library/nginx:1.27-alpine

The temporary container mounts the same nginx.conf (and TLS cert directory if TLS is enabled), so the validation is identical to what the real container would see on startup.

reload — hot reload configuration

pg addon nginx reload --name proxy

Sends nginx -s reload to the running container — a graceful restart that picks up config changes without dropping in-flight connections. Requires the container to be running (use pg addon start nginx --name proxy first if it is stopped).

exec — run commands inside the container

pg addon nginx exec --name proxy -- cat /etc/nginx/nginx.conf
pg addon nginx exec --name proxy -- nginx -V
pg addon nginx exec --name proxy -- ls -la /var/log/nginx/

Runs an arbitrary command inside the nginx container with stdio passthrough. Requires the container to be running. The -- separator is mandatory — everything after it is passed verbatim to the container.

Parameters

One container from the upstream docker.io/library/nginx image (pull-only — pgcli never builds it), configured entirely through the rendered (or custom) nginx.conf and the podman run flags. The table lists every knob and its default:

Flag / pg.yaml key Default Meaning
--image / image_tag docker.io/library/nginx:1.27-alpine override the tag verbatim
--http-port / http_port auto from nginx_start_port (base 8080) HTTP listener host port
--https-port / https_port auto (next free port after HTTP) HTTPS listener host port (TLS only)
--listen / listen 127.0.0.1 bind address (0.0.0.0 to expose)
--worker-connections / worker_connections 1024 worker_connections in the events block (max simultaneous connections per worker)
--tls / tls false enable HTTPS listener alongside HTTP
--tls-cert / tls_cert unset BYO cert path (PEM leaf + chain); without it, pgcli generates a self-signed cert
--tls-key / tls_key unset BYO private key path (PEM)
--upstream unset (repeatable) name=<n>,path=<p>,backend=<h:p>[,backend=<h:p>...] — one upstream target, may include multiple backends
--conf-file / conf_file unset path to a custom nginx.conf (mutually exclusive with --upstream)
— autostart: false start on boot (pg autostart enable --nginx)

How the knobs combine:

  • --conf-file is mutually exclusive with --upstream. Both mean “here is the config” — one by path, the other by declaring backends. The install rejects the combination.
  • --tls without --tls-cert/--tls-key generates a self-signed cert. The cert lives under <base-dir>/addon/nginx/<name>/tls/ and is bind-mounted at /etc/nginx/certs. The HTTPS listener runs alongside HTTP on the next free port.
  • --tls-cert/--tls-key without --tls is ignored. The flags only take effect when TLS is enabled.
  • --worker-connections injects into --conf-file mode. When both are set, pgcli patches the user’s events block (or adds one) to set the given value. The user’s worker_connections directive, if any, is replaced — not merged.
  • --listen defaults to loopback — the proxy stays on 127.0.0.1 unless you pass --listen 0.0.0.0 to reach it from another host. On Linux the container shares the host network, so 0.0.0.0 answers on <host-ip>:<port>; on macOS the bridge publishes the port and proxyBindHost widens loopback to 0.0.0.0 on the bridge.

Ports

Each instance takes one or two ports from nginx’s own pool, nginx_start_port (default 8080) — a separate cursor from pgAdmin’s, Redis’s, Predixy’s, and the object stores’ pools, so an nginx, a redis, and a minio instance never collide:

pg addon install nginx --name proxy                          # 8080 (HTTP only)
pg addon install nginx --name proxy-tls --tls                # 8081 (HTTP) + 8082 (HTTPS)
pg addon install nginx --name proxy2                         # 8083

--http-port and --https-port fix an instance to specific ports; auto-assignment skips anything already explicit or live on the host. A TLS instance consumes two ports (HTTP + HTTPS); a plain instance consumes one.

Configuration

Instances live under the top-level addons.nginx map in pg.yaml:

namespace: default
nginx_start_port: 8080     # nginx's own pool
addons:
  nginx:
    proxy:
      container_name: pgcli-nginx-default-proxy
      name: proxy
      image_tag: docker.io/library/nginx:1.27-alpine
      listen: 127.0.0.1
      http_port: 8080
      https_port: 0        # 0 = auto-assign (TLS only)
      worker_connections: 1024
      tls: false
      # tls_cert: /path/to/cert.pem   # BYO cert (tls: true required)
      # tls_key:  /path/to/key.pem
      # conf_file: /etc/nginx/custom.conf  # custom mode (skips backends)
      autostart: false     # pg autostart enable --nginx --name proxy
      backends:
        - { name: web,  path: /app, backends: ["127.0.0.1:8000"] }
        - { name: api,  path: /api, backends: ["127.0.0.1:3000"] }

Edits to listen, http_port, https_port, worker_connections, tls, tls_cert/tls_key, conf_file, or backends take effect on the next pg addon install nginx --name proxy — config-only changes are auto-reloaded (no --force needed). Use --force when the change requires a container recreate (image tag, listen address, ports).

Common custom config patterns

When the template mode is not enough, use --conf-file with a full nginx.conf. The following patterns are extracted from a real 70+ server production config and cover the most common cases.

Complete http block skeleton — the patterns below show individual server blocks; wrap them in an http block like this:

worker_processes auto;
error_log /var/log/nginx/error.log;
pid /tmp/nginx.pid;

events {
    worker_connections 60000;
    multi_accept on;
}

http {
    ##
    # Basic Settings
    ##

    sendfile on;
    tcp_nopush on;
    types_hash_max_size 2048;

    include /etc/nginx/mime.types;
    default_type application/octet-stream;

    ##
    # Logging
    ##

    log_format postdata '$remote_addr - $request_id [$time_local] "$request" '
                        '$status $body_bytes_sent $server_name "$request_body" '
                        '$request_length "$http_referer" "$http_user_agent" '
                        '"$http_x_forwarded_for" $request_time $upstream_response_time';

    access_log /var/log/nginx/access.log postdata;

    ##
    # SSL Settings
    ##

    ssl_protocols TLSv1.2 TLSv1.3;
    ssl_prefer_server_ciphers on;

    ##
    # Gzip Settings
    ##

    gzip on;

    ##
    # Rate Limiting (declare zones at http level, apply in server/location)
    ##

    # limit_req_zone $uri zone=api_fast:10m rate=5000r/s;
    # limit_req_zone $uri zone=api_slow:10m rate=100r/s;

    ##
    # Virtual Hosts
    ##

    # server { ... }  # see patterns below
}

Dynamic DNS resolution with resolver + variable proxy_pass — avoids nginx resolving the hostname at startup and caching it forever. The variable forces a fresh lookup on every request:

http {
    server {
        listen 127.0.0.1:9001;
        access_log /var/log/nginx/access_dns.log;
        error_log  /var/log/nginx/error_dns.log;

        resolver 8.8.8.8 8.8.4.4 ipv6=off;
        set $backend "https://api.example.com";

        location / {
            proxy_pass $backend;
        }
    }
}

Rate limiting per URL — limit_req_zone at the http level, applied per location. Use different zones for different rate tiers:

http {
    limit_req_zone $uri zone=api_fast:10m rate=5000r/s;
    limit_req_zone $uri zone=api_slow:10m rate=100r/s;

    server {
        listen 127.0.0.1:9001;
        access_log /var/log/nginx/access_ratelimit.log;
        error_log  /var/log/nginx/error_ratelimit.log;

        location /fast-api/ {
            limit_req zone=api_fast burst=10000 nodelay;
            limit_req_status 429;
            proxy_pass https://backend.example.com;
        }
        location /slow-api/ {
            limit_req zone=api_slow burst=200 nodelay;
            limit_req_status 429;
            proxy_pass https://backend.example.com;
        }
    }
}

WebSocket proxy — requires Upgrade and Connection headers plus HTTP/1.1:

http {
    server {
        listen 127.0.0.1:9001;
        access_log /var/log/nginx/access_ws.log;
        error_log  /var/log/nginx/error_ws.log;

        location / {
            proxy_set_header Upgrade $http_upgrade;
            proxy_set_header Connection "upgrade";
            proxy_set_header Host $host;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_pass https://ws-backend.example.com;
            proxy_http_version 1.1;
        }
    }
}

Upstream with keepalive — reduces connection overhead for high-throughput backends:

http {
    upstream backend-pool {
        server 10.0.0.1:8080;
        server 10.0.0.2:8080;
        keepalive 10;
    }

    server {
        listen 127.0.0.1:9001;
        access_log /var/log/nginx/access_pool.log;
        error_log  /var/log/nginx/error_pool.log;

        location / {
            proxy_pass http://backend-pool;
            proxy_http_version 1.1;
            proxy_set_header Connection "";
        }
    }
}

Host-based routing with proxy_set_header Host — proxy to a backend by IP but set the correct virtual host:

http {
    server {
        listen 127.0.0.1:9001;
        access_log /var/log/nginx/access_host.log;
        error_log  /var/log/nginx/error_host.log;

        resolver 8.8.8.8 8.8.4.4 ipv6=off;

        location / {
            proxy_set_header Host api.internal.example.com;
            proxy_pass http://10.0.0.100;
            proxy_http_version 1.1;
        }
    }
}

SNI passthrough with proxy_ssl_server_name — required when the upstream is behind HTTPS and uses SNI to select the certificate. Without it, nginx does not send the Host header during the TLS handshake and the upstream may reject the connection:

http {
    server {
        listen 127.0.0.1:9001;
        access_log /var/log/nginx/access_sni.log;
        error_log  /var/log/nginx/error_sni.log;

        resolver 8.8.8.8 8.8.4.4 ipv6=off;

        location / {
            proxy_set_header Host api.example.com;
            proxy_pass https://api.example.com;
            proxy_ssl_server_name on;
        }
    }
}

Per-location rate limiting in a single server — when multiple paths need different rate limits, declare separate zones and apply them per location. A catch-all limit_req at the server level provides a baseline; specific paths override with tighter or looser limits:

http {
    limit_req_zone $uri zone=general:10m rate=5000r/s;
    limit_req_zone $uri zone=sensitive:10m rate=100r/s;

    server {
        listen 127.0.0.1:9001;
        access_log /var/log/nginx/access_backend.log;
        error_log  /var/log/nginx/error_backend.log;

        location / {
            limit_req zone=general burst=5000 nodelay;
            limit_req_status 429;
            proxy_pass https://backend.example.com;
        }
        location /admin/ {
            limit_req zone=sensitive burst=200 nodelay;
            limit_req_status 429;
            proxy_pass https://backend.example.com;
        }
    }
}

Custom log format — replace the default combined format with one that captures request body, response timing, and upstream latency. log_format is declared once in the http block; each server sets its own access_log path. The log directory /var/log/nginx/ is bind-mounted by pgcli — use it for all custom log paths:

http {
    log_format postdata '$remote_addr - $request_id [$time_local] "$request" '
                        '$status $body_bytes_sent $server_name "$request_body" '
                        '$request_length "$http_referer" "$http_user_agent" '
                        '"$http_x_forwarded_for" $request_time $upstream_response_time';

    server {
        listen 127.0.0.1:9001;
        access_log /var/log/nginx/access_api.log postdata;
        error_log  /var/log/nginx/error_api.log;

        location / {
            proxy_pass https://api.example.com;
        }
    }

    server {
        listen 127.0.0.1:9002;
        access_log /var/log/nginx/access_web.log postdata;
        error_log  /var/log/nginx/error_web.log;

        location / {
            proxy_pass https://web.example.com;
        }
    }
}

Git HTTP push with client_max_body_size — front a Git host (Gitea, GitLab, a bare git http-backend) with a complete custom nginx.conf that lifts the 1 MiB body limit and keeps long git-receive-pack requests alive:

worker_processes auto;
pid /tmp/nginx.pid;

events {
    worker_connections 1024;
}

http {
    # nginx's built-in default is 1 MiB — a bigger git push dies with HTTP 413.
    # 10m covers typical pushes; raise it (or use 0 to disable the check) if
    # you commit larger binaries.
    client_max_body_size 10m;

    # push/receive-pack streams can outlast the 60s default.
    proxy_read_timeout 300s;
    proxy_send_timeout 300s;

    upstream gitea {
        server 127.0.0.1:3080;
    }

    server {
        listen 0.0.0.0:80;
        access_log /var/log/nginx/gitea.access.log;
        error_log  /var/log/nginx/gitea.error.log;

        location / {
            proxy_pass http://gitea;
            proxy_set_header Host $host;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_set_header X-Forwarded-Proto $scheme;
        }
    }

    server {
        listen 0.0.0.0:443 ssl;
        # pgcli bind-mounts the --tls-cert / --tls-key files at these paths.
        ssl_certificate     /etc/nginx/certs/public.crt;
        ssl_certificate_key /etc/nginx/certs/private.key;
        ssl_protocols TLSv1.2 TLSv1.3;

        access_log /var/log/nginx/gitea.access.log;
        error_log  /var/log/nginx/gitea.error.log;

        location / {
            proxy_pass http://gitea;
            proxy_set_header Host $host;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_set_header X-Forwarded-Proto $scheme;
        }
    }
}
pg cert --host 10.0.0.9,git.internal \
        --cert-file /srv/gitea.crt --key-file /srv/gitea.key
pg addon install nginx --name proxy --conf-file /srv/gitea-nginx.conf \
  --tls --tls-cert /srv/gitea.crt --tls-key /srv/gitea.key \
  --http-port 80 --https-port 443

--conf-file and --upstream are mutually exclusive, but --tls / --tls-cert / --tls-key still apply in custom mode: pgcli mounts the cert pair at /etc/nginx/certs/public.crt and /etc/nginx/certs/private.key, which the config above references — a custom file simply takes over writing the listen/ssl_certificate lines itself.

Static file serving with caching — serve files from a host-mounted directory with browser caching headers, sendfile optimization, and access control:

http {
    server {
        listen 127.0.0.1:9001;
        access_log /var/log/nginx/access_static.log;
        error_log  /var/log/nginx/error_static.log;
        root /srv/static/;

        location / {
            sendfile on;
            sendfile_max_chunk 2m;
            autoindex on;
            try_files $uri $uri/ =404;
        }
        location ~* \.(css|js|png|jpg|jpeg|gif|ico|svg)$ {
            expires 1d;
            add_header Cache-Control "public";
            access_log off;
        }
        location ~ /\. {
            deny all;
        }
    }
}

List

pg addon list
Web add-ons (nginx):
  nginx (name: proxy)
    Status:      running
    HTTP:        127.0.0.1:8080
    HTTPS:       (disabled)
    Backends:    2
      - web   /app → 127.0.0.1:8000
      - api   /api → 127.0.0.1:3000
    Config:      ~/pg/addon/nginx/proxy/nginx.conf
    Logs:        ~/pg/addon/nginx/proxy/log/
    Image:       docker.io/library/nginx:1.27-alpine
    Container:   pgcli-nginx-default-proxy

Start and stop

pg addon start nginx --name proxy
pg addon stop  nginx --name proxy

start only starts an existing container (and self-heals an improper state by recreating it from the nginx.conf already on disk). The config and log directories are preserved across stop/start.

Auto-start on Boot

Containers carry a --restart unless-stopped policy (crashes, not reboots). To bring instances up after a host reboot:

pg autostart enable --nginx --name proxy

nginx autostart is start-only (install the instance first). On boot it reads the nginx.conf already on disk, so the proxy comes up with the last known config. nginx is independent of the PostgreSQL stack — it is a reverse proxy that dials its backends itself — so there is no ordering constraint and boot-time pg start --autostart starts it alongside the other non-database addons.

Remove

pg addon remove nginx --name proxy

Stops and removes the container and deletes its config directory (including TLS certs and logs). An empty per-instance parent directory is pruned.

Logs

pg logs addon nginx --name proxy        # last 50 lines
pg logs addon nginx --name proxy -f     # follow

The container logs to stdout, so access and error events show up here. For per-backend logs, look at the bind-mounted log directory:

ls ~/pg/addon/nginx/proxy/log/
# access.log  access_web.log  access_api.log
# error.log   error_web.log   error_api.log

Troubleshooting

  • Config syntax error on startup. The container exits and the restart policy spins it. Check with pg addon nginx test --name proxy (works even when the container is stopped) — it runs nginx -t in a temporary container and reports the exact line number.
  • --conf-file and --upstream together. The install rejects the combination — pick one mode.
  • Can’t reach the proxy from another machine. listen defaults to 127.0.0.1. Reinstall --listen 0.0.0.0 --force and accept that the proxy is then the only gate in front of the backends.
  • Image not found at install. docker.io/library/nginx is pulled on demand; on an air-gapped host, podman load the tar first (catalog and export steps in docs/images.md in the repo) and the pull is skipped.
  • Reload fails with “container not running”. pg addon nginx reload requires the container to be up. Start it first with pg addon start nginx --name proxy.

Known limitations

  • No load balancing or health checks. nginx here is a reverse proxy (path-based routing to a single upstream per location), not a TCP load balancer. For load balancing in front of Patroni, use HAProxy.
  • Template is simple by design. The rendered nginx.conf covers path-based routing to a handful of backends with optional TLS. Production configs that need limit_req_zone, resolver + variable proxy_pass, WebSocket, SNI, multiple locations per backend, or upstream keepalive should use --conf-file instead.
  • macOS is code-complete, lightly tested. The bridge path (published ports, proxyBindHost widening loopback to 0.0.0.0 on the bridge) mirrors the other bridge addons; it has been exercised but not yet under load.

15 - Grafana

Run the Grafana observability dashboard as a managed container.

pg addon install grafana runs Grafana — the open-source observability dashboard — as a managed container from the official upstream image. Like pgAdmin it is a top-level addon: it is not attached to any one PostgreSQL instance and fronts none of them automatically — you add datasources and dashboards through the web UI. v1 ships the pure web UI: configuration is environment-only (the GF_* variables), with no datasource or dashboard provisioning mounted.

The web login password is generated on first install, printed once, and stored in pg.yaml; retrieve it later with pg addon password grafana. Unlike pgAdmin, Listen defaults to 0.0.0.0: a monitoring dashboard is meant to be viewed from other machines, and containers run on the host network. The exposure is guarded by the generated strong password and closed self-signup — pass --listen 127.0.0.1 for loopback-only access.

Platform: Linux is the tested platform. The design supports macOS (the image is multi-arch; the container runs under the podman machine VM on the pgcli-net bridge with the port published), but it has not been validated there yet.

Parameters

Flag Default Description
--name grafana Instance name (map key)
--image docker.io/grafana/grafana:13.2.4 Image override
--port auto (base 3000) Host web port; auto-allocated from grafana_start_port
--listen 0.0.0.0 Bind address — defaults to every interface; use 127.0.0.1 for loopback-only
--admin-user admin Web login user (GF_SECURITY_ADMIN_USER)
--password auto-generated Web login password (GF_SECURITY_ADMIN_PASSWORD; generated when omitted, applied only on the first startup — see below)
--data-dir auto Data directory override (default under the base dir)
--force false Recreate even when running — to apply changed ports, credentials or listen address

The data directory holds Grafana’s own sqlite meta DB (grafana.db): dashboards, datasources, users and settings live there. It survives pg addon remove (delete it with --clean-data), so reinstalling under the same name revives everything. The image’s entrypoint does not fix up ownership (it runs as a baked uid 472, group root, and only warns when the directory is unwritable), so pgcli chowns the data dir on the host before creating the container — via podman unshare chown 472:0 under rootless podman, or a direct recursive chown when pgcli runs as root on a rootful host.

Install

pg addon install grafana

The command pulls the image if needed, creates the container, and prints the URL and login password:

✓ Grafana installed: "grafana"
  Container:  pgcli-grafana-default-grafana
  URL:        http://0.0.0.0:3000/
  Login user:     admin
  Login password: <auto-generated>

Open the URL in a browser and sign in with the printed credentials. Add a PostgreSQL datasource in the UI (Connect data → PostgreSQL; the host port of each managed instance is in its pg.yaml entry or shown by pg status <instance>). Build dashboards against it.

GF_SECURITY_ADMIN_USER / GF_SECURITY_ADMIN_PASSWORD take effect only while grafana.db does not exist — they initialise the login, they don’t overwrite it. Reinstalling over a kept data dir keeps the original web login; the printed password is then inert (install says so explicitly). To change the login of an existing store, run grafana-cli admin reset-admin-password <new> inside the container (pg exec-style: podman exec -it <container> ...), or remove with --clean-data and reinstall.

Re-running install reuses a running container and starts a stopped one — config changes only apply after a remove + reinstall or --force.

Listening and exposure

Grafana’s Listen defaults to 0.0.0.0: the container shares the host’s network namespace, so the dashboard is reachable on every interface at the assigned port. This is deliberate — a monitoring panel is viewed from other machines — and is protected by the generated strong admin password plus GF_USERS_ALLOW_SIGN_UP=false (self-service registration is off). For a loopback-only deployment pass --listen 127.0.0.1 (recreate with --force); pg addon list then shows http://127.0.0.1:<port>/. --listen <addr> accepts any specific interface address.

Retrieving the web login

The login is Grafana’s web sign-in, unrelated to any PostgreSQL role. Re-read the password at any time:

pg addon password grafana              # bare password on stdout
pg addon password grafana --file ./pw  # or write it to a 0600 file

It is also stored in pg.yaml (addons.grafana.<name>.password).

Ports

Each Grafana instance owns a single port: the web UI. It is allocated from a pool with base grafana_start_port (default 3000 — Grafana’s conventional web port; it starts at 3000 because that is what bookmarks and docs expect), incrementing for every additional instance and skipping ports already taken by any managed container or the used_ports list. The allocation is written into pg.yaml, so a reinstall never re-hands-out a port another addon is using:

pg addon install grafana --name dash2   # second instance: next free port (3001 if taken)
pg addon install grafana --name dash3 --port 3100  # explicit port still wins

Grafana’s own ports share no number with any other addon’s pool bases; an explicit --port still takes precedence.

Configuration

addons:
  grafana:
    ui:
      name: ui
      image_tag: docker.io/grafana/grafana:13.2.4
      host_port: 3000
      listen: 0.0.0.0
      admin_user: admin
      password: <generated>
      autostart: false
      # data_dir: /srv/grafana-data    # optional, overrides the default location

Config is env-only (GF_*): the grafana.ini inside the image is not editable from the host. The variables pgcli sets are the login pair, the listener (port + bind address), analytics-off (GF_ANALYTICS_REPORTING_ENABLED / GF_ANALYTICS_CHECK_FOR_UPDATES), and GF_USERS_ALLOW_SIGN_UP=false. Anything beyond that is v1 out of scope; override the image with --image if you need a different build.

List

pg addon list
Web add-ons (grafana):
  grafana (name: ui)
    Status:      running
    URL:         http://0.0.0.0:3000/
    Login user:  admin
    Data:        /home/you/.pgcli/addon/grafana/ui/data
    Image:       docker.io/grafana/grafana:13.2.4
    Container:   pgcli-grafana-ui

Passwords are hidden by default to keep the listing paste-safe; pg addon list --show-password reveals the plaintext value, and pg addon password grafana prints a single one bare for scripting.

Start and stop

Containers run with podman’s unless-stopped restart policy, so they come back automatically with the podman service after a host reboot. start/stop manage them explicitly:

pg addon stop grafana
pg addon start grafana

Auto-start on Boot

To have a Grafana instance started automatically on host boot, enable it:

pg autostart enable --grafana --name ui

This flags the instance in pg.yaml and installs/refreshes a boot service (a systemd --user unit on Linux, a LaunchAgent on macOS) that runs pg start --autostart. A boot-time start only brings the container up — the data dir was already chowned at create time, so it needs no host privileges beyond podman itself. See Autostart for the full mechanism, status and disabling.

Remove

pg addon remove grafana              # keeps the data dir — dashboards and login survive a reinstall
pg addon remove grafana --clean-data # deletes the data dir too (Grafana's data is gone)

Under rootless podman, --clean-data deletes the data dir through podman unshare rm — Grafana writes as its container uid (472), which maps to a subordinate uid the host user cannot rm directly.

Logs

pg logs addon grafana            # show recent console output
pg logs addon grafana -f         # follow
pg logs addon grafana -n 200     # last 200 lines (also -i / --tail)

Troubleshooting

  • install fails with “chowning Grafana data dir … to 472:0” — the image runs as uid 472 and never fixes ownership itself, so pgcli chowns the host data dir before creating the container: through podman unshare chown under rootless podman (where the mapped subordinate uid is the only correct target), or a direct recursive chown when pgcli itself runs as root on a rootful host (sudo podman, or pg run as root). The manager shells out to the plain podman CLI, so this only fails outside those two cases — e.g. a non-root pg explicitly pointed at someone else’s rootful daemon. Run the install as root, or switch to rootless podman; a manual sudo chown -R 472:0 <data-dir> alone does not clear it, since pgcli re-checks ownership on every install attempt.
  • Login password doesn’t work — GF_SECURITY_ADMIN_PASSWORD only initialises the login while grafana.db is absent. On an existing store use grafana-cli admin reset-admin-password <new> inside the container, or pg addon remove grafana --clean-data + reinstall (wipes the dashboards).
  • Dashboard unreachable from another machine — Listen defaults to 0.0.0.0, so the port is open on the host’s interfaces; a failure there is host firewall, not bind address. Check pg addon list for the port, then open it.
  • Port already allocated — the assigned port is held in pg.yaml and skipped for later instances; free it with pg addon remove first, or pick another with --port N.
  • Data won’t load / the container exits with a permissions warning — the data dir must stay owned by uid 472; a manual chown on the host dir or restoring a backup with the wrong ownership breaks it. Re-run install (--force) to re-apply the ownership fix.

Known limitations

  • v1 is the bare web UI: no datasource or dashboard provisioning, no reverse-proxy subpath support (no --root-url flag — GF_SERVER_ROOT_URL is not set, so front it with nginx at the root path), and plaintext HTTP (TLS termination is the nginx addon’s job).
  • The host-side ownership chown is automatic under rootless podman (podman unshare chown) and when pgcli runs as root on a rootful host (direct chown). A rootful daemon talked to by a non-root pgcli (only via an explicitly configured remote socket) has no automatic path.
  • On macOS the container runs inside the podman machine; it has been validated on Linux only.

16 - Privoxy

Run Privoxy as a pgcli addon — an HTTP/HTTPS forward proxy with client ACLs, automatic port assignment, and no TLS interception

Privoxy is a non-caching forward proxy: plain HTTP requests are forwarded directly, HTTPS requests are tunnelled with CONNECT. It never intercepts TLS, so pgcli manages no CA and no certificates — the client’s own trust store keeps working. pgcli runs it as a standalone, top-level addon with the usual lifecycle (install / start / stop / logs / autostart / remove) managed through pg.yaml.

Typical uses:

  • a shared egress proxy for hosts and containers that have no direct route (or need a single, auditable outbound address),
  • a HTTP_PROXY / HTTPS_PROXY endpoint for package managers, curl, and applications inside the fleet,
  • a network-level gate: only clients in --allow-network may use it.

Platform support: Linux uses host networking; macOS uses the pgcli-net bridge with the port published. The image is multi-arch (amd64 + arm64).

How It Works

pgcli renders a complete Privoxy config from your flags and bind-mounts it read-only at /etc/privoxy/config. Logs go to the container’s stdout (logfile /dev/stdout), visible with pg logs addon privoxy. The image’s own entrypoint is bypassed (--entrypoint /usr/sbin/privoxy) because it rewrites the config file in place, which would fail on a read-only mount.

The rendered defaults are deliberately minimal and safe: caching is off, remote toggles and CGI editing are disabled, request-blocking is not enforced, and the proxy does not forward proxy authentication headers. No actions files are loaded, so it is a pure forwarder — use --conf-file when you need filtering.

Port assignment

Each instance gets its own port. The first one starts at privoxy_start_port (default 8118); additional instances increment from there, and any port already listening on the host (ss -tlnH) is skipped, so installing several proxies on one machine never collides with each other or with existing services:

pg addon install privoxy --name p1     # 8118
pg addon install privoxy --name p2     # 8119
pg addon install privoxy --name p3     # 8120, unless a host service owns it

Pin a port explicitly with --port N (a port already pinned to another privoxy instance is rejected; a port owned by a non-pgcli process shows up as a container start error).

Client ACLs

ACLs use Privoxy’s native syntax (host, addr[/mask][:port], and the optional two-part form client-spec destination-spec). Two rules of Privoxy’s own semantics matter:

  1. Once any permit-access / deny-access line exists, the default is deny.
  2. The last matching line wins.

pgcli therefore renders permits before denies:

Flags Rendered result Meaning
--allow-network A,B permit-access A, permit-access B whitelist — everyone else is denied
--deny-network C permit-access 0.0.0.0/0, deny-access C blacklist — everyone allowed except C
--allow-network A --deny-network C permits first, then denies allow a range, deny a narrower address inside it

Both flags are repeatable and accept comma-separated lists; all forms are merged (--allow-network 10.0.0.0/8,192.168.0.0/16 --allow-network 172.16.0.0/12 is one three-entry whitelist, and the same applies to --deny-network with several addresses). Passing either flag replaces the stored list on reinstall; passing neither clears it. With no ACL and a non-loopback listener the install prints an open proxy warning — anyone who can reach the port can proxy through it. Bind loopback (--listen 127.0.0.1) or add an ACL unless the port is already firewalled.

# Blacklist several clients: repeatable and/or comma-separated (all merged).
pg addon install privoxy --name p2 \
  --deny-network 10.0.0.66/32,10.0.0.67/32 \
  --deny-network 192.0.2.10/32

For an IPv6 listener the catch-all permit is [::]/0 instead of 0.0.0.0/0.

Custom configuration

--conf-file FILE copies a full Privoxy config into the addon directory instead of rendering one. It is mutually exclusive with the ACL flags; the file owns listen-address (pgcli’s --port is then used only in the summary and for macOS port publishing). Use this for upstream SOCKS forwarding, the stock actions/filter files shipped in the image, or any directive the template does not expose.

Because the file replaces the rendered config, it must be complete — nothing is inherited. A complete example that sends all traffic through a local SOCKS5 proxy and accepts only private-network clients:

# privoxy.conf
confdir /etc/privoxy
logdir /var/log/privoxy
logfile /dev/stdout
listen-address 0.0.0.0:8118

# Upstream: forward everything through a SOCKS5 proxy. Plain forward-socks5
# resolves target hostnames locally; use forward-socks5t for remote DNS.
forward-socks5 / 127.0.0.1:1080 .

# Client ACL: any ACL line makes the default deny, so list every allowed net.
permit-access 127.0.0.1/32
permit-access 10.0.0.0/8
permit-access 172.16.0.0/12
permit-access 192.168.0.0/16
pg addon install privoxy --name p4 --conf-file ./privoxy.conf

Keep logfile /dev/stdout if you want pg logs addon privoxy to show request logs. Only the config file itself is bind-mounted at /etc/privoxy/config; directories and extra files are not mounted, so an actionsfile can only refer to files already present in the image (the stock /etc/privoxy/*.action set).

Commands

# install (port auto-assigned from 8118)
pg addon install privoxy --name p1

# whitelist two private ranges (repeatable and/or comma-separated)
pg addon install privoxy --name p1 --allow-network 10.0.0.0/8,192.168.0.0/16

# blacklist several clients (repeatable and/or comma-separated)
pg addon install privoxy --name p2 --deny-network 10.0.0.66/32,10.0.0.67/32 \
  --deny-network 192.0.2.10/32

# explicit port and loopback bind
pg addon install privoxy --name p3 --port 8120 --listen 127.0.0.1

# custom config
pg addon install privoxy --name p4 --conf-file ./privoxy.conf

# lifecycle
pg addon list
pg addon stop privoxy --name p1
pg addon start privoxy --name p1
pg logs addon privoxy --name p1 -n 50
pg addon remove privoxy --name p1

Re-running install re-renders the config and recreates the container only when the rendered file changed (or when --force is set).

Using the proxy

# HTTP: forwarded directly
curl -x http://10.0.0.5:8118 http://example.com/

# HTTPS: CONNECT tunnel; the client still validates example.com's own cert
curl -x http://10.0.0.5:8118 https://example.com/

# environment variables for most tools
export HTTP_PROXY=http://10.0.0.5:8118
export HTTPS_PROXY=http://10.0.0.5:8118
export NO_PROXY=localhost,127.0.0.1,10.0.0.0/8

For Ansible-managed fleets, set pgcli_proxy_url once in group_vars/all/main.yml; see egress proxy.

A curl -v against an HTTPS URL shows CONNECT example.com:443 followed by a normal TLS handshake with the origin — no certificate is replaced.

Autostart

pg autostart enable --privoxy --name p1
pg autostart status
pg autostart disable --privoxy --name p1

At boot, pg start --autostart starts the container from the config already on disk, recreating it if it was removed. Install the instance first.

Notes

  • No TLS interception by design: no MITM CA, no certificate distribution. Clients validate the origin’s real certificate through the tunnel.
  • No caching and no content filtering in template mode; add actions files through --conf-file if you need filtering.
  • No authentication: Privoxy’s ACLs are address-based. Protect the port with --allow-network, a loopback bind, or a firewall.
  • The config directory is <base_dir>/addon/privoxy/<name>/; remove deletes it, and there is no other state.
  • Default image: ghcr.io/mars-base/pgcli/pgcli-privoxy:4.2.0 (official amd64 .deb, arm64 built from the official source tarball).

17 - Prometheus

Run Prometheus, the metrics collection backend Grafana reads from, as a managed container.

pg addon install prometheus runs Prometheus — the metrics collection and alerting backend — as a managed container from the official docker.io/prom/prometheus image. Like Grafana it is a top-level addon: it fronts no single PostgreSQL instance (it scrapes many endpoints), so it is not attached to any one of them. The two are natural partners — Prometheus scrapes and stores, Grafana visualises — and share the same lifecycle shape (single container, host networking on Linux, one web port from its own pool, persistent data dir, autostart, logs).

Prometheus diverges from Grafana in how it is configured. Grafana is env-only (GF_*); Prometheus reads a config file (prometheus.yml) and takes its runtime tuning as CLI flags passed after the image name (--config.file / --web.listen-address / --storage.tsdb.path / --storage.tsdb.retention.time). So pgcli renders prometheus.yml, bind-mounts it read-only, and points --config.file at the in-container path.

There is NO web login/password. Unlike Grafana (whose 0.0.0.0 default is guarded by a generated strong password), Prometheus ships no authentication at all. Its HTTP API runs arbitrary PromQL and can be loaded by expensive queries, so a remote-exposed instance is guarded only by the network boundary — your firewall, or --listen 127.0.0.1 for loopback. Treat exposing it like exposing an unauthenticated read/write console, not like a password-protected dashboard.

Platform: Linux is the tested platform. The design supports macOS (the image is multi-arch; the container runs under the podman machine VM on the pgcli-net bridge with the port published), but it has not been validated there yet.

Parameters

Flag Default Description
--name prometheus Instance name (map key)
--image docker.io/prom/prometheus:v3.15.0 Image override
--port auto (base 9090) Host web port; auto-allocated from prometheus_start_port
--listen 0.0.0.0 Bind address — defaults to every interface; use 127.0.0.1 for loopback-only (see the exposure warning above)
--scrape — (self job always present) Scrape spec JOB=HOST:PORT[,HOST:PORT...] [KEY=VALUE...] (repeatable) — the job name is required, every comma-separated target joins that one static_configs job in the generated prometheus.yml, and bare KEY=VALUE tokens after the target list become per-target labels applied to that spec’s targets (a spec with labels now contains a space — quote the whole value as one shell argument). Declares the FULL job set (replaces the stored list). Same job name across specs folds into one job; a node named by two specs merges both label sets and is scraped once, while nodes carrying different label sets split into separate static_configs blocks (Prometheus’s native shape for nodename=api1-style per-node labels). Targets are probed with GET /metrics from the host; unreachable ones only warn
--scrape-append — Same spec form (labels included), but folds the appended jobs’ targets — and their labels — into the stored --scrape list (same-named job merges, new names append) instead of replacing it. Every appended target is probed and the install ABORTS — writing nothing — if any returns no data. Mutually exclusive with --scrape and --conf-file
--scrape-interval 15s Global scrape_interval in the rendered config; mutually exclusive with --conf-file
--retention 15d TSDB retention (--storage.tsdb.retention.time); a duration like 15d, 6mo, 2y. A CLI flag, so it stays valid alongside --conf-file
--conf-file — Path to your own prometheus.yml — skip rendering entirely (mutually exclusive with --scrape/--scrape-append/--scrape-interval/--alertmanager-url/--remote-write-url/--remote-write-queue); see below
--alertmanager-url — Alertmanager instance(s) to forward fired alerts to (repeatable): bare HOST[:PORT] (portless gets 9093) or http(s)://HOST[:PORT][/path]. The rendered config gains an alerting: section pushing there and a matching alertmanager scrape job (so Alertmanager’s own /metrics is watched — not a separate opt-in). All entries validated up front and must share one scheme (mixing http/https aborts); connectivity is not probed. Mutually exclusive with --conf-file; see below
--remote-write-url — Remote-write URL(s) to push scraped samples to a long-term store (repeatable; a full http(s)://host:port/path URL). The rendered config gains a top-level remote_write: section. The local TSDB keeps its own --retention regardless — the remote is a WAL-backed copy, so a dead remote only stalls the queue and replays once it returns. Validated up front (must parse as http(s) with a host); connectivity is not probed. Mutually exclusive with --conf-file; see “Pushing samples to VictoriaMetrics” below
--remote-write-queue — A queue_config tuning applied under every --remote-write-url entry (repeatable KEY=VALUE): positive integers capacity, max_shards, min_shards, max_samples_per_send, and durations batch_send_deadline, min_backoff, max_backoff (e.g. 5s, 1m30s, 2y). VictoriaMetrics suggests bigger batches under load (max_samples_per_send=10000 capacity=20000 max_shards=30). Requires --remote-write-url; keys and values are validated up front (unknown keys, non-positive integers, and unitless durations abort before anything is written). Render-mode only, like --remote-write-url; per-remote tuning still needs --conf-file
--rule-file — Path to a rule file (*.rules.yml with a top-level groups:; repeatable) — pgcli copies each into its managed rules dir (basename only; two files sharing a basename abort), mounts that dir read-only at /etc/prometheus/rules, and the rendered config loads the copies via rule_files. Valid alongside --conf-file: the copy and mount happen either way, your own file decides whether to reference them. A missing/empty file aborts, writing nothing; see below
--data-dir auto Data directory override (default under the base dir)
--force false Recreate even when running — instead of hot-reloading a changed config, or to apply changed ports / listen / retention (install also recreates on its own when --rule-file goes from empty to non-empty or back, since that changes the container’s mount set)

The data directory is Prometheus’s TSDB. It survives pg addon remove (delete it with --clean-data), so reinstalling under the same name revives collected metrics. The image runs as a baked nobody (uid/gid 65534) and creates no writable directory itself, so pgcli chowns the data dir on the host before creating the container — via podman unshare chown 65534:65534 under rootless podman, or a direct recursive chown when pgcli runs as root on a rootful host (exactly Grafana’s mechanism, different id).

Install

pg addon install prometheus

The command pulls the image if needed, renders a prometheus.yml, creates the container, and prints the URL, config path, and retention:

✓ Prometheus installed: "prometheus"
  Container:  pgcli-prometheus-default-prometheus
  Image:      docker.io/prom/prometheus:v3.15.0
  Data:       /home/you/.pgcli/addon/prometheus/prometheus/data
  Config:     /home/you/.pgcli/addon/prometheus/prometheus/prometheus.yml (rendered: 1 self job + 0 scrape job(s))
  Retention:  15d
  URL:        http://0.0.0.0:9090/

The rendered config always contains a self-monitoring job that scrapes this server’s own /metrics, so it is never idle; --scrape adds more jobs. Point Grafana at http://<host>:9090/ as a Prometheus datasource and you can query immediately.

# each --scrape spec declares a job; the name before = is required, and several
# comma-separated targets share that one job (the shape for a fleet of exporters)
pg addon install prometheus --name p1 \
  --scrape postgres-exporter=127.0.0.1:9187 \
  --scrape node=10.0.0.5:9100,10.0.0.6:9100

Per-target labels (the nodename: api1 your Ansible-rendered config carries) are bare KEY=VALUE tokens after the target list — one spec per labelled node:

# one windows job, three targets, each labelled with its node name
# (a spec with labels contains a space, so quote it as ONE shell argument)
pg addon install prometheus --name p1 \
  --scrape "windows=10.0.0.1:9182 nodename=api1" \
  --scrape "windows=10.0.0.2:9182 nodename=api2" \
  --scrape "windows=10.0.0.3:9182 nodename=api3"
# renders exactly the native per-node shape: one job_name, one labelled
# static_configs block per distinct label set
  - job_name: windows
    static_configs:
      - targets: ["10.0.0.1:9182"]
        labels:
          nodename: "api1"
      - targets: ["10.0.0.2:9182"]
        labels:
          nodename: "api2"
      - targets: ["10.0.0.3:9182"]
        labels:
          nodename: "api3"

Grouping is target-centric, so naming the same node twice never scrapes it twice: two specs carrying the same 10.0.0.5:9100 merge into ONE target with the union of their labels (node=a:1 nodename=api1 + node=a:1 env=prod → a:1 carrying both). The only rejection is a contradiction — the same node labelled with the same key to two different values aborts instead of silently dropping one. Label values may not contain whitespace (a device="eth0, eth1" needs --conf-file), and label keys must be [A-Za-z_][A-Za-z0-9_]*; values are emitted quoted, so yes or 2 cannot retype under YAML.

Re-running install with --scrape replaces the whole stored job set. To add to it instead, use --scrape-append — same spec form, labels included; it folds each appended target (and its labels) into the stored job of the same name and appends unseen names, then hot-reloads:

pg addon install prometheus --name p1 --scrape-append node=10.0.0.7:9100
# the stored node job grows a third target; its labels are untouched
pg addon install prometheus --name p1 --scrape-append "node=10.0.0.5:9100 env=prod"
# ...or an existing target gains a label in place (merged, still one scrape)

The two flags probe differently, on purpose: a freshly appended target must answer GET /metrics with 200 or the command aborts before writing anything (pg.yaml and the running container untouched); with plain --scrape an unreachable target is only a warning and the install proceeds — Prometheus will surface it as DOWN, and a full-list declaration is often pointed at endpoints that are legitimately not up yet. The probe dials from the host — on Linux (host network) that is the same namespace the container scrapes from; on the macOS bridge it differs, so the probe is skipped there.

Scrape targets are dialled from the Prometheus container. On Linux (host network) a 127.0.0.1:<port> target reaches the host’s loopback directly; on the macOS bridge it reaches the container’s own namespace instead, so a remote or VM-resident target should be given a routable address.

Re-running install on a running instance hot-reloads it (SIGHUP) when the rendered/copied config actually changed, and leaves it alone when it didn’t; --force recreates the container instead — to apply a changed --port / --listen / --retention (which are container arguments, not config-file contents).

Forwarding alerts to Alertmanager (--alertmanager-url)

Point a Prometheus instance at one or more pgcli-managed Alertmanagers and it will push fired alerts to them:

pg addon install alertmanager --name am1
pg addon install prometheus --name p1 \
  --scrape postgres-exporter=127.0.0.1:9187 \
  --alertmanager-url 127.0.0.1:9093

The rendered prometheus.yml then gains two things from the one flag — an alerting: section that pushes fired alerts, and a matching alertmanager scrape job that watches each instance’s own /metrics:

alerting:
  alertmanagers:
    - static_configs:
        - targets: ["127.0.0.1:9093"]
...
  - job_name: alertmanager
    static_configs:
      - targets: ["127.0.0.1:9093"]

Accepted forms are bare host[:port] (a portless entry gets Alertmanager’s conventional 9093) or a full http(s)://host[:port][/path] URL; the scheme and path are stripped for the scrape target, and https is carried through as scheme: https on both sections (TLS knobs like CA files are out of render scope — they need --conf-file). Entries are validated before anything is written and must all share one scheme (http and https mixed together abort), but they are not connectivity-probed: Prometheus tracks dead alertmanagers on its own, and pg addon prometheus reload can’t fix a network problem anyway. A re-run replaces the stored URL list wholesale (there is no append form for it, unlike --scrape).

Verify the wiring live:

curl -s localhost:9090/api/v1/alertmanagers           # activeAlertmanagers lists the target
curl -s 'localhost:9090/api/v1/targets?state=any' | grep -c alertmanager

Pushing samples to VictoriaMetrics (--remote-write-url)

Prometheus’s built-in TSDB is compiled in and cannot be swapped out — the way to put VictoriaMetrics (or any remote store) behind it is remote_write: each scrape cycle pushes a copy of every sample to the remote, while the local TSDB keeps its own --retention window and keeps serving queries regardless. pgcli already runs both ends, so the pair is two installs:

# long-term store — single-node VictoriaMetrics on the loopback, or the
# vmcluster addon's vminsert (http://<host>:8480/insert/0/prometheus/api/v1/write)
pg addon install victoriametrics --name vm --listen 127.0.0.1

# the scrape backend pushes every sample into it
pg addon install prometheus --name p1 --listen 127.0.0.1 \
  --remote-write-url http://127.0.0.1:8428/api/v1/write

# same, with VictoriaMetrics's suggested batching under load
pg addon install prometheus --name p1 --listen 127.0.0.1 \
  --remote-write-url http://127.0.0.1:8428/api/v1/write \
  --remote-write-queue max_samples_per_send=10000 \
  --remote-write-queue capacity=20000 \
  --remote-write-queue max_shards=30

The rendered prometheus.yml gains a top-level remote_write: section — with a queue_config: block under each URL when --remote-write-queue is set:

remote_write:
  - url: "http://127.0.0.1:8428/api/v1/write"
    queue_config:
      max_samples_per_send: 10000
      capacity: 20000
      max_shards: 30

A re-run replaces the stored URL list wholesale (no append form, like --alertmanager-url), and a changed URL is applied by hot reload (SIGHUP) — no container recreate. Entries must be full http(s)://host[:port]/path URLs (unlike Alertmanager targets there is no portless/scheme default — the path is the write endpoint); they are validated up front but not connectivity-probed. --remote-write-queue rides the same path: a repeated list replaces the stored one, it is validated up front (whitelisted keys only — integer sizes/shards and duration timeouts), and the same KEY=VALUE set is emitted under every remote, so differentiated per-remote tuning still drops to --conf-file. Passing it without any --remote-write-url aborts — there is nothing to tune under.

Verify the link is alive and delivering:

# the remote-write queue is draining (pending ~0, samples_total rising)
curl -s 'localhost:9090/api/v1/query?query=prometheus_remote_storage_samples_pending'
# the sample actually landed in VictoriaMetrics
curl -s 'localhost:8428/api/v1/query?query=prometheus_build_info'

Once Grafana is pointed at VictoriaMetrics instead of Prometheus (http://<host>:8428/, or http://<host>:8481/select/0/prometheus/ for the cluster edition), the Prometheus instance is a thin scrape-and-forward layer and VictoriaMetrics is the queryable store. Historical data already in the Prometheus TSDB does not backfill automatically — use the vmctl prometheus tool for a one-time migration.

Loading alerting rules (--rule-file)

Prometheus evaluates alerting/recording rules from rule_files:. Give pgcli the rule file and it becomes a managed copy:

pg addon install prometheus --name p1 --rule-file /srv/rules/alert.rules.yml

pgcli copies each file into <base>/addon/prometheus/<name>/rules/, bind-mounts that directory read-only at /etc/prometheus/rules, and the rendered config references the copy by name:

rule_files:
  - "/etc/prometheus/rules/alert.rules.yml"

A flat directory means the basename is what matters: two source files sharing one basename abort the install (the copy would silently clobber one).

Editing your original rule file takes effect with a plain reload: pg addon prometheus reload re-copies every --rule-file into the managed dir before signalling, so Prometheus rereads the new rules in place — no reinstall, no container restart:

# edit /srv/rules/alert.rules.yml ...
pg addon prometheus reload --name p1
curl -s localhost:9090/api/v1/rules    # groups reflect the edit; or watch pg logs addon prometheus

A bad rule file is rejected the same way a bad config is: Prometheus keeps serving the previous rule set and logs the parse error, so check the log (or the rules API) after reloading hand-edited rules. The copies are managed artifacts, deleted by pg addon remove regardless of --clean-data, exactly like the rendered prometheus.yml. Your originals are never touched.

--rule-file differs from the other render knobs in that it stays valid alongside --conf-file: pgcli copies the rules and adds the mount either way, and your own file decides whether to reference /etc/prometheus/rules (a rule_files: ["/etc/prometheus/rules/*.rules.yml"] glob in it picks up whatever you passed). The one flag whose addition cannot be hot-reloaded is this one going from empty to non-empty (or back): the /etc/prometheus/rules mount exists only while there are rule files, and a SIGHUP cannot add a volume, so that transition recreates the container.

Custom config file (--conf-file)

Give pgcli your own prometheus.yml and it skips rendering entirely:

pg addon install prometheus --name p1 --conf-file /etc/prometheus/my.yml

pgcli copies your file into its managed path (<base>/addon/prometheus/<name>/prometheus.yml) and mounts that copy read-only — never your original. This is deliberate: a single-file bind mount pins the source inode, so an in-place edit of your original file would not propagate into the running container. Because it’s a copy, editing your own file and running pg addon prometheus reload re-copies it and signals Prometheus to reread. pgcli does not validate or rewrite the file’s contents (same contract as the nginx/haproxy --conf-file). --conf-file is mutually exclusive with the render knobs --scrape/--scrape-append/--scrape-interval/--alertmanager-url/--remote-write-url/--remote-write-queue (an operator file owns its alerting: and remote_write: sections); --retention, --listen and --rule-file are not render knobs and stay valid alongside it. Omit --conf-file on a reinstall to go back to render mode.

Worked example

A real operator file wired to a pgcli Alertmanager and loading pgcli-managed rule files:

# /etc/prometheus/my.yml
# pg addon install prometheus --name p1 --conf-file /etc/prometheus/my.yml
global:
  scrape_interval: 15s
  scrape_timeout: 15s
  evaluation_interval: 1m

alerting:
  alertmanagers:
    - static_configs:
        - targets:
            - localhost:9093 # a pgcli alertmanager on its default base port

rule_files:
  - /etc/prometheus/rules/*.rules.yml # pgcli's managed rules dir (--rule-file)

remote_write: []

scrape_configs:
  - job_name: prometheus
    static_configs:
      - targets:
          - localhost:9090 # this Prometheus itself
  - job_name: nodes
    static_configs:
      - targets:
          - 10.0.0.5:9100
        labels:
          nodename: lhcloud1
      - targets:
          - 10.0.0.6:9100
        labels:
          nodename: lhcloud2
      - targets:
          - 10.0.0.7:9100
        labels:
          nodename: lhcloud3

That labelled nodes shape is exactly what render mode now emits — the three --scrape node=…:9100 nodename=… specs fold into one nodes job carrying one labelled static_configs block each; the hand-written file remains the way to add per-job extras (scrape timeouts, relabels) the renderer does not expose.

localhost:9090 and localhost:9093 work because Linux containers run on the host network — localhost inside Prometheus is the host, where both web ports listen. The two pieces pgcli contributes are visible in the file: --rule-file copies your rule files into <base>/addon/prometheus/<name>/rules/ and bind-mounts that directory at /etc/prometheus/rules, which is why the rule_files: glob above resolves; the alerting: block, on the other hand, is yours to write — in --conf-file mode pgcli adds nothing to the file, does not derive the alertmanager scrape job either, and rejects --alertmanager-url as a render knob. Check a hand-written file before relying on pg addon prometheus reload to surface errors in the log:

c=$(podman ps --filter name=pgcli-prometheus --format '{{.Names}}' | head -1)
podman exec "$c" promtool check config /etc/prometheus/prometheus.yml

That inspects the copy pgcli mounted, so run it after an install (or a reload) rather than against your original path.

Reload (hot config change)

pg addon prometheus reload --name p1

This rewrites the managed prometheus.yml (re-render in render mode, re-copy your file in --conf-file mode, re-copy the --rule-file copies in both) and sends SIGHUP to the running container, which makes Prometheus reread it in place — no container recreate, no dropped scrapes. It uses a signal rather than the HTTP POST /-/reload endpoint on purpose, so the unauthenticated reload route never has to be enabled (--web.enable-lifecycle is not set). Prometheus keeps serving on its last good config and logs an error if the new one is malformed, so check pg logs addon prometheus after reloading a hand-written file. The instance must already be running (pg addon start prometheus). One change a signal cannot apply: --rule-file going from empty to non-empty (or back) adds/removes the /etc/prometheus/rules mount, so a plain install recreates the container for that transition — reload is enough for edits within a non-empty rule set.

Listening and exposure

Prometheus’s Listen defaults to 0.0.0.0: the container shares the host’s network namespace, so the UI and API are reachable on every interface at the assigned port. This matches Grafana’s default for the same practical reason (Grafana on another host needs to reach it) — but there is no password behind it. Anyone who can reach the port can run arbitrary PromQL and read your collected metrics. For a loopback-only deployment pass --listen 127.0.0.1 (recreate with --force); pg addon list then shows http://127.0.0.1:<port>/. Otherwise, restrict access at the firewall.

Ports

Each Prometheus instance owns a single port: the web UI/API. It is allocated from a pool with base prometheus_start_port (default 9090 — Prometheus’s conventional web port), incrementing for every additional instance and skipping ports already taken by any managed container or the used_ports list. The allocation is written into pg.yaml, so a reinstall never re-hands-out a port another addon is using. 9090 shares no number with Grafana (3000), pgAdmin (5050), or nginx (8080); an explicit --port still wins.

pg addon install prometheus --name p2          # second instance: next free port (9091 if 9090 taken)
pg addon install prometheus --name p3 --port 9100  # explicit port still takes precedence

Configuration

addons:
  prometheus:
    p1:
      name: p1
      image_tag: docker.io/prom/prometheus:v3.15.0
      host_port: 9090
      listen: 0.0.0.0
      retention: 15d
      scrape:
        - postgres-exporter=127.0.0.1:9187
        - node=10.0.0.5:9100,10.0.0.6:9100
        - node=10.0.0.5:9100 env=prod   # same node again → ONE scrape carrying the union of labels
        - windows=10.0.0.1:9182 nodename=api1   # bare KEY=VALUE tokens = per-target labels
      scrape_interval: 15s
      autostart: false
      # alertmanager: [127.0.0.1:9093]        # render-mode only: forward fired alerts + a derived scrape job
      # remote_write: [http://127.0.0.1:8428/api/v1/write]  # render-mode only: push samples to a long-term store (VictoriaMetrics)
      # remote_write_queue: [max_samples_per_send=10000, capacity=20000]  # queue_config under every remote above
      # rule_files: [/srv/rules/alert.rules.yml]  # copied into <name>/rules, mounted at /etc/prometheus/rules
      # conf_file: /etc/prometheus/my.yml   # operator-file mode, skips rendering
      # data_dir: /srv/prometheus-data      # optional, overrides the default location

The rendered prometheus.yml carries the global scrape_interval, the always-present self job, and one static_configs job per scrape JOB — every target a job’s specs list folds into that job, bucketed by merged label set so each distinct KEY=VALUE combination becomes its own - targets:/labels: block; --alertmanager-url adds the alerting: section plus its alertmanager scrape job, --remote-write-url adds a top-level remote_write: section (--remote-write-queue fills each entry with a queue_config: block), and --rule-file adds a rule_files: section. retention and the listener bind are not in that file — they are passed to the prometheus binary as CLI flags (--storage.tsdb.retention.time, --web.listen-address), which is why they remain settable alongside --conf-file.

List

pg addon list
Web add-ons (prometheus):
  prometheus (name: p1)
    Status:      running
    URL:         http://0.0.0.0:9090/
    Config:      /home/you/.pgcli/addon/prometheus/p1/prometheus.yml [rendered (1 scrape job(s))]
    Retention:   15d
    Data:        /home/you/.pgcli/addon/prometheus/p1/data
    Image:       docker.io/prom/prometheus:v3.15.0
    Container:   pgcli-prometheus-p1

There are no credentials to reveal — Prometheus has none — so --show-password shows nothing extra for it.

Start and stop

Containers run with podman’s unless-stopped restart policy, so they come back automatically with the podman service after a host reboot. start/stop manage them explicitly:

pg addon stop prometheus
pg addon start prometheus

Auto-start on Boot

To have a Prometheus instance started automatically on host boot, enable it:

pg autostart enable --prometheus --name p1

This flags the instance in pg.yaml and installs/refreshes a boot service (a systemd --user unit on Linux, a LaunchAgent on macOS) that runs pg start --autostart. A boot-time start only brings the container up — reading the managed prometheus.yml already on disk, and the data dir was already chowned at create time, so it needs no host privileges beyond podman itself. Prometheus starts after Grafana and before nginx in the boot order. See Autostart for the full mechanism, status and disabling.

Remove

pg addon remove prometheus              # keeps the TSDB — collected metrics survive a reinstall
pg addon remove prometheus --clean-data # deletes the TSDB too

Under rootless podman, --clean-data deletes the data dir through podman unshare rm — Prometheus writes as its container uid (65534), which maps to a subordinate uid the host user cannot rm directly. --conf-file mode removes only pgcli’s copy; your original file wherever you put it is never touched. --rule-file originals likewise survive — only the managed rules/ copies go away, and they go away on every remove, with or without --clean-data (like the rendered prometheus.yml, they carry no state worth reviving).

Logs

pg logs addon prometheus            # show recent console output
pg logs addon prometheus -f         # follow
pg logs addon prometheus -n 200     # last 200 lines (also -i / --tail)

Troubleshooting

  • install fails with “chowning Prometheus data dir … to 65534:65534” — the image runs as nobody (uid/gid 65534) and never fixes ownership itself, so pgcli chowns the host data dir before creating the container: through podman unshare chown under rootless podman (where the mapped subordinate uid is the only correct target), or a direct recursive chown when pgcli itself runs as root on a rootful host. The manager shells out to the plain podman CLI, so this only fails outside those two cases — e.g. a non-root pg explicitly pointed at someone else’s rootful daemon. Run the install as root, or switch to rootless podman; a manual sudo chown -R 65534:65534 <data-dir> alone does not clear it, since pgcli re-checks ownership on every install attempt.
  • A scrape target shows DOWN — confirm Prometheus can reach it (it dials from the container; on Linux 127.0.0.1:<port> is the host loopback, but a cross-host/VM target needs a routable address, especially on the macOS bridge). Check the exporter is up and the path is /metrics. pg logs addon prometheus shows scrape failures.
  • --scrape-append aborted with “returned no data” — by design: an appended target must answer GET /metrics with 200 from the host before anything is written (the existing instance and pg.yaml stay untouched). Bring the exporter up, or use plain --scrape (which only warns) when declaring the full job set. The probe is skipped on macOS.
  • A config reload didn’t take effect — pg addon prometheus reload needs the container running; if the new prometheus.yml is malformed Prometheus keeps serving the last good config and logs the error. Check pg logs addon prometheus, fix the file, reload again.
  • Port already allocated — the assigned port is held in pg.yaml and skipped for later instances; free it with pg addon remove first, or pick another with --port N.
  • Remote API unreachable / unexpectedly reachable — on the default 0.0.0.0 a failure to reach it is host firewall, not bind address; conversely, if you did not want it reachable, --listen 127.0.0.1 --force.

Known limitations

  • v1 is a bare collection backend: it ships no PostgreSQL exporter (install one yourself and point --scrape postgres-exporter=127.0.0.1:9187 at it). Long-term storage and alerting are wired, though: --remote-write-url pushes scraped samples to a VictoriaMetrics addon (single-node or vmcluster), --alertmanager-url forwards fired alerts to a pgcli Alertmanager, and --rule-file loads alerting rules (all render-mode; --conf-file covers the rest by hand). It is the scrape/store/query layer you point Grafana at.
  • No authentication. Prometheus’s API runs arbitrary PromQL; the only protection for a 0.0.0.0 bind is the network boundary. This is a materially weaker posture than Grafana’s password-guarded 0.0.0.0 — do not expose it on an untrusted network.
  • pgcli renders or copies prometheus.yml but does not validate it (there is no promtool check config gate at install). A bad rendered config is impossible, but a bad --conf-file surfaces only in the container logs on reload.
  • The host-side ownership chown is automatic under rootless podman (podman unshare chown) and when pgcli runs as root on a rootful host (direct chown). A rootful daemon talked to by a non-root pgcli (only via an explicitly configured remote socket) has no automatic path.
  • On macOS the container runs inside the podman machine; it has been validated on Linux only.

18 - Alertmanager

Run Alertmanager, Prometheus’s alert deduplication/grouping/routing frontend, as a managed container.

pg addon install alertmanager runs Alertmanager — the alert deduplication, grouping, routing and notification layer that sits downstream of Prometheus — as a managed container from the official docker.io/prom/alertmanager image. Like Prometheus and Grafana it is a top-level addon: it fronts no single PostgreSQL instance, so it is not attached to any one of them. Prometheus and Alertmanager are the natural pair — Prometheus fires alerts, Alertmanager decides who gets notified and how — and this addon is Prometheus’s near-exact twin in shape (single container, host networking on Linux, one web port from its own pool, persistent data dir, autostart, logs, rendered config file + trailing CLI flags, SIGHUP reload, no web login).

The wiring lives on the Prometheus side. pg addon install alertmanager does not touch any prometheus.yml — and it does not need to: Prometheus points at this instance itself, with pg addon install prometheus --alertmanager-url <host:port of this instance>, which injects the alerting: section (and a scrape job watching this instance’s /metrics). On a hand-written Prometheus config (--conf-file), write the alerting: block yourself. Either way, once pointed here, alerts flow.

There is NO web login/password — and the stakes are higher than Prometheus’s. Alertmanager ships no authentication at all, and its unauthenticated API is write-capable in a way Prometheus’s read-mostly one is not: anyone who reaches the port can create silences — i.e. silently mute every notification your on-call expects, with no trace in Prometheus’s own metrics. Its 0.0.0.0 default is therefore guarded only by the network boundary, and that boundary matters more here than anywhere else in the addon family. Treat exposing it as handing out a mute switch for your alerting, not like a password-protected dashboard.

Platform: Linux is the tested platform. The design supports macOS (the image is multi-arch; the container runs under the podman machine VM on the pgcli-net bridge with the port published), but it has not been validated there yet.

Parameters

Flag Default Description
--name alertmanager Instance name (map key)
--image docker.io/prom/alertmanager:v0.34.1 Image override
--port auto (base 9093) Host web port; auto-allocated from alertmanager_start_port
--listen 0.0.0.0 Bind address — defaults to every interface; use 127.0.0.1 for loopback-only (see the exposure warning above)
--webhook-url — Webhook URL to notify (repeatable). Each URL is rendered as one webhook_configs entry of the SAME web.hook receiver — multiple URLs fan out to all of them. Validated with net/url (parseable, http/https, non-empty host) before anything is written; a bad URL aborts the install touching nothing. Connectivity is NOT probed (see below). Mutually exclusive with --conf-file
--conf-file — Path to your own alertmanager.yml — skip rendering entirely (mutually exclusive with --webhook-url); see below
--data-dir auto Data directory override (default under the base dir)
--force false Recreate even when running — instead of hot-reloading a changed config, or to apply changed ports / listen

The data directory holds Alertmanager’s state: silences and notification state. It survives pg addon remove (delete it with --clean-data), so reinstalling under the same name revives them. The image runs as a baked nobody (uid/gid 65534) and creates no writable directory itself, so pgcli chowns the data dir on the host before creating the container — via podman unshare chown 65534:65534 under rootless podman, or a direct recursive chown when pgcli runs as root on a rootful host (exactly Prometheus’s and Grafana’s mechanism, different id).

--webhook-url is not connectivity-probed, on purpose: unlike a Prometheus scrape (GET /metrics, reachable at install time and answerable then), a webhook is a POST that only fires when an alert actually routes through it — dialling it at install would tell you nothing you could rely on. The only early gate is the URL’s shape; whether the endpoint exists, is reachable, and accepts the payload is discovered at alert time (check pg logs addon alertmanager when notifications go missing).

Install

pg addon install alertmanager

The command pulls the image if needed, renders an alertmanager.yml, creates the container, and prints the URL, config path, and what the route renders to:

✓ Alertmanager installed: "alertmanager"
  Container:  pgcli-alertmanager-default-alertmanager
  Image:      docker.io/prom/alertmanager:v0.34.1
  Data:       /home/you/.pgcli/addon/alertmanager/alertmanager/data
  Config:     /home/you/.pgcli/addon/alertmanager/alertmanager/alertmanager.yml (rendered: no-op receiver)
  URL:        http://0.0.0.0:9093/

With no --webhook-url the rendered config is a single route pointing at a name-only no-op receiver: a legal, fully-functional config — the web UI and API are live, silences work, the HA cluster port is disabled — that simply sends nothing. This is the “bring up the endpoint, decide routing later” default. To actually notify something, add a webhook:

# one URL → the route's receiver becomes web.hook with one webhook_configs entry
pg addon install alertmanager --name am1 --webhook-url http://127.0.0.1:5001/

# several URLs → all of them land under ONE web.hook receiver (fan-out to each)
pg addon install alertmanager --name am1 \
  --webhook-url http://127.0.0.1:5001/ \
  --webhook-url https://hooks.example.com/alert?token=abc

Re-running install on a running instance hot-reloads it (SIGHUP) when the rendered/copied config actually changed, and leaves it alone when it didn’t; --force recreates the container instead — to apply a changed --port / --listen (which are container arguments, not config-file contents).

Re-running with a different --webhook-url set replaces the stored list wholesale (passing none clears it back to no-op); the diff is what decides whether to reload.

Receiving webhooks in Python

Alertmanager sends one JSON document per notification group to every configured --webhook-url; the endpoint must answer with a 2xx or Alertmanager retries. A minimal FastAPI receiver (webhook_app.py):

import logging

from fastapi import FastAPI, Request

logging.basicConfig(level=logging.INFO, format="%(asctime)s %(levelname)s %(message)s")
app = FastAPI()


@app.post("/alertmanager")
async def receive_alert(request: Request) -> dict:
    payload = await request.json()

    for alert in payload.get("alerts", []):
        if alert.get("status") == "resolved":
            continue

        labels = alert.get("labels", {})
        annotations = alert.get("annotations", {})
        logging.warning(
            "%s %s: %s",
            labels.get("severity", "warning").upper(),
            labels.get("alertname", "unknown"),
            annotations.get("summary") or annotations.get("description", ""),
        )
        # Hand off to your notifier here; keep the HTTP response fast.

    return {"status": "ok"}

Run it on the same host and point Alertmanager at it:

uv run --with fastapi --with uvicorn uvicorn webhook_app:app --host 0.0.0.0 --port 18801

pg addon install alertmanager --name am1 \
  --webhook-url http://127.0.0.1:18801/alertmanager

Test it without waiting for a real alert:

curl -sS -X POST http://127.0.0.1:18801/alertmanager \
  -H 'Content-Type: application/json' \
  -d '{
        "version": "4",
        "status": "firing",
        "alerts": [{
          "status": "firing",
          "labels": {"alertname": "PGDown", "severity": "critical", "instance": "10.0.0.5:5432"},
          "annotations": {"summary": "PostgreSQL instance is down"},
          "fingerprint": "abc123"
        }]
      }'

To exercise the full chain instead of posting to the receiver directly:

curl -sS -X POST http://127.0.0.1:9093/api/v2/alerts \
  -H 'Content-Type: application/json' \
  -d '[
        {
          "labels": {
            "alertname": "PGDown",
            "severity": "critical",
            "instance": "10.0.0.5:5432"
          },
          "annotations": {
            "summary": "PostgreSQL instance is down"
          }
        }
      ]'

sleep 35   # the rendered config uses group_wait: 30s

The uvicorn console then shows, with the logging.basicConfig format above:

2026-11-02 08:28:08,123 WARNING CRITICAL PGDown: PostgreSQL instance is down

Run the receiver as a managed daemon (Linux)

Leaving uv run in a terminal works for testing, but a real receiver should survive logout and come back after a reboot. On Linux, register the command with pg daemon (see Daemon) and let pgcli manage the process:

mkdir -p /opt/webhook
python3 -m venv /opt/webhook/.venv
/opt/webhook/.venv/bin/pip install fastapi uvicorn
# save the receiver above as /opt/webhook/webhook_app.py

pg daemon add webhook --dir /opt/webhook -- \
  /opt/webhook/.venv/bin/uvicorn webhook_app:app --host 0.0.0.0 --port 18801
pg daemon start webhook

add only records the command; start runs it. Use the venv’s absolute paths: at boot the receiver does not get the PATH of your login shell, so uv run and a bare uvicorn are not available. Check it and follow its log with:

pg daemon status webhook
pg daemon logs webhook -f

To start it automatically at boot — after every instance and addon, so the receiver can dial its dependencies while they are up:

pg autostart enable --daemon --name webhook

pg daemon stop webhook and pg daemon restart webhook manage it; pg daemon remove webhook --clean-log stops it and deletes the registration and the managed log. Autostart starts the process once and does not supervise it: a crash after boot is not restarted. Point Alertmanager at it exactly as before with --webhook-url http://127.0.0.1:18801/alertmanager.

Receiver on another host

When the receiver and Alertmanager run on different hosts, bind the receiver to 0.0.0.0 and use an address of the receiver host that is reachable from the Alertmanager host; 127.0.0.1 only works when both run on the same host.

On the receiver host (example address 10.0.0.5):

uv run --with fastapi --with uvicorn uvicorn webhook_app:app --host 0.0.0.0 --port 18801

The receiver can also be registered as a pg daemon on this host — same command, same --host 0.0.0.0 — so it survives logout and restarts with the host (see above).

From the Alertmanager host, verify the route before wiring it up:

curl -sS -X POST http://10.0.0.5:18801/alertmanager \
  -H 'Content-Type: application/json' \
  -d '{
        "version": "4",
        "status": "firing",
        "alerts": [{
          "status": "firing",
          "labels": {"alertname": "RemoteProbe", "severity": "info"},
          "annotations": {"summary": "receiver reachability probe"},
          "fingerprint": "remote-1"
        }]
      }'
# {"status": "ok"}

Then install (or reinstall) Alertmanager with the receiver host’s IP and port:

pg addon install alertmanager --name am1 \
  --webhook-url http://10.0.0.5:18801/alertmanager

Reinstalling under the same name with a changed URL hot-reloads the config (SIGHUP). The receiver console prints:

2026-11-02 08:36:22,950 WARNING INFO RemoteProbe: receiver reachability probe

After submitting an alert through Alertmanager, wait at least group_wait (30s in the rendered config) before checking the receiver log.

  • The receiver host firewall must allow TCP 18801 from the Alertmanager host.

  • Do not bind the receiver to 127.0.0.1 for cross-host use; 0.0.0.0 (or a specific reachable interface address) is required.

  • The --webhook-url path (/alertmanager) must match the FastAPI route.

  • If the Alertmanager host sets HTTP_PROXY/HTTPS_PROXY, add the receiver address to NO_PROXY; otherwise Alertmanager may send the webhook through the proxy.

  • One POST carries a group of alerts (alerts[]), not a single alert; iterate it.

  • send_resolved defaults to true for webhook receivers, so status: "resolved" entries arrive too — filter them as above, or set send_resolved: false in your own --conf-file.

  • alerts[].fingerprint identifies an alert across repeats; use it for deduplication when deliveries may overlap.

  • Respond 2xx quickly and move slow work off the request path; a non-2xx response makes Alertmanager retry.

  • With Alertmanager on host networking (the Linux default), 127.0.0.1 reaches a receiver on the same host. Under the macOS bridge network use host.containers.internal; when the receiver runs on another host, use its reachable address. Bind the server to 0.0.0.0 (as above) whenever the container is not on host networking.

Custom config file (--conf-file)

Give pgcli your own alertmanager.yml and it skips rendering entirely:

pg addon install alertmanager --name am1 --conf-file /etc/alertmanager/my.yml

pgcli copies your file into its managed path (<base>/addon/alertmanager/<name>/alertmanager.yml) and mounts that copy read-only — never your original. This is deliberate: a single-file bind mount pins the source inode, so an in-place edit of your original file would not propagate into the running container. Because it’s a copy, editing your own file and running pg addon alertmanager reload re-copies it and signals Alertmanager to reread. pgcli does not validate or rewrite the file’s contents (same contract as the nginx/haproxy/prometheus --conf-file). --conf-file is mutually exclusive with --webhook-url (the flag that shapes the rendered file) — a real routing tree (email/Slack/PagerDuty, sub-routes, inhibition) lives in your own file. Omit --conf-file on a reinstall to go back to render mode.

The file is plain Alertmanager YAML — pgcli adds nothing to it and expects nothing from it beyond “parses”. A worked example with a sub-route tree, inhibition, and three different receiver types:

# Complete Alertmanager config for `pg addon install alertmanager
# --name am1 --conf-file /path/to/this.yml` — everything pgcli would
# render is replaced by what follows; only the container flags
# (--web.listen-address, --storage.path, --cluster.listen-address=)
# stay pgcli's job.
global:
  resolve_timeout: 5m
  smtp_smarthost: "smtp.example.com:587"
  smtp_from: "alertmanager@example.com"
  smtp_auth_username: "alertmanager@example.com"
  smtp_auth_password: "CHANGE-ME"
  slack_api_url: "https://hooks.slack.com/services/T00000/B00000/XXXXXXXX"

inhibit_rules:
  # a critical alert mutes warning/info noise from the SAME alert on the SAME instance
  - source_matchers: ['severity = critical']
    target_matchers: ['severity =~ warning|info']
    equal: ['alertname', 'instance']

route:
  receiver: default
  group_by: ['alertname']
  group_wait: 30s
  group_interval: 5m
  repeat_interval: 4h
  routes:
    # critical goes to the on-call mailbox, and still falls through to default
    - matchers: ['severity = critical']
      receiver: oncall-email
      continue: true
    # storage team's alerts get their own Slack channel
    - matchers: ['team = storage']
      receiver: storage-slack
      group_by: ['alertname']
      group_wait: 10s

receivers:
  - name: default
    webhook_configs:
      - url: "http://127.0.0.1:5001/"

  - name: oncall-email
    email_configs:
      - to: "oncall@example.com"
        send_resolved: true

  - name: storage-slack
    slack_configs:
      - channel: "#storage-alerts"
        send_resolved: true

pgcli itself never validates this file (no amtool check-config gate at install — see Known limitations), but the image ships amtool, so you can check the managed copy inside the running container before trusting a reload (container name as printed by pg addon list, namespace-scoped — pgcli-alertmanager-default-am1 in the transcript above):

pg addon install alertmanager --name am1 --conf-file /etc/alertmanager/my.yml
# edit /etc/alertmanager/my.yml ...
podman exec pgcli-alertmanager-default-am1 amtool check-config /etc/alertmanager/alertmanager.yml
pg addon alertmanager reload --name am1   # re-copies and SIGHUPs once the file is good

Reload (hot config change)

pg addon alertmanager reload --name am1

This rewrites the managed alertmanager.yml (re-render in render mode, re-copy your file in --conf-file mode) and sends SIGHUP to the running container, which makes Alertmanager reread it in place — no container recreate, no dropped notifications.

Unlike Prometheus, Alertmanager’s POST /-/reload endpoint exists and cannot be disabled (there is no --web.enable-lifecycle-style gate on it). pgcli still reloads via SIGHUP — not because the route is closed, but so it never has to depend on an unauthenticated HTTP endpoint that is, by the image’s design, always open. Anyone who can reach the port can already hit that route directly; pgcli simply doesn’t add to the surface. If you reload a hand-written --conf-file whose config is rejected, Alertmanager keeps its last good config and logs the error, so check pg logs addon alertmanager afterwards. The instance must already be running (pg addon start alertmanager).

Listening and exposure

Alertmanager’s Listen defaults to 0.0.0.0: the container shares the host’s network namespace, so the UI and API are reachable on every interface at the assigned port. There is no password behind it, and — unlike Prometheus — the API lets a caller CREATE SILENCES, i.e. mute every notification your on-call expects, and reload its config. A loopback-only deployment is the safe default: pass --listen 127.0.0.1 (recreate with --force); pg addon list then shows http://127.0.0.1:<port>/. Otherwise restrict access at the firewall, and treat an open 0.0.0.0 as a reachable mute switch.

Ports

Each Alertmanager instance owns a single port: the web UI/API. It is allocated from a pool with base alertmanager_start_port (default 9093 — Alertmanager’s conventional web port), incrementing for every additional instance and skipping ports already taken by any managed container or the used_ports list. The allocation is written into pg.yaml, so a reinstall never re-hands-out a port another addon is using. 9093 shares no number with Grafana (3000), pgAdmin (5050), Prometheus (9090), or nginx (8080); an explicit --port still wins.

9094 — the HA gossip port — is never opened, because it’s disabled by a flag. Alertmanager’s high-availability clustering listens on TCP+UDP 9094 by default and will keep trying to bootstrap peers that never arrive for a single instance. pgcli passes --cluster.listen-address= (empty) to switch it off entirely — a single-instance contract, enforced at every create, so the cluster port never opens and no UDP listener lingers. (This is only about the cluster use of 9094; the number is not reserved, so the web-port pool is free to hand 9094 out as the second instance’s web port — see the example below.) Clustering several pgcli-managed Alertmanagers into one gossip group is not wired up (see Known limitations).

pg addon install alertmanager --name am2          # second instance: next free port after 9093 (e.g. 9094 — the pool is plain numeric assignment; nothing reserves the disabled cluster port's number)
pg addon install alertmanager --name am3 --port 9200  # explicit port still takes precedence

Configuration

addons:
  alertmanager:
    am1:
      name: am1
      image_tag: docker.io/prom/alertmanager:v0.34.1
      host_port: 9093
      listen: 0.0.0.0
      webhook:
        - http://127.0.0.1:5001/
        - https://hooks.example.com/alert?token=abc
      autostart: false
      # conf_file: /etc/alertmanager/my.yml   # operator-file mode, skips rendering
      # data_dir: /srv/alertmanager-data      # optional, overrides the default location

The rendered alertmanager.yml carries a global.resolve_timeout, one root route (group_by: ['alertname'], default group_wait/interval/repeat_interval) pointing at a single receiver, and that receiver’s webhook_configs — one entry per webhook URL under web.hook, or a name-only no-op receiver when the list is empty. The listener bind, storage path, and the disabled cluster address are not in that file — they are passed to the alertmanager binary as CLI flags (--web.listen-address, --storage.path, --cluster.listen-address=), which is why --listen remains settable alongside --conf-file.

List

pg addon list
Web add-ons (alertmanager):
  alertmanager (name: am1)
    Status:      running
    URL:         http://0.0.0.0:9093/
    Config:      /home/you/.pgcli/addon/alertmanager/am1/alertmanager.yml [rendered (2 webhook)]
    Data:        /home/you/.pgcli/addon/alertmanager/am1/data
    Image:       docker.io/prom/alertmanager:v0.34.1
    Container:   pgcli-alertmanager-am1

There are no credentials to reveal — Alertmanager has none — so --show-password shows nothing extra for it, and pg addon password alertmanager resolves nothing.

Start and stop

Containers run with podman’s unless-stopped restart policy, so they come back automatically with the podman service after a host reboot. start/stop manage them explicitly:

pg addon stop alertmanager
pg addon start alertmanager

Auto-start on Boot

To have an Alertmanager instance started automatically on host boot, enable it:

pg autostart enable --alertmanager --name am1

This flags the instance in pg.yaml and installs/refreshes a boot service (a systemd --user unit on Linux, a LaunchAgent on macOS) that runs pg start --autostart. A boot-time start only brings the container up — reading the managed alertmanager.yml already on disk, and the data dir was already chowned at create time, so it needs no host privileges beyond podman itself. In the boot order Alertmanager starts right after Prometheus and before nginx — the natural companion to the collector above, which is also where the two get linked (pg addon install prometheus --alertmanager-url …). See Autostart for the full mechanism, status and disabling.

Remove

pg addon remove alertmanager              # keeps silences + notification state — they survive a reinstall
pg addon remove alertmanager --clean-data # deletes them too

Under rootless podman, --clean-data deletes the data dir through podman unshare rm — Alertmanager writes as its container uid (65534), which maps to a subordinate uid the host user cannot rm directly. --conf-file mode removes only pgcli’s copy; your original file wherever you put it is never touched.

Logs

pg logs addon alertmanager            # show recent console output
pg logs addon alertmanager -f         # follow
pg logs addon alertmanager -n 200     # last 200 lines (also -i / --tail)

Troubleshooting

  • install fails with “chowning Alertmanager data dir … to 65534:65534” — the image runs as nobody (uid/gid 65534) and never fixes ownership itself, so pgcli chowns the host data dir before creating the container: through podman unshare chown under rootless podman (where the mapped subordinate uid is the only correct target), or a direct recursive chown when pgcli itself runs as root on a rootful host. The manager shells out to the plain podman CLI, so this only fails outside those two cases — e.g. a non-root pg explicitly pointed at someone else’s rootful daemon. Run the install as root, or switch to rootless podman; a manual sudo chown -R 65534:65534 <data-dir> alone does not clear it, since pgcli re-checks ownership on every install attempt.
  • No notifications arrive — the most common cause is a no-op receiver: an install with no --webhook-url renders a config that never sends anything. Check the Config: line in pg addon list (it says no-op receiver vs rendered (N webhooks)). If a real webhook is configured, it is not connectivity-probed at install — reachability is only discovered when an alert fires, so check pg logs addon alertmanager for POST failures and confirm the endpoint accepts Alertmanager’s webhook payload.
  • --webhook-url aborted with a parse error — by design: every URL is validated (net/url parse, http/https scheme, non-empty host) before pg.yaml or any file is written, so a bad URL leaves the running instance and config untouched. Fix the URL and re-run.
  • A config reload didn’t take effect — pg addon alertmanager reload needs the container running; if the new alertmanager.yml is rejected (a route referencing an undefined receiver, bad YAML) Alertmanager keeps serving the last good config and logs the error. Check pg logs addon alertmanager, fix the file, reload again.
  • Port already allocated — the assigned port is held in pg.yaml and skipped for later instances; free it with pg addon remove first, or pick another with --port N.
  • Remote API unreachable / unexpectedly reachable — on the default 0.0.0.0 a failure to reach it is host firewall, not bind address; conversely, if you did not want it reachable (and remember: reachability means anyone can create silences), --listen 127.0.0.1 --force.

Known limitations

  • One-sided wiring. This addon neither injects an alerting: section into a prometheus.yml nor reads one from Prometheus — it only receives whatever is pushed to its API. The linking is done from the Prometheus side (pg addon install prometheus --alertmanager-url …, render mode; in --conf-file mode write the alerting: block yourself). An alertmanager-aware prometheus.yml is never inspected from here.
  • No authentication — and its consequences are sharper than Prometheus’s. The API can create silences (mute on-call) and reload config, and POST /-/reload cannot be disabled in the image (pgcli just doesn’t use it). The only protection for a 0.0.0.0 bind is the network boundary; do not expose it on an untrusted network.
  • Single instance / cluster disabled. --cluster.listen-address= is always passed empty, so HA gossip (TCP+UDP 9094) never opens. Clustering several pgcli-managed Alertmanagers is not supported in v1.
  • Webhooks are not connectivity-probed at install (only their URL shape is validated). Reachability and payload acceptance surface at alert time, in the logs.
  • pgcli renders or copies alertmanager.yml but does not validate it (there is no amtool check-config gate at install). A bad rendered config is impossible, but a bad --conf-file surfaces only in the container logs on reload.
  • The host-side ownership chown is automatic under rootless podman (podman unshare chown) and when pgcli runs as root on a rootful host (direct chown). A rootful daemon talked to by a non-root pgcli (only via an explicitly configured remote socket) has no automatic path.
  • On macOS the container runs inside the podman machine; it has been validated on Linux only.

19 - Gitea

Run Gitea — self-hosted Git service — as a managed container, with a no-wizard install and an auto-generated web login.

pg addon install gitea runs Gitea — the lightweight self-hosted Git service — as a managed container from the official upstream image (docker.io/gitea/gitea, rootful build). Like Grafana it is a top-level addon: it is not attached to any one PostgreSQL instance — it fronts none, though it can use one as its metadata database (see --dsn below). One container serves the web UI, the Git HTTP traffic, and git-over-ssh on the image’s OpenSSH sshd (see Git SSH — that sshd runs on every instance whether or not --ssh-port is set; the flag only makes it the live clone endpoint).

The install is fully non-interactive: INSTALL_LOCK=true skips Gitea’s web setup wizard, and the admin account is created afterwards via the in-container gitea admin user create CLI. The web login password is generated on first install, printed once, and stored in pg.yaml; retrieve it later with pg addon password gitea. Listen defaults to 0.0.0.0 — a Git host is cloned from other machines — and the exposure is guarded by the generated strong password plus closed self-registration; pass --listen 127.0.0.1 for loopback-only access.

Platform: Linux is the tested platform. The design supports macOS (the image is multi-arch; the container runs under the podman machine VM on the pgcli-net bridge with the web port — and, when enabled, the SSH port — published), but it has not been validated there yet.

Parameters

Flag Default Description
--name gitea Instance name (map key)
--image docker.io/gitea/gitea:28.1.0 Image override (rootful build only — see Known limitations)
--port auto (base 3080) Host web port; auto-allocated from gitea_start_port
--ssh-port unset Make the always-running sshd the live git-over-ssh endpoint on this host port (see Git SSH). A port is allocated from gitea_ssh_start_port (base 2222) for every instance to park sshd off 22, SSH on or off; --ssh-port 0 disables live cloning but keeps the reservation
--listen 0.0.0.0 Bind address — defaults to every interface; use 127.0.0.1 for loopback-only. Also the host Gitea renders into clone URLs
--admin-user gitea Web login user (deliberately not git — that is the container’s OS user ssh:// clones authenticate as)
--password auto-generated Web login password (applied only when the admin account does not yet exist — see below)
--dsn empty postgres://user:pass@host:port/db to keep Gitea’s metadata in an external PostgreSQL instead of the embedded SQLite; the database must already exist
--allow-registration false Open self-service signup (the web UI shows a Register entry). Closed by default — see Listening and exposure
--data-dir auto Data directory override (default under the base dir)
--force false Recreate even when running — to apply changed ports, credentials, dsn, listen address or the registration toggle

Install

pg addon install gitea

The command pulls the image if needed, creates and starts the container, waits for Gitea’s first-boot migrations to finish, creates the admin account, and prints:

✓ Gitea installed: "gitea"
  Container:  pgcli-gitea-gitea
  Image:      docker.io/gitea/gitea:28.1.0
  Data:       /home/you/.pgcli/addon/gitea/gitea/data
  Web URL:    http://localhost:3080/
  Git SSH:    disabled (HTTP clone/push only; enable with --ssh-port N --force)

  Login user:     gitea
  Login password: <auto-generated>

Open the URL, sign in with the printed credentials, and create your first org/repo in the web UI. Clone over HTTP with the same login:

git clone http://127.0.0.1:3080/<owner>/<repo>.git

The data directory and /data

Everything Gitea owns lives in one bind-mounted directory: the repositories, the rendered /data/gitea/conf/app.ini, the SQLite metadata database (/data/gitea/gitea.db — absent with --dsn), the SSH host keys, and logs. It survives pg addon remove (delete it with --clean-data), so reinstalling under the same name revives everything.

The image’s rootful build runs as the git user — uid/gid 1000, pinned via USER_UID/USER_GID so the host-side pre-chown and the container process can never drift apart — and its entrypoint only chowns what it creates itself, so pgcli chowns the data dir on the host before creating the container: via podman unshare chown 1000:1000 under rootless podman, or a direct recursive chown when pgcli runs as root on a rootful host.

pgcli never injects SECRET_KEY or INTERNAL_TOKEN. Gitea folds every GITEA__<section>__<KEY> environment variable into the persisted app.ini on each boot; if pgcli regenerated and injected crypto secrets, a reinstall over a kept data dir would re-key the persisted app.ini while the surviving database still holds 2FA seeds and OAuth client secrets encrypted under the old key — a silent, unlogged lockout. So those keys belong to the volume: Gitea generates them itself on first boot, and pgcli owns only the admin login password.

The admin password takes effect only when the admin account does not exist in the database — it is created with gitea admin user create, never reset. Reinstalling over a kept data dir (or a kept --dsn database) keeps the original login; the printed password is then inert (install says so explicitly). To change the login of an existing store, run gitea admin user change-password inside the container (pg exec <instance> -- ... style: podman exec -it <container> gitea admin user change-password ...), or remove with --clean-data and reinstall (SQLite mode — a --dsn database also has to be dropped by hand).

Re-running install reuses a running container and starts a stopped one — config changes only apply after a remove + reinstall or --force.

Database: SQLite or --dsn

By default Gitea uses its embedded SQLite database inside /data — zero dependencies, one file, revived with the data dir. For anything shared or long-lived, point the metadata at PostgreSQL:

pg addon install gitea --name git1 --dsn "postgres://gitea:secret@127.0.0.1:35432/gitea"

pgcli validates the DSN before writing anything and renders it into GITEA__database__DB_TYPE=postgres plus HOST/NAME/USER/PASSWD. The install summary and pg addon list echo it back with the credentials hidden (host:port/db). Same contract as PostgREST’s --dsn: the database must already exist (create it on a managed instance with pg exec <instance> -c 'CREATE DATABASE gitea ...' or any other way); Gitea creates its own schema on first boot. pg addon remove gitea — even with --clean-data — never touches the external database; it only holds Gitea’s tables.

Git SSH (optional)

Every Gitea instance runs an OpenSSH sshd — the official image’s s6 openssh service is unconditional (its run script execs sshd; no GITEA__server__* env turns it off). What --ssh-port actually toggles is whether that sshd is the live git-over-ssh clone endpoint or just an idle listener. --ssh-port takes a host port from gitea_ssh_start_port (base 2222) for every instance — SSH on or off — precisely so the always-on sshd is parked off 22: on the host network, leaving it on 22 would race the host’s own sshd and the log would fill with Bind to port 22 … Address in use forever. pgcli moves it by setting the image’s bare SSH_LISTEN_PORT / SSH_PORT env (those are what the rendered sshd_config’s Port line actually consumes — GITEA__server__SSH_LISTEN_PORT alone only changes what Gitea believes the port is, not what sshd binds).

  • SSH off (default, no --ssh-port): DISABLE_SSH=true so Gitea neither writes the git user’s authorized_keys nor advertises ssh:// clone URLs. The s6 sshd is still running, parked on a pool port, and no client will ever reach it. The pool reservation stays — nothing frees it.
  • SSH on (--ssh-port N, N>0): git-over-ssh rides that same s6 sshd — the image’s native route. DISABLE_SSH=false makes Gitea populate the git user’s authorized_keys (which sshd reads via AuthorizedKeysFile pointed into /data/gitea/ssh/); Gitea’s own built-in Go SSH listener is pinned off with START_SSH_LISTENER=false so it does not double-bind the same port in the same netns; and SSH_DOMAIN / SSH_PORT render the ssh://git@<host>:N/<owner>/<repo>.git clone URL.
pg addon install gitea --name git1 --ssh-port 2222   # explicit, or omit for pool

Auth is the git account’s SSH keys added through the web UI (the OS user is git; the web admin is gitea). Host keys live under <data>/ssh/, so they survive reinstalls — if you remove with --clean-data, clients see a new-host-key warning the next time.

Under the macOS bridge the SSH port is additionally published, but only when SSH is on — a parked sshd is unreachable by design, so it gets no -p. Not passing --ssh-port on a later install keeps the stored setting; --ssh-port 0 disables live cloning (the port reservation stays — only the DISABLE_SSH flip and the clone-URL change take effect, with a --force recreate).

Listening and exposure

Gitea’s Listen defaults to 0.0.0.0: the container shares the host’s network namespace, so the web UI and Git HTTP are reachable on every interface at the assigned port. This is deliberate — a Git host is cloned from other machines — and is protected by the generated strong admin password plus DISABLE_REGISTRATION=true (self-service account creation is off; create accounts with pg addon gitea user create). For a loopback-only deployment pass --listen 127.0.0.1 (recreate with --force).

--allow-registration flips that second guard: pg addon install gitea --name <n> --allow-registration --force renders DISABLE_REGISTRATION=false and the web UI grows a Register entry. Close it again with --allow-registration=false --force — the toggle is a stored config value gated on the flag being passed, so a plain re-install (or one without the flag) keeps whatever state is stored, and only --force pushes a change into the live container. What opens up is account spam, not takeover: a field test confirmed the register form creates a NORMAL user (IsAdmin=false) — Gitea has no way to make signup produce an admin; elevation is exclusively pg addon gitea user create --admin or the admin panel, independent of how the account was born. Companion Gitea-side hardening for an open-registration site lives in the same service section (REGISTER_EMAIL_CONFIRM, CAPTCHA, REQUIRE_SIGNIN_VIEW) — outside pgcli’s rendered env set, so it stays Gitea-side configuration.

--listen is also what displayed clone URLs use: a wildcard bind is not a connectable address, so it is echoed as localhost, and any explicit host/IP appears verbatim in ROOT_URL and the ssh:// URLs. When Gitea sits behind a reverse proxy that forwards X-Forwarded-Proto and Host — which pgcli’s nginx template does by default — Gitea rewrites the displayed clone URL to match the incoming request, so the code button on the repo page reads https://<proxy-host>/<owner>/<repo>.git correctly (scheme from X-Forwarded-Proto, host from Host, standard port dropped). pgcli’s rendered ROOT_URL stays http://<host>:<web-port>/ because there is no config face to advertise https/the proxy port — but that only governs webhook/redirect URLs generated server-side; interactive clone URLs follow the request. For TLS, see HTTPS via nginx.

HTTPS via nginx

Gitea serves plaintext HTTP; to reach it over https:// you front it with the nginx addon, which terminates TLS and proxies to the Gitea web port. Two things to get right: bring your own certificate (or let pgcli mint a self-signed one), and use nginx’s custom --conf-file mode — the template’s default client_max_body_size (1 MiB) rejects any larger git push with HTTP 413.

# 1. a self-signed leaf whose SAN covers the host you clone by (IP and/or DNS)
pg cert --host 10.0.0.9,git.internal \
        --cert-file /srv/gitea.crt --key-file /srv/gitea.key

Write the proxy config as /srv/gitea-nginx.conf — the parts that matter for Git are client_max_body_size 10m (nginx’s built-in default is 1 MiB, and without raising it a larger git push dies with HTTP 413 before reaching Gitea) and the long proxy_*_timeout (streaming git push outlives the 60s default). The same file as a generic template also lives in the nginx docs (“Git HTTP push with client_max_body_size”):

worker_processes auto;
pid /tmp/nginx.pid;

events {
    worker_connections 1024;
}

http {
    # Lift nginx's request-body cap so git pushes aren't rejected. nginx's
    # built-in default is 1 MiB — anything larger dies with HTTP 413 before
    # reaching Gitea. 10m covers typical pushes; raise it (or use 0 for no
    # limit) if you commit larger binaries.
    client_max_body_size 10m;
    proxy_read_timeout 300s;
    proxy_send_timeout 300s;

    upstream gitea {
        server 127.0.0.1:3080;    # the Gitea web port pgcli allocated
    }

    server {
        listen 0.0.0.0:80;
        location / {
            return 308 https://$host$request_uri;   # force HTTPS (308 keeps method+body,
        }                                           # so git push survives the redirect)
    }

    server {
        listen 0.0.0.0:443 ssl;
        # pgcli bind-mounts the --tls-cert / --tls-key files at these paths:
        ssl_certificate     /etc/nginx/certs/public.crt;
        ssl_certificate_key /etc/nginx/certs/private.key;
        ssl_protocols TLSv1.2 TLSv1.3;

        location / {
            proxy_pass http://gitea;
            proxy_set_header Host $host;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_set_header X-Forwarded-Proto $scheme;   # what makes the displayed
        }                                                 # clone URL read https://…
    }
}
# 2. install the proxy on that file (recreate anytime with --force)
pg addon install nginx --name proxy --conf-file /srv/gitea-nginx.conf \
  --tls --tls-cert /srv/gitea.crt --tls-key /srv/gitea.key \
  --http-port 80 --https-port 443 --listen 0.0.0.0

The nginx proxy now serves https://10.0.0.9/ and forwards to Gitea’s 127.0.0.1:3080. Clone and push over the proxy URL (hand clients the .crt as their CA so the self-signed cert verifies):

git clone https://10.0.0.9/<owner>/<repo>.git        # over the TLS proxy
git -c http.sslCAInfo=/srv/gitea.crt push ...        # trust the self-signed leaf

Notes:

  • The Gitea web port (3080) is still open directly; the proxy does not hide it. For an origin that only nginx may reach, reinstall Gitea with --listen 127.0.0.1 so it binds loopback only, and point the proxy’s backend at 127.0.0.1:3080 (same host) — works because both run on the host network.
  • pg addon nginx reload will not pick up an external edit to the mounted nginx.conf (the bind mount pins the original inode, so a sed -i/editor rewrite is invisible until the container restarts). Reload only applies changes pgcli itself wrote. After hand-editing the conf, restart with pg addon stop nginx --name proxy && pg addon start nginx --name proxy, or reinstall with --force.
  • A real CA cert (Let’s Encrypt / ZeroSSL / corporate) is the right choice in production — see Production domain + a real CA below; it drops the --cacert hand-off entirely, browsers and git trust it out of the box.
  • git-over-ssh (--ssh-port) is independent of this; TLS here only fronts the web UI and Git-over-HTTP.

Production domain + a real CA (Let’s Encrypt / corporate)

For anything facing the internet, don’t ship a pg cert self-signed leaf — point a real domain at the host (e.g. git.example.com → 203.0.113.7) and get a CA-signed certificate for it. How you obtain that certificate is outside pgcli’s scope — any CA and any tool you like; all that matters is ending up with a PEM cert (including its intermediate chain) and its private key.

Then create the nginx proxy exactly as in the steps above, only swapping the certificate paths for your domain cert — the same --conf-file, ports and --tls are unchanged:

pg addon install nginx --name proxy --conf-file /srv/gitea-nginx.conf \
  --tls \
  --tls-cert /etc/ssl/git.example.com/fullchain.pem \
  --tls-key  /etc/ssl/git.example.com/privkey.pem \
  --http-port 80 --https-port 443 --listen 0.0.0.0

Set --listen git.example.com on the Gitea install too (with --force), so ROOT_URL and any ssh:// hints carry the real hostname. Once it’s up, users clone https://git.example.com/<owner>/<repo>.git with no CA hand-off — browsers and git trust public CAs by default.

Remember to replace the certificate before it expires. pgcli copies the BYO pair into the addon’s TLS dir (<base>/addon/nginx/<name>/tls/ as public.crt / private.key) at install, and that directory is bind-mounted into the container — so renewal is: overwrite those two files, then

pg addon nginx reload --name proxy

(Verified: the served certificate changes immediately after the reload. This works because the TLS dir is mounted as a directory; unlike the single-file nginx.conf mount, new contents are visible to the running container.)

Retrieving the web login

The login is Gitea’s web/Git-HTTP sign-in, unrelated to any PostgreSQL role (even with --dsn). Re-read the password at any time:

pg addon password gitea              # bare password on stdout
pg addon password gitea --file ./pw  # or write it to a 0600 file

It is also stored in pg.yaml (addons.gitea.<name>.password).

Managing accounts (members and admins)

Self-registration is closed, so every account beyond the install admin is created by an admin. pg addon gitea user wraps the in-container gitea admin user … CLI (run as the git uid automatically) so you manage accounts from the host without a manual podman exec. The instance must be running.

# a member, generated password (printed once, NOT stored in pg.yaml)
pg addon gitea user create --username alice --email alice@corp.example
# a member, pinned password
pg addon gitea user create --username bob   --password 'B0b-pin-pass'
# a second site admin
pg addon gitea user create --username carol --admin
# list everyone
pg addon gitea user list
# remove an account (must own nothing, or use --purge) ...
pg addon gitea user delete --username bob
# ... or drop everything the account owns
pg addon gitea user delete --username bob --purge
flag (create) default meaning
--username (required) the account name
--email <username>@localhost pass a real address when the user should get notifications / password resets
--password generated pin the login, or let pgcli generate a strong one and print it once
--admin false create a site admin instead of a normal member
--must-change-password false Gitea’s own default is true for every account after the first; that forces a change on first login and, until it happens, returns 403 for HTTP clone/push and API basic-auth. pgcli sends =false explicitly so a member can clone immediately — set it true only to hand out a one-time password

These logins are Gitea’s own accounts, not pgcli-managed, so a generated password is printed once and is not written to pg.yaml — record it at creation. (Only the install admin’s login is stored; that one you retrieve with pg addon password gitea.) To change an existing account’s password, run gitea admin user change-password inside the container.

delete refuses to remove the install admin (it is pgcli’s stored login). A plain delete only succeeds for an account that owns nothing; if it still owns repositories Gitea refuses with user still has ownership of repositories — pass --purge to remove the account and everything it owns (repos, orgs, comments).

Ports

Each Gitea instance takes one port for the web UI, allocated from a pool with base gitea_start_port (default 3080 — Gitea’s conventional 3000 is the Grafana pool’s base in pgcli, so Gitea starts one pool over; still recognizably “the Gitea port”). Every instance also takes a port from a second pool (gitea_ssh_start_port, default 2222 — the conventional Gitea SSH mapping) to park the image’s always-running sshd off 22; whether SSH is on or off only decides whether that port is a live clone endpoint or an idle listener, so the reservation is held either way. Both pools skip ports already taken by any managed container or the used_ports list, and the allocations are written into pg.yaml:

pg addon install gitea --name git2                 # second instance: next free web port
pg addon install gitea --name git3 --port 3100     # explicit port still wins
pg addon install gitea --name git4 --ssh-port 0    # SSH disabled: parked sshd keeps its pool port

The two pools’ bases (3080 / 2222) are disjoint from every other addon’s pool.

Configuration

addons:
  gitea:
    git1:
      name: git1
      image_tag: docker.io/gitea/gitea:28.1.0
      host_port: 3080
      listen: 0.0.0.0
      admin_user: gitea
      password: <generated>
      ssh: true
      ssh_port: 2222
      dsn: postgres://gitea:secret@127.0.0.1:35432/gitea
      autostart: false
      # data_dir: /srv/gitea-data    # optional, overrides the default location

Config is env-only (GITEA__<section>__<KEY> plus two bare SSH_LISTEN_PORT / SSH_PORT vars — those are what the image’s always-running sshd actually binds; the GITEA__server__* copy only drives Gitea’s own SSH-aware clone-URL rendering), folded by the image into app.ini on every boot; the app.ini inside /data is rewritten from these variables, so hand-editing it is not a supported configuration path (settings pgcli does not set survive the rewrite, but changing one of pgcli’s own keys by hand just gets undone on the next boot). The variables pgcli sets are: the wizard skip (INSTALL_LOCK), the listener (HTTP_PORT/HTTP_ADDR), the display URL (ROOT_URL), the registration gate (DISABLE_REGISTRATION, rendered in both states — true by default, false with --allow-registration, since Gitea’s own default is open and an omitted line could not override a persisted one), the always-emitted bare SSH_LISTEN_PORT/SSH_PORT pair that parks the s6 sshd off 22, DISABLE_SSH=true when SSH is off (Gitea then also does not write authorized_keys or show ssh:// URLs) or — when SSH is on — DISABLE_SSH=false plus the URL-rendering trio SSH_LISTEN_PORT/SSH_PORT/SSH_DOMAIN under GITEA__server__ and START_SSH_LISTENER=false so Gitea’s own Go listener does not double-bind the same port, the optional database block, and the process uid pin (USER_UID/USER_GID).

List

pg addon list
Web add-ons (gitea):
  gitea (name: git1)
    Status:      running
    Web URL:     http://localhost:3080/
    Git SSH:     ssh://git@localhost:2222/
    Database:    external PostgreSQL (127.0.0.1:35432/gitea)
    Login user:  gitea
    Data:        /home/you/.pgcli/addon/gitea/git1/data
    Image:       docker.io/gitea/gitea:28.1.0
    Container:   pgcli-gitea-git1

Passwords are hidden by default to keep the listing paste-safe; pg addon list --show-password reveals the plaintext value, and pg addon password gitea prints a single one bare for scripting.

Start and stop

Containers run with podman’s unless-stopped restart policy, so they come back automatically with the podman service after a host reboot. start/stop manage them explicitly:

pg addon stop gitea
pg addon start gitea

Auto-start on Boot

To have a Gitea instance started automatically on host boot, enable it:

pg autostart enable --gitea --name git1

This flags the instance in pg.yaml and installs/refreshes a boot service (a systemd --user unit on Linux, a LaunchAgent on macOS) that runs pg start --autostart. A boot-time start only brings the container up — the data dir was already chowned to uid 1000 at create time, so it needs no host privileges beyond podman itself. With --dsn, the external PostgreSQL must be up too: a managed instance with its own autostart starts earlier in the same pass; any other endpoint just needs to be reachable. See Autostart for the full mechanism, status and disabling.

Remove

pg addon remove gitea              # keeps the data dir — repos and login survive a reinstall
pg addon remove gitea --clean-data # deletes the data dir too (repositories are gone)

Under rootless podman, --clean-data deletes the data dir through podman unshare rm — Gitea writes as the container’s git uid (1000), which maps to a subordinate uid the host user cannot rm directly. With --dsn the external database is never touched either way — drop it yourself if you really want the data gone.

Logs

pg logs addon gitea            # show recent console output
pg logs addon gitea -f         # follow
pg logs addon gitea -n 200     # last 200 lines (also -i / --tail)

Troubleshooting

  • install fails with a chown diagnostic — the image runs as uid 1000 and never fixes ownership of an existing mount, so pgcli chowns the host data dir before creating the container: through podman unshare chown under rootless podman, or a direct recursive chown when pgcli itself runs as root on a rootful host. The manager shells out to the plain podman CLI, so this only fails outside those two cases — e.g. a non-root pg explicitly pointed at someone else’s rootful daemon. Run the install as root, or switch to rootless podman; a manual sudo chown -R 1000:1000 <data-dir> alone does not clear it, since pgcli re-checks ownership on every install attempt.
  • The login password doesn’t work after a reinstall — the admin account is created, never reset. On an existing store (kept /data or --dsn database) use gitea admin user change-password inside the container, or wipe and start over (--clean-data, and drop the external DB by hand in dsn mode).
  • Clone URLs show localhost even though Gitea is on a server — a wildcard --listen 0.0.0.0 collapses to localhost in displayed URLs because 0.0.0.0 is not connectable. Pass --listen <host-or-ip> (with --force) to make clone URLs real.
  • ssh:// clone says connection refused / wrong port — live cloning is off unless the instance was installed with --ssh-port (the s6 sshd is running but parked, so it is not a clone endpoint). And pgcli keeps SSH_PORT (what URLs show), the Gitea-side SSH_LISTEN_PORT, and the bare SSH_LISTEN_PORT (what the s6 sshd actually binds) all equal — a hand-mismatched config breaks exactly this way.
  • Log line Bind to port 22 … Address in use — the sshd’s park port has somehow reverted to 22 (an app.ini edit survived a boot, or bare env was stripped). A fresh install never hits this: pgcli always emits bare SSH_LISTEN_PORT=<pool port> for every instance, SSH on or off.
  • git push over HTTP asks for a password and rejects the web one — Gitea asks for the account’s credentials; if the account has 2FA on, HTTP push needs a personal access token or an SSH key instead of the password.
  • Port already allocated — the assigned ports are held in pg.yaml and skipped for later instances; free them with pg addon remove first, or pick others with --port / --ssh-port.

Known limitations

  • The image must be pinned to a version tag and upgraded by changing --image (Gitea migrates its database forward on first boot of the newer image — there is no downgrade path). Rootful and rootless builds have mutually incompatible data layouts: pgcli pins the rootful build and an -rootless tag will not read the existing /data (or the data written by another rootless deployment).
  • Plaintext HTTP: TLS termination and real hostnames are the nginx addon’s job — front Gitea with it in custom --conf-file mode (the template’s 1 MiB client_max_body_size default breaks larger git push). Gitea rewrites the on-page clone URL from X-Forwarded-Proto + Host, so behind nginx’s default proxy headers the copy button reads https://<proxy>/… correctly. pgcli renders ROOT_URL as http://<host>:<web-port>/ and v1 exposes no knob to change that — the only visible effect so far is anything Gitea generates from ROOT_URL directly (rather than from the request) keeps the internal http origin.
  • v1 sets no OAuth, SMTP, webhook-tuning, or repository-storage (MinFS) options — everything beyond the table above is Gitea-side configuration pgcli deliberately leaves alone. Self-registration is closed; create users with pg addon gitea user create.
  • On macOS the container runs inside the podman machine; it has been validated on Linux only.

20 - VictoriaMetrics

Run VictoriaMetrics, a fast Prometheus-compatible time-series database, as a managed container.

pg addon install victoriametrics runs VictoriaMetrics — a fast, Prometheus-compatible time-series database — as a managed container from the official docker.io/victoriametrics/victoria-metrics image. Like Prometheus and Grafana it is a top-level addon: it fronts no single PostgreSQL instance (it ingests metrics from many sources), so it is not attached to any one of them. The three are natural partners — Prometheus scrapes, VictoriaMetrics stores long-term with superior compression, Grafana visualises — and share the same lifecycle shape (single container, host networking on Linux, one web port from its own pool, persistent data dir, autostart, logs).

VictoriaMetrics diverges from Prometheus in how it is configured. Prometheus reads a config file (prometheus.yml) plus CLI flags; VictoriaMetrics needs no config file at all — everything is passed as CLI flags after the image name (-storageDataPath / -httpListenAddr / -retentionPeriod / custom flags via --extra-arg). So pgcli passes these flags directly when creating the container; there is no config to render, no SIGHUP reload, no chown needed (the image runs as root).

There is NO web login/password. Unlike Grafana (whose 0.0.0.0 default is guarded by a generated strong password), VictoriaMetrics ships no authentication at all. Its HTTP API runs arbitrary MetricsQL (a superset of PromQL) and can be loaded by expensive queries, so a remote-exposed instance is guarded only by the network boundary — your firewall, or --listen 127.0.0.1 for loopback. Treat exposing it like exposing an unauthenticated read/write console, not like a password-protected dashboard.

Platform: Linux is the tested platform. The design supports macOS (the image is multi-arch; the container runs under the podman machine VM on the pgcli-net bridge with the port published), but it has not been validated there yet.

Parameters

Flag Default Description
--name vm Instance name (map key)
--image docker.io/victoriametrics/victoria-metrics:v1.154.1 Image override
--port auto (base 8428) Host web port; auto-allocated from victoriametrics_start_port
--listen 0.0.0.0 Bind address — defaults to every interface; use 127.0.0.1 for loopback-only (see the exposure warning above)
--retention-months 1 Data retention in months (-retentionPeriod); e.g. 3 = 3 months, 12 = 1 year
--extra-arg — Extra CLI flag passed to the binary (repeatable); appended last so last-wins overrides earlier flags. E.g. --extra-arg -search.maxUniqueTimeseries=1000000
--data-dir auto Data directory override (default under the base dir)
--force false Recreate even when running — to apply changed ports / listen / retention / extra-args (install also recreates on its own when config changes)

The data directory holds VictoriaMetrics’s TSDB. It survives pg addon remove (delete it with --clean-data), so reinstalling under the same name revives stored time series. The image runs as root (unlike Prometheus’s uid 65534), so no pre-chown of the data dir is needed.

Install

pg addon install victoriametrics

The command pulls the image if needed, creates the container, and prints the URL, retention, and any extra args:

✓ VictoriaMetrics installed: "vm"
  Container:  pgcli-victoriametrics-default-vm
  Image:      docker.io/victoriametrics/victoria-metrics:v1.154.1
  Data:       /home/you/.pgcli/addon/victoriametrics/vm/data
  Retention:  1 month(s)
  URL:        http://0.0.0.0:8428/

VictoriaMetrics is ready to ingest and query immediately. Point Grafana at http://<host>:8428/ as a Prometheus datasource (VictoriaMetrics is Prometheus-compatible) and you can query using PromQL or MetricsQL.

# custom retention and search limits
pg addon install victoriametrics --name vm1 \
  --retention-months 12 \
  --extra-arg -search.maxUniqueTimeseries=1000000

Re-running install on a running instance recreates it when the config actually changed (ports, listen, retention, extra-args), and leaves it alone when it didn’t; --force recreates the container even when config is unchanged.

VictoriaMetrics does not support hot config reload (SIGHUP), so all changes require container recreation. This is simpler than Prometheus (no config file to render, no reload signal), but means brief interruption when changing settings.

Custom flags (--extra-arg)

VictoriaMetrics accepts many CLI flags for tuning cache sizes, query limits, ingestion rates, and more. Pass them via --extra-arg (repeatable):

pg addon install victoriametrics --name vm1 \
  --extra-arg -search.maxUniqueTimeseries=1000000 \
  --extra-arg -selfScrapeInterval=10s

Extra args are appended last to the container’s command line, so they override earlier flags via last-wins semantics. This lets you tune VictoriaMetrics beyond pgcli’s first-class knobs without editing any config file.

Verify the flags took effect:

podman logs pgcli-victoriametrics-default-vm1 | grep -E '(maxUniqueTimeseries|selfScrapeInterval)'
# 2026-10-22T...  -search.maxUniqueTimeseries="1000000"
# 2026-10-22T...  -selfScrapeInterval="10s"

Listening and exposure

VictoriaMetrics’s Listen defaults to 0.0.0.0: the container shares the host’s network namespace, so the UI and API are reachable on every interface at the assigned port. This matches Prometheus’s default for the same practical reason (Grafana on another host needs to reach it) — but there is no password behind it. Anyone who can reach the port can run arbitrary MetricsQL and read your stored time series. For a loopback-only deployment pass --listen 127.0.0.1 (recreate with --force); pg addon list then shows http://127.0.0.1:<port>/. Otherwise, restrict access at the firewall.

Ports

Each VictoriaMetrics instance owns a single port: the web UI/API. It is allocated from a pool with base victoriametrics_start_port (default 8428 — VictoriaMetrics’s conventional HTTP port), incrementing for every additional instance and skipping ports already taken by any managed container or the used_ports list. The allocation is written into pg.yaml, so a reinstall never re-hands-out a port another addon is using. 8428 shares no number with Prometheus (9090), Grafana (3000), pgAdmin (5050), or nginx (8080); an explicit --port still wins.

pg addon install victoriametrics --name vm2          # second instance: next free port (8429 if 8428 taken)
pg addon install victoriametrics --name vm3 --port 8500  # explicit port still takes precedence

Configuration

addons:
  victoriametrics:
    vm1:
      name: vm1
      image_tag: docker.io/victoriametrics/victoria-metrics:v1.154.1
      host_port: 8428
      listen: 0.0.0.0
      retention: "1"
      extra_args:
        - -search.maxUniqueTimeseries=1000000
        - -selfScrapeInterval=10s
      autostart: false
      # data_dir: /srv/victoriametrics-data      # optional, overrides the default location

There is no config file — everything is passed as CLI flags to the victoria-metrics binary (-storageDataPath, -httpListenAddr, -retentionPeriod, plus any extra_args). retention is stored as a string (months), and extra_args is a list of CLI flags appended last.

List

pg addon list
Web add-ons (victoriametrics):
  victoriametrics (name: vm1)
    Status:      running
    URL:         http://0.0.0.0:8428/
    Retention:   1 month(s)
    Extra args:  -search.maxUniqueTimeseries=1000000 -selfScrapeInterval=10s
    Data:        /home/you/.pgcli/addon/victoriametrics/vm1/data
    Image:       docker.io/victoriametrics/victoria-metrics:v1.154.1
    Container:   pgcli-victoriametrics-default-vm1

There are no credentials to reveal — VictoriaMetrics has none — so --show-password shows nothing extra for it.

Start and stop

Containers run with podman’s unless-stopped restart policy, so they come back automatically with the podman service after a host reboot. start/stop manage them explicitly:

pg addon stop victoriametrics
pg addon start victoriametrics

Auto-start on Boot

To have a VictoriaMetrics instance started automatically on host boot, enable it:

pg autostart enable --victoriametrics --name vm1

This flags the instance in pg.yaml and installs/refreshes a boot service (a systemd --user unit on Linux, a LaunchAgent on macOS) that runs pg start --autostart. A boot-time start only brings the container up — the data dir was already created at install time, so it needs no host privileges beyond podman itself. VictoriaMetrics starts after Prometheus in the boot order. See Autostart for the full mechanism, status and disabling.

Remove

pg addon remove victoriametrics              # keeps the TSDB — stored time series survive a reinstall
pg addon remove victoriametrics --clean-data # deletes the TSDB too

Under rootless podman, --clean-data deletes the data dir through podman unshare rm — VictoriaMetrics writes as root (container uid 0), which maps to a subordinate uid the host user cannot rm directly.

Logs

pg logs addon victoriametrics            # show recent console output
pg logs addon victoriametrics -f         # follow
pg logs addon victoriametrics -n 200     # last 200 lines (also -i / --tail)

Troubleshooting

  • A query returns no data — confirm VictoriaMetrics is running (pg addon list shows running), the health endpoint responds (curl -s http://<host>:<port>/-/healthy prints VictoriaMetrics is Healthy.), and you’re querying the correct time range (use query_range with explicit start/end/step). Check pg logs addon victoriametrics for ingestion errors.
  • Install fails with “container already exists” — the container name is derived from --name and the namespace; use --force to recreate, or pg addon remove first to clean up a partial install.
  • Extra args didn’t take effect — --extra-arg is applied at container creation time, not runtime. Reinstall with --force to recreate the container with the new flags. Check podman logs <container> to confirm the flags appear in the startup log.
  • Port already allocated — the assigned port is held in pg.yaml and skipped for later instances; free it with pg addon remove first, or pick another with --port N.
  • Remote API unreachable / unexpectedly reachable — on the default 0.0.0.0 a failure to reach it is host firewall, not bind address; conversely, if you did not want it reachable, --listen 127.0.0.1 --force.

Known limitations

  • v1 is a bare storage backend: it ships no scrape capability (point a pgcli Prometheus instance at it with pg addon install prometheus --remote-write-url http://<host>:8428/api/v1/write, or use vmagent separately) and no alerting. It is the long-term storage layer you point Prometheus and Grafana at.
  • No authentication. VictoriaMetrics’s API runs arbitrary MetricsQL; the only protection for a 0.0.0.0 bind is the network boundary. This is the same posture as Prometheus — do not expose it on an untrusted network.
  • pgcli does not validate --extra-arg values (there is no pre-flight check at install). A bad flag surfaces only in the container logs on startup.
  • On macOS the container runs inside the podman machine; it has been validated on Linux only.

21 - BeeGFS

Run a BeeGFS parallel filesystem as a managed addon.

BeeGFS is a parallel filesystem that chose the easy route. It was born in 2004 at Fraunhofer ITWM in Germany — a research group that needed Lustre, found its deployment and operations too heavy, and wrote its own instead, with the goal set from day one: not the biggest scale, but the least human effort to deploy and run. In 2014 the core team spun out as the commercial company ThinkParQ, the product was renamed BeeGFS, and it grew from an institute-internal tool into the shared storage you find on many European universities and regional supercomputers.

It solves the “many machines, one high-throughput dataset” problem: a local filesystem lives on a single host, and NFS-style shares cap out quickly under concurrent large-file IO from many clients. Like Lustre, BeeGFS is a parallel filesystem — metadata separated from data, files striped across storage servers, clients reading data blocks directly once they know where they are — so aggregate bandwidth scales with the number of servers. But at every point where it could be complicated, it chose simple: service roles may share one machine, daemons self-register into the cluster when they start (no hand-synced configuration), growing means adding a box, and plain Ethernet works — InfiniBand is not mandatory. The trade: it does not chase extreme scale or the deepest tuning control; what it buys is that a research group or department cluster without a dedicated storage team can be up within a day or two.

Typical fit: HPC clusters from a few up to a couple hundred nodes, the data supply layer for AI training (GPUDirect Storage since 7.3 — storage-to-GPU direct paths, so large training/inference jobs read shared datasets directly), post-production editing media in film and video (many editors reading and writing large concurrent streams without fighting for bandwidth), and department-scale shared volumes of many large files. One-line selection rule: national-lab scale, thousands of nodes, a storage team on staff → Lustre; “usable today, no storage team” → BeeGFS.

Platform: Linux only. BeeGFS daemons run on host networking (BeeGFS speaks its own TCP/UDP protocol, not HTTP, so there is no container port-mapping to hide behind). macOS has no host networking under podman, so pg addon install beegfs is refused there with a clear error.

The client is out of scope, on purpose. Mounting a BeeGFS filesystem needs the beegfs-client kernel module (DKMS). Kernel modules cannot be containerised, so pgcli neither installs nor mounts it — it manages the server services only (three containers on a converged host, the configured subset on a cross-host member). pg addon beegfs mount-hint prints the exact host-side config a machine with the beegfs-client + beegfs-utils packages needs. See Mounting a client.

Parameters

Flag Default Description
--name beegfs Filesystem name (map key); containers are <prefix>-<role> for each role this host runs
--image 8.4.0 Version suffix — the manager builds ghcr.io/thinkparq/beegfs-<role>:<version> from it (all roles share one tag)
--data-dir <base>/addon/beegfs/<name> One dir for the whole filesystem; its services use <dir>/{mgmtd,meta,storage}
--listen 0.0.0.0 The address clients self-reference as sysMgmtdHost; with host networking the daemons actually bind every interface
--password generated (mgmtd hosts) The connection-auth secret (ConnAuth) shared by all daemons and every client; generated on first install only if this host runs mgmtd — a join host must pass the cluster’s existing value
--roles all three v2: which services THIS host runs — comma list of mgmtd,meta,storage; omitting it is the converged single-host filesystem
--mgmtd-host — v2: address of the mgmtd host this host’s meta/storage register against (required when --roles excludes mgmtd)
--node-id 1 v2: this host’s BeeGFS node ID (1..655); storage target IDs derive from it (2 → 201, 202, …). Must be unique per service type across hosts
--storage-target single dir v2: one host dir per storage target — repeat for multiple disks (one target each)
--license-file — Path to a ThinkParQ license .pem to carry into the mgmtd container (stored in pg.yaml, injected as BEEGFS_LICENSE_FILE_DATA). mgmtd host only — pgcli never generates a license; pg addon beegfs license shows/hot-swaps it later
--beegfs-mgmtd-port 8008 Move mgmtd’s BeeMsg port (the only movable meta/storage registration target); 0 = stock
--beegfs-mgmtd-grpc-port 8010 Move mgmtd’s gRPC port (what the beegfs CLI dials); 0 = stock
--force — Recreate this host’s containers even if they are already running

There is deliberately no --port for meta or storage: see Ports.

Install

pg addon install beegfs              # default filesystem named "beegfs"
pg addon install beegfs --name fs1
pg addon install beegfs --listen 10.0.0.5   # advertise a reachable mgmtd address

The install is fully non-interactive. It pulls the images for the roles this host runs up front (so a mid-cluster network failure never leaves a half-registered filesystem), then brings them up in dependency order: mgmtd first, then meta, then storage — a join host with --roles storage just runs its own step. meta/storage block until they log Registration and management info download complete, the line that proves both “mgmtd is reachable” and “this service joined”. Each container’s first boot runs a beegfs-setup-<service> step (driven by beegfs_setup_N env vars the image’s entrypoint consumes) that initialises its target directory; the marker is idempotent, so a recreated container against a surviving data dir reuses the existing target.

Re-running install is safe and cluster-granular (over this host’s roles):

  • all of them up → skip (use --force to recreate, or pg addon beegfs check);
  • all of them down and present → just start the stored cluster (no pull, no recreate);
  • anything else (partial, or a fresh install) → EnsureCluster recreates the set in order.

The install summary lists this host’s roles and their container names, the images, the mgmtd address and its two ports (marked remote on a join host), the node ID and data dirs, the conn-auth state, and a pointer to pg addon beegfs mount-hint. If --listen is the wildcard 0.0.0.0 it prints an exposure NOTE (a parallel filesystem with TLS off is reachable from any machine that holds the conn-auth secret).

Cross-host clusters (v2)

A BeeGFS filesystem scales by adding hosts, not by hand-syncing config: each service daemon starts with sysMgmtdHost=<mgmtd address> plus the shared conn-auth secret and self-registers into the cluster — mgmtd is the registry. pgcli mirrors that model exactly: there is no central deploy command and pgcli never SSHes anywhere. Every host runs its own pg addon install beegfs --roles <subset> with its own local pg.yaml, and BeeGFS does the rest — the same declarative, per-host pattern Patroni cross-host members use (where etcd, not pgcli, aggregates topology; here the role is mgmtd’s own SQLite registry).

Three hosts, one filesystem:

# vm01 — management + metadata on this host; conn-auth generated here:
pg addon install beegfs --name fs1 --roles mgmtd,meta --listen 192.0.2.10

# render the verbatim join commands (secret included) from vm01:
pg addon beegfs join-hint --name fs1

# vm02 — two data disks, one storage target each:
pg addon install beegfs --name fs1 --roles storage --mgmtd-host 192.0.2.10 \
    --node-id 2 --password <conn-auth> \
    --storage-target /mnt/d1 --storage-target /mnt/d2

# vm03 — another storage node (or --roles meta to move metadata off vm01):
pg addon install beegfs --name fs1 --roles storage --mgmtd-host 192.0.2.10 \
    --node-id 3 --password <conn-auth> --storage-target /mnt/d3

Clients mount from vm01’s address as usual — cross-host changes nothing about the kernel-module client.

Rules and boundaries, honestly stated:

  • --mgmtd-host is required whenever --roles excludes mgmtd (there is no localhost to fall back to), and the join must carry the cluster’s existing conn-auth — pgcli never generates a secret for a member of an existing cluster. A wrong secret fails the install in seconds with a pointer to pg addon password beegfs, not after a registration timeout.
  • --node-id must be unique per service type across hosts (node IDs are per-type namespaces: meta_1 and storage_1 coexist). It seeds the storage target IDs: node 2’s targets are 201, 202, … (target IDs derive as node_id*100 + ordinal, capped at node_id 655).
  • Each pg.yaml entry stores only what its own host runs; check, start/stop, list and autostart are all per-host views. The cluster’s full membership lives in mgmtd (beegfs ... node list).
  • mgmtd remains a single point: if it dies, existing client IO keeps flowing (clients talk to meta/storage directly) but registration and admin stop. A redundant management pair is an enterprise-license feature, not pgcli wiring. The license rides on the mgmtd host alone — join hosts neither store nor need a PEM (join-hint says so), since mgmtd verifies the certificate for the whole filesystem.
  • There is still one filesystem per host — cross-host is the scaling axis, not second-filesystems-per-host (the fixed 8005/8003 ports make those collide).

The data directories and persistence

A converged host owns three host directories, each bind-mounted into its own container at /data/<role>:

<base>/addon/beegfs/<name>/mgmtd     mgmtd.sqlite — the node/target registry
<base>/addon/beegfs/<name>/meta      the metadata target
<base>/addon/beegfs/<name>/storage   the storage target (the actual file data)

--data-dir <dir> lays all three out as <dir>/{mgmtd,meta,storage} in one flag — operators never address the roles separately. On a cross-host member only its own role’s dir is used. Multiple storage targets (the --storage-target repeat) each get their own host dir mounted at /data/storage/<targetID> inside the single storage container; a single target keeps the plain /data/storage path so a v1 store still revives unchanged (a target directory records its own path internally, so revival must mount the same path). The three images run as root and own their data dirs, so unlike Gitea (uid 1000) or Grafana (uid 472) there is no pre-chown dance — the host dirs are writable as-is.

All data survives container removal: pg addon remove beegfs without --clean-data keeps the dirs, and reinstalling the same name revives the filesystem (the install prints a NOTE when it detects an existing mgmtd.sqlite). Revival keeps whatever registry and connection auth the store already had — a new --password only reaches freshly-initialised daemons, not a surviving SQLite registry.

Failure handling: striping for performance, ZFS for reliability

BeeGFS’s cross-node striping is a performance mechanism, not a redundancy one: in the default RAID0 layout, losing ANY one storage target loses the chunks it held — and on a striped file that means the file is corrupt. Node-level data redundancy is buddy mirroring, an enterprise-license feature. So the community edition splits the two concerns, and the storage side needs a local-failure scheme underneath it:

  • Across nodes: striping for throughput. Each file’s chunks spread over many targets on many hosts; aggregate bandwidth scales with the number of servers. This is what --num-targets/--chunk-size tune. It buys speed, never safety.
  • Within each storage server: a resilient volume under every target. The recommended baseline is ZFS, because a BeeGFS storage target is “just a directory” and ZFS turns that directory into a self-healing store for free — checksums against silent corruption, copy-on-write, snapshots, compression. The daemon cannot tell the difference, so this layer needs zero pgcli or BeeGFS involvement: build the pool, make a dataset per target, and point --storage-target at it.
    # two disks → a mirror vdev (ZFS's RAID1; capacity = one disk, survives
    # either disk dying). raidz1/2 need 3+/4+ disks.
    zpool create bgtank mirror /dev/disk1 /dev/disk2
    zfs create -o recordsize=1M -o compression=lz4 bgtank/t1
    # ...then:  pg addon install beegfs --roles storage ... \
    #              --storage-target /bgtank/t1
    (mdadm RAID1/5/6 works too, but ZFS’s checksumming catches the silent bit rot a BeeGFS target would otherwise serve straight to clients.) One target per dataset keeps a disk fault entirely out of the BeeGFS target path.
  • Whole-node loss is still not survivable (community edition): a dead server takes its storage targets down with it — local ZFS/RAID survives a disk, not a burnt-out machine. Mitigations without a license: keep meta/mgmtd services duplicated across hosts (free — service redundancy, so the filesystem stays mounted and admin keeps working), snapshot the metadata, and treat storage data as rebuild-from-upstream where the workload allows (re-generable training datasets — the honest community trade-off). A temporary full-feature certificate (free, time-limited, one per system) or a paid enterprise license is the only way to get real cross-node mirroring.
  • Metadata deserves the same care: losing the meta target makes the whole tree unreadable regardless of data redundancy — keep its dir on a local mirror too (it is small). pgcli takes no BeeGFS backups, so protecting the mgmtd registry and meta target is host-level work: a ZFS snapshot of the volume holding the role dirs, or a quiesced file copy while the daemons are stopped.

Ports

The four BeeGFS listener ports are the stock protocol ports, not a pool:

mgmtd   8008  BeeMsg — meta/storage register here   (movable: --beemsg-port)
mgmtd   8010  gRPC   — the `beegfs` CLI dials here  (movable: --grpc-port)
meta    8005  metadata service                      (FIXED)
storage 8003  storage service                       (FIXED)

Verified on a live host: BeeGFS 8.4’s meta and storage daemons accept no listen-port override (connPortsList/connTcpPort are rejected as invalid, and connMetaPort is accepted but breaks registration). Only mgmtd’s two ports can move, and moving mgmtd’s BeeMsg port re-targets meta/storage registration automatically (the manager emits connMgmtdPort=<port> into both). The direct consequence: exactly one BeeGFS filesystem can exist per host — a second one could never bind 8005/8003 regardless of what pgcli allocated, so EnsureCluster guards it out with an explicit error, and the CLI rejects a hand-pinned non-default meta_port/storage_port in pg.yaml with the real reason. There is therefore no beegfs_start_port pool — unlike every other addon, BeeGFS ports are fixed, not allocated.

Connection auth and TLS

Every daemon in the filesystem and every client share one connection-authentication secret (ConnAuth, delivered as the CONN_AUTH_FILE_DATA env var that the image’s init writes to /etc/beegfs/conn.auth). It is generated on first install (20 random chars) only on a host that runs mgmtd, printed once, and stored in pg.yaml — retrieve it with pg addon password beegfs. A cross-host join host must be given that existing value via --password (see Cross-host clusters); pgcli never generates a secret for a member of an existing cluster. Like every pgcli secret it is never defaulted into the config by ApplyDefaults.

TLS is disabled on mgmtd (--tls-disable true, the explicit v1 decision). This means only clients that pass --tls-disable too can join, and it is a real exposure consideration: a wildcard --listen 0.0.0.0 with TLS off leaves ports 8008/8010/8005/8003 open to any machine on the network that holds the conn-auth secret. For anything not on a private network, either bind loopback (--listen 127.0.0.1) or firewall those four ports.

Licensing: as of BeeGFS 8 a license is expected on every deployment. pgcli never generates a license (same principle as Gitea’s crypto secrets) — but it carries one you obtained: the PEM content is stored in pg.yaml (so it survives and travels with your config backups) and injected into the mgmtd container as BEEGFS_LICENSE_FILE_DATA, which the official image’s init writes to /etc/beegfs/license.pem and mgmtd’s start.sh passes as --license-cert-file. Only the mgmtd host may carry it: its image is the only one shipping the license library, and its daemon verifies the certificate for the whole filesystem (the install refuses --license-file on a join host).

What a license costs, by tier (all three self-serve via ThinkParQ’s portal):

Tier Price What it does
community free Lifts the unlicensed limits (8.4’s five-client mount cap, quota warnings); has a capacity ceiling and does NOT unlock enterprise features
temporary free trial Unlocks everything for a limited period; since 8.4 one system can hold only one
enterprise paid Storage pools, quotas, mirroring (buddy groups), the HA management pair

Mirroring (buddy groups) is an ENTERPRISE feature — it needs a paid license. Without one, mgmtd refuses every mirroring request (beegfs mirror create → “no license loaded” — verified on a live cluster). The free community license does NOT unlock it; only a paid enterprise license (or a temporary full-feature trial certificate) does. Data redundancy in the community edition is limited to running multiple meta/mgmtd daemons — that is service redundancy, not mirrored storage targets.

Obtaining a PEM is out-of-band and takes a minute for a community license: beegfs license --get prints a system-bound URL → open it in a browser → download the .pem. Then hand it to pgcli — at install time (--license-file license.pem) or later with pg addon beegfs license --set (see License status and hot-swap).

The 8.4 realities of running unlicensed: mgmtd logs a quota warning, every beegfs command nags, client mounts are capped at five (a sixth mount is rejected), and enterprise features are refused outright (e.g. beegfs mirror create fails with “no license loaded”). Any valid license — even the free community one — lifts the warnings and the mount cap.

Mounting a client

The client is a host kernel module — pgcli does not install it. To mount a filesystem from a Debian/Ubuntu host, add ThinkParQ’s apt repository and install the client packages yourself. For 8.4 on Debian 12 (bookworm) — the exact commands, verified on a test host:

# 1. the BeeGFS signing key (fingerprint 0683 AF2B 9AC5 BC7D 59B2 D623 40CE 4E24 3CD5 0804)
wget https://www.beegfs.io/release/beegfs_8.4/gpg/GPG-KEY-beegfs -O /etc/apt/trusted.gpg.d/beegfs.asc
# 2. the repo file (bookworm = Debian 12; use beegfs-trixie.list for Debian 13,
#    beegfs-jammy/noble.list for Ubuntu, …)
wget https://www.beegfs.io/release/beegfs_8.4/dists/beegfs-bookworm.list -O /etc/apt/sources.list.d/beegfs.list
apt update
# 3. client + tools; the module is DKMS-built against the kernel headers
apt install beegfs-client beegfs-utils beegfs-tools linux-headers-$(uname -r)

On RHEL-family hosts the same repo lives under https://www.beegfs.io/release/beegfs_8.4/dists/ as an .repo file (rpm --import …/GPG-KEY-beegfs + wget …/beegfs-rhel9.repo -O /etc/yum.repos.d/beegfs.repo). Always take the URLs for your BeeGFS version and distribution from the ThinkParQ download page — pinning the server to 8.4 means clients should mount from the matching 8.4 repo.

beegfs-client depends on build-essential and recommends kernel headers — DKMS compiles the beegfs module against linux-headers-$(uname -r) at install time, so it needs the running kernel’s headers present and will rebuild on every kernel update.

Then write the config pg addon beegfs mount-hint prints — it renders the three files verbatim:

pg addon beegfs mount-hint --name fs1
1. /etc/beegfs/conn.auth (mode 0600) — the SAME secret as the servers
2. /etc/beegfs/beegfs-client.conf — set in the main section:
     sysMgmtdHost=<mgmtd-host>          # + connMgmtdPort=<port> only if mgmtd's BeeMsg port was moved
3. /etc/beegfs/beegfs-mounts.conf (one mount per line, fields:
   <mountpoint> <client-conf> <fstype>):
     /mnt/beegfs /etc/beegfs/beegfs-client.conf beegfs

conn.auth gotcha: the client’s connection-auth file must end in a newline. echo <secret> > /etc/beegfs/conn.auth works; printf <secret> > … (no trailing newline) is rejected with tried to authenticate stream with wrong secret — the trailing byte is part of what both sides compare.

Then mount and verify:

systemctl restart beegfs-client            # reads beegfs-mounts.conf and mounts
df -h /mnt/beegfs
echo hi > /mnt/beegfs/t && cat /mnt/beegfs/t   # end-to-end write/read

Because the cluster runs with TLS disabled, every beegfs CLI call needs the disabled-TLS form pointed at the gRPC port; node list shows all four node types (management, meta, storage, and this client once mounted):

beegfs --tls-disable --mgmtd-addr=<mgmtd-host>:8010 node list

Common client-side operations (all verified against 8.4 — the beegfs CLI is the 8.x rewrite; 7.x beegfs-*-ctl incantations do not apply):

B="beegfs --tls-disable --mgmtd-addr=<mgmtd-host>:8010"

$B node list                          # every node: mg / meta / storage / client
$B target list                        # storage targets, their node and state
$B entry info /mnt/beegfs/big.bin     # one file's stripe pattern and the
                                      # targets its chunks landed on
$B entry set /mnt/beegfs/data --num-targets 3 --chunk-size 4Mi
                                      # new files under data/ stripe across 3
                                      # targets, 4 MiB chunks (dirs set the
                                      # pattern for what is created after)
$B entry set /mnt/beegfs/data --num-targets 0   # back to the cluster default
$B health check                       # cluster-wide health report
$B stats server                       # live IO counters per server (8.x stats)

mount-hint is pure local rendering — it never touches podman, since the client is out of pgcli’s management. It renders the mgmtd address from the config entry: on a cross-host member that is the stored --mgmtd-host; when the local --listen is the wildcard, it prints <mgmtd-host-ip> as a placeholder (0.0.0.0 is not dial-able) rather than a value clients cannot connect to.

Health check

pg addon beegfs check             # default name
pg addon beegfs check --name fs1

Reports the aggregate state of this host’s roles (running / stopped / partial (mgmtd,meta)) and, per service, whether its container is up and whether it logged its readiness marker — mgmtd Waiting for shutdown signal (serving), meta/storage Registration and management info download complete (joined). None of the images ships beegfs-ctl/check-servers, so the daemons’ own logs are the authoritative in-container signal; the cluster-wide membership lives in mgmtd — for the whole picture use the beegfs gRPC CLI above (node list), and for a stopped cluster check still works (it reports state, it does not require running).

Retrieving the connection-auth secret

pg addon password beegfs             # the "beegfs" filesystem
pg addon password beegfs --name fs1

pg addon list shows only a presence marker (Auth: none / set (connection-auth)) and prints the secret itself only with --show-password, so it never leaks to a casual listing.

License status and hot-swap

pg addon beegfs license                     # what does mgmtd think of the cert?
pg addon beegfs license --name fs1 --set /path/license.pem   # load/replace, reloads mgmtd
pg addon beegfs license --name fs1 --clear                    # drop it again

Run on the mgmtd host (the license lives there — see Connection auth and TLS). Without flags it reports both sides: whether pg.yaml carries a PEM, and what mgmtd itself logged when loading it — Successfully loaded license certificate for a valid one, or the verification errors when mgmtd rejects a bad/expired certificate. pgcli only shape-checks the PEM (BEGIN/END block); the real verification is always mgmtd’s.

--set <pem> reads the file (shape-checked for a BEGIN/END PEM block — the cryptographic verification is mgmtd’s, not pgcli’s), stores the content in pg.yaml, and recreates the mgmtd container so the new env lands (podman env only exists from creation). meta/storage and every client re-register on their own — the swap is a few seconds and IO-safe. --clear removes the PEM and reloads unlicensed. --set and --clear are mutually exclusive; passing --license-file at install is the same load without the recreate (the container is being created anyway).

List

pg addon list

The BeeGFS block (“Infra add-ons (beegfs)”) prints one entry per filesystem with its aggregate state over this host’s roles, the role list, the mgmtd address and its two ports (marked remote on a join host), the fixed meta/storage ports, conn-auth presence, image, the data dirs of the roles this host runs (one line per storage target), and the container names. When podman is unavailable it still lists the configured entries (state shown as n/a).

Start and stop

Containers run with podman’s unless-stopped restart policy, so they come back with the podman service after a host reboot. start/stop manage this host’s roles explicitly, respecting dependency order:

pg addon stop beegfs     # storage → meta → mgmtd (reverse order, targets stay GOOD)
pg addon start beegfs    # mgmtd → meta → storage

A cross-host member runs only its own subset (a --roles storage host starts and stops just storage).

Auto-start on Boot

pg autostart enable --beegfs --name fs1

BeeGFS is the only cluster-granular autostart: pg start --autostart brings up the filesystem as this host runs it (mgmtd → meta → storage in order, or the configured subset), not one container. Because the images run as root and own their dirs, an autostart needs no host privileges beyond podman itself (no chown step like Gitea’s). The client on each mounting host re-attaches on its own via beegfs-mounts.conf — pgcli never manages that. See Autostart for the full mechanism, status, and disabling.

Remove

pg addon remove beegfs                # keeps the data dirs — reinstall revives the filesystem
pg addon remove beegfs --clean-data   # deletes them too (the data is gone)

Remove tears down this host’s roles in reverse order (storage → meta → mgmtd). --clean-data refuses to delete a directory that is still a mount point. A client mountpoint pointing at this host must be unmounted either way — pgcli cannot reach the client (it is not pgcli’s), so unmount it on the client host first.

Logs

A filesystem spans up to three containers, so pg logs addon beegfs takes --service to pick one (default mgmtd):

pg logs addon beegfs                       # mgmtd (default)
pg logs addon beegfs --service meta -f     # follow the metadata daemon
pg logs addon beegfs --service storage -n 200

--service is only valid for beegfs (a value like meta against another addon type is rejected).

Troubleshooting

  • install beegfs --name fs2 refuses with “a BeeGFS filesystem already exists on this host” — this is the one-filesystem-per-host rule, not a bug: meta (8005) and storage (8003) cannot move their listen ports in 8.4, so a second filesystem on the same host could never bind them. Grow by adding roles on ANOTHER host (pg addon beegfs join-hint renders the commands), or pg addon remove the first one.
  • meta/storage stuck “not registered” in check — mgmtd must be serving first; if mgmtd’s container died, both block on registration until beegfsSetupTimeout (60 s) fails the install. Check pg logs addon beegfs --service mgmtd for why mgmtd exited (port already in use on the host, or an un-writable data dir).
  • install refuses on the meta_port/storage_port config check — a non-default value was hand-edited into pg.yaml. The daemons cannot bind those, so remove the pinned values and let them fall back to 8005/8003.
  • Client cannot mount / beegfs CLI says TLS error — the cluster runs with mgmtd TLS disabled; every client and every beegfs CLI call needs --tls-disable too, and /etc/beegfs/conn.auth must be the exact ConnAuth from pg addon password beegfs.
  • A join host fails fast with “wrong secret” — the --password passed to its install is not the cluster’s connection-auth value (BeeGFS logs tried to authenticate stream with wrong secret). The install aborts in seconds rather than timing out; re-run with the value from pg addon password beegfs on the mgmtd host.
  • pg addon beegfs license prints a verification error from mgmtd — the stored PEM is not valid for this system (certificates are system-bound — request one with beegfs license --get on the mgmtd host) or has expired. The container still runs and community functionality is unaffected; mgmtd simply behaves as unlicensed. --clear (or --set with the right PEM) fixes the config side.
  • Clone/mount to localhost fails from another machine — a wildcard --listen 0.0.0.0 renders sysMgmtdHost as a placeholder in mount-hint; install with --listen <reachable-ip> (with --force) so clients get a real mgmtd address.

Known limitations

  • Linux only. Host networking is mandatory and podman provides it on Linux only; installation is refused on macOS. No bridge fallback exists because BeeGFS is not HTTP.
  • One filesystem per host, fixed ports. pgcli pins the stock ports (8008/8010/8005/8003); meta and storage have no movable listen port in 8.4, so a single host holds a single filesystem. Scaling out is cross-host (--roles), not a second filesystem.
  • The client is never installed or mounted by pgcli. It is a kernel module (DKMS) that cannot be containerised; pgcli manages only the server containers and documents the mount via mount-hint.
  • TLS off; licenses are carried, not issued. mgmtd runs --tls-disable true; the beegfs gRPC CLI and clients must match. pgcli never generates a license and never handles renewal — it carries a ThinkParQ PEM you obtained out of band (beegfs license --get prints the system-bound URL) to the mgmtd container, and pg addon beegfs license shows/hot-swaps it. Mirroring, pools, and quota stay enterprise-license features you still have to buy; an unlicensed 8.4 caps client mounts at five.
  • Cross-host deployment is per-host and manual by design (v2). Each host runs its own pg addon install beegfs --roles ...; pgcli never SSHes and has no “deploy the whole cluster from one box” command. Growing means running one command on the new host (the conn-auth secret is carried by hand — see join-hint), and every host’s pg.yaml describes only its own slice.
  • mgmtd is a single point. The management daemon is the cluster’s registry; if it stops, new registrations and admin operations stop (existing mounted clients keep doing IO against meta/storage). A redundant management pair is a BeeGFS enterprise-license feature and is outside pgcli’s v1/v2 wiring.

22 - VMCluster

Run VictoriaMetrics cluster edition — three components (vminsert + vmselect + vmstorage) as managed containers with cross-host support and horizontal scaling.

pg addon install vmcluster runs VictoriaMetrics cluster edition — three components each in its own container from the official docker.io/victoriametrics/{vminsert,vmselect,vmstorage}:v1.154.1-cluster images. Unlike the single-node victoriametrics addon (one container, one port), this manages up to three containers with three separate images and five ports, supporting cross-host deployment and horizontal scaling.

Architecture:

Component Role HTTP Port Internal TCP
vminsert Ingestion — shards writes across all vmstorage nodes by metric hash 8480 Dials vmstorage:InternalInsertPort
vmselect Queries — merges results from all vmstorage nodes 8481 Dials vmstorage:InternalSelectPort
vmstorage Data storage (sharded, replicable) 8482 Listens on InternalInsertPort + InternalSelectPort

There is NO web login/password. Like the single-node VictoriaMetrics, the cluster edition ships no authentication at all. Its HTTP API runs arbitrary MetricsQL (a superset of PromQL), so remote-exposed instances are guarded only by the network boundary — your firewall, or --listen 127.0.0.1 for loopback. Treat it like an unauthenticated read/write console.

Platform: Linux only. VMCluster requires host networking for the internal TCP ports between components. On macOS, installation is refused with a clear error.

Deployment Models

Model 1 — Converged single-host (default)

All three components on one host, analogous to BeeGFS v1:

pg addon install vmcluster --name vmc
# 1 host, 3 containers (vminsert + vmselect + vmstorage)
# --storage-node auto-derived as 127.0.0.1:<internalPorts>

Model 2 — Cross-host distribution

# Host A — storage node 1
pg addon install vmcluster --name vmc --roles storage --listen 10.0.0.1

# Host B — storage node 2
pg addon install vmcluster --name vmc --roles storage --listen 10.0.0.2

# Host C — ingestion + query layer
pg addon install vmcluster --name vmc --roles insert,select \
  --storage-node 10.0.0.1:8483:8484 \
  --storage-node 10.0.0.2:8483:8484

Model 3 — Horizontal scaling with replication

# replicationFactor=2 → each write goes to 2 vmstorage nodes
pg addon install vmcluster --name vmc --roles insert,select \
  --replication-factor 2 \
  --storage-node 10.0.0.1:8483:8484 \
  --storage-node 10.0.0.2:8483:8484

Parameters

Flag Default Description
--name vmc Instance name (map key)
--roles insert,select,storage Comma-separated roles this host runs (subset for cross-host)
--storage-node auto-derived vmstorage address (repeatable; format host:insertPort:selectPort). Lists ALL vmstorage nodes for sharding/replication. Omit for converged single-host
--insert-port auto (base 8480) vminsert HTTP port
--select-port auto (base 8481) vmselect HTTP port
--storage-port auto (base 8482) vmstorage HTTP port
--internal-insert-port auto (base 8483) vmstorage TCP port for vminsert protocol
--internal-select-port auto (base 8484) vmstorage TCP port for vmselect protocol
--listen 0.0.0.0 Bind address — defaults to every interface; use 127.0.0.1 for loopback-only
--retention-months 1 Data retention in months (only for vmstorage role)
--replication-factor 1 How many vmstorage nodes each write goes to (vminsert flag)
--insert-image docker.io/victoriametrics/vminsert:v1.154.1-cluster vminsert image override
--select-image docker.io/victoriametrics/vmselect:v1.154.1-cluster vmselect image override
--storage-image docker.io/victoriametrics/vmstorage:v1.154.1-cluster vmstorage image override
--insert-extra-arg — Extra CLI flag for vminsert (repeatable)
--select-extra-arg — Extra CLI flag for vmselect (repeatable)
--storage-extra-arg — Extra CLI flag for vmstorage (repeatable)
--data-dir auto vmstorage data directory override
--force false Recreate even when running

Install

pg addon install vmcluster --name vmc

The command pulls the three images if needed, creates the containers in dependency order (storage → insert → select), and prints the summary:

✓ VMCluster installed: "vmc"
  Roles:       storage, insert, select (converged on this host)
  Containers:  pgcli-vmcluster-default-vmc-storage, pgcli-vmcluster-default-vmc-insert, pgcli-vmcluster-default-vmc-select
  Images:      docker.io/victoriametrics/vmstorage:v1.154.1-cluster, docker.io/victoriametrics/vminsert:v1.154.1-cluster, docker.io/victoriametrics/vmselect:v1.154.1-cluster
  Data:        /home/you/.pgcli/addon/vmcluster/vmc/data
  Retention:   1 month(s)
  Insert URL:  http://0.0.0.0:8480/ (vminsert — ingestion)
  Select URL:  http://0.0.0.0:8481/ (vmselect — queries)
  Storage URL: http://0.0.0.0:8482/ (vmstorage — admin/metrics)
  Internal:    TCP 8483 (vminsert), 8484 (vmselect)

VMCluster is ready to ingest and query immediately.

Cluster URL Format

Important: The cluster edition uses different URL paths than the single-node VictoriaMetrics. All API endpoints require an <accountID> in the path (use 0 for the default account):

Ingestion via vminsert:

# Prometheus remote_write
curl -X POST -d 'test_metric{job="pgcli"} 42' \
  http://127.0.0.1:8480/insert/0/prometheus/api/v1/import/prometheus

# InfluxDB line protocol
curl -X POST -d 'cpu,host=vm01 value=42' \
  http://127.0.0.1:8480/insert/0/influx/write

# Graphite plaintext
echo "test.metric 42 $(date +%s)" | nc 127.0.0.1 8480

Query via vmselect:

# Prometheus query API
curl 'http://127.0.0.1:8481/select/0/prometheus/api/v1/query?query=test_metric'

# Range query
curl 'http://127.0.0.1:8481/select/0/prometheus/api/v1/query_range?query=test_metric&start=2024-01-01T00:00:00Z&end=2024-01-02T00:00:00Z&step=1h'

# Export
curl 'http://127.0.0.1:8481/select/0/prometheus/api/v1/export?match[]={__name__!=""}'

Grafana datasource: Point at vmselect with URL http://<host>:8481/select/0/prometheus/

Prometheus remote_write: Configure remote_write to http://<host>:8480/insert/0/prometheus/api/v1/write

Ports

Each VMCluster instance owns 5 consecutive ports from the vmcluster_start_port pool (default 8480):

  • +0 InsertPort (vminsert HTTP — ingestion endpoint)
  • +1 SelectPort (vmselect HTTP — query endpoint)
  • +2 StoragePort (vmstorage HTTP — admin/metrics endpoint)
  • +3 InternalInsertPort (vmstorage TCP — vminsert dials this)
  • +4 InternalSelectPort (vmstorage TCP — vmselect dials this)

The consecutive allocation matters because --storage-node references the internal TCP ports explicitly, so the block must stay together. 8480 shares no number with VictoriaMetrics (8428), Prometheus (9090), Grafana (3000), or the rest.

Configuration

addons:
  vmcluster:
    vmc:
      name: vmc
      container_prefix: pgcli-vmcluster-default-vmc
      insert_image_tag: docker.io/victoriametrics/vminsert:v1.154.1-cluster
      select_image_tag: docker.io/victoriametrics/vmselect:v1.154.1-cluster
      storage_image_tag: docker.io/victoriametrics/vmstorage:v1.154.1-cluster
      listen: 0.0.0.0
      insert_port: 8480
      select_port: 8481
      storage_port: 8482
      internal_insert_port: 8483
      internal_select_port: 8484
      roles:
        - storage
        - insert
        - select
      storage_nodes:
        - address: "10.0.0.1:8483"
          select_port: 8484
        - address: "10.0.0.2:8483"
          select_port: 8484
      replication_factor: 1
      retention: "1"
      autostart: false

There is no config file — everything is passed as CLI flags to the three binaries. storage_nodes is the cross-host topology; empty means auto-derived single-node.

Adding storage nodes

VictoriaMetrics cluster has no dynamic discovery — the -storageNode list is baked into the vminsert/vmselect containers at startup. Adding a vmstorage node requires a brief maintenance window to recreate the access-layer containers (not a hot reload). Existing vmstorage data is unaffected.

Maintenance impact: rebuilding vminsert/vmselect causes a few-second write interruption. Plan this during a low-traffic window if write continuity is critical. Historical data in vmstorage remains available throughout — only ingestion is briefly interrupted.

Steps

  1. Create the new vmstorage on the target host:
# Host C — new storage node
pg addon install vmcluster --name vmc --roles storage --listen 10.0.0.3
  1. Recreate vminsert + vmselect on the access-layer host, appending the new --storage-node:
pg addon install vmcluster --name vmc --roles insert,select --force \
  --storage-node 10.0.0.1:8483:8484 \
  --storage-node 10.0.0.2:8483:8484 \
  --storage-node 10.0.0.3:8483:8484

--force drops and recreates the vminsert/vmselect containers. There is a few-second write interruption; existing vmstorage data is untouched (only the access-layer containers are replaced).

Data distribution after adding a node

  • Old data stays on the original vmstorage nodes (no automatic rebalance).
  • New writes are re-sharded across all nodes (old + new) by metric hash.
  • vmselect merges from all nodes, so queries see both old and new data seamlessly.

VictoriaMetrics cluster does not migrate existing data to a newly added node. For most monitoring workloads this is acceptable — time series are continuously written, and after a few hours the new node holds enough data for queries to be balanced. If even distribution is required, export and re-import the old data (/api/v1/export → /api/v1/import).

Removing storage nodes

Reverse the process: recreate vminsert/vmselect without the departing node’s --storage-node, then pg addon remove vmcluster on the departing host. Data on the removed vmstorage becomes inaccessible to queries — export it first if it needs to be preserved.

Start and stop

pg addon stop vmcluster
pg addon start vmcluster

Containers run with podman’s unless-stopped restart policy, so they come back automatically after a host reboot.

Autostart on boot

pg autostart enable --vmcluster --name vmc

Boot is cluster-granular: each host starts only the roles it runs, in dependency order (storage → insert → select), bringing up existing containers and recreating only what is missing — it never recreates running services. Run the command on every host in a cross-host deployment. See Autostart for the full mechanism.

Remove

pg addon remove vmcluster              # keeps vmstorage data — reinstall revives time series
pg addon remove vmcluster --clean-data # deletes vmstorage data too

Only vmstorage has persistent data; vminsert and vmselect are stateless and leave nothing behind.

Logs

pg logs addon vmcluster                # vmstorage logs (default service)
pg logs addon vmcluster --service insert   # vminsert logs
pg logs addon vmcluster --service select   # vmselect logs

Known limitations

  • No authentication. The cluster edition’s API runs arbitrary MetricsQL; the only protection for a 0.0.0.0 bind is the network boundary.
  • Linux only. Host networking is required for the internal TCP ports between components.
  • No automatic load balancing. For multiple vminsert/vmselect instances, put HAProxy or nginx in front manually.
  • No TLS. Use the nginx addon for TLS termination if needed.
  • pgcli does not validate --extra-arg values. A bad flag surfaces only in the container logs on startup.

23 - JuiceFS

Mount an S3-backed POSIX filesystem as a managed addon (host binary).

JuiceFS puts a real POSIX filesystem on top of object storage: file data is split into chunks and stored in an S3 bucket, while a separate metadata engine (SQLite, Redis, PostgreSQL…) keeps the namespace, file attributes and chunk maps. You get an ordinary directory you can ls, cat and grep — every write eventually lands as immutable objects in the bucket. It solves the “I want a filesystem, but the bytes should live in S3” problem: snapshots are cheap (objects are immutable), capacity is the bucket’s, and the same bucket can be re-mounted from any host that knows the metadata URL.

As a pgcli addon, JuiceFS is pgcli’s first host-binary addon: there is no container. pg addon install juicefs downloads the official binary from GitHub releases (sha256-verified; a juicefs already on PATH is reused), formats the volume against an external S3 service and mounts it on the host.

Platform: Linux only (macOS refuses with a clear error, like BeeGFS). The mount is a plain host directory — visible to host processes only. It does NOT propagate into running PG instance containers (no rshared mount propagation in v1; the addon manages this host’s mount, not a cluster’s).

Everything is explicit

Both sides of the volume are named on the command line — pgcli never auto-detects or inherits from same-host addons:

  • Object store: an EXTERNAL S3 service (cloud, or a MinIO on another machine) given as --s3-endpoint http(s)://host[:port] plus --access-key/--secret-key. pgcli probes the endpoint before formatting, so an unreachable host fails fast with “not answering” instead of hanging inside juicefs format. The endpoint is baked into the volume metadata at format time — later mounts need only the metadata URL.
  • Metadata engine: an explicit URL — --dsn (alias --meta-dsn) accepting postgres://, redis:// or sqlite3://. pgcli never creates or drops the database; for PostgreSQL it must already exist.
  • Bucket: never created by pgcli. Provision it yourself (once) with the pg mc wrapper — the install prints the exact two lines:
pg mc alias set externals3 http://minio.example.com:9000 AK '***'
pg mc mb externals3/juicefs-data
pg addon install juicefs --name data \
    --s3-endpoint http://minio.example.com:9000 \
    --access-key AK --secret-key SK \
    --bucket juicefs-data \
    --dsn "sqlite3:///var/lib/juicefs/data.db"

Any engine works the same way — pick the URL:

# PostgreSQL: the database must already exist (pgcli never creates or drops
# it); juicefs builds its own jfs_* tables inside.
--dsn "postgres://jfs:pass@meta-host:5432/jfs?sslmode=disable"

# Redis (+TLS): the /N suffix selects the logical database.
--dsn "redis://:pass@redis-host:6379/0"
--dsn "rediss://user:pass@redis-host:6380/1"

The mount point is yours to choose — by default it lives under pgcli’s addon dir; point it anywhere with --mount-point. Create the directory yourself (mkdir -p) at a path the user running pg has read-write access to:

mkdir -p /mnt/cloudfs
pg addon install juicefs --name data \
    --s3-endpoint https://s3.amazonaws.com \
    --access-key AK --secret-key SK \
    --dsn "postgres://jfs:pass@meta-host:5432/jfs?sslmode=disable" \
    --bucket juicefs-data --mount-point /mnt/cloudfs

The three engines can all be pgcli’s own services — created with pgcli, then wired in explicitly as ordinary external URLs (the install never looks them up by itself; it could equally well point at a managed DB or a cloud bucket):

# PostgreSQL metadata: create the instance, then the database (pgcli's
# install path never creates or drops it). `pg status` prints the admin
# connection URL — swap its /postgres path for the new database.
pg create meta-pg
pg exec meta-pg -c "CREATE DATABASE jfs"
pg status meta-pg

pg addon install juicefs --name data \
    --s3-endpoint http://minio-host:9000 --access-key AK --secret-key SK \
    --bucket juicefs-data \
    --dsn "postgres://admin:PASS@127.0.0.1:35432/jfs?sslmode=disable"
# Redis metadata (a pgcli redis addon; `pg addon password redis` returns the
# generated password bare — paste it in, and /N picks the logical database):
pg addon install redis --name mred
pg addon password redis --name mred
pg addon install juicefs --name r1 \
    --s3-endpoint http://minio-host:9000 --access-key AK --secret-key SK \
    --bucket juicefs-r1 --dsn "redis://:PASS@127.0.0.1:6379/1"
# MinIO as the object store (a pgcli minio addon — or silo/rustfs/garage/
# seaweedfs; create the bucket by hand, pgcli never does; the root user is
# admin unless --root-user said otherwise, and `pg addon password minio`
# returns the secret key bare):
pg addon install minio --name ms3
pg mc mb ms3/juicefs-data
pg addon install juicefs --name m1 \
    --s3-endpoint http://127.0.0.1:9000 --bucket juicefs-data \
    --access-key admin --secret-key "$(pg addon password minio --name ms3)" \
    --dsn "sqlite3:///var/lib/juicefs/m1.db"

These examples run pg on the same machine as the store, so loopback (default 127.0.0.1) is enough. When the JuiceFS client lives on another host, publish the store on the network and point --s3-endpoint at its address — the endpoint is baked into the volume at format time, so publish it from the start:

pg addon install minio --name ms3 --listen 0.0.0.0   # --force if already installed
# from the other host:
pg addon install juicefs --name m1 --s3-endpoint http://10.0.0.5:9000 …

(The same note applies to the redis example: redis already binds 0.0.0.0 by default — its password is the gate.)

The same volume can then be mounted from any host that has the metadata URL — the credentials and endpoint already live inside it.

Parameters

Flag Default Description
--name juicefs Volume name (config map key; also the JuiceFS volume name at format time)
--dsn / --meta-dsn — REQUIRED. Metadata-engine URL: postgres://, redis:// or sqlite3://
--s3-endpoint — REQUIRED. External S3 service as http(s)://host[:port] (no bucket path, no embedded credentials)
--access-key / --secret-key — REQUIRED together. S3 credentials for the external service
--bucket juicefs-<name> Bucket name — pgcli does NOT create it (see above)
--mount-point <base>/addon/juicefs/<name>/mnt Host directory to mount — pgcli never creates it: mkdir -p it beforehand, writable for the user running pg
--cache-dir <base>/addon/juicefs/<name>/cache Local data cache dir
--install-dir /usr/local/bin Where the host binary goes (falls back to ~/.local/bin when not writable — keep it on PATH)
--version pinned (1.4.1) Release to download (its sha256 is pinned in pgcli; pass a version whose digest pgcli knows)
--no-mount off Format and configure, leave it unmounted
--force off Rebuild the config entry from the flags (format is still skipped when the volume already exists in the metadata engine)

FUSE itself (/dev/fuse + fusermount3) is probed, never installed — a missing fuse3 package fails the install with the apt line to run.

Daily operations

pg addon juicefs status --name data      # endpoint, bucket, meta URL, binary, mount state
pg addon juicefs umount --name data
pg addon juicefs mount --name data       # juicefs mount -d self-daemonizes
pg addon juicefs mount --name data --mount-point /mnt/cloudfs
                       # mount at a custom path (mkdir -p it first); while
                       # unmounted this also PERMANENTLY relocates the volume
pg addon start juicefs --name data       # top-level aliases of mount/umount
pg addon stop  juicefs --name data
pg logs addon juicefs --name data -f     # tail the mount log
pg addon password juicefs --name data    # the stored S3 secret key
pg addon remove juicefs --name data      # unmount + forget; bucket, metadata, binary stay
pg addon remove juicefs --name data --clean-data   # also deletes the addon host dir

remove never deletes S3 data or the metadata store — losing the --dsn target means losing the filesystem. The mount owner is the user running pg.

Moving to a different mount point

The mount point is recorded on the config entry, and mount accepts a --mount-point override that relocates the volume — the new path is persisted to pg.yaml, so later plain mounts (and autostart) use it. The old mount must be down first, and the new directory must exist and be writable (same contract as install):

pg addon juicefs umount --name data
mkdir -p /srv/cloudfs
pg addon juicefs mount --name data --mount-point /srv/cloudfs
#   [i] mount point moved to /srv/cloudfs (saved)
# ✓ juicefs "data" mounted at /srv/cloudfs

Attempting the move while still mounted refuses with an “umount first” hint; pointing it at a missing directory fails with the mkdir -p remedy. The mount point is fully decoupled from pgcli’s bookkeeping (pid/log/cache stay under <base>/addon/juicefs/<name>/), so relocation never disturbs the volume itself — it is the same bucket and metadata re-attached elsewhere.

Autostart

pg autostart enable --juicefs --name data

JuiceFS is a host-binary addon, so pg start --autostart re-mounts the volume at boot instead of starting a container. The backend is external — boot succeeds only when the S3 endpoint is reachable again. It never re-formats. The mount comes up as the user the boot service runs as.

24 - VictoriaLogs

Run VictoriaLogs, the log database of the VictoriaMetrics family, as a managed container.

pg addon install victorialogs runs VictoriaLogs — a fast, cost-effective log database from the VictoriaMetrics family — as a managed container from the official docker.io/victoriametrics/victoria-logs image. Like VictoriaMetrics and Prometheus it is a top-level addon: it fronts no single PostgreSQL instance (it ingests logs from many sources), so it is not attached to any one of them. VictoriaMetrics keeps metrics, VictoriaLogs keeps logs, Grafana visualises both — and all three share the same lifecycle shape (single container, host networking on Linux, one web port from its own pool, persistent data dir, restart policy).

VictoriaLogs is the exact mirror of the VictoriaMetrics addon in how it is configured: it needs no config file at all — everything is passed as CLI flags after the image name (-storageDataPath / -httpListenAddr / -retentionPeriod / custom flags via --extra-arg). So pgcli passes these flags directly when creating the container; there is no config to render, no SIGHUP reload, no chown needed (the image runs as root). One container serves everything on a single HTTP port: ingestion (JSON Lines, Elasticsearch-compatible bulk, syslog, OTLP), LogsQL queries, and the built-in UI.

There is NO web login/password. VictoriaLogs ships no authentication at all. Its HTTP API can ingest and query arbitrary logs and be loaded by expensive LogsQL queries, so a remote-exposed instance is guarded only by the network boundary — your firewall, or --listen 127.0.0.1 for loopback. Treat exposing it like exposing an unauthenticated read/write console, not like a password-protected dashboard.

Platform: Linux is the tested platform. The design supports macOS (the image is multi-arch; the container runs under the podman machine VM on the pgcli-net bridge with the port published), but it has not been validated there yet.

Parameters

Flag Default Description
--name vl Instance name (map key)
--image docker.io/victoriametrics/victoria-logs:v1.53.0 Image override
--port auto (base 9428) Host web port; auto-allocated from victorialogs_start_port
--listen 0.0.0.0 Bind address — defaults to every interface; use 127.0.0.1 for loopback-only (see the exposure warning above)
--retention binary default Data retention as a duration (30d, 3months, 1y, …), passed verbatim as -retentionPeriod. Omitting it keeps the victoria-logs default
--extra-arg — Extra CLI flag passed to the binary (repeatable); appended last so last-wins overrides earlier flags. E.g. --extra-arg -search.maxQueryDuration=60s
--data-dir auto Data directory override (default under the base dir)
--force false Recreate even when running — to apply changed ports / listen / retention / extra-args

The data directory holds VictoriaLogs’s log storage. It survives pg addon remove (delete it with --clean-data), so reinstalling under the same name revives stored logs. The image runs as root (unlike Prometheus’s uid 65534), so no pre-chown of the data dir is needed.

Install

pg addon install victorialogs

The command pulls the image if needed, creates the container, and prints the URL and retention:

✓ VictoriaLogs installed: "vl"
  Container:  pgcli-victorialogs-default-vl
  Image:      docker.io/victoriametrics/victoria-logs:v1.53.0
  Data:       /home/you/.pgcli/addon/victorialogs/vl/data
  Retention:  binary default (--retention to change)
  URL:        http://0.0.0.0:9428/

VictoriaLogs is ready to ingest and query immediately. Open http://<host>:9428/select/vmui/ for the built-in web UI (the root path / is just an index of useful endpoints), or query via the HTTP API:

# ingest a JSON Lines log entry (the JSON content type is REQUIRED —
# without it VictoriaLogs answers 200 but silently drops the payload)
echo '{"_msg":"hello from pgcli","app":"demo"}' | \
  curl -s -X POST -H 'Content-Type: application/json' \
    http://127.0.0.1:9428/insert/jsonline --data-binary @-

# query with LogsQL
curl -s http://127.0.0.1:9428/select/logsql/query \
  --data-urlencode 'query=app:demo' --data-urlencode 'limit=10'

Re-running install on a running instance recreates it when the config actually changed (ports, listen, retention, extra-args), and leaves it alone when it didn’t; --force recreates the container even when config is unchanged.

VictoriaLogs does not support hot config reload, so all changes require container recreation — same as VictoriaMetrics. This is simpler than Prometheus (no config file to render, no reload signal), but means brief interruption when changing settings.

Web UI

Every VictoriaLogs instance ships with a built-in web UI (VMUI) — there is no extra component to install. Open:

http://<host>:<port>/select/vmui/

The root path (/) is only an index of useful HTTP endpoints; the UI lives under /select/vmui/.

The UI is a LogsQL console for logs:

  • Query — type a LogsQL query (e.g. app:demo, level:error, error app:demo-api) and pick the time range; results update as you run the query.
  • Views — switch between Group (rows grouped by stream fields), Table (click a row to expand every field), JSON (raw /select/logsql/query response), and Live (live tail of matching logs as they arrive).
  • Exploration — field and stream pickers list the stored field names/values (backed by /select/logsql/field_names, field_values, facets, …), so you can build queries without knowing the schema up front.

For example, ingest one line and search for it in the UI (app:demo):

curl -s -X POST -H 'Content-Type: application/json' \
  -d '{"_msg":"hello from pgcli","app":"demo"}' \
  http://127.0.0.1:9428/insert/jsonline

The UI shares the same port and the same no-authentication posture as the HTTP API: anyone who can reach the port can search and also ingest logs. Restrict it with --listen 127.0.0.1 or a firewall, as described above.

Common queries

Queries use LogsQL. The examples below run against the HTTP query API; the same strings work in the VMUI at /select/vmui/.

curl -s http://127.0.0.1:9428/select/logsql/query \
  --data-urlencode 'query=_time:15m level:error' \
  --data-urlencode 'limit=20'

The response is newline-delimited JSON, one object per log entry.

Always include a _time: filter when querying production data. Without one, VictoriaLogs scans every log in the retention period.

Goal Query
All logs from the last 5 minutes _time:5m
Full-text search _time:15m error
Match specific fields _time:1h app:demo level:error
Exact value (case-sensitive) _time:1h level:=error
Regex match (RE2) _time:1h path:~"/api/v[0-9]+/"
Phrase / prefix match _time:1h _msg:"payment timeout" / _time:1h _msg:timeout*
Numeric comparison _time:1h request_duration:>1s
AND / OR / NOT _time:5m level:error -app:buggy / _time:5m (level:error OR level:warn)
Stream filter _time:1h {app="demo"}
Search every field _time:5m | *:timeout
Newest first, top 10 _time:5m error | sort by (_time) desc | limit 10
Keep only some fields _time:5m error | fields _time, level, _msg
Count by level _time:1h | stats by (level) count()
Total count _time:1h error | stats count() errors
Unique values with hit counts _time:1h | uniq by (user) with hits
Top N values _time:1d level:error | top 10 (path)

Notes:

  • field:word matches the word within that field; field:=value is an exact match and field:~"regex" is a regex match. Negated forms are -filter, != and !~.
  • Time filters accept durations (5m, 1h, 30d), absolute timestamps (2026-10-23Z, 2026-10-23T10:00:00Z) and ranges (_time:[2026-10-01Z, 2026-10-23Z]).
  • Pipes run left to right, so filters must come before sort, limit, stats, top and the other processing stages.

Ingestion: vlagent, HTTP APIs, collectors

pgcli runs the VictoriaLogs backend only — how logs reach it is up to you. There are three routes.

vlagent (official agent)

vlagent is the official log agent for VictoriaLogs — the log counterpart of vmagent (vmagent ships metrics only; do not use it for logs). It accepts the same HTTP ingestion protocols as VictoriaLogs on its own port (9429 by default), can tail log files from disk, and forwards everything to VictoriaLogs via -remoteWrite.url, which must end with /insert/native. pgcli runs and manages it for you — see the vlagent addon page for the full reference:

# Relay-only: accept HTTP pushes on :9429 and forward them to VictoriaLogs.
pg addon install vlagent \
  --remote-write-url http://127.0.0.1:9428/insert/native

# Track host files: /var/log/nginx is mounted read-only into the container at
# the same path; --include/--exclude use vlagent's native glob syntax (NOT regex).
pg addon install vlagent \
  --log-path /var/log/nginx \
  --include '/var/log/nginx/**/*.log' \
  --exclude '/var/log/nginx/*.gz' \
  --remote-write-url http://127.0.0.1:9428/insert/native

The first form tracks no log files: without --log-path/--include (or -kubernetesCollector via --extra-arg), vlagent only receives logs pushed to it over HTTP and forwards them. --log-path accepts any host file or directory; with no --include, a directory defaults to <dir>/**/*.log and a file to itself. The globs are matched inside the container, which is why pgcli mounts each host path at the identical absolute path.

Use vlagent when you need:

  • Replication / HA — repeat --remote-write-url for every VictoriaLogs instance. vlagent copies each log to all of them and keeps an independent on-disk buffer per URL (-remoteWrite.tmpDataPath, capped by -remoteWrite.maxDiskUsagePerURL); logs collected while a backend is down are replayed when it returns.
  • Kubernetes Pod logs — pass --extra-arg -kubernetesCollector and mount the host’s /var/log (plus /var/lib with the Docker runtime so runtime symlinks resolve) via --log-path. It follows /var/log/pods and /var/log/containers, adds container metadata, and checkpoints its read position in the data dir under -tmpDataPath.
  • Files on disk — --log-path /var/log/nginx --include '/var/log/nginx/*.log' (globs must point at files, not directories). By default hostname and file become stream fields, and reading checkpoints/buffers live in the addon’s data dir.

For a single, stable VictoriaLogs instance, sending logs directly (below) is simpler — that is the recommended default.

HTTP APIs

VictoriaLogs exposes several ingestion endpoints on the same port as the UI and query API:

Endpoint Format Notes
/insert/jsonline JSON Lines (ndjson) Requires Content-Type: application/json; without it the request returns 200 but the payload is silently dropped
/insert/elasticsearch/_bulk Elasticsearch / OpenSearch bulk Point Filebeat / Logstash / Fluent Bit Elasticsearch outputs here
/insert/loki/api/v1/push Loki JSON push Point Promtail / Grafana Alloy / Loki clients here
/insert/opentelemetry/v1/logs OTLP/HTTP logs Point an OpenTelemetry Collector exporter here
syslog TCP / UDP / Unix RFC3164 / RFC5424 Enable via --extra-arg -syslog.listenAddr.tcp=:514 (or .udp / .unix), then recreate

All HTTP ingestion endpoints accept the same tuning parameters, either as query-string args or VL-* headers: _msg_field (field holding the log message, e.g. message), _time_field (e.g. @timestamp), _stream_fields (comma-separated fields that define a log stream), extra_fields (env=prod), ignore_fields, decolorize_fields, and debug=1 (log the payload instead of storing it). Use them when your collector emits a schema VictoriaLogs does not auto-detect.

# JSON Lines with explicit field mapping
curl -s -X POST -H 'Content-Type: application/json' \
  --data-binary @app.jsonl \
  'http://127.0.0.1:9428/insert/jsonline?_stream_fields=host,app&_time_field=@timestamp&_msg_field=message'

Log collectors

Any collector that can speak one of the formats above works; pgcli installs and configures none of them. Commonly used ones, each with an official setup guide:

Collector Send to
Filebeat Elasticsearch output → /insert/elasticsearch/_bulk
Logstash Elasticsearch or HTTP output
Fluent Bit / Fluentd Elasticsearch or HTTP output
Vector http sink → /insert/jsonline, or Elasticsearch sink
Promtail / Grafana Alloy Loki push → /insert/loki/api/v1/push
OpenTelemetry Collector OTLP/HTTP exporter → /insert/opentelemetry/v1/logs
Telegraf http output → jsonline
journald Vector / Fluent Bit journald source → jsonline, or vlagent
rsyslog / syslog-ng syslog listener (-syslog.listenAddr.*)
Datadog Agent Datadog intake API

Collectors can also point at a vlagent instance (port 9429) instead of VictoriaLogs directly — useful when you want buffering, replication, or a single egress point.

Custom flags (--extra-arg)

VictoriaLogs accepts many CLI flags for tuning cache sizes, query limits, ingestion rates, and more. Pass them via --extra-arg (repeatable):

pg addon install victorialogs --name vl1 \
  --extra-arg -search.maxQueryDuration=60s \
  --extra-arg -memory.allowedPercent=80

Extra args are appended last to the container’s command line, so they override earlier flags via last-wins semantics. This lets you tune VictoriaLogs beyond pgcli’s first-class knobs without editing any config file. Verify the flags took effect (the binary does not print them in its logs):

podman inspect pgcli-victorialogs-default-vl1 --format '{{json .Config.Cmd}}'

Listening and exposure

VictoriaLogs’s Listen defaults to 0.0.0.0: the container shares the host’s network namespace, so the UI and API are reachable on every interface at the assigned port. This matches VictoriaMetrics’s default for the same practical reason (log shippers and Grafana on other hosts need to reach it) — but there is no password behind it. Anyone who can reach the port can run arbitrary LogsQL and read your stored logs. For a loopback-only deployment pass --listen 127.0.0.1 (recreate with --force); pg addon list then shows http://127.0.0.1:<port>/. Otherwise, restrict access at the firewall.

Ports

Each VictoriaLogs instance owns a single port: the web UI/API. It is allocated from a pool with base victorialogs_start_port (default 9428 — VictoriaLogs’s conventional HTTP port), incrementing for every additional instance and skipping ports already taken by any managed container or the used_ports list. The allocation is written into pg.yaml, so a reinstall never re-hands-out a port another addon is using. 9428 shares no number with VictoriaMetrics (8428), vmcluster (8480-8484), Prometheus (9090), Grafana (3000), pgAdmin (5050), or nginx (8080); an explicit --port still wins.

pg addon install victorialogs --name vl2          # second instance: next free port (9429 if 9428 taken)
pg addon install victorialogs --name vl3 --port 9500  # explicit port still takes precedence

Configuration

addons:
  victorialogs:
    vl1:
      name: vl1
      image_tag: docker.io/victoriametrics/victoria-logs:v1.53.0
      host_port: 9428
      listen: 0.0.0.0
      retention: "30d"
      extra_args:
        - -search.maxQueryDuration=60s
        - -memory.allowedPercent=80
      # data_dir: /srv/victorialogs-data      # optional, overrides the default location

There is no config file — everything is passed as CLI flags to the victoria-logs binary (-storageDataPath, -httpListenAddr, -retentionPeriod, plus any extra_args). retention is stored as a duration string (omitted = binary default), and extra_args is a list of CLI flags appended last.

List

pg addon list
Web add-ons (victorialogs):
  victorialogs (name: vl1)
    Status:      running
    URL:         http://0.0.0.0:9428/
    Retention:   30d
    Extra args:  -search.maxQueryDuration=60s -memory.allowedPercent=80
    Data:        /home/you/.pgcli/addon/victorialogs/vl1/data
    Image:       docker.io/victoriametrics/victoria-logs:v1.53.0
    Container:   pgcli-victorialogs-default-vl1

There are no credentials to reveal — VictoriaLogs has none — so --show-password shows nothing extra for it.

Start and stop

Containers run with podman’s unless-stopped restart policy, so they come back automatically with the podman service after a host reboot. start/stop manage them explicitly:

pg addon stop victorialogs
pg addon start victorialogs

Autostart on boot

pg autostart enable --victorialogs --name vl

This flags the instance in pg.yaml and installs/refreshes a boot service (a systemd --user unit on Linux, a LaunchAgent on macOS) that runs pg start --autostart. A boot-time start only brings the container up — the log data dir already exists, so stored logs survive the reboot. Disable with pg autostart disable --victorialogs --name vl; see Autostart for the full mechanism.

Remove

pg addon remove victorialogs              # keeps the log storage — stored logs survive a reinstall
pg addon remove victorialogs --clean-data # deletes the log storage too

Under rootless podman, --clean-data deletes the data dir through podman unshare rm — VictoriaLogs writes as root (container uid 0), which maps to a subordinate uid the host user cannot rm directly.

Troubleshooting

  • Ingestion answers 200 but queries return nothing — the JSON Lines endpoint requires Content-Type: application/json; without it VictoriaLogs accepts the request and silently drops the payload (vl_rows_ingested_total{type="jsonline"} on /metrics stays 0). Add the header, or use an ingestion client that sets it.
  • A query returns no data — confirm VictoriaLogs is running (pg addon list shows running), the health endpoint responds (curl -s http://<host>:<port>/-/healthy), and you’re querying the correct time range and stream filters (_stream: prefix, _time: bounds). Check podman logs <container> for ingestion errors.
  • Install fails with “container already exists” — the container name is derived from --name and the namespace; use --force to recreate, or pg addon remove first to clean up a partial install.
  • Extra args didn’t take effect — --extra-arg is applied at container creation time, not runtime. Reinstall with --force to recreate the container with the new flags. Check podman inspect <container> --format '{{json .Config.Cmd}}' to confirm the flags are on the command line (the binary does not log them).
  • Port already allocated — the assigned port is held in pg.yaml and skipped for later instances; free it with pg addon remove first, or pick another with --port N.
  • Remote API unreachable / unexpectedly reachable — on the default 0.0.0.0 a failure to reach it is host firewall, not bind address; conversely, if you did not want it reachable, --listen 127.0.0.1 --force.

Known limitations

  • VictoriaLogs itself is a bare log backend: pgcli ships a dedicated vlagent addon for file/HTTP collection (plus direct HTTP ingestion APIs and third-party collectors, as described above), but configures no third-party shippers and does no alerting (use vlalert separately). It is the long-term log store you point Grafana (VictoriaLogs datasource) and your shippers at.
  • No authentication. VictoriaLogs’s API ingests and queries arbitrary logs; the only protection for a 0.0.0.0 bind is the network boundary. This is the same posture as VictoriaMetrics — do not expose it on an untrusted network.
  • pgcli does not validate --extra-arg values (there is no pre-flight check at install). A bad flag surfaces only in the container logs on startup.
  • On macOS the container runs inside the podman machine; it has been validated on Linux only.

25 - vlagent

Run vlagent, the official VictoriaLogs log agent, as a managed container: track any host log path and forward to VictoriaLogs

pg addon install vlagent runs vlagent — the official log agent of the VictoriaLogs family and the log counterpart of vmagent — as a managed container from the official docker.io/victoriametrics/vlagent image. It is a top-level addon (it fronts no single PostgreSQL instance) and the natural partner of the VictoriaLogs addon: VictoriaLogs stores logs, vlagent collects them from files or over HTTP and forwards them to one or more VictoriaLogs instances.

Like VictoriaMetrics and VictoriaLogs there is no config file at all — everything is passed as CLI flags after the image name. pgcli adds the file-collector wiring on top: every --log-path is bind-mounted read-only at the same absolute path inside the container, and --include/--exclude select files using vlagent’s native glob syntax (not regular expressions).

There is NO authentication. vlagent’s HTTP listener accepts logs from anyone who can reach the port, and it forwards to VictoriaLogs instances that (by default) have no auth either. A remote-exposed instance is guarded only by the network boundary — use --listen 127.0.0.1 for loopback or restrict access at the firewall.

Platform: Linux is the tested platform. The design supports macOS (the image is multi-arch; the container runs under the podman machine VM on the pgcli-net bridge with the port published), but it has not been validated there yet.

Parameters

Flag Default Description
--name va Instance name (map key)
--image docker.io/victoriametrics/vlagent:v1.53.0 Image override
--port auto (base 9429) Host HTTP ingest port; auto-allocated from vlagent_start_port
--listen 0.0.0.0 Bind address — defaults to every interface; use 127.0.0.1 for loopback-only
--remote-write-url required VictoriaLogs endpoint(s) to forward to (repeatable). Every URL must end with /insert/native
--log-path — Host file or directory to track (repeatable). Mounted read-only at the same absolute path inside the container
--include derived Glob pattern(s) selecting files (repeatable; absolute container paths). Defaults to <dir>/**/*.log per directory and the file itself per file
--exclude — Glob pattern(s) excluding files (repeatable; positionally paired with --include)
--extra-arg — Extra CLI flag passed to the binary (repeatable); appended last so last-wins overrides earlier flags
--data-dir auto Data directory override (default under the base dir)
--force false Recreate even when running — to apply changed ports / listen / URLs / paths / globs

The data directory holds vlagent’s on-disk remote-write buffers and the file-collector checkpoints (its read positions). It survives pg addon remove (delete it with --clean-data), so reinstalling under the same name resumes exactly where collection stopped instead of re-sending or skipping file contents. The image runs as root, so no pre-chown is needed.

There is no --password: vlagent has no concept of a local account, and neither side of the connection authenticates.

Install

Relay-only — accept HTTP pushes on :9429 and forward them to a local VictoriaLogs:

pg addon install vlagent \
  --remote-write-url http://127.0.0.1:9428/insert/native

Track a directory of host log files (the common case):

pg addon install vlagent \
  --log-path /var/log/nginx \
  --remote-write-url http://127.0.0.1:9428/insert/native

With no --include, the directory defaults to /var/log/nginx/**/*.log — every .log file at any depth below it. The flag is quoted here only for shell safety; pgcli stores the glob literally.

✓ vlagent installed: "va"
  Container:  pgcli-vlagent-default-va
  Image:      docker.io/victoriametrics/vlagent:v1.53.0
  Data:       /home/you/.pgcli/addon/vlagent/va/data
  Listen:     http://0.0.0.0:9429/ (HTTP ingest: jsonline, ES bulk, Loki, OTLP)
  Remote:     http://127.0.0.1:9428/insert/native
  Mount:      /var/log/nginx (dir, read-only, same path in the container)
  Include:    /var/log/nginx/**/*.log
  Checkpoint: file-checkpoints.json under /var/lib/vlagent

Track a single file, or several paths with explicit globs and excludes:

# one file (default include is the file itself)
pg addon install vlagent --name va-app \
  --log-path /var/log/myapp/app.log \
  --remote-write-url http://127.0.0.1:9428/insert/native

# several paths, glob per path, excluding compressed archives
pg addon install vlagent --name va-all \
  --log-path /var/log/nginx --include '/var/log/nginx/*.log' --exclude '/var/log/nginx/*.gz' \
  --log-path /var/log/redis --include '/var/log/redis/**/*.log' \
  --remote-write-url http://127.0.0.1:9428/insert/native

Every --log-path becomes one read-only bind mount (host:host:ro), so the globs pgcli passes to vlagent are literally the host paths. Paths must be absolute and must already exist.

Re-running install on a running instance recreates it when the config actually changed (port, listen, URLs, log paths, includes/excludes, extra-args), and leaves it alone when it didn’t; --force recreates the container even when config is unchanged. List-valued flags replace the stored list: to add a path, repeat the whole set.

How file collection works

vlagent’s file collector is driven by -fileCollector.glob. pgcli maps its flags one-to-one:

pgcli flag vlagent flag Notes
--log-path (bind mount) -v <path>:<path>:ro — required so the container can see the file
--include -fileCollector.glob Repeatable; must match files, not directories
--exclude -fileCollector.excludeGlob Positionally paired with the Nth include
--data-dir -tmpDataPath Contains buffers and file-checkpoints.json

Each collected line becomes a log entry with two extra fields: file (the source path) and hostname. Both are stream fields by default, so each file is its own log stream in VictoriaLogs — exactly what you want for LogsQL filtering. Tune them with --extra-arg -fileCollector.streamFields=..., -fileCollector.fileField=..., or -fileCollector.hostnameField=....

The collector polls for new files every 10 seconds (-fileCollector.refreshInterval). It supports the create and nocreate rotation strategies: on rotation it finishes the old file before switching, and it resumes rotated files from the saved position after a restart. Checkpoints are written under the data dir.

Glob syntax

This is not a regular expression — it is vlagent’s own glob dialect:

Pattern Matches
* Any sequence of characters except path separators
/**/ Zero or more directories (recursive)
? Any single character except a path separator
[abc], [a-z] Character class; prefix with ^ or ! to negate
{a,b,c} Alternatives — any one of the comma-separated terms
\c Escaped character literal

Examples:

--include '/var/log/nginx/*.log'              # one level below
--include '/var/log/nginx/**/*.log'           # any depth
--include '/var/log/nginx/{access,error}.log' # alternatives
--include '/var/log/nginx/access.log.[0-9]'   # rotated files

* does not match hidden files (names starting with .); name the leading dot explicitly (.*.log) if you need them.

Excludes are positional

vlagent pairs the Nth --exclude with the Nth --include, like its own flags. An empty string '' is a placeholder meaning “no exclude at this position”:

--include '/var/log/*/*.log' --exclude '/var/log/nginx/*' \
--include '/var/log/nginx/*.log' --exclude '' \

This collects everything except nginx first, then nginx in the second pair. Without the positional pairing, the nginx exclusion would also silence the second pair.

pgcli emits every exclude entry up to the last non-empty one; trailing empty placeholders are simply dropped. If you change --log-path without passing --include, the default globs are recomputed for the new paths and stored excludes beyond the new pair count are trimmed (pass --exclude explicitly in the same run to override).

Replication and high availability

Repeat --remote-write-url for every VictoriaLogs instance:

pg addon install vlagent --name va-ha \
  --log-path /var/log/myapp \
  --remote-write-url http://10.0.0.1:9428/insert/native \
  --remote-write-url http://10.0.0.2:9428/insert/native

vlagent copies every log to all targets, keeps an independent disk buffer per URL, and replays buffered logs when a backend returns. Cap each buffer with --extra-arg -remoteWrite.maxDiskUsagePerURL=....

Other ingestion over HTTP

Even without --log-path, vlagent is a useful HTTP front door: it accepts the same protocols as VictoriaLogs on its listen port and forwards them, so collectors can push into vlagent instead of directly into VictoriaLogs:

Endpoint Format
/insert/jsonline JSON Lines (requires Content-Type: application/json)
/insert/elasticsearch/_bulk Elasticsearch / OpenSearch bulk
/insert/loki/api/v1/push Loki JSON push
/insert/opentelemetry/v1/logs OTLP/HTTP logs

For Kubernetes node logs, pass --extra-arg -kubernetesCollector and mount the node’s /var/log (plus /var/lib with the Docker runtime) via --log-path. See the VictoriaLogs ingestion section for the full protocol and collector table.

Ports

Each vlagent instance owns a single port: the HTTP ingest listener. It is allocated from a pool with base vlagent_start_port (default 9429 — vlagent’s conventional port), incrementing for every additional instance and skipping ports already taken by any managed container or the used_ports list. The pool is separate from VictoriaLogs (9428), so adding a VictoriaLogs instance can never steal a vlagent port. An explicit --port still wins.

pg addon install vlagent --name va2 \
  --remote-write-url http://127.0.0.1:9428/insert/native   # next free port (9430 when 9429 is taken)

Configuration

addons:
  vlagent:
    va:
      name: va
      image_tag: docker.io/victoriametrics/vlagent:v1.53.0
      host_port: 9429
      listen: 0.0.0.0
      remote_write_urls:
        - http://127.0.0.1:9428/insert/native
      log_paths:
        - /var/log/nginx
      includes:
        - /var/log/nginx/**/*.log
      excludes:
        - /var/log/nginx/*.gz
      extra_args:
        - -fileCollector.refreshInterval=5s
      # data_dir: /srv/vlagent-data        # optional, overrides the default location

Everything is passed as CLI flags to the vlagent binary: remote_write_urls becomes repeated -remoteWrite.url, includes become -fileCollector.glob, excludes become -fileCollector.excludeGlob, log_paths become read-only bind mounts, and data_dir becomes -tmpDataPath.

List

pg addon list
Log agents (vlagent):
  vlagent (name: va)
    Status:      running
    Listen:      http://0.0.0.0:9429/
    Remote:      http://127.0.0.1:9428/insert/native
    Log paths:   /var/log/nginx
    Includes:    /var/log/nginx/**/*.log
    Excludes:    /var/log/nginx/*.gz
    Data:        /home/you/.pgcli/addon/vlagent/va/data
    Image:       docker.io/victoriametrics/vlagent:v1.53.0
    Container:   pgcli-vlagent-default-va

Start and stop

pg addon stop vlagent
pg addon start vlagent

The container runs with podman’s unless-stopped restart policy. File read positions are checkpointed to the data dir, so a stop/start (or host reboot) resumes without duplicating or losing file content.

Autostart on boot

pg autostart enable --vlagent --name va

This flags the instance in pg.yaml and installs/refreshes a boot service (a systemd --user unit on Linux, a LaunchAgent on macOS) that runs pg start --autostart. A boot-time start only brings the container up — the data dir with the file checkpoints and remote-write buffers already exists, so the agent resumes where it stopped. vlagent starts after VictoriaLogs in the boot sequence, so a same-host remote-write target is already listening. Disable with pg autostart disable --vlagent --name va; see Autostart for the full mechanism.

Remove

pg addon remove vlagent              # keeps buffers and file checkpoints
pg addon remove vlagent --clean-data # deletes them too

Removing the agent does not remove any log files it tracked — they are mounted read-only and never modified.

Troubleshooting

  • No file logs in VictoriaLogs — confirm the container is running (pg addon list), the globs match real files (--include must match files, not directories), and the paths are visible inside the container. podman inspect pgcli-vlagent-<ns>-<name> --format '{{json .Config.Cmd}}' shows the exact flags; podman logs <container> shows collector errors.
  • Some files are skipped — * does not match hidden files, and rotated names like app.log.1 do not match *.log. Add explicit patterns (e.g. --include '/var/log/myapp/app.log.[0-9]'). Excludes are positional: a broad first-pair exclude can hide files from a later pair.
  • Data lands with the wrong stream — file and hostname are stream fields by default; override with --extra-arg -fileCollector.streamFields=....
  • Extra args didn’t take effect — --extra-arg is applied at container creation time. Reinstall (config changes recreate automatically) or use --force; verify with podman inspect <container> --format '{{json .Config.Cmd}}'.
  • Container cannot read the logs (SELinux hosts) — pgcli mounts log paths with :ro only, deliberately not :z, because relabeling /var/log would modify the host. On enforcing-SELinux systems pass workload-appropriate labeling yourself (e.g. a shared container_log_t label or --extra-arg-independent podman policy) or run the container with a matching security profile.
  • Remote write fails — the URL must end in /insert/native; check VictoriaLogs health (curl -s http://<vl>:9428/-/healthy) and whether a firewall separates the hosts. Buffered logs replay once it is reachable again.

Known limitations

  • No regular expressions. vlagent matches globs only (*, /**/, ?, [a-z], {a,b}). Complex file-name rules need a broader include plus a LogsQL filter on the query side.
  • No authentication on the ingest listener or the remote-write side; guard it with --listen 127.0.0.1 or a firewall.
  • pgcli does not validate --extra-arg values; a bad flag surfaces in the container logs at startup.
  • macOS is code-complete but untested; Linux is the validated platform.

26 - vmalert

Run vmalert, the VictoriaMetrics rule-evaluation engine, as a managed container: evaluate alerting/recording rules against VictoriaLogs or VictoriaMetrics and notify Alertmanager

pg addon install vmalert runs vmalert — the rule-evaluation engine of the VictoriaMetrics family — as a managed container from the official docker.io/victoriametrics/vmalert image. It is a top-level addon: it evaluates alerting (and recording) rules and forwards firing alerts to one or more Alertmanager-compatible notifiers. It is the missing link between the VictoriaLogs addon / VictoriaMetrics addon and the Alertmanager addon.

One instance evaluates against exactly one datasource. Logs and metrics cannot be mixed in the same vmalert process: the default datasource is VictoriaLogs (http://127.0.0.1:9428), and a metrics rule set must pass --datasource-url http://127.0.0.1:8428 (or another MetricsQL/PromQL-compatible endpoint) explicitly.

Rules and templates live in host directories bind-mounted read-only into the container. There is no rendered config file: edit the YAML directly, then run pg addon vmalert reload.

There is NO authentication and NO TLS. The rules/alerts API and GET /-/reload are open to anyone who can reach the port. --listen defaults to 0.0.0.0 (the Prometheus-stack convention); use --listen 127.0.0.1 on an untrusted network or restrict access at the firewall.

Platform: Linux is the tested platform. The design supports macOS (the image is multi-arch; the container runs under the podman machine VM on the pgcli-net bridge with the port published), but it has not been validated there yet. On macOS the container’s 127.0.0.1 is its own loopback, so the default datasource/notifier URLs must point at host.containers.internal (or a container name) instead.

Parameters

Flag Default Description
--name vmalert Instance name (map key)
--image docker.io/victoriametrics/vmalert:v1.133.0 Image override
--port auto (base 8880) Host HTTP/API port; auto-allocated from vmalert_start_port
--listen 0.0.0.0 Bind address — defaults to every interface; use 127.0.0.1 for loopback-only
--datasource-url http://127.0.0.1:9428 The ONE backend rules query (VictoriaLogs by default; http://127.0.0.1:8428 for VictoriaMetrics)
--notifier-url http://127.0.0.1:9093 Alertmanager-compatible notifier(s), repeatable. Passing the flag replaces the stored list
--rules-dir <base_dir>/addon/vmalert/<name>/rules Host rules directory, mounted read-only at /etc/vmalert/rules
--templates-dir <base_dir>/addon/vmalert/<name>/templates Host templates directory, mounted read-only at /etc/vmalert/templates
--remote-write-url — Remote-write base URL(s) for recording rules and alert-state persistence, repeatable
--remote-read-url — Remote-read base URL(s) restoring alert state after a restart, repeatable
--external-label — Extra NAME=VALUE label on every generated alert/series (repeatable; use for HA replica labels)
--external-url — Externally reachable base URL used in UI links
--extra-arg — Extra CLI flag passed to the binary (repeatable); appended last so last-wins overrides earlier flags
--force false Recreate even when running — to apply changed ports / listen / URLs / labels

--data-dir and --conf-file are rejected for vmalert: it keeps no local state and has no config file.

Rules and templates

The rules directory is seeded once with alert.rules.yaml and the templates directory with default.tpl; pgcli never overwrites a file you have edited. Both directories are bind-mounted read-only, so the operator owns the files.

Loading uses the container-side globs:

-rule=/etc/vmalert/rules/*.yaml
-rule.templates=/etc/vmalert/templates/*.tpl

Only top-level *.yaml and *.tpl files match. A *.yml file is silently ignored — rename it to .yaml. New files added to the directory are picked up on reload without recreating the container. Subdirectories are not loaded.

A VictoriaLogs rule group (the reference layout):

groups:
  - name: victoria-logs
    type: vlogs
    interval: 1m
    rules:
      - alert: found-999-log
        expr: '_time:5m | 999 | count() as cnt | filter cnt:>0'
        labels:
          severity: critical
        annotations:
          description: 'Found 999 logs in the last 5 minutes'

A metrics rule group (requires --datasource-url http://127.0.0.1:8428):

groups:
  - name: metrics
    interval: 30s
    rules:
      - alert: instance-down
        expr: up == 0
        for: 5m
        labels:
          severity: warning
        annotations:
          summary: 'Instance {{ $labels.instance }} is down'

Install

Log alerting with the defaults (VictoriaLogs datasource, Alertmanager notifier):

pg addon install vmalert

Metrics alerting — point it at VictoriaMetrics instead:

pg addon install vmalert --name vmalert-metrics \
  --datasource-url http://127.0.0.1:8428

Custom directories, several notifiers, and an HA replica label:

pg addon install vmalert \
  --rules-dir /srv/vmalert/rules \
  --templates-dir /srv/vmalert/templates \
  --notifier-url http://127.0.0.1:9093 \
  --notifier-url http://127.0.0.1:9094 \
  --external-label replica=a \
  --listen 127.0.0.1

The install summary prints the container, image, URL, datasource, notifiers, rules/templates directories and any remote write/read or external labels.

Reload

pg addon vmalert reload --name vmalert

Reload sends GET /-/reload to the running instance. It is asynchronous: a 2xx response only means the signal was accepted. Malformed YAML is reported in the container log while the previous rules keep running, so confirm the result with:

pg addon vmalert status --name vmalert
pg logs addon vmalert --name vmalert

status prints the stored config plus the live Groups, Rules, firing/pending counts and each group’s name/rule count/file, read from /api/v1/rules. A stopped instance prints stopped without querying the API.

Alert state across restarts

These two flags are not the rule-evaluation datasource — that is always --datasource-url. They persist vmalert’s own output: recording-rule series and the ALERTS / ALERTS_FOR_STATE state series.

  • Recording rules only (persist their output series): --remote-write-url alone.
  • Alert state across restarts: both flags, pointing at the same store.
  • Pure log alerting where a state reset on restart is acceptable: neither.

vmalert keeps alert state in memory. To restore it after a restart, configure both --remote-write-url and --remote-read-url (for example against the VictoriaMetrics addon):

pg addon install vmalert \
  --remote-write-url http://127.0.0.1:8428 \
  --remote-read-url http://127.0.0.1:8428

Pass base URLs: vmalert appends /api/v1/write for remote write and /api/v1/query for remote read itself, so http://127.0.0.1:8428/api/v1/write would become /api/v1/write/api/v1/write and 404. This differs from the Prometheus addon, whose --remote-write-url takes the full path.

Both are required, and the targets must be compatible. A hot reload never triggers a state restore; configuring only one of the pair does not either. --remote-write-url alone is still useful for recording-rule results.

HA

Run one vmalert per replica with a distinct external label so Alertmanager can deduplicate identical alerts:

pg addon install vmalert --name vmalert-a --external-label replica=a
pg addon install vmalert --name vmalert-b --external-label replica=b

There is no leader election — every replica evaluates the same rules and sends alerts; Alertmanager deduplicates by label set. --external-url only shapes UI links.

Lifecycle, logs, autostart

pg addon start vmalert --name vmalert
pg addon stop vmalert --name vmalert
pg addon remove vmalert --name vmalert              # rules/templates kept
pg addon remove vmalert --name vmalert --clean-data # delete pgcli-managed dirs too
pg logs addon vmalert --name vmalert
pg autostart enable --vmalert --name vmalert

Re-running install recreates a running container when the effective config changed (or with --force), and is a no-op when nothing changed. Rules and templates are never modified by install, start, stop, or --force.

remove keeps the rules and templates directories by default. --clean-data deletes only pgcli-managed directories; a user-supplied --rules-dir/--templates-dir is never deleted (the paths are printed). A directory that is a mount point is skipped with a warning.

At boot, pg start --autostart starts vmalert after VictoriaLogs, VictoriaMetrics and Alertmanager, so the default datasource and notifier are already listening.

Limitations

  • One datasource per instance — logs and metrics cannot be mixed.
  • No basic auth, TLS, or any authentication on the API or /-/reload.
  • No leader election (HA relies on external labels + Alertmanager deduplication).
  • No local alert-state persistence; use remote write + remote read.
  • Only *.yaml / *.tpl at the top level are loaded; *.yml is ignored.
  • The vmalert release cadence differs from the VictoriaMetrics main version; upgrade with --image.

Verification

End-to-end tested on Linux (debian12-01) on 2026-11-03 with docker.io/victoriametrics/vmalert:v1.133.0 via test/addon/test_vmalert.sh (48 assertions): the default VictoriaLogs datasource fires a real vlogs alert that reaches Alertmanager, reload picks up a new group, an identical reinstall is a no-op while a changed flag recreates the container, --force leaves the operator’s rules untouched, and remove/--clean-data respect managed-vs-explicit directories.

27 - VLCluster

Run VictoriaLogs cluster edition — vlinsert + vlselect + vlstorage, all from one image, as managed containers with cross-host sharding.

pg addon install vlcluster runs VictoriaLogs cluster edition — the horizontally scalable log database. Unlike the single-node victorialogs addon (one container, one port), this manages up to three containers from the same image (docker.io/victoriametrics/victoria-logs:v1.53.0) and three HTTP ports per host. The role is selected entirely by flags.

Architecture:

Component Role HTTP Port Talks to
vlinsert Ingestion — shards writes across all vlstorage nodes by stream hash 9430 Dials every vlstorage:StoragePort
vlselect Queries — fans out LogsQL and merges results 9431 Dials every vlstorage:StoragePort
vlstorage Data storage (sharded, not replicated) 9432 Serves /internal/insert + /internal/select/* on that one port

vlinsert and vlselect are stateless and dial the same single port on each vlstorage node; there are no separate internal TCP ports like VMCluster’s host:insertPort:selectPort. A storage node address is therefore just host:storagePort.

There is NO web login/password. Like single-node VictoriaLogs, the cluster edition ships no authentication at all. Its HTTP API can ingest, query, and delete arbitrary logs, so a remote-exposed instance is guarded only by the network boundary — your firewall, or --listen 127.0.0.1 for loopback. Treat it as an unauthenticated read/write console.

Platform: Linux only. VLCluster requires host networking for the ports that vlinsert/vlselect dial on every vlstorage node. On macOS, installation is refused with a clear error.

No replication. vlinsert shards but does not copy: every stream lives on exactly one vlstorage node. Losing any vlstorage makes queries return HTTP 502 until it comes back (ingestion keeps working, buffered by vlagent or the client). Plan capacity and backup accordingly — this is an upstream design property, not a pgcli limitation.

Deployment Models

Model 1 — Converged single-host (default)

All three components on one host:

pg addon install vlcluster --name vlc --listen 127.0.0.1
# 1 host, 3 containers (vlstorage + vlinsert + vlselect)
# --storage-node auto-derived as 127.0.0.1:<StoragePort>

Model 2 — Cross-host sharding

Same --roles + --storage-node model as VMCluster: each host runs its own pg addon install vlcluster, and pgcli never SSHes.

# Host A — storage node 1
pg addon install vlcluster --name vlc --roles storage --listen 10.0.0.1

# Host B — storage node 2
pg addon install vlcluster --name vlc --roles storage --listen 10.0.0.2

# Host C — ingestion + query layer
pg addon install vlcluster --name vlc --roles insert,select --listen 10.0.0.3 \
  --storage-node 10.0.0.1:9432 \
  --storage-node 10.0.0.2:9432

An access-only host (--roles insert and/or --roles select) must pass --storage-node — install aborts otherwise, because the auto-derived loopback address would create an isolated node that silently joins nothing.

All hosts must allocate the same port block for the instance name so the addresses match. The default base is 9430 (see Ports); if you change vlcluster_start_port on one host, set it identically on the others.

Parameters

Flag Default Description
--name vlc Instance name (map key)
--roles insert,select,storage Comma-separated roles this host runs (subset for cross-host)
--storage-node auto-derived vlstorage address (repeatable; format host:storagePort, e.g. 10.0.0.1:9432). Lists ALL vlstorage nodes for sharding. Omit on a converged host
--insert-port auto (base 9430) vlinsert HTTP port
--select-port auto (base 9431) vlselect HTTP port
--storage-port auto (base 9432) vlstorage HTTP port
--listen 0.0.0.0 Bind address — use 127.0.0.1 for loopback-only
--retention binary default vlstorage retention, e.g. 30d (only when this host runs storage)
--image docker.io/victoriametrics/victoria-logs:v1.53.0 Image override (one image for all roles)
--insert-extra-arg — Extra CLI flag for vlinsert (repeatable, appended last)
--select-extra-arg — Extra CLI flag for vlselect (repeatable, appended last)
--storage-extra-arg — Extra CLI flag for vlstorage (repeatable, appended last)
--data-dir auto vlstorage data directory override
--force false Recreate even when running and unchanged

--retention is deliberately not defaulted: empty means the victoria-logs binary default. Unlike vmcluster’s --retention-months, VictoriaLogs parses durations such as 30d, 3months, or 1y.

Install

pg addon install vlcluster --name vlc --listen 127.0.0.1

The command pulls the image if needed, creates the containers in dependency order (storage → insert → select), and prints the summary:

✓ VLCluster installed: "vlc"
  Roles:       storage, insert, select (converged on this host)
  Containers:  pgcli-vlcluster-default-vlc-storage, ...
  Image:       docker.io/victoriametrics/victoria-logs:v1.53.0
  Data:        /home/you/.pgcli/addon/vlcluster/vlc/data
  Retention:   binary default (--retention to change)
  Insert URL:  http://127.0.0.1:9430/ (vlinsert — ingestion)
  Select URL:  http://127.0.0.1:9431/ (vlselect — LogsQL queries)
  Storage URL: http://127.0.0.1:9432/ (vlstorage — internal APIs + admin)

Reinstalling with the same flags is a no-op (unchanged); changed flags recreate only what is needed. A role removed from --roles has its stale container deleted.

URL Format

The cluster edition uses the same API paths as single-node VictoriaLogs — no account ID, no extra prefix:

Ingestion via vlinsert:

curl -X POST http://127.0.0.1:9430/insert/jsonline \
  -H 'Content-Type: application/json' \
  -d '{"_msg":"hello from vlcluster","app":"demo"}'

Query via vlselect:

curl 'http://127.0.0.1:9431/select/logsql/query?query=app:demo&limit=10'

vlselect also serves the built-in UI at http://<host>:9431/select/vmui/. vlagent forwards to http://<vlinsert>:9430/insert/native.

The vlstorage port (9432) serves /internal/insert and /internal/select/* for the other two roles; its own LogsQL endpoints query only that node’s local data, which is useful for per-node debugging but not for cluster-wide queries.

Ports

Each VLCluster instance owns 3 consecutive ports from the vlcluster_start_port pool (default 9430):

  • +0 InsertPort (vlinsert HTTP — ingestion endpoint)
  • +1 SelectPort (vlselect HTTP — query endpoint)
  • +2 StoragePort (vlstorage HTTP — internal insert/select APIs)

All three are allocated even on hosts that run only a subset, so a storage node’s address is predictable across hosts. The base sits just above single-node VictoriaLogs (9428) and vlagent (9429); the three pools are mutually aware and never hand out the same port.

Configuration

addons:
  vlcluster:
    vlc:
      name: vlc
      container_prefix: pgcli-vlcluster-default-vlc
      image_tag: docker.io/victoriametrics/victoria-logs:v1.53.0
      listen: 0.0.0.0
      insert_port: 9430
      select_port: 9431
      storage_port: 9432
      roles:
        - storage
        - insert
        - select
      storage_nodes:
        - "10.0.0.1:9432"
        - "10.0.0.2:9432"
      retention: 30d
      autostart: false

There is no config file inside the containers — everything is passed as CLI flags. storage_nodes is the cross-host topology; empty means auto-derived single-node.

Adding storage nodes

vlinsert/vlselect bake the -storageNode list at startup, so adding a node requires recreating the access-layer containers (a brief ingestion pause; existing data is untouched):

# New storage host
pg addon install vlcluster --name vlc --roles storage --listen 10.0.0.3

# Access-layer hosts: reinstall with the full node list
pg addon install vlcluster --name vlc --roles insert,select --listen 10.0.0.3 \
  --storage-node 10.0.0.1:9432 \
  --storage-node 10.0.0.2:9432 \
  --storage-node 10.0.0.3:9432

No automatic rebalance: old data stays on the original nodes; only new writes are spread across the enlarged set. vlselect merges all nodes, so queries see both. To rebalance older data, wait for retention to expire it or manually copy per-day partitions (upstream offers no rebalance tool).

Start and stop

pg addon stop vlcluster
pg addon start vlcluster

Containers run with podman’s unless-stopped restart policy and come back after a host reboot. Stop goes in reverse dependency order (select → insert → storage).

Autostart on boot

pg autostart enable --vlcluster --name vlc

Boot is cluster-granular: each host starts only the roles it runs, in dependency order (storage → insert → select), starting existing containers and recreating only what is missing. Run it on every host in a cross-host deployment. See Autostart for the full mechanism.

Remove

pg addon remove vlcluster              # keeps vlstorage data — reinstall revives stored logs
pg addon remove vlcluster --clean-data # deletes the data directory too

Removal deletes all three role containers on this host, even orphans left behind by a role change. On an access-only host this does not touch remote storage nodes.

Logs

pg logs addon vlcluster                # vlstorage logs (default service)
pg logs addon vlcluster --service insert   # vlinsert logs
pg logs addon vlcluster --service select   # vlselect logs

A role this host does not run is rejected with a clear error.

Known limitations

  • No replication. One copy per stream; any vlstorage outage makes queries return 502. Ingestion continues and can be buffered upstream (e.g. vlagent’s disk queue). Cross-cluster HA needs multiple vlagent --remote-write-url targets and a routing layer such as vmauth — out of scope here.
  • No automatic rebalance. Adding a storage node only affects new data.
  • No authentication. The HTTP API ingests and queries arbitrary logs; a 0.0.0.0 bind is protected only by the network boundary.
  • Linux only. Host networking is required.
  • No TLS. Terminate TLS in front (nginx) or use a private network.
  • Per-host status. pg addon list reports only the roles configured on the current host; it does not probe remote storage nodes.
  • pgcli does not validate --*-extra-arg values. A bad flag surfaces only in the container logs on startup.

28 - ZeroFS

Mount an encrypted, self-maintaining S3 filesystem as a managed addon (host binary).

ZeroFS is an S3-backed filesystem that keeps everything inside the bucket: instead of JuiceFS’s external metadata engine, it runs its own LSM tree directly on object storage, and every object is encrypted with a per-volume data key wrapped by your encryption password. Snapshots and consistency are handled by background compaction — there is no database to back up, no Redis to keep alive. You lose neither property than a normal filesystem gives you (it mounts via FUSE through a local 9P hop), and the bucket alone is a complete, encrypted copy of the volume.

Like JuiceFS, ZeroFS is a host-binary addon — no container. pg addon install zerofs downloads the official release binary (sha256-verified; a zerofs already on PATH is reused), writes the volume’s config.toml itself, and runs two host processes:

  • the server (zerofs run -c config.toml) — owns the S3 + encryption side and speaks 9P on a loopback port (default 5564). 9P has no authentication, so pgcli hard-rejects a non-loopback --listen;
  • the client (zerofs mount 127.0.0.1:<port> <mount-point>) — the FUSE mount you actually use, auto-reconnecting if the server bounces.

Platform: Linux only (host FUSE; macOS refuses, like BeeGFS). The mount is a plain host directory — it does not propagate into PG instance containers.

Everything is explicit

The object store is an EXTERNAL S3 service (cloud, or a MinIO on another machine), named on the command line — pgcli never auto-detects or inherits a same-host addon’s credentials:

pg addon install zerofs --name z1 \
    --s3-endpoint http://minio.example.com:9000 \
    --access-key AK --secret-key SK \
    --bucket zerofs-data
  • --s3-endpoint is a bare http(s)://host[:port] (no bucket path, no embedded credentials); pgcli probes it before starting the server, so an unreachable host fails fast instead of hanging the server’s retry loop.
  • --access-key/--secret-key are required, always together.
  • The bucket is never created by pgcli — provision it yourself with the pg mc wrapper; the install prints the exact two lines.
  • ZeroFS signs requests, so --s3-region is honoured (optional — zerofs itself defaults to us-east-1; most MinIO-compatible stores accept the default).

The mount point is yours to choose — by default it lives under pgcli’s addon dir; point it anywhere with --mount-point. Create the directory yourself (mkdir -p) at a path the user running pg has read-write access to — pgcli never creates it:

mkdir -p /mnt/cloudfs
pg addon install zerofs --name z1 \
    --s3-endpoint http://minio.example.com:9000 \
    --access-key AK --secret-key SK \
    --bucket zerofs-data --mount-point /mnt/cloudfs

A missing or unwritable directory fails the install (and every later mount) with the exact mkdir -p remedy before anything is downloaded or started.

Both backends can be pgcli’s own services — created with pgcli, then wired in explicitly as ordinary external URLs (the install never looks them up by itself; it could equally well point at a cloud bucket or a remote Redis):

# MinIO as the object store (a pgcli minio addon — or silo/rustfs/garage/
# seaweedfs; create the bucket by hand, pgcli never does; the root user is
# admin unless --root-user said otherwise, and `pg addon password minio`
# returns the secret key bare — safe to inline):
pg addon install minio --name ms3
pg mc mb ms3/zerofs-data

pg addon install zerofs --name z1 \
    --s3-endpoint http://127.0.0.1:9000 --bucket zerofs-data \
    --access-key admin --secret-key "$(pg addon password minio --name ms3)"
# Redis as the fence backend (--conditional-put redis — for stores lacking
# conditional put; pgcli's MinIO needs none, this shows the wiring). `pg
# addon password redis` returns the generated password bare, paste it into
# the URL, /N picks the logical database:
pg addon install redis --name fence
pg addon password redis --name fence

pg addon install zerofs --name z2 \
    --s3-endpoint http://silo.example.com:9000 \
    --access-key AK --secret-key SK --bucket zerofs-fenced \
    --conditional-put redis --redis-dsn "redis://:PASS@127.0.0.1:6379/0"

These examples run pg on the same machine as the store, so loopback (default 127.0.0.1) is enough. When the zerofs client lives on another host, publish the store on the network and point --s3-endpoint at its address — the endpoint goes into config.toml, so re-render with --force if you change it later:

pg addon install minio --name ms3 --listen 0.0.0.0   # --force if already installed
# from the other host:
pg addon install zerofs --name z1 --s3-endpoint http://10.0.0.5:9000 …

(Redis already binds 0.0.0.0 by default — its password is the gate. Note this is about the S3/redis backends only: zerofs’s OWN 9P --listen must stay loopback — 9P has no authentication.)

The password is the data

⚠️ 🔑 pg addon remove DESTROYS your only copy of the password — save it first. remove keeps the bucket but deletes the config entry, and the password lives only in that entry and its config.toml. Without the original password the kept bucket is permanently unreadable — no recovery path exists. Before any remove you might want to undo later: pg addon password zerofs --name z1 > /somewhere/safe (outside pgcli’s dirs).

The encryption password wraps the bucket’s data-encryption key (DEK). It is generated on first install — retrieve it any time with:

pg addon password zerofs --name z1

Lose it and the bucket’s contents are unrecoverable. This also matters on pg addon remove, which deliberately keeps the bucket: the config entry (and its copy of the password) is gone, so a plain re-install generates a new password that cannot unwrap the old DEK — the server fails to start with Invalid password or corrupted key. Re-attach the kept bucket by passing the original password back in:

pg addon install zerofs --name z1 --encryption-password '<the stored one>'

(To truly start over: empty the bucket, or pick a new --bucket.)

Fencing: conditional put

ZeroFS fences concurrent writers with S3 conditional puts (If-None-Match). --conditional-put selects how:

Mode Meaning
auto (default) Use the store’s native If-None-Match — needs MinIO RELEASE.2022-08+ or real S3
redis Fence through Redis instead — for stores lacking conditional-put (e.g. silo); requires an explicit --redis-dsn redis://… (no same-host addon lookup)
none No fencing — safe only when nothing else ever touches the bucket

If a server start fails on a store that lacks conditional-put, the install recognises the log signature and tells you to retry with --conditional-put redis --redis-dsn ….

--redis-dsn is a plain redis:// URL — the DSN is written verbatim into config.toml, and any Redis works, including a pgcli redis addon (see the wiring example above; pg addon password redis returns its generated password bare, /N picks the logical database). TLS endpoints use the same URL shape as everywhere else in pgcli: rediss://user:pass@redis-host:6380/1.

One 9P port per instance: a zerofs server that loses the port bind starts silently and listens on nothing, so install and start refuse an already- answering --port outright — run several volumes by giving each its own port.

Parameters

Flag Default Description
--name zerofs Volume name (config map key)
--s3-endpoint — REQUIRED. External S3 service as http(s)://host[:port]
--s3-region zerofs’s own us-east-1 SigV4 region for the endpoint
--bucket zerofs-<name> Bucket — pgcli does NOT create it
--access-key / --secret-key — REQUIRED together. S3 credentials
--encryption-password generated Wrap password; pass the stored one to re-attach a kept bucket
--mount-point <base>/addon/zerofs/<name>/mnt Host directory to mount — pgcli never creates it: mkdir -p it beforehand, writable for the user running pg
--cache-dir <base>/addon/zerofs/<name>/cache Server-side disk cache dir
--server-cache-gb 100 Server cache size (GiB)
--listen 127.0.0.1 9P bind address — must be loopback (no auth in 9P)
--port 5564 9P port (refused when already answering — one per zerofs instance)
--conditional-put auto auto / redis / none (see Fencing)
--redis-dsn — Redis fence backend, REQUIRED with --conditional-put redis
--install-dir /usr/local/bin Where the host binary goes (falls back to ~/.local/bin)
--version pinned (2.3.5) Release to download (digest pinned in pgcli)
--no-mount off Write config + start server, leave it unmounted
--force off Re-render config.toml and restart — keeps the stored encryption password (a fresh one could not unwrap existing data)

FUSE (/dev/fuse + fusermount3) is probed, never installed.

Daily operations

pg addon zerofs status --name z1     # server process, mount state, files, fence mode
pg addon zerofs umount --name z1     # detach the FUSE client
pg addon zerofs mount  --name z1     # attach it again (server must run)
pg addon zerofs mount  --name z1 --mount-point /mnt/cloudfs
                                     # custom path (mkdir -p it first); while
                                     # unmounted this relocates the volume too
pg addon zerofs stop   --name z1     # unmount + kill server
pg addon zerofs start  --name z1
pg addon start/stop zerofs --name z1 # top-level aliases (start=server, stop=full)
pg logs addon zerofs --name z1 -f                      # the server log
pg logs addon zerofs --name z1 --service mount -f      # the FUSE client log
pg addon remove zerofs --name z1     # stop + forget; bucket + encrypted data stay
                                     # 🔑 save the password FIRST: pg addon password zerofs --name z1
pg addon remove zerofs --name z1 --clean-data   # also deletes the addon host dir

The config.toml, server/client logs and pid files live under <base>/addon/zerofs/<name>/; the secrets (encryption password + S3 keys) are kept in the 0600 config.toml and — like every pgcli addon credential — in plain view in your pg.yaml.

Relocating the mount point works exactly like JuiceFS: umount, mkdir -p the new directory (writable — same contract as install), then mount with the override; the new path is persisted to pg.yaml, so plain mounts and autostart use it from then on:

pg addon zerofs umount --name z1
mkdir -p /srv/cloudfs
pg addon zerofs mount --name z1 --mount-point /srv/cloudfs
#   [i] mount point moved to /srv/cloudfs (saved)
# ✓ zerofs "z1" mounted at /srv/cloudfs

Attempting the move while still mounted refuses with an “umount first” hint; the FUSE mount point is fully decoupled from pgcli’s bookkeeping (the 9P server keeps running on its port, config.toml/logs/pid stay under <base>/addon/zerofs/<name>/), so the move never touches the volume.

Autostart

pg autostart enable --zerofs --name z1

At boot, pg start --autostart brings up the 9P server (waiting for the port to listen) and then the FUSE client. The backend is external — boot succeeds only when the S3 endpoint is reachable again. Nothing is re-rendered or regenerated: the existing config.toml and stored password are reused verbatim.

29 - DuckDB

Install an embedded OLAP database as a managed host-binary addon.

DuckDB is an embedded analytical database — often called “SQLite for analytics”. It is a C++ columnar engine with vectorised execution that queries Parquet, CSV, JSON and Arrow files directly, without a server process. Think of it as a single-binary OLAP engine you point at your data: SELECT * FROM read_parquet('s3://bucket/data.parquet') works out of the box once the httpfs extension is loaded.

As a pgcli addon, DuckDB is a host-binary addon: there is no container and no daemon. pg addon install duckdb downloads the official CLI zip from GitHub releases (sha256-verified; a duckdb already on PATH is reused), installs the httpfs extension (parquet and json are bundled in the binary), and records the entry in pg.yaml.

Platform: Linux only, amd64 only (macOS and other architectures refuse with a clear error). DuckDB is a standalone CLI tool — it does not run as a background service, does not listen on a port, and does not propagate into running PG instance containers.

Why DuckDB alongside pgcli

DuckDB fills the analytical gap that PostgreSQL’s row-oriented engine does not target: ad-hoc queries over large Parquet/CSV datasets, data-lake exploration, ETL pre-processing before loading into PostgreSQL, or quick aggregations on files that already live in S3. pgcli already manages S3 stores (MinIO, silo, rustfs, garage, seaweedfs) — DuckDB queries their contents directly via httpfs.

Usage

# Default: v1.5.6 LTS, install httpfs extension (parquet/json are bundled)
pg addon install duckdb

# Pin a specific version
pg addon install duckdb --version 2.0.0

# Custom name and data directory
pg addon install duckdb --name analytics --data-dir /srv/duckdb

# Skip extension installation
pg addon install duckdb --no-extensions

# Re-install with different flags (entry already exists)
pg addon install duckdb --version 2.0.0 --force

Once installed, launch the interactive shell or run one-shot queries:

# Interactive shell (data dir is set as the working directory)
pg addon duckdb shell

# One-shot query against a local Parquet file
pg addon duckdb shell -- -c "SELECT * FROM read_parquet('/tmp/data.parquet')"

# Query S3 directly (needs the httpfs extension, installed by default)
duckdb -c "SELECT count(*) FROM read_parquet('s3://bucket/data/*.parquet')"

# Open a persistent database file
duckdb ~/.pgcli/addon/duckdb/duckdb/analytics.duckdb

Parameters

Flag Default Description
--name duckdb Instance name (config map key)
--version 1.5.6 Release to download (its sha256 is pinned in pgcli; 1.5.6 LTS and 2.0.0 supported)
--data-dir <base>/addon/duckdb/<name> Default database directory for .duckdb files
--install-dir /usr/local/bin Where the host binary goes (falls back to ~/.local/bin when not writable — keep it on PATH)
--no-extensions off Skip installing the httpfs extension (parquet and json are bundled in the binary)
--force off Rebuild the config entry from the flags

Daily operations

pg addon duckdb status --name duckdb        # binary version, path, data dir
pg addon duckdb shell --name duckdb         # interactive DuckDB session
pg addon duckdb shell -- -c "SELECT 1"      # one-shot query (args after --)
pg addon list                               # duckdb appears under "Analytics add-ons"
pg addon start duckdb                       # no-op (CLI tool, not a daemon)
pg addon stop  duckdb                       # no-op (CLI tool, not a daemon)
pg addon remove duckdb --name duckdb        # forget config; binary and data dir stay
pg addon remove duckdb --name duckdb --clean-data   # also deletes the data directory

remove never deletes the binary — it may be shared across multiple named instances. Pass --clean-data to delete the data directory (database files); without it, the directory is kept and reported.

Server/Client mode (v2.0.0+)

DuckDB v2.0.0 introduced the Quack protocol for native server/client operation. This allows DuckDB to serve its databases over HTTP, letting multiple clients query the same instance.

Starting a server

# Interactive server (stdin must stay open)
duckdb /path/to/db.duckdb -serve

# Background server (redirect stdin to keep alive)
nohup duckdb /path/to/db.duckdb -serve < /dev/zero > /tmp/duckdb-serve.log 2>&1 &

# Or use quack_serve() from SQL
duckdb -c "INSTALL quack; LOAD quack; CALL quack_serve(token='mytoken')"

The server listens on localhost:9494 by default and prints an auto-generated auth token. By default, it only accepts local connections — for remote access, put it behind a TLS-terminating reverse proxy (see DuckDB docs).

Cross-host access (0.0.0.0 binding)

To accept connections from any network interface, use quack_serve() with explicit parameters instead of -serve:

-- Server: bind to all interfaces on port 9494
CALL quack_serve(
  listen_uri='quack:0.0.0.0:9494',
  allow_other_hostname=true,  -- required for non-localhost binding
  disable_ssl=true,            -- optional, default is HTTPS
  token='mytoken'
);

Three parameters are needed:

  • listen_uri='quack:0.0.0.0:9494' — bind to all interfaces (not just localhost)
  • allow_other_hostname=true — bypass the localhost-only restriction
  • disable_ssl=true — use plain HTTP (default is HTTPS with auto-generated cert)

Clients connect using the server’s IP address:

# Client connecting to remote server
duckdb -c "ATTACH 'quack:192.0.2.10:9494' AS qk (TOKEN 'mytoken', DISABLE_SSL true); CONNECT qk; SELECT * FROM t"

The client uses HTTP automatically only for localhost, 127.0.0.1 and ::1; any other host defaults to HTTPS. When the server was started with disable_ssl=true, the client must pass DISABLE_SSL true as well (as above), otherwise it fails with an SSL error.

Security warning: Binding to 0.0.0.0 with disable_ssl=true exposes the database to the network without encryption. Use only on trusted networks or behind a firewall. For production, use a reverse proxy with TLS.

Connecting to a server

# Using -connect flag (v2.0.0+)
duckdb -connect -c "SELECT * FROM t"

# Or via SQL (short form, localhost default)
duckdb -c "ATTACH 'quack:localhost' AS qk (TOKEN 'BAED...'); CONNECT qk; SELECT * FROM t"

# Explicit ip:port form (for remote or non-default port)
duckdb -c "ATTACH 'quack:127.0.0.1:9494' AS qk (TOKEN 'BAED...'); CONNECT qk; SELECT * FROM t"

# Plain-HTTP remote server
duckdb -c "ATTACH 'quack:192.0.2.10:9494' AS qk (TOKEN 'BAED...', DISABLE_SSL true); CONNECT qk; SELECT * FROM t"

The -connect flag auto-discovers the token from the server’s output. For manual connections, copy the token from the server’s startup message.

While a CONNECT is active, unqualified SQL — including read_csv / read_parquet with local paths — executes on the server, so files on the client are not visible. Run DISCONNECT to return to the local database, or skip CONNECT and use qk.<table> qualified names to mix local and remote queries in one session.

Serving S3/OSS data to remote clients

A common deployment keeps the data files in object storage (AWS S3, Alibaba Cloud OSS, MinIO, …) and runs only the Quack server on the ECS instance. The server reads the files through httpfs, so remote clients need neither S3 credentials nor a route to the bucket — they only query the server.

On the server, configure the S3 secret and expose a view, then start Quack in the same session (the view resolves at query time):

CREATE SECRET (
  TYPE S3,
  ENDPOINT 'oss-cn-hangzhou.aliyuncs.com',  -- omit for AWS S3; use REGION instead
  KEY_ID '...',
  SECRET '...',
  USE_SSL true,
  URL_STYLE 'vhost'                         -- MinIO/silo/rustfs need 'path'
);

CREATE VIEW events AS
  SELECT * FROM read_parquet('s3://my-bucket/events/*.parquet');

CALL quack_serve(
  listen_uri = 'quack:0.0.0.0:9494',
  allow_other_hostname = true,
  token = 'my_token',
  ssl_cert_file = '/etc/duckdb/server.crt',  -- omit to use a generated cert
  ssl_key_file  = '/etc/duckdb/server.key'
);

If the server is launched non-interactively, keep stdin open:

( cat server.sql; tail -f /dev/null ) | duckdb

Managing the server with pg daemon

For a long-running server, let pg daemon own the process: it detaches it from the terminal, redirects output to a log, and can start it at boot. DuckDB still needs stdin to stay open, so wrap it in a small script that feeds the SQL and then blocks:

cat > /srv/duckdb/quack-serve.sh <<'SH'
#!/bin/bash
{
  cat /srv/duckdb/server.sql
  exec tail -f /dev/null
} | duckdb
SH
chmod +x /srv/duckdb/quack-serve.sh

pg daemon add duckdb-serve --dir /srv/duckdb -- /bin/bash /srv/duckdb/quack-serve.sh
pg daemon start duckdb-serve
pg daemon status duckdb-serve
pg daemon logs duckdb-serve
pg daemon restart duckdb-serve
pg daemon stop duckdb-serve

pg daemon runs the wrapper in its own session/process group; stop signals the whole group, so the wrapper, tail and duckdb terminate together. Logs default to <base>/daemon/duckdb-serve/daemon.log.

To start the server at boot:

pg autostart enable --daemon --name duckdb-serve

Daemons start after instances and addons, so a same-host MinIO/silo/rustfs is already listening when Quack starts. Use persistent paths for server.sql and the wrapper (not /tmp) when enabling autostart.

Connect from the local machine. With TLS (recommended) no DISABLE_SSL is needed:

duckdb -c "ATTACH 'quack:ecs.example.com:9494' AS qk (TOKEN 'my_token'); CONNECT qk; SELECT count(*) FROM events"

Without CONNECT, qualify the view (SELECT count(*) FROM qk.events); an unqualified name is resolved in the local catalog and will not find the server-side view. The read_parquet itself always runs on the server, and only the server needs the S3 secret.

For a plain-HTTP test server add DISABLE_SSL true on the client, as shown above, and add the server host to NO_PROXY when the client uses an HTTP proxy.

The same pattern was tested end to end with MinIO as the object store: a 100,000-row Parquet file at s3://ducktest/events/events.parquet was exposed as a server-side view, and a remote client returned the same row count and sum via both ATTACH … CONNECT and quack_query().

  • The S3 secret stays in the serving session (or ~/.duckdbrc); clients never need it.
  • The token grants server-side SQL execution, not just access to the exposed view: a client can query any S3 object reachable with the server’s credentials, and any local file the server process can read. Use a dedicated, least-privilege S3 key and keep the Quack port private.
  • Keep the Quack port private (security group/firewall). Token auth does not replace network isolation.

Analyzing other files on the server

The view is only one entry point. Any SQL executed on the server can read other objects with the server’s S3 credentials, or files on the server’s filesystem. Use quack_query for one-off analysis without attaching:

-- Aggregate a CSV that is not part of any view
FROM quack_query(
  'quack:ecs.example.com:9494',
  'SELECT count(*) AS n, round(avg(score), 1) AS avg_score
     FROM read_csv_auto(''s3://my-bucket/csv/users.csv'', header = true)',
  token = 'my_token'
);

-- Join two object prefixes entirely on the server
FROM quack_query(
  'quack:ecs.example.com:9494',
  'SELECT count(*) FROM read_parquet(''s3://my-bucket/a/*.parquet'') a
     JOIN read_parquet(''s3://my-bucket/b/*.parquet'') b USING (id)',
  token = 'my_token'
);

With an attachment, route the session with CONNECT and run plain SQL, or stay local and use the attached query macro:

ATTACH 'quack:ecs.example.com:9494' AS qk (TOKEN 'my_token');

CONNECT qk;
SELECT count(*) FROM read_parquet('s3://my-bucket/other/*.parquet');

-- Equivalent without CONNECT: the SQL string runs on the server
SELECT * FROM qk.query(
  'SELECT count(*) FROM read_parquet(''s3://my-bucket/other/*.parquet'')'
);

These examples assume HTTPS. For a plain-HTTP server add disable_ssl = true to quack_query or DISABLE_SSL true to ATTACH. Statements that execute locally use the client’s own credentials — a local read_parquet on s3://... fails without a client-side S3 secret.

Calling over the HTTP API

Quack is an HTTP RPC protocol: clients POST to /quack with Authorization: Bearer <token> and Content-Type: application/vnd.duckdb. Request and response bodies use DuckDB’s internal binary serialization (the same format as the WAL), not JSON, so hand-written HTTP requests can check the service but cannot easily run SQL.

# Protocol hint / liveness
curl http://192.0.2.10:9494/

# CORS preflight
curl -i -X OPTIONS http://192.0.2.10:9494/quack    # 204

There is no JSON/REST endpoint: a JSON body posted to /quack is treated as a binary protocol frame and fails to deserialize. To run SQL over HTTP from another language, use a DuckDB client library and quack_query (or quack_query_by_name on an attached catalog), or put your own JSON service in front of DuckDB.

For an API-style call without ATTACH, use the stateless quack_query function — one request/response per query:

FROM quack_query(
  'quack:192.0.2.10:9494',
  'SELECT count(*) AS rows FROM events',
  token = 'mytoken',
  disable_ssl = true          -- omit for HTTPS servers
);

Any DuckDB client (CLI, Python, …) can execute this SQL. quack_query is the practical HTTP API surface; for a long-lived session use ATTACH + CONNECT.

Python example

The Python client uses the same SQL surface; duckdb must be v2.0.0 or newer. A 1.x package does not speak Quack. Install it with uv:

# Recommended: project virtualenv
uv venv .venv
source .venv/bin/activate
uv pip install 'duckdb>=2.0.0'

# Isolated target dir (does not touch the current environment)
uv pip install --target /tmp/duckpkg 'duckdb==2.0.0'
PYTHONPATH=/tmp/duckpkg python3 quack_demo.py

# One-off run without a persistent install
uv run --with 'duckdb>=2.0.0' python3 quack_demo.py
import os
os.environ["NO_PROXY"] = "ecs.example.com"   # plain-HTTP server behind a proxy

import duckdb

con = duckdb.connect()

rows = con.execute("""
    FROM quack_query(
        'quack:ecs.example.com:9494',
        'SELECT count(*) AS rows, sum(amount)::BIGINT AS total FROM events',
        token = 'my_token',
        disable_ssl = true
    )
""").fetchall()
print(rows)

# Attach once, query the exposed view with a qualified name
con.execute("ATTACH 'quack:ecs.example.com:9494' AS qk (TOKEN 'my_token', DISABLE_SSL true)")
print(con.execute("SELECT count(*) FROM qk.events").fetchall())

# Stay local and run arbitrary SQL on the server via the query macro
print(con.execute("""
    SELECT * FROM qk.query(
        'SELECT count(*) FROM read_parquet(''s3://my-bucket/other/*.parquet'')'
    )
""").fetchall())

fetchdf() requires pandas; fetchall() works without it. Set NO_PROXY before importing DuckDB when the server is plain HTTP and the environment has an HTTP proxy configured.

Key points

  • stdin must stay open: the server exits when stdin closes (use < /dev/zero or tail -f /dev/null | for background operation, or manage it with pg daemon)
  • localhost by default: bind to 0.0.0.0 with allow_other_hostname=true for remote access; prefer a TLS-terminating reverse proxy or disable_ssl=false
  • Auth token: auto-generated, printed at startup, required for client connections
  • Not managed by pgcli: pg addon start/stop duckdb remain no-ops — the Quack server is a standalone process you manage yourself
  • HTTP proxies: the client honors HTTP_PROXY/HTTPS_PROXY. A plain-HTTP connection to a private host can be swallowed by a proxy and reported as Unauthorized; add the host to NO_PROXY (e.g. NO_PROXY=192.0.2.10)

Extensions

DuckDB’s extension system installs shared libraries on first use. pgcli pre-installs httpfs at install time — it enables reading files over HTTP/S3. parquet and json are statically linked into the DuckDB CLI binary, so they are always available without a network download.

  • httpfs — read files over HTTP/S3 (read_parquet('s3://...'))
  • parquet — Parquet file reader/writer (bundled)
  • json — JSON file reader (read_json_auto(...)) (bundled)

Additional extensions can be installed later from the DuckDB shell:

INSTALL 'spatial';       -- geospatial functions
INSTALL 'sqlite';        -- read/write SQLite databases
INSTALL 'mysql';         -- query MySQL directly
LOAD 'httpfs';           -- load an installed extension in the current session

Pass --no-extensions at install time if you prefer to manage extensions manually, or if the host has no internet access at install time.

Accessing S3, Parquet, JSON and CSV data

DuckDB is built for analytical queries over files — no server, no COPY, no import step. Point it at your data.

Parquet files

-- Single file
SELECT * FROM read_parquet('/tmp/events.parquet');

-- Wildcard: all parquet files in a directory
SELECT * FROM read_parquet('/data/logs/*.parquet');

-- Schema inference + count
SELECT count(*) FROM read_parquet('s3://bucket/year=2026/*.parquet');

-- Specific columns + filter
SELECT user_id, event, ts
FROM read_parquet('/data/events.parquet')
WHERE ts > '2026-01-01'
LIMIT 100;

JSON files

-- Auto-detect schema (handles JSON lines and nested JSON)
SELECT * FROM read_json_auto('/tmp/users.json');

-- Explicit schema with read_json
SELECT * FROM read_json('/tmp/users.json',
    columns = {'id': 'INTEGER', 'name': 'VARCHAR', 'email': 'VARCHAR'},
    format = 'newline_delimited');

-- Nested objects: extract fields with ->>
SELECT
    data->>'user_id' AS user_id,
    data->>'event'   AS event
FROM read_json_auto('/tmp/events.jsonl');

CSV files

-- Auto-detect header and types
SELECT * FROM read_csv_auto('/tmp/sales.csv');

-- Explicit column types (when auto-detection guesses wrong)
SELECT * FROM read_csv('/tmp/sales.csv',
    columns = {'id': 'INTEGER', 'amount': 'DOUBLE', 'date': 'DATE'},
    header = true);

-- TSV or custom delimiter
SELECT * FROM read_csv_auto('/tmp/data.tsv', delim = '\t');

S3 access (httpfs extension)

The httpfs extension enables S3 access. Credentials and endpoint are configured via CREATE SECRET (v2.0.0+) or legacy SET commands (v1.5.x).

DuckDB v2.0.0+ — CREATE SECRET

-- Configure S3 credentials (v2.0.0+ syntax)
CREATE SECRET (
  TYPE S3,
  ENDPOINT 'minio.example.com:9000',
  KEY_ID 'admin',
  SECRET 'your-secret-key',
  USE_SSL false,
  URL_STYLE 'path'   -- required for MinIO and compatible stores
);

-- Query Parquet directly from S3
SELECT count(*) FROM read_parquet('s3://my-bucket/events/2026/*.parquet');

-- Query CSV from S3
SELECT * FROM read_csv_auto('s3://my-bucket/users.csv') LIMIT 10;

-- Query JSON from S3
SELECT * FROM read_json_auto('s3://my-bucket/config.json');

-- Write Parquet back to S3 (needs write permissions on the bucket)
COPY (SELECT * FROM read_parquet('/tmp/*.parquet') WHERE year = 2026)
  TO 's3://output-bucket/filtered/2026.parquet' (FORMAT parquet);

DuckDB v1.5.x — legacy SET commands

-- Configure S3 credentials in the DuckDB session (v1.5.x only)
SET s3_endpoint = 'minio.example.com:9000';
SET s3_access_key_id = 'admin';
SET s3_secret_access_key = 'your-secret-key';
SET s3_use_ssl = false;   -- true for https endpoints
SET s3_region = 'us-east-1';   -- 'us-east-1' works for MinIO (region is ignored)
SET s3_url_style = 'path';   -- MinIO and compatible stores use path-style

Connecting to pgcli-managed S3 stores

pgcli manages several S3-compatible stores (MinIO, silo, rustfs, garage, seaweedfs). DuckDB queries them directly — the s3_endpoint is the store’s HTTP address, and credentials come from pg addon password.

First, create an S3 store instance and a bucket. The setup is identical across MinIO, silo (Pigsty’s MinIO fork), and rustfs (Rust reimplementation) — they all share the same pg mc wrapper and the same DuckDB s3_url_style = 'path':

# MinIO
pg addon install minio --name ms3
S3_SECRET=$(pg addon password minio --name ms3)

# or silo (same API surface, shares the port pool with minio)
pg addon install silo --name ms3
S3_SECRET=$(pg addon password silo --name ms3)

# or rustfs (Rust S3-compatible store, Linux only)
pg addon install rustfs --name ms3
S3_SECRET=$(pg addon password rustfs --name ms3)

# Create a bucket via the pg mc wrapper
pg mc alias set ms3 http://127.0.0.1:9000 admin "${S3_SECRET}"
pg mc mb ms3/my-bucket

# Upload test data (optional)
pg mc cp /tmp/data.parquet ms3/my-bucket/data.parquet

Then query it from DuckDB — note URL_STYLE 'path' is required for MinIO, silo, rustfs and compatible stores (they do not support virtual-host style):

# DuckDB v2.0.0+
duckdb -c "
  CREATE SECRET (
    TYPE S3,
    ENDPOINT '127.0.0.1:9000',
    KEY_ID 'admin',
    SECRET '${S3_SECRET}',
    USE_SSL false,
    URL_STYLE 'path'
  );
  SELECT count(*) FROM read_parquet('s3://my-bucket/data/*.parquet');
"

# DuckDB v1.5.x (legacy SET syntax)
duckdb -c "
  SET s3_endpoint = '127.0.0.1:9000';
  SET s3_access_key_id = 'admin';
  SET s3_secret_access_key = '${S3_SECRET}';
  SET s3_use_ssl = false;
  SET s3_url_style = 'path';
  SELECT count(*) FROM read_parquet('s3://my-bucket/data/*.parquet');
"

For a more permanent setup, create a DuckDB startup file (~/.duckdbrc) with the CREATE SECRET (v2.0.0+) or SET (v1.5.x) commands — they run on every session start:

-- ~/.duckdbrc (DuckDB v2.0.0+)
CREATE SECRET (
  TYPE S3,
  ENDPOINT 'minio.example.com:9000',
  KEY_ID 'admin',
  SECRET 'your-secret-key',
  USE_SSL false,
  URL_STYLE 'path'
);

Environment variables for S3

DuckDB reads endpoint and SSL settings from DUCKDB_S3_* environment variables, but credentials must use standard AWS variables (AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY) — DuckDB’s enable_global_s3_configuration auto-detects these.

v2.0.0 limitation: URL_STYLE cannot be set via environment variables. It defaults to virtual-host, which breaks MinIO/silo/rustfs (they require path-style). For these stores, use CREATE SECRET with URL_STYLE 'path' instead of env vars.

# Endpoint and SSL via DUCKDB_S3_*
export DUCKDB_S3_ENDPOINT='127.0.0.1:9000'
export DUCKDB_S3_USE_SSL='false'

# Credentials via AWS_* (standard variables, auto-detected by DuckDB)
export AWS_ACCESS_KEY_ID='admin'
export AWS_SECRET_ACCESS_KEY='your-secret-key'

# URL style must still be set in the session or startup file (v1.5.x)
duckdb -c "SET s3_url_style = 'path'; SELECT * FROM read_parquet('s3://my-bucket/data.parquet');"

# For v2.0.0, URL_STYLE must be set via CREATE SECRET — env vars alone are insufficient
# for MinIO/silo/rustfs (virtual-host style is not supported by these stores)
duckdb -c "
  CREATE SECRET (TYPE S3, ENDPOINT '127.0.0.1:9000', KEY_ID 'admin',
    SECRET 'your-secret-key', USE_SSL false, URL_STYLE 'path');
  SELECT * FROM read_parquet('s3://my-bucket/data.parquet');
"

For MinIO/silo/rustfs, you still need s3_url_style = 'path' because these stores don’t support virtual-host style URLs.

30 - Node_exporter

Run node_exporter, the official Prometheus host-metrics exporter, as a managed container.

pg addon install nodeexporter runs node_exporter — the official Prometheus exporter that publishes the host’s CPU, memory, disk, network and filesystem metrics at /metrics — as a managed container from the official docker.io/prom/node-exporter image. Like Prometheus, VictoriaMetrics and Grafana it is a top-level addon: it describes the machine, not one PostgreSQL instance, so it is attached to none of them. It is the natural companion to a pgcli Prometheus addon — node_exporter exposes, Prometheus scrapes.

node_exporter shares VictoriaMetrics’s shape — single container, no config file (everything is CLI flags after the image name), no hot reload, no authentication — but it has one requirement no other web addon does, described below.

The non-negotiable: host mounts. A container reading its own /proc reports the CONTAINER’s metrics, not the host’s. To export the machine, pgcli hard-wires three read-only bind mounts — host /proc → /host/proc, /sys → /host/sys, / → /rootfs — and points the binary at them with --path.procfs / --path.sysfs / --path.rootfs. These are fixed in pgcli, not user-configurable; without them the addon would silently export the wrong numbers. They are mounted :ro only (never :z), so pgcli never relabels the host root filesystem.

There is NO login/password and no TLS. node_exporter just serves /metrics in plain text. Because Prometheus scraping it is usually on a different host, Listen defaults to 0.0.0.0 — anyone who can reach the port can read detailed host facts (hardware, mounts, network). Restrict it to your monitoring network, or pass --listen 127.0.0.1 for a same-host Prometheus.

Platform: Linux is the tested platform (the container uses host networking, so the exporter binds the host port directly). The design supports macOS (bridge + published port), but it has not been validated there yet.

Parameters

Flag Default Description
--name nodeexporter Instance name (map key)
--image docker.io/prom/node-exporter:v1.12.1 Image override
--port auto (base 9100) Host port; auto-allocated from nodeexporter_start_port
--listen 0.0.0.0 Bind address — every interface by default (cross-host Prometheus); use 127.0.0.1 for loopback-only
--extra-arg — Extra CLI flag passed to the binary (repeatable); appended last so last-wins overrides earlier flags. E.g. --extra-arg --no-collector.cpufreq
--force false Recreate even when running — to apply changed ports / listen / extra-args

node_exporter is stateless — it stores nothing, so there is no data directory. pg addon remove deletes only the container; reinstalling always starts fresh.

Install

pg addon install nodeexporter

The command pulls the image if needed, creates the container with the three host mounts, and prints the scrape URL:

✓ node_exporter installed: "nodeexporter"
  Container:  pgcli-nodeexporter-default-nodeexporter
  Image:      docker.io/prom/node-exporter:v1.12.1
  Metrics:    http://0.0.0.0:9100/metrics
  Host mounts: /proc, /sys, / (read-only) → /host/proc, /host/sys, /rootfs

Because the default bind is 0.0.0.0, the summary also prints an exposure warning and the matching Prometheus command. Verify the exporter serves real host numbers:

curl -s http://127.0.0.1:9100/metrics | grep -E '^node_(memory_MemAvailable_bytes|load1|cpu_seconds_total)'

The values should track the host (free -b, cat /proc/loadavg) — if they track the container instead, a mount is missing (they cannot be, via pgcli, but a hand-run node_exporter often gets this wrong).

Wire it into Prometheus

The exporter is only useful once something scrapes it. A pgcli Prometheus instance does, via a one-line --scrape job (no service discovery, no Prometheus config edits):

pg addon install prometheus --name p1 --scrape node-exporter=127.0.0.1:9100
# remote Prometheus → use the host's LAN address instead of 127.0.0.1:
pg addon install prometheus --name p1 --scrape node-exporter=<host-ip>:9100

To add this exporter to a pgcli Prometheus that is already running and already scraping other jobs, use --scrape-append instead — it folds the node-exporter job into the stored scrape list (merging same-named jobs, appending unseen ones) and SIGHUP-reloads, so it never wipes the existing targets:

pg addon install prometheus --name p1 --scrape-append node-exporter=127.0.0.1:9100

(A plain --scrape replaces the whole job set, so re-running install with it would drop any other jobs p1 was scraping.) Then in Prometheus, up{job="node-exporter"} is 1 and count(node_cpu_seconds_total) is large. See the Prometheus addon for the full --scrape / --scrape-append mechanics.

Re-running install on a running instance recreates it when the config changed (port, listen, extra-args), and leaves it alone otherwise; --force recreates even when unchanged. node_exporter has no SIGHUP reload, so every change requires container recreation.

Custom flags (--extra-arg)

node_exporter has dozens of collector flags. Toggle individual collectors off/on, or add --collector.*/--no-collector.* switches, via --extra-arg (repeatable):

pg addon install nodeexporter --extra-arg --no-collector.cpufreq \
                              --extra-arg --collector.netdev.device-exclude='^veth.*'

Extra args are appended last to the command line, so they override pgcli’s injected defaults via last-wins (including pgcli’s own --collector.filesystem.mount-points-exclude, which drops the pseudo-filesystems pgcli just mounted so node_filesystem_* isn’t all noise). There is no config file to edit.

Listening and exposure

Listen defaults to 0.0.0.0: on Linux the container shares the host network namespace, so /metrics is reachable on every interface at the assigned port. This is deliberate — a Prometheus scraping node_exporter is usually on another machine. But there is no authentication, and node_exporter exposes fine-grained host detail (mount table, network interfaces, hardware). For a same-host Prometheus, pass --listen 127.0.0.1 (recreate with --force); otherwise restrict the port at the firewall. (Under the macOS bridge build, pgcli widens the bind to 0.0.0.0 automatically so the published port stays reachable through the podman VM.)

Ports

Each node_exporter instance owns a single port — the metrics endpoint — allocated from a pool with base nodeexporter_start_port (default 9100, node_exporter’s conventional port), incrementing for each additional instance and skipping ports taken by any managed container or used_ports. The allocation is saved to pg.yaml, so a reinstall never re-hands-out a port another addon holds. 9100 shares no number with Prometheus (9090), VictoriaMetrics (8428), Grafana (3000), Alertmanager (9093), or nginx (8080); an explicit --port still wins.

pg addon install nodeexporter --name ne2            # second instance: next free port (9101)
pg addon install nodeexporter --name ne3 --port 9200  # explicit port takes precedence

Configuration

addons:
  nodeexporter:
    nodeexporter:
      name: nodeexporter
      image_tag: docker.io/prom/node-exporter:v1.12.1
      host_port: 9100
      listen: 0.0.0.0
      extra_args:
        - --no-collector.cpufreq
      autostart: false

There is no config file — everything is passed as CLI flags to the node_exporter binary, and the three host mounts are fixed by pgcli. extra_args is a list of flags appended last.

List

pg addon list
Web add-ons (nodeexporter):
  nodeexporter (name: nodeexporter)
    Status:      running
    Metrics:     http://0.0.0.0:9100/metrics
    Extra args:  --no-collector.cpufreq
    Image:       docker.io/prom/node-exporter:v1.12.1
    Container:   pgcli-nodeexporter-default-nodeexporter

There are no credentials to reveal — node_exporter has none.

Start and stop

Containers run with podman’s unless-stopped restart policy, so they come back with podman after a host reboot. start/stop manage them explicitly:

pg addon stop nodeexporter
pg addon start nodeexporter

Auto-start on Boot

To bring a node_exporter instance up on host boot:

pg autostart enable --nodeexporter --name nodeexporter

This flags the instance in pg.yaml and installs/refreshes a boot service (a systemd --user unit on Linux, a LaunchAgent on macOS) that runs pg start --autostart. A boot-time start only brings the container up — node_exporter is stateless, so there is nothing to prepare. See Autostart for the full mechanism, status and disabling.

Remove

pg addon remove nodeexporter   # deletes the container; there is no data to clean

node_exporter keeps nothing on disk, so --clean-data has no effect beyond an informational note.

Logs

pg logs addon nodeexporter            # show recent console output
pg logs addon nodeexporter -f         # follow
pg logs addon nodeexporter -n 200     # last 200 lines (also -i / --tail)

Troubleshooting

  • Metrics look like the container’s, not the host’s — not possible via pg addon install (the mounts are hard-wired), but if you ever run node_exporter by hand you must pass the /proc//sys// read-only mounts and the matching --path.* flags. Confirm with curl -s …/metrics | grep node_uname_info and compare node_memory_MemAvailable_bytes to the host free -b.
  • Prometheus shows the target DOWN — check the exporter is running (pg addon list), that the scrape target address/port match (--scrape node-exporter=<host>:<port>), and that a loopback --listen 127.0.0.1 exporter isn’t being scraped from another host.
  • A collector flag didn’t take effect — --extra-arg is applied at container creation. Reinstall with --force to recreate, then check pg logs addon nodeexporter for the flag on the startup line.
  • Port already allocated — the assigned port is held in pg.yaml and skipped for later instances; free it with pg addon remove first, or pick another with --port N.

Known limitations

  • No authentication, no TLS. node_exporter serves plain-text /metrics; the only protection for a 0.0.0.0 bind is the network boundary. Front with nginx or restrict by firewall if it must leave a trusted network.
  • Stateless — no data dir, no retention; nothing survives beyond the running process. Reinstall always starts fresh.
  • Rootful assumption. The -v /:/rootfs:ro mount reads the whole host tree; under rootless podman some host paths may be unreadable. All target VMs run rootful podman, matching the rest of pgcli.
  • pgcli does not validate --extra-arg values; a bad flag surfaces only in the container logs on startup.
  • On macOS the container runs inside the podman machine with the port published; validated on Linux only.

31 - InfluxDB

Run InfluxDB 1.x as a managed addon container, with authentication, config overrides, backups and a passthrough influx CLI for local or remote servers

pg addon install influxdb runs InfluxDB 1.13.1 OSS — a single-node time-series database with TSM storage and InfluxQL — as a managed container from pgcli’s own ghcr.io/mars-base/pgcli/pgcli-influxdb image (the official linux/amd64 release binaries on Alpine). Like VictoriaMetrics, it is a top-level addon: it does not front a PostgreSQL instance.

The addon is Linux/amd64 only (the image is single-arch). InfluxDB 1.x has no clustering/HA, no built-in web UI, and upstream has put v1 into maintenance mode; pgcli pins the final 1.13.1 release. For new deployments consider VictoriaMetrics or VictoriaLogs if you need a maintained, auth-free-but-modern engine; InfluxDB 1.x remains a good fit when you need InfluxQL compatibility with existing tooling.

Authentication is always enabled. The install generates an admin password, stores it in pg.yaml, and pg addon password influxdb [--name NAME] prints it again. The HTTP API cannot be used anonymously. The backup/restore RPC port is loopback-only by design — upstream has no authentication for it, so pgcli never exposes it on the network regardless of --listen.

Parameters

Flag Default Description
--name influxdb Instance name (map key; default subcommand name is the same)
--version 1.13.1 Pinned image release (selects the published pgcli-influxdb tag)
--data-dir <base_dir>/addon/influxdb/<name>/data Data directory bind-mounted at /var/lib/influxdb; absolute or relative to base_dir
--listen 0.0.0.0 HTTP bind address. The RPC endpoint always stays on 127.0.0.1
--http-port auto (base 8086) Host HTTP port; auto-allocated from influxdb_start_port
--rpc-port auto (base 8088) Backup/restore RPC port, loopback only; each instance gets a unique port
--admin-user admin InfluxQL admin username (no web UI)
--admin-password generated Admin password. On --force the stored password is kept unless this is set
--config-option — Extra influxdb.conf setting as KEY=VALUE (top-level) or SECTION.KEY=VALUE (table), raw TOML value (repeatable). Replaces the stored override list and is persisted
--force false Rewrite the generated config and recreate the container, keeping data and the stored admin password

The generated config only overrides paths, listeners and auth; every other value is the upstream 1.13.1 default. The rendered file lives at <base_dir>/addon/influxdb/<name>/influxdb.conf and is mounted read-only. Overrides are stored both in pg.yaml and in that file so they survive restarts and a re-render.

Install

pg addon install influxdb --name metrics
✓ InfluxDB "metrics" installed
  Version:   1.13.1
  Image:     ghcr.io/mars-base/pgcli/pgcli-influxdb:1.13.1
  Container: pgcli-influxdb-metrics
  HTTP:      http://0.0.0.0:8086 (auth enabled)
  RPC:       127.0.0.1:8088 (backup/restore, loopback only)
  Admin:     admin
  Password:  <generated>
  Data dir:  /home/you/.pgcli/addon/influxdb/metrics/data
  Config:    /home/you/.pgcli/addon/influxdb/metrics/influxdb.conf

Second and later instances automatically take the next free HTTP/RPC ports from their pools (for example 8087/8089) and can point --data-dir anywhere:

pg addon install influxdb --name metrics2 --data-dir /srv/influx-data --listen 127.0.0.1

Re-running install without --force is a no-op that reports the current state. --force rewrites the config and recreates the container, but keeps the data dir and the stored admin password (the existing admin user would otherwise become unreachable); pass --config-option again to retain your overrides, because the flag replaces the stored list.

Credentials

pg addon password influxdb --name metrics   # print the admin password
pg addon list                               # shows both instances and state

The password is stored in pg.yaml (mode 0644 by default — protect that file). Commands that need credentials pass them to containers through the environment, never on the podman command line.

Config overrides

# Persist an override at install time
pg addon install influxdb --name metrics --config-option 'data.index-version="tsi1"'

# Change it on a live instance, applying immediately
pg addon influxdb config set --name metrics 'data.cache-max-memory-size=1000000000' --restart
pg addon influxdb config list --name metrics
pg addon influxdb config unset --name metrics data.cache-max-memory-size

config set/unset rewrites both the generated file and pg.yaml; --restart recreates the container so the change takes effect. Without --restart the new value applies at the next start. Values are raw TOML: quote strings ('data.index-version="tsi1"'), leave numbers bare.

The upstream default index is inmem. For high-cardinality series set data.index-version="tsi1" — it can only be changed on a fresh data dir, so decide before loading data.

The pg influx CLI

pg influx runs the influx client from the same image in a throwaway container — nothing is installed on the host and the container is removed after each command. Any flag pg’s own parser rejects goes after --; arguments are forwarded verbatim.

Local instance

pg influx --name metrics -- -execute "SHOW DATABASES"
pg influx --name metrics --database demo -- -execute "SELECT * FROM cpu LIMIT 5"
pg influx --name metrics                      # interactive shell

The host, port and credentials are injected automatically.

Remote InfluxDB 1.x

# host/port flags
pg influx --host db.example.com --username admin --ssl -- -execute "SHOW DATABASES"

# DSN (userinfo, database and TLS query options)
pg influx --dsn 'influxdb://admin:secret@db.example.com:8086/demo' -- -execute "SHOW MEASUREMENTS"
pg influx --dsn 'https://admin:secret@db.example.com:8086/demo?unsafe_ssl=true' -- -execute "SHOW DATABASES"

Credentials fall back to INFLUX_USERNAME / INFLUX_PASSWORD in both modes. Prefer the environment variables over --password, whose value is visible in the process list. --ssl enables HTTPS; --unsafe-ssl skips certificate verification and requires --ssl. --dsn already carries the connection settings and cannot be combined with --host/--port/--ssl/...; --name cannot be combined with any remote flag.

Import files in remote mode

pg influx --host db.example.com --database demo -- -import -path /tmp/demo.txt

The file named by -path is bind-mounted into the throwaway container at its absolute path, so exports produced by pg addon influxdb export (or influx_inspect export) import into remote servers too.

A # DML section with a # CONTEXT-DATABASE: marker is required; the # DDL section is optional. Include it when the target database may not exist — CREATE DATABASE is a no-op when it already does. The import target comes from the context marker, not from --database; importing into a missing database fails with database not found. A file without a # DML header is parsed as InfluxQL and fails with a syntax error.

/tmp/demo.txt is read on the machine running pg (it is bind-mounted into the container), not on db.example.com. A minimal file:

# DDL
CREATE DATABASE demo

# DML
# CONTEXT-DATABASE: demo
# CONTEXT-RETENTION-POLICY: autogen
cpu,host=server01,region=us-west value=0.64 1434055562000000000
cpu,host=server02,region=us-west value=0.55 1434055562000000001
mem,host=server01 used_percent=42.1,free=123456789i 1434055563000000000

The # DDL block runs as InfluxQL before the data (CREATE DATABASE is a no-op if the database exists). Everything after # DML is line protocol; timestamps are optional (default nanoseconds, -precision changes the interpretation). Add -pps N to throttle and -compressed if the file is gzip-compressed. When the remote server has authentication enabled, pass --username/--password or export INFLUX_USERNAME/INFLUX_PASSWORD.

Cross-host workflows

pg influx remote mode runs entirely from the client machine — it needs podman and the pgcli-influxdb image, but no local InfluxDB and no add-on instance.

# on any machine that can reach db.example.com
export INFLUX_USERNAME=admin
export INFLUX_PASSWORD=secret

pg influx --host db.example.com --database demo -- -execute "SHOW MEASUREMENTS"
pg influx --host db.example.com --database demo -- -execute "SELECT * FROM cpu LIMIT 10"
pg influx --host db.example.com -- -execute "CREATE DATABASE demo"
pg influx --host db.example.com -- -execute "CREATE RETENTION POLICY rp_30d ON demo DURATION 30d REPLICATION 1 DEFAULT"
pg influx --host db.example.com --database demo          # interactive shell

# HTTPS, and HTTPS with a self-signed certificate
pg influx --host influx.example.com --ssl --database demo -- -execute "SHOW MEASUREMENTS"
pg influx --host influx.example.com --ssl --unsafe-ssl --database demo -- -execute "SHOW MEASUREMENTS"

Add-on lifecycle and backup commands always act on the local podman instance, so they cannot reach a server on another host: pg addon influxdb status|backup|restore|export|import, pg addon start|stop|remove and pg logs addon influxdb must be run on the InfluxDB host itself — log in to that host and run them there. From other machines use pg influx --host/--dsn or the HTTP API (/query, /write) described below.

Move data between hosts with export + import:

# on the source host: offline export (the container is stopped for the duration)
pg addon influxdb export --name metrics --database demo
# transfer the file printed by the command (default under <instance dir>/exports/)
# to the target, then import it there

# logged in to the target host: import into the local instance
pg influx --name metrics --database demo -- -import -path /tmp/demo-export.txt

# or from any client that has the file: import into the remote server
pg influx --host target.example.com --database demo -- -import -path /tmp/demo-export.txt

Restores use the loopback-only RPC endpoint, so the backup directory must be present on the target host and restore run there:

# fresh target without a `demo` database: keep the original name
pg addon influxdb restore /tmp/influx-backup --name metrics --database demo

# if the target already has a `demo` database, `influxd restore` refuses to overwrite it;
# restore it under a new name instead
pg addon influxdb restore /tmp/influx-backup --name metrics --database demo --newdb demo_copy

Common operations

Databases

# pgcli convenience wrappers
pg addon influxdb database create demo --name metrics
pg addon influxdb database create demo --retention 30d --shard-duration 1d --rp rp_30d --name metrics
pg addon influxdb database list --name metrics
pg addon influxdb database drop demo --name metrics --yes   # --yes skips the confirmation

# the same via InfluxQL
pg influx --name metrics -- -execute "CREATE DATABASE demo"
pg influx --name metrics -- -execute "SHOW DATABASES"
pg influx --name metrics -- -execute "DROP DATABASE demo"

Retention policies

Every database has at least one retention policy — the default autogen never expires data. A retention policy controls how long data is kept and how it is sharded; expired shards are dropped automatically.

# pgcli convenience wrappers
pg addon influxdb retention list   --name metrics --database demo
pg addon influxdb retention create --name metrics --database demo --rp rp_7d --duration 7d --default
pg addon influxdb retention alter  --name metrics --database demo --rp rp_7d --duration 14d --default
pg addon influxdb retention drop   --name metrics --database demo --rp rp_7d --yes

Equivalent InfluxQL:

# create a 30-day policy (REPLICATION must be 1 in OSS)
pg influx --name metrics -- \
  -execute "CREATE RETENTION POLICY rp_30d ON demo DURATION 30d REPLICATION 1"

# same, and make it the default for writes/queries without an explicit RP
pg influx --name metrics -- \
  -execute "CREATE RETENTION POLICY rp_30d ON demo DURATION 30d REPLICATION 1 DEFAULT"

# create a new database with a bounded default RP in one statement
pg influx --name metrics -- \
  -execute "CREATE DATABASE demo WITH DURATION 30d REPLICATION 1 SHARD DURATION 1d NAME rp_30d"

# change duration / default later
pg influx --name metrics -- \
  -execute "ALTER RETENTION POLICY rp_30d ON demo DURATION 90d DEFAULT"

# list and drop
pg influx --name metrics -- -execute "SHOW RETENTION POLICIES ON demo"
pg influx --name metrics -- -execute "DROP RETENTION POLICY rp_30d ON demo"

# write to / query a non-default policy explicitly
pg influx --name metrics -- -execute "INSERT INTO demo.rp_30d cpu,host=server01 value=0.64"
pg influx --name metrics -- -execute "SELECT * FROM demo.rp_30d.cpu LIMIT 10"
  • DURATION accepts h, d, w and INF; the minimum is 1h. SHARD DURATION is optional — by default it is derived from DURATION.
  • Only one policy can be DEFAULT; making another one default demotes the previous one. Queries without an RP prefix use the default policy.
  • DROP RETENTION POLICY deletes its data. Expired shards are removed by the background retention check (every 30 minutes by default), so disk usage drops after the next check.

Interactive shell

pg influx --name metrics --database demo

Type InfluxQL directly (SHOW MEASUREMENTS, SELECT ..., use otherdb, …); exit or Ctrl-D leaves the shell. --database selects the initial database context.

Inspect the schema

# all measurements
pg influx --name metrics --database demo -- -execute "SHOW MEASUREMENTS"
# measurements matching a regex
pg influx --name metrics --database demo -- -execute "SHOW MEASUREMENTS WITH MEASUREMENT =~ /cpu.*/"
# field keys and their types
pg influx --name metrics --database demo -- -execute "SHOW FIELD KEYS FROM cpu"
# tag keys
pg influx --name metrics --database demo -- -execute "SHOW TAG KEYS FROM cpu"
# values of one tag
pg influx --name metrics --database demo -- -execute 'SHOW TAG VALUES FROM cpu WITH KEY = "host"'
# every series (measurement + tag set)
pg influx --name metrics --database demo -- -execute "SHOW SERIES FROM cpu"

InfluxQL quoting: double quotes delimit identifiers ("host", "cpu"), single quotes delimit string values ('server01'). If the query itself contains double quotes, wrap the whole -execute argument in single quotes as in the SHOW TAG VALUES example.

Query data

# newest 10 points, human-readable timestamps
pg influx --name metrics --database demo -- -precision rfc3339 \
  -execute "SELECT * FROM cpu ORDER BY time DESC LIMIT 10"

# last hour
pg influx --name metrics --database demo -- \
  -execute "SELECT * FROM cpu WHERE time > now() - 1h"

# 5-minute averages per host
pg influx --name metrics --database demo -- \
  -execute "SELECT mean(value) FROM cpu WHERE time > now() - 1h GROUP BY time(5m), host"

# row count
pg influx --name metrics --database demo -- -execute "SELECT COUNT(value) FROM cpu"

# JSON output for scripting
pg influx --name metrics --database demo -- -format json -pretty \
  -execute "SELECT * FROM cpu LIMIT 5"

Write and delete

# write a point (line protocol; timestamp optional — server time is used)
pg influx --name metrics --database demo -- \
  -execute "INSERT cpu,host=server01,region=us-west value=0.64"

# delete points older than 30 days (now() is supported)
pg influx --name metrics --database demo -- \
  -execute "DELETE FROM cpu WHERE time < now() - 30d"

# an unqualified DELETE affects every retention policy; prefix the policy to scope it
pg influx --name metrics --database demo -- \
  -execute "DELETE FROM autogen.cpu WHERE time < now() - 30d"

# drop a whole measurement / selected series
pg influx --name metrics --database demo -- -execute "DROP MEASUREMENT cpu"
pg influx --name metrics --database demo -- \
  -execute "DROP SERIES FROM cpu WHERE host = 'server01'"

For bulk writes use pg influx ... -- -import -path FILE — see Export and import.

Users and permissions

pg influx --name metrics -- -execute "SHOW USERS"
pg influx --name metrics -- -execute 'SHOW GRANTS FOR "admin"'
pg influx --name metrics -- -execute 'CREATE USER "readonly" WITH PASSWORD '\''change-me'\'''
pg influx --name metrics -- -execute 'GRANT READ ON demo TO "readonly"'
pg influx --name metrics -- -execute 'REVOKE ALL PRIVILEGES ON demo FROM "readonly"'
pg influx --name metrics -- -execute 'DROP USER "readonly"'

Avoid putting the admin password in argv (ps shows it); use the interactive shell, INFLUX_USERNAME/INFLUX_PASSWORD, or --password '' to be prompted.

Logs and status

pg addon influxdb status --name metrics        # state, endpoints, version, paths
pg logs addon influxdb --name metrics          # last 50 container log lines
pg logs addon influxdb --name metrics -n 200   # last 200 lines
pg logs addon influxdb --name metrics -f       # follow

HTTP API (URL operations)

The addon serves the stock InfluxDB 1.x HTTP API on <listen>:<http-port> with authentication always enabled (HTTP Basic). The same calls work locally (http://127.0.0.1:8086) and remotely (http://db.example.com:8086, or https://influx.example.com when nginx terminates TLS).

URL=http://db.example.com:8086
AUTH='admin:secret'     # prefer --netrc-file: a literal -u value is visible in ps

# health check — 204, no auth required
curl -i "$URL/ping"

# run InfluxQL (GET /query)
curl -s -G "$URL/query" \
  --data-urlencode 'db=demo' \
  --data-urlencode 'q=SHOW MEASUREMENTS' \
  -u "$AUTH"

# create a database and a retention policy
curl -s -XPOST "$URL/query" -u "$AUTH" \
  --data-urlencode 'q=CREATE DATABASE demo'
curl -s -XPOST "$URL/query" -u "$AUTH" \
  --data-urlencode 'q=CREATE RETENTION POLICY rp_30d ON demo DURATION 30d REPLICATION 1 DEFAULT'

# write one point (POST /write) — 204 on success
curl -s -o /dev/null -w '%{http_code}\n' -XPOST "$URL/write?db=demo&precision=s" -u "$AUTH" \
  --data-binary 'cpu,host=web01,region=us-east value=0.42 1793069000'

# write many points from a line-protocol file (one point per line)
curl -s -XPOST "$URL/write?db=demo" -u "$AUTH" --data-binary @points.txt

# query with pretty JSON (timestamps stay RFC3339 unless epoch= is given)
curl -s -G "$URL/query" -u "$AUTH" \
  --data-urlencode 'db=demo' \
  --data-urlencode 'q=SELECT * FROM cpu ORDER BY time DESC LIMIT 10' \
  --data-urlencode 'pretty=true'

# the same with Unix-second timestamps
curl -s -G "$URL/query" -u "$AUTH" \
  --data-urlencode 'db=demo' --data-urlencode 'epoch=s' \
  --data-urlencode 'q=SELECT * FROM cpu LIMIT 10'

# drop a database
curl -s -XPOST "$URL/query" -u "$AUTH" --data-urlencode 'q=DROP DATABASE demo'
Parameter Endpoint Meaning
db /query, /write Target database (required for most statements)
rp /query, /write Target retention policy (defaults to the database default)
q /query InfluxQL statement; URL-encode it (--data-urlencode does this)
pretty=true /query Indent the JSON response
epoch /query ns, u, ms, s, m, h; omit for RFC3339 timestamps
precision /write Timestamp precision of the supplied line protocol (ns by default)

Notes:

  • Unauthenticated requests return 401. A successful write returns 204; malformed points return 400 with a partial write message that names the dropped points.
  • curl -u user:pass exposes the password in the process list. Prefer a mode-0600 netrc file: machine db.example.com login admin password secret, then curl --netrc-file ~/.netrc-influx ....
  • For day-to-day local work pg influx is simpler and injects credentials through the environment; the HTTP API is the way to integrate from other machines, scripts and applications.

Backup and restore

Portable backups are online — the instance keeps running:

pg addon influxdb backup --name metrics                        # whole instance
pg addon influxdb backup --name metrics --database demo
pg addon influxdb backup --name metrics --since 2026-10-01T00:00:00Z
pg addon influxdb backup --name metrics --start 2026-10-01T00:00:00Z --end 2026-10-02T00:00:00Z

The default output dir is <instance dir>/backups/<UTC timestamp>; --out DIR overrides it. A backup directory contains .manifest, .meta and per-shard .tar.gz files.

⚠️ Store backups on remote S3. The backup is written on the InfluxDB host, so losing that host would lose the backup too. Upload each backup directory with any S3 client — for example the pg mc add-on:

pg mc alias set store https://s3.example.com ACCESS_KEY SECRET_KEY   # once
pg mc mb store/influxdb-backups
pg mc cp /path/to/backup-demo store/influxdb-backups/ -- --recursive

A restore reads the directory through the loopback RPC, so download it back to the target host before running pg addon influxdb restore.

Restores are online too (the helper talks to the running server over the loopback RPC; a stopped instance is started first). A complete backup → drop → restore cycle for one database:

# 1. back up the database before replacing it
pg addon influxdb backup --name metrics --database demo --out /path/to/backup-demo

# 2. drop the old database
pg addon influxdb database drop demo --name metrics --yes

# 3. restore it under the original name
pg addon influxdb restore /path/to/backup-demo --name metrics --database demo

influxd restore refuses to overwrite an existing database. To restore alongside the old one instead of replacing it, use a new name — --newdb requires --database:

pg addon influxdb restore /path/to/backup-demo --name metrics --database demo --newdb demo_copy

The instance is left running after the restore.

⚠️ A restore is not a complete identity/metadata copy. Users, privileges and continuous queries are not restored — recreate them manually after a restore. Retention policies and their durations are restored.

Export and import

export is offline: pgcli stops the container so influx_inspect reads consistent TSM files, then restarts it unless --no-start is given.

pg addon influxdb export --name metrics --database demo
pg addon influxdb export --name metrics --out /tmp/all.txt --compress --no-start
pg addon influxdb export --name metrics --start 2026-10-01T00:00:00Z --end 2026-10-02T00:00:00Z

The default file is <instance dir>/exports/<database|all>-<UTC timestamp>.txt (.gz with --compress).

⚠️ After an import you must recreate users, privileges and continuous queries, and recreate non-default retention policies with their real DURATION/SHARD DURATION. The export DDL emits RPs as DURATION 0s and omits the shard duration, so a 30d RP would become infinite unless fixed.

An export file is a logical data copy, not a full instance snapshot: it contains every data point (TSM plus WAL) with per-database/retention-policy context markers, plus CREATE DATABASE / CREATE RETENTION POLICY DDL. Without --database, all databases including _internal are exported. Use backup/restore for disaster recovery and export/import to move points between servers.

import needs a running instance and takes an export-format file:

pg addon influxdb database create demo_copy --name metrics
pg addon influxdb import /tmp/demo.txt --name metrics --database demo_copy
pg addon influxdb import /tmp/demo.txt --name metrics --precision ms

With --database, pgcli copies the file under the instance directory and rewrites the # CONTEXT-DATABASE: lines to the target database, so the original export is not modified. Importing into a remote server is done with pg influx --host ... -- -import -path FILE (above).

Unlike restore, import has no new-name restriction: it writes line-protocol points into the target and merges them with existing data (a point with the same series and timestamp overwrites the old one). The demo_copy above is only an example of importing into another database — importing into the original demo is fine. The target database must already exist (the file’s # DDL can create it) unless --database names a database you created first.

Lifecycle

pg addon start influxdb --name metrics     # starts the container
pg addon stop influxdb --name metrics
pg addon influxdb status --name metrics    # state, ping, endpoints, version
pg logs addon influxdb --name metrics -f   # container logs
pg addon remove influxdb --name metrics    # removes the container and pg.yaml entry, keeps data
pg addon remove influxdb --name metrics --clean-data   # also deletes the config/backups and data dir

Data and the generated config survive remove without --clean-data, so reinstalling under the same name revives the stored series. --clean-data also removes a custom --data-dir.

Auto-start after reboot:

pg autostart enable --influxdb --name metrics
pg autostart status
pg autostart disable --influxdb --name metrics

At boot pgcli starts the existing container; it does not re-run authentication bootstrap.

Production notes

  • No HTTPS listener. InfluxDB 1.x serves plain HTTP. Front it with the nginx addon if you need TLS, or bind --listen 127.0.0.1 and keep it local.
  • RPC is loopback-only. The backup/restore RPC protocol has no authentication; pgcli pins it to 127.0.0.1 and allocates one unique port per instance. Do not expose it.
  • No HA. InfluxDB 1.x OSS is single-node. Backups (backup / export) are the disaster-recovery path; there is no scheduled backup — wire pg addon influxdb backup into your own timer if needed.
  • v1 is in maintenance mode. The version is pinned to 1.13.1; upgrading means publishing a new image tag and re-testing. There is no in-place major upgrade path from v1 to v2/v3.
  • High cardinality: switch to data.index-version="tsi1" before loading data (above).
  • Platform: Linux/amd64 only — the image packages the official amd64 tarball.

CLI flag reference

A one-page lookup of every pgcli flag that applies to InfluxDB. InfluxDB’s own CLI flags go after -- and are forwarded verbatim (see influx -help).

pg addon install influxdb

Flag Default Description
--name NAME influxdb Instance name (map key); [A-Za-z0-9][A-Za-z0-9_-]*, max 48 chars
--version V 1.13.1 Pinned image release; only versions shipped as a pgcli image are accepted
--data-dir DIR <base_dir>/addon/influxdb/<name>/data Host dir bind-mounted at /var/lib/influxdb; absolute or relative to base_dir
--listen ADDR 0.0.0.0 HTTP bind address only; the RPC listener is always 127.0.0.1
--http-port N auto (base 8086) HTTP host port; 0 = auto-assign from influxdb_start_port
--rpc-port N auto (base 8088) Backup/restore RPC port, loopback only; 0 = auto-assign; must differ from --http-port
--admin-user USER admin InfluxQL admin username
--admin-password PW generated Admin password; on --force the stored value is kept unless supplied
--config-option K=V — Extra influxdb.conf entry: KEY=VALUE (top-level) or SECTION.KEY=VALUE (table), raw TOML; repeatable; replaces the stored override list
--force false Rewrite the generated config and recreate the container; keeps data and the stored password

--image does not apply to InfluxDB — use --version.

pg addon influxdb status

Argument/flag Default Description
--name NAME influxdb Instance to inspect

pg addon influxdb shell [-- influx args...]

Argument/flag Default Description
--name NAME influxdb Instance to connect to
--database DB — Adds -database DB
args after -- — Forwarded verbatim to the influx client (-execute, -format, …)

pg addon influxdb database create NAME / database list

Argument/flag Default Description
NAME — Database to create (positional, create only)
--name NAME influxdb Instance to operate on

pg addon influxdb backup

Flag Default Description
--name NAME influxdb Instance to back up (must be running)
--out DIR <instance dir>/backups/<UTC timestamp> Backup output directory
--database DB all Back up one database (-db)
--since RFC3339 — Back up data since this instant; cannot be combined with --start/--end
--start RFC3339 — Range start; requires --end
--end RFC3339 — Range end; requires --start

pg addon influxdb restore BACKUP_DIR

Argument/flag Default Description
BACKUP_DIR — Backup directory to restore (positional, required)
--name NAME influxdb Target instance (started first if stopped)
--database DB all Restore one database (-db)
--newdb NAME — Restore under a new database name (-newdb); requires --database

Restoring a database that already exists fails; use --newdb to restore alongside it.

pg addon influxdb export

Flag Default Description
--name NAME influxdb Instance to export (stopped for the duration)
--database DB all Export one database (-database)
--out FILE <instance dir>/exports/<database|all>-<UTC timestamp>.txt[.gz] Output file
--compress false Gzip the output (-compress)
--start RFC3339 — Range start; requires --end
--end RFC3339 — Range end; requires --start
--no-start false Leave the instance stopped afterwards

pg addon influxdb import FILE

Argument/flag Default Description
FILE — Export-format file to import (positional, required)
--name NAME influxdb Target instance (must be running)
--database DB file’s context Target database (-database); rewrites # CONTEXT-DATABASE: lines
--precision P — Timestamp precision (-precision): ns, u, ms, s, m, h

pg addon influxdb config list / set / unset

Argument/flag Default Description
KEY=VALUE... — Entries to set (positional, set only; one or more)
SECTION.KEY... — Entries to remove (positional, unset only; one or more)
--name NAME influxdb Instance to modify
--restart false Restart the container after rewriting the config (set/unset only)

pg influx

Flag Default Description
--name NAME influxdb Managed addon instance; conflicts with every remote flag
--database DB — Adds -database DB
--host HOST — Remote host; enables remote mode
--port N 8086 Remote HTTP port
--dsn URL — influxdb://user:pass@host:port/db or http(s)://...; exclusive with the other connection flags
--username USER $INFLUX_USERNAME Remote username
--password PW $INFLUX_PASSWORD Remote password (prefer the env var: ps shows argv)
--ssl false Use HTTPS (-ssl)
--unsafe-ssl false Skip TLS verification (-unsafeSsl); requires --ssl
args after -- — Forwarded verbatim to the influx client

Lifecycle, credentials, logs, autostart

Command Flags Description
pg addon start influxdb --name NAME (default influxdb) Start (create if missing) the container
pg addon stop influxdb --name NAME (default influxdb) Stop the container
pg addon remove influxdb --name NAME (default influxdb), --clean-data Remove the container and config entry; --clean-data also deletes the instance dir, backups and data dir
pg addon password influxdb --name NAME (default influxdb) Print the admin password
pg logs addon influxdb --name NAME (default influxdb), -n N (--tail, default 50), -f (--follow) Container logs
pg autostart enable|disable --influxdb, --name NAME (default influxdb) Toggle boot start for one instance

Global flags

Flag Description
-c, --config FILE Config file (default ~/.pgcli/pg.yaml)
-o, --output FILE Output config path (default the same file)
-i, --instance NAME PostgreSQL instance selector — not used by InfluxDB; use --name instead

Full influxdb.conf parameter reference

The generated config is minimal: pgcli renders only the keys below and leaves every other InfluxDB 1.13.1 default in place. The defaults in the tables are the effective values printed by influxd config (1.13.1).

pgcli-managed key Rendered value Why
reporting-disabled true Disables upstream usage reporting
bind-address (top level) "127.0.0.1:<rpc-port>" Backup/restore RPC; upstream has no auth for it, so it is never exposed
[meta] dir /var/lib/influxdb/meta Inside the data-dir bind mount
[data] dir /var/lib/influxdb/data Inside the data-dir bind mount
[data] wal-dir /var/lib/influxdb/wal Inside the data-dir bind mount
[http] bind-address <listen>:<http-port> Host networking: this is the actual host listener
[http] auth-enabled true Authentication is always on

These seven keys are rejected by --config-option / config set — change them through pg addon install / config flags instead. Everything else can be overridden.

How to override

# SECTION.KEY=VALUE for a table entry; KEY=VALUE for a top-level entry
pg addon influxdb config set --name metrics 'data.index-version="tsi1"' --restart
pg addon influxdb config set --name metrics 'http.max-row-limit=50000' --restart
pg addon influxdb config unset --name metrics data.index-version

Values are raw TOML — quote strings, durations and sizes ('cache-max-memory-size="2g"'), leave numbers/bools bare. Limitations:

  • Only single [section] tables are supported. The repeated [[graphite]], [[collectd]], [[opentsdb]] and [[udp]] listener tables cannot be expressed; neither can nested keys such as https-client-ca.paths or http.headers.
  • Such settings require editing <base_dir>/addon/influxdb/<name>/influxdb.conf directly and restarting the container (pg addon stop|start influxdb). Ordinary start/stop keeps the file; install --force and any config set/unset re-render it and will drop hand edits.
  • --config-option replaces the whole stored override list; re-pass all entries when changing one.

Top level

Key Default Description
reporting-disabled false pgcli renders true (managed)
bind-address "127.0.0.1:8088" RPC backup/restore listener (managed)
hardening-enabled false Restrict Flux HTTP requests to public addresses (SSRF hardening)

[meta]

Key Default Description
dir ~/.influxdb/meta (/var/lib/influxdb/meta in the container) Metadata/Raft database directory (managed)
retention-autocreate true Auto-create the autogen retention policy on CREATE DATABASE
logging-enabled true Log meta-service messages

[data]

Key Default Description
dir ~/.influxdb/data TSM storage directory (managed)
wal-dir ~/.influxdb/wal WAL directory (managed)
wal-fsync-delay "0s" Batch window before fsync; 0s fsyncs every write; 0–100ms helps non-SSD disks
index-version "inmem" Shard index: inmem (default) or tsi1 (high cardinality; only settable on a fresh data dir)
validate-keys false Reject keys with invalid UTF-8/unicode (small write overhead)
skip-field-size-validation false Skip the maximum field-size check on writes
strict-error-handling false Return errors instead of silently dropping invalid points (e.g. ±Inf in SELECT INTO)
query-log-enabled true Log queries before execution (may log sensitive data)
cache-max-memory-size "1g" Per-shard cache limit before writes are rejected
cache-snapshot-memory-size "25m" Cache size that triggers a snapshot to TSM
cache-snapshot-write-cold-duration "10m" Snapshot the cache after this long without writes/deletes
compact-full-write-cold-duration "4h" Full compaction after this long without writes/deletes
compact-throughput "48m" Compaction write rate limit (bytes/s)
compact-throughput-burst "48m" Allowed short burst above the compaction rate limit
aggressive-points-per-block 10000 Points per block for aggressive compaction
ingress-metric-by-measurement-enabled false Collect per-measurement write statistics
ingress-metric-by-login-enabled false Collect per-login write statistics
max-series-per-database 1000000 Series limit per database before writes are dropped (0 = unlimited)
max-values-per-tag 100000 Tag-value limit per tag (0 = unlimited)
max-concurrent-compactions 0 Concurrent full/level compactions; 0 = 50% of GOMAXPROCS
max-concurrent-optimized-compactions 0 Concurrent optimized compactions (0 = default)
max-index-log-file-size "1m" TSI index WAL threshold before compaction into an index file
max-concurrent-deletes 1 Simultaneous DELETE calls per shard
series-id-set-cache-size 100 TSI series-id-set cache entries (0 disables)
series-id-set-cache-max-size 0 Upper bound for adaptive cache growth (0 = adaptive sizing off)
series-id-set-cache-target-hit-rate 0.0 Target hit rate for adaptive sizing (0.0 = off, 1.0 invalid)
series-id-set-cache-shrink-conservatism 2.5 Shrink-policy margin in standard deviations
series-file-max-concurrent-snapshot-compactions 0 Concurrent series-file snapshot compactions (0 = default)
trace-logging-enabled false Verbose TSM engine trace logging
tsm-use-madv-willneed false Advise the kernel with MADV_WILLNEED for TSM files
tar-stream-buffer-size "1m" Buffer size for tar streaming during backup/rename/copy

[coordinator]

Key Default Description
write-timeout "10s" How long a write waits before returning a timeout
max-concurrent-queries 0 Concurrent query limit (0 = unlimited)
query-timeout "0s" Kill queries after this long (0s = no limit)
log-queries-after "0s" Slow-query logging threshold (0s = off)
log-timedout-queries false Log queries killed by query-timeout
max-select-point 0 Maximum points a SELECT may process (0 = unlimited)
max-select-series 0 Maximum series a SELECT may touch (0 = unlimited)
max-select-buckets 0 Maximum GROUP BY time() buckets (0 = unlimited)
termination-query-log false Print running queries on SIGTERM

[flux-controller]

Key Default Description
query-concurrency 0 Concurrent Flux queries (0 = default)
query-initial-memory-bytes "0" Initial memory budget per Flux query
query-max-memory-bytes "0" Maximum memory per Flux query
total-max-memory-bytes "0" Total memory for all Flux queries
query-queue-size 0 Flux query queue length

[retention]

Key Default Description
enabled true Enforce retention policies
check-interval "30m" How often retention enforcement runs

[shard-precreation]

Key Default Description
enabled true Pre-create shards before data arrives
check-interval "10m" How often pre-creation runs
advance-period "30m" How far ahead of a shard group’s end its successor is created

[monitor]

Key Default Description
store-enabled true Record internal statistics
store-database "_internal" Destination database
store-interval "10s" Recording interval

[http]

Key Default Description
enabled true Enable the HTTP API
bind-address ":8086" HTTP listener (managed: <listen>:<http-port>)
auth-enabled false Require authentication (managed: true)
realm "InfluxDB" Basic-auth challenge realm
log-enabled true HTTP request logging
suppress-write-log false Hide write requests from the HTTP log
access-log-path "" Access-log file; empty writes to stderr
access-log-status-filters [] Status filters (NNN, NNX, NXX); empty logs everything
write-tracing false Detailed write logging
flux-enabled false Enable the Flux query endpoint
flux-log-enabled false Log Flux queries
flux-testing false Expose Flux testing endpoints
pprof-enabled true Enable /debug/pprof
pprof-auth-enabled false Require admin auth for pprof
debug-pprof-enabled false Bind an extra pprof endpoint on localhost:6060 at startup
ping-auth-enabled false Require auth on /ping, /metrics, /status
prom-read-auth-enabled false Require auth on the Prometheus remote-read API
https-enabled false Serve HTTPS
https-certificate "/etc/ssl/influxdb.pem" TLS certificate (PEM)
https-private-key "" TLS private key; empty = combined with the certificate
https-insecure-certificate false Allow insecure certificate file permissions
https-ignore-sanity-checks false Load certificates that fail server-auth sanity checks
https-client-auth-type unset Mutual TLS client-auth mode (NoClientCert, RequestClientCert, RequireAnyClientCert, VerifyClientCertIfGiven, RequireAndVerifyClientCert)
https-client-ca unset Client CA bundle: { paths = [...], include-system = false }
shared-secret "" JWT validation secret
max-row-limit 0 Chunked-result row limit (0 = unlimited)
max-connection-limit 0 Concurrent HTTP connections (0 = unlimited)
unix-socket-enabled false Serve HTTP over a Unix socket
unix-socket-permissions "0777" Unix socket permissions
bind-socket "/var/run/influxdb.sock" Unix socket path
max-body-size 25000000 Maximum request body in bytes (0 = unlimited)
max-concurrent-write-limit 0 Concurrent writes (0 = unlimited)
max-enqueued-write-limit 0 Queued writes (0 = unlimited)
enqueued-write-timeout "30s" Maximum queue wait for a write
user-query-bytes-enabled false Track query response bytes per user
user-write-bytes-enabled false Track write request bytes per user
[http.headers] unset Arbitrary response headers, e.g. X-Header-1 = "value"

[logging]

Key Default Description
format "auto" Log encoder: auto, logfmt or json
level "info" Minimum level: error, warn, info, debug
suppress-logo false Suppress the startup logo

[subscriber]

Key Default Description
enabled true Enable subscriptions (fork every write to an endpoint)
http-timeout "30s" Subscriber write timeout
insecure-skip-verify false Skip TLS verification for subscribers
ca-certs "" PEM CA bundle path; empty uses the system roots
root-ca unset Extra subscriber CAs: { paths = [...], include-system = false }
certificate "" Client certificate presented to subscribers (mutual TLS)
private-key "" Key for certificate
insecure-certificate false Allow insecure certificate/key file permissions
ignore-cert-sanity-checks false Load certificates failing server-auth sanity checks
write-concurrency 40 Writer goroutines
write-buffer-size 1000 In-flight writes buffered in the channel
total-buffer-bytes "0" Total buffer budget (0 = unlimited)

Repeated listener tables

These are array-of-tables ([[graphite]], [[collectd]], [[opentsdb]], [[udp]]) and cannot be set with --config-option; edit the generated file directly if you need them. Each table starts disabled.

Section Key Default Description
[[graphite]] enabled false Enable the Graphite listener
bind-address ":2003" Listener address
database "graphite" Target database
retention-policy "" Target retention policy
protocol "tcp" tcp or udp
consistency-level "one" Write consistency level
batch-size 5000 Points buffered before flush
batch-pending 10 Pending batches
batch-timeout "1s" Maximum time before a flush
udp-read-buffer 0 UDP read buffer (0 = OS default)
separator "." Joins template measurement parts
tags [] Default tags, e.g. ["region=us-east"]
templates [] Template rules (one default)
[[collectd]] enabled false Enable the collectd listener
bind-address ":25826" Listener address
database "collectd" Target database
retention-policy "" Target retention policy
typesdb "/usr/share/collectd/types.db" Types DB file or directory
security-level "none" none, sign or encrypt
auth-file "/etc/collectd/auth_file" Auth file for signed/encrypted traffic
batch-size 5000 Points buffered before flush
batch-pending 10 Pending batches
batch-timeout "10s" Maximum time before a flush
read-buffer 0 UDP read buffer (0 = OS default)
parse-multivalue-plugin "split" split or join multi-value plugins
[[opentsdb]] enabled false Enable the OpenTSDB listener
bind-address ":4242" Listener address
database "opentsdb" Target database
retention-policy "" Target retention policy
consistency-level "one" Write consistency level
tls-enabled false Serve TLS
certificate "/etc/ssl/influxdb.pem" TLS certificate
private-key "" TLS key; empty = combined with the certificate
insecure-certificate false Allow insecure certificate file permissions
ignore-cert-sanity-checks false Load certificates failing sanity checks
client-auth-type unset Mutual TLS client-auth mode
client-ca unset Client CA bundle: { paths = [...], include-system = false }
log-point-errors true Log every malformed point
batch-size 1000 Points buffered before flush (telnet only)
batch-pending 5 Pending batches
batch-timeout "1s" Maximum time before a flush
[[udp]] enabled false Enable the line-protocol UDP listener
bind-address ":8089" Listener address
database "udp" Target database
retention-policy "" Target retention policy
precision "n" Input precision: "", n, u, ms, s, m, h
batch-size 5000 Points buffered before flush
batch-pending 10 Pending batches
batch-timeout "1s" Maximum time before a flush
read-buffer 0 UDP read buffer (0 = OS default)
writers 1 Parallel writers

[continuous_queries]

Key Default Description
enabled true Run continuous queries
log-enabled true Log CQ executions
query-stats-enabled false Write CQ stats to the monitoring store
run-interval "1s" How often CQs are checked

[tls]

Key Default Description
ciphers Go defaults Allowed cipher suites (Go names)
min-version Go default Minimum TLS version, e.g. "tls1.2"
max-version Go default Maximum TLS version, e.g. "tls1.3"

HTTPS on the addon: pgcli never enables [http] https-enabled. Use the nginx addon for TLS termination, or expose only loopback. The [tls] section only tunes cipher/version negotiation for listeners that are already TLS-enabled.

32 - Pg_exporter

Run pg_exporter, Pigsty’s declarative PostgreSQL metrics exporter, as a managed container — over pgcli instances or any remote PostgreSQL.

pg addon install pgexporter runs pg_exporter — Pigsty’s PostgreSQL metrics exporter — as a managed container from the official docker.io/pgsty/pg_exporter image. Where the node_exporter addon describes the machine, pg_exporter describes a database: it connects to a PostgreSQL server and publishes ~460 pg_* metrics (activity, locks, replication, bloat, WAL, per-database stats…) at /metrics. Like Prometheus, VictoriaMetrics, Grafana and node_exporter it is a top-level addon: it is attached to no instance of its own — instead it points at a target it monitors.

Its reason to exist alongside node_exporter is unified collection: the target can be a pgcli-managed instance or any reachable PostgreSQL server pgcli does not manage. That is the whole point — one exporter shape collects metrics from databases inside and outside pgcli alike.

Three target modes, mutually exclusive — pass exactly one. --pg-name <inst> monitors a pgcli-managed instance; its admin DSN is re-derived from pg.yaml on every start (so a rotated password or changed port never goes stale). For a server pgcli does not manage, the target is given as ONE URL — and which URL you pass decides whether pgcli touches the database:

  • --admin-dsn postgres://… — an admin-privileged URL. pgcli uses it once to create a low-privilege monitor role on the target, then discards it: only its credential-free address (host/port/database) is stored, and host/port/database for the exporter come from it. The exporter thereafter connects as the monitor role.
  • --dsn postgres://… — dial-as-is. The exporter connects with exactly this URL’s own credentials and pgcli runs no SQL on the target. Use it when a suitable role already exists, or when pgcli must not touch the database at all.

--dsn and --admin-dsn never appear together — there’s no second URL to give, because the target’s host/port/database come from whichever one you pass.

The exporter never dials as an admin in the local and --admin-dsn modes: pgcli creates the low-privilege monitor role (a pg_monitor member, CONNECTION LIMIT 5) and hands the container that role’s URL. To create it, pgcli needs admin rights once: for --pg-name the admin credentials are derived automatically; for --admin-dsn you supply an admin URL that runs the single CREATE ROLE/GRANT batch and is never stored in pg.yaml. The monitor password is generated and printed once unless you pin it with --monitor-password/--monitor-password-file; either way it is retrievable via pg addon password pgexporter. In the dial-as-is --dsn mode pgcli creates nothing — it is your job (or a prior --admin-dsn install) that the role already exists.

There is NO authentication and no TLS on the exporter endpoint, and pg_exporter also serves admin endpoints (/reload, /explain, /stat) on the same port — anyone who can reach it can scrape metrics and trigger reloads. Because a Prometheus scraping it is usually on another host, Listen defaults to 0.0.0.0; the only protection is the network boundary. Restrict it to your monitoring network, or --listen 127.0.0.1 for a same-host Prometheus.

Platform: Linux is the tested platform (host networking, so the exporter binds the host port directly and can dial a local instance’s 127.0.0.1 target). On macOS the container runs on the pgcli-net bridge and cannot reach a local instance’s 127.0.0.1 DSN — there, use --dsn pointed at a reachable address (the remote path works; the local path does not).

Parameters

Flag Default Description
--name pgexporter Instance name (map key)
--pg-name — Monitor a pgcli-managed instance by name (admin DSN re-derived each start; mutually exclusive with --dsn and --admin-dsn)
--admin-dsn — Remote, create-role mode: an admin-privileged URL for a server pgcli does not manage. Used once to create the monitor role, then discarded — only its credential-free address (host/port/database) is stored, and never in a form carrying the admin password. The exporter connects as the monitor role. Mutually exclusive with --dsn and --pg-name
--dsn — Remote, dial-as-is mode: the exporter connects with THIS URL’s own credentials and pgcli runs no SQL on the target — for a role that already exists or a database pgcli must not touch. Mutually exclusive with --admin-dsn and --pg-name
--monitor-user pgexporter Name of the low-privilege role pgcli creates (pg_monitor member; plain identifier only). Use a distinct value per instance when several exporters monitor the same target
--monitor-password generated Pin the monitor role’s password instead of generating one. Only valid with --pg-name/--admin-dsn (which run the role-setup SQL); the value is stored in pg.yaml and never echoed. Useful when several installs must share one credential, such as a primary and a standby’s --dsn exporter. Prefer --monitor-password-file so it stays out of argv/ps
--monitor-password-file — Read the pinned monitor password from FILE (a trailing newline is ignored); mutually exclusive with --monitor-password
--image docker.io/pgsty/pg_exporter:1.5.0 Image override
--port auto (base 9630) Host port; auto-allocated from pgexporter_start_port
--listen 0.0.0.0 Bind address — every interface by default (cross-host Prometheus); use 127.0.0.1 for loopback-only
--config-file — Path to a custom pg_exporter collector YAML, mounted read-only at /etc/pg_exporter.yml (the binary’s baked-in default set is used when unset)
--extra-arg — Extra CLI flag passed to the binary (repeatable); appended last so last-wins overrides earlier flags. E.g. --extra-arg --auto-discovery=false
--force false Recreate even when running — to apply changed port / listen / target / extra-args

pg_exporter is stateless — it stores nothing, so there is no data directory. pg addon remove deletes only the container (the monitor role on the target is kept, since it may be shared or hand-managed); reinstalling always starts fresh.

Install

Monitor a pgcli-managed instance (the monitor role is created automatically):

pg addon install pgexporter --pg-name demo

The command derives the local admin DSN, creates the monitor role on demo, pulls the image if needed, starts the container pointed at the monitor URL, and prints the scrape info:

✓ pg_exporter installed: "pgexporter"
  Container:  pgcli-pgexporter-pgexporter
  Image:      docker.io/pgsty/pg_exporter:1.5.0
  Metrics:    http://0.0.0.0:9630/metrics
  Target:     instance demo
  Monitor as: pgexporter (pg_monitor)

  Monitor password: pgx_3f9a…            # printed ONCE
  (printed once — retrieve it later with `pg addon password pgexporter --name pgexporter`)

To pin the monitor password — for example so a primary and a standby’s dial-as-is exporter agree without a post-install fetch — pass a file (recommended) or the value:

pg addon install pgexporter --pg-name demo --monitor-password-file /srv/secrets/pgexporter.pw

A pinned password is written to pg.yaml so the container can reconnect after restarts, but it is not printed back; pg addon password pgexporter still retrieves it.

Monitor a database outside pgcli’s management, letting pgcli create the monitor role — pass an admin URL alone; the target’s host/port/database come from it:

pg addon install pgexporter --name ext \
  --admin-dsn "postgres://admin:adminpw@db.example.com:5432/app"

The --admin-dsn runs the one-time CREATE ROLE/GRANT pg_monitor batch and is then discarded — only the credential-free address postgres://db.example.com:5432/app is kept in pg.yaml. Thereafter the exporter connects only as pgexporter, and pg addon password pgexporter --name ext returns that role’s password.

If the monitor role already exists and you’d rather pgcli not touch the target at all, pass a --dsn with usable credentials instead (mutually exclusive with --admin-dsn — you give one URL, not two):

pg addon install pgexporter --name ext \
  --dsn "postgres://pgexporter:existingpw@db.example.com:5432/app"

Here pgcli runs no SQL: the exporter dials exactly this URL with its own credentials.

(To create the role by hand instead, the minimum is CREATE ROLE pgexporter LOGIN CONNECTION LIMIT 5 PASSWORD '…'; GRANT pg_monitor TO pgexporter; — plus GRANT SELECT (oid) ON pg_subscription on PostgreSQL 10–13.)

Verify the exporter is serving real numbers for the target:

curl -s http://127.0.0.1:9630/metrics | grep -E '^pg_(up|version_info)'
curl -s http://127.0.0.1:9630/up        # 200 == the target is reachable

pg_up 1 means the monitor role connected. Cross-check pg_version_info against pg exec demo -c "SHOW server_version" — and confirm the role landed on the target with pg exec demo -c "\du pgexporter" (or query pg_roles / pg_auth_members for the pg_monitor grant). With the default --auto-discovery, metrics carry a datname label per database on the target.

Repeated installs and one monitor user

The monitor-role SQL is idempotent, so re-running install never damages the target’s role: a plain reinstall on a running, unchanged instance is a no-op (no SQL runs), and a --force reinstall ALTERs the existing role — its OID and grants survive and the pg_monitor membership is never duplicated.

What a --force / config-changed reinstall does do is rotate the generated password (that instance stays fine — the new password is stored and injected together — but it overwrites a password you may have set by hand or reused; pg addon password pgexporter retrieves the current one). Because every such install writes a fresh password onto the role, two exporter instances sharing one target and the default pgexporter user collide: installing the second rotates the shared role’s password, and the first keeps its now-stale one — its open pool works, but the next reconnect fails and it drops to pg_up 0. When you run more than one exporter against the same target, give each its own role:

pg addon install pgexporter --name pe2 --pg-name demo --monitor-user pgexporter2

Wire it into Prometheus

The exporter is only useful once something scrapes it. A pgcli Prometheus instance does, via a one-line --scrape job:

pg addon install prometheus --name p1 --scrape pg=127.0.0.1:9630
# remote Prometheus → use the host's LAN address instead of 127.0.0.1:
pg addon install prometheus --name p1 --scrape pg=<host-ip>:9630

To add this exporter to a pgcli Prometheus that is already running and already scraping other jobs, use --scrape-append — it folds the pg job into the stored scrape list (merging same-named jobs, appending unseen ones) and SIGHUP-reloads, so it never wipes the existing targets:

pg addon install prometheus --name p1 --scrape-append pg=127.0.0.1:9630

(A plain --scrape replaces the whole job set, so re-running install with it would drop any other jobs p1 was scraping.) Then in Prometheus, up{job="pg"} is 1 and count(pg_activity_count) is positive. See the Prometheus addon for the full --scrape / --scrape-append mechanics.

Reuse the health probes

pg_exporter’s /primary and /replica return 200 only when the target is in that role, so they double as HAProxy-style liveness probes for read/write routing — see the HAProxy addon for wiring a pgcli HAProxy to point-check a PostgreSQL. /up (target reachable at all) and /read are the other probes.

Re-running install on a running instance is a no-op without --force (config fields you pass are saved; the container keeps serving). With --force the container is recreated — and the role SQL re-runs (rotating the monitor password) in --pg-name mode, or in --admin-dsn mode only when a fresh --admin-dsn is passed (without one, the stored monitor password is reused, since pgcli deliberately kept no admin rights). A --dsn install never runs SQL at all. Changing port / listen / extra-args needs --force (container recreation) — only the collector config is hot-reloadable (see below).

Custom collectors (--config-file) and reload

pg_exporter ships a full default collector set baked into the binary and plans it at runtime by server version / role / extensions, so no config file is needed to get useful metrics — most installs omit --config-file. When you do want a custom set, point --config-file at a pg_exporter collector YAML; it is mounted read-only at /etc/pg_exporter.yml and selected via PG_EXPORTER_CONFIG. After editing the file on the host, hot-reload it in place with SIGHUP (no container restart):

pg addon install pgexporter --pg-name demo --config-file /srv/collectors.yml
# …edit /srv/collectors.yml, then:
pg addon pgexporter reload --name pgexporter

Reloading an instance started without --config-file is a harmless no-op — pgcli tells you so (the built-in default set has nothing on disk to re-read). URL / port / listen changes are not covered by SIGHUP; recreate with install --force.

Custom flags (--extra-arg)

pg_exporter has a rich flag surface beyond the env-configured URL. Toggle features via --extra-arg (repeatable):

pg addon install pgexporter --pg-name demo \
  --extra-arg --auto-discovery=false \
  --extra-arg --tag=env=prod

Extra args are appended last to the command line, so they override pgcli’s injected flags via last-wins. Common ones: --auto-discovery=false (stop adding a datname per database), --exclude-database (skip databases), --tag (add constant labels), --namespace (prefix every metric). After --force, confirm with curl -s http://127.0.0.1:9630/metrics that a --auto-discovery=false target reports only the postgres database’s labels.

Listening and exposure

Listen defaults to 0.0.0.0: on Linux the container shares the host network namespace, so /metrics is reachable on every interface at the assigned port. This is deliberate — a Prometheus scraping it is usually on another machine. But there is no authentication, and pg_exporter also serves /reload, /explain and /stat on the same port, so anyone who can reach it can read config and trigger reloads, not just scrape. For a same-host Prometheus pass --listen 127.0.0.1 (recreate with --force); otherwise restrict the port at the firewall. (Under the macOS bridge build, pgcli widens the bind to 0.0.0.0 automatically so the published port stays reachable through the podman VM.)

Ports

Each pg_exporter instance owns a single port — the metrics endpoint — allocated from a pool with base pgexporter_start_port (default 9630, pg_exporter’s conventional port), incrementing for each additional instance and skipping ports taken by any managed container or used_ports. The allocation is saved to pg.yaml, so a reinstall never re-hands-out a port another addon holds. 9630 shares no number with node_exporter (9100), Prometheus (9090), VictoriaMetrics (8428), Grafana (3000) or Alertmanager (9093); an explicit --port still wins.

pg addon install pgexporter --name pe2 --monitor-user pgexporter2 --pg-name demo   # second instance: next free port (9631)
pg addon install pgexporter --name pe3 --port 9700 --monitor-user pgexporter3 --pg-name demo  # explicit port takes precedence

(Each extra instance on the same target needs its own --monitor-user — see Repeated installs and one monitor user.)

Configuration

addons:
  pgexporter:
    pgexporter:
      name: pgexporter
      image_tag: docker.io/pgsty/pg_exporter:1.5.0
      host_port: 9630
      listen: 0.0.0.0
      target_instance: demo              # local mode
      monitor_user: pgexporter
      monitor_dsn: postgres://pgexporter:…@127.0.0.1:5432/demo?sslmode=disable   # what the container dials
      monitor_password: "…"              # A SECRET — the generated monitor password
      autostart: false
    ext:
      name: ext
      host_port: 9631
      listen: 0.0.0.0
      admin_dsn: postgres://db.example.com:5432/app   # --admin-dsn mode: credential-FREE address only
      monitor_user: pgexporter
      monitor_dsn: postgres://pgexporter:…@db.example.com:5432/app
      monitor_password: "…"

The three target fields are mutually exclusive — set exactly one: target_instance (a pgcli-managed instance, DSN re-derived every start), admin_dsn (a remote server pgcli created a monitor role on — pgcli keeps only its credential-free address; the admin URL you passed is never persisted), or dsn (a remote server dialed as given, stored verbatim with its own credentials, and no role SQL ever runs). monitor_dsn / monitor_password are what pgcli generates and injects into the container (absent in dsn mode, where the exporter dials the dsn itself). extra_args is a list of flags appended last; config_file is an optional host path mounted read-only.

List

pg addon list
Web add-ons (pgexporter):
  pgexporter (name: pgexporter)
    Status:      running
    Metrics:     http://0.0.0.0:9630/metrics
    Target:      instance demo
    Monitor as:  pgexporter (pg_monitor)
    Extra args:  --auto-discovery=false
    Image:       docker.io/pgsty/pg_exporter:1.5.0
    Container:   pgcli-pgexporter-pgexporter

The Target line is redacted in remote mode (the DSN’s password never appears). The monitor password is not shown — retrieve it with pg addon password pgexporter.

Password

pg addon password pgexporter          # print the stored monitor-role password

This is the password of the pgexporter role the exporter connects with — not a PostgreSQL admin password.

Start and stop

Containers run with podman’s unless-stopped restart policy, so they come back with podman after a host reboot. start/stop manage them explicitly:

pg addon stop pgexporter
pg addon start pgexporter

start re-derives the monitor DSN first (for a --pg-name target, so a rotated instance password or changed port takes effect on recreation).

Auto-start on Boot

pg autostart enable --pgexporter --name pgexporter

This flags the instance in pg.yaml and installs/refreshes a boot service (a systemd --user unit on Linux, a LaunchAgent on macOS) that runs pg start --autostart. A boot-time start only brings the container up with the stored monitor credentials — it does not re-run the role-creation SQL (that happens at install). See Autostart for the full mechanism, status and disabling.

Remove

pg addon remove pgexporter   # deletes the container; there is no data to clean

pg_exporter keeps nothing on disk, so --clean-data has no effect beyond an informational note. The monitor role created on the target is not dropped — it may be shared or hand-managed. To remove it yourself, first revoke its per-database grant (a bare DROP ROLE fails while the pg_subscription column grant exists in any database it touched): REVOKE SELECT (oid) ON pg_catalog.pg_subscription FROM "pgexporter"; in each monitored database, then DROP ROLE "pgexporter";.

Logs

pg logs addon pgexporter            # show recent console output
pg logs addon pgexporter -f         # follow
pg logs addon pgexporter -n 200     # last 200 lines (also -i / --tail)

Troubleshooting

  • pg_up 0 / no pg_* metrics — the monitor role can’t connect. Check /up returns 200, that the target’s pg_hba.conf admits the container’s source address, and that the stored password matches the role (pg addon password pgexporter; if they diverged, reinstall to rotate it). On a --dsn target, confirm the DSN’s host/port is reachable from the exporter host (a 127.0.0.1 DSN means the target is local to the exporter).
  • pg_up went 0 right after installing a second exporter on the same target — both share the default pgexporter role, and the second install rotated its password, staling the first. Recreate the first (install … --force) to re-sync it, give each instance its own --monitor-user, or pin the same --monitor-password on both installs (see Repeated installs and one monitor user).
  • Metrics present but thin/empty — a missing GRANT pg_monitor yields a connected exporter with partial collectors. Reinstall (the role setup is idempotent) and confirm membership: pg exec <inst> -c "SELECT r.rolname, m.rolname FROM pg_auth_members a JOIN pg_roles r ON r.oid=a.member JOIN pg_roles m ON m.oid=a.roleid WHERE r.rolname='pgexporter'".
  • Prometheus shows the target DOWN — the exporter is running (pg addon list), but the scrape address/port don’t match (--scrape pg=<host>:<port>), or a loopback --listen 127.0.0.1 exporter is being scraped from another host.
  • --dsn and --admin-dsn are mutually exclusive — you passed two remote URLs; give exactly one: --admin-dsn to have pgcli create the monitor role (its host/port/database become the target), or --dsn to dial a URL with credentials you already manage.
  • has an admin_dsn target but no stored monitor password — a --force reinstall of an --admin-dsn instance after the secret was lost (never stored by pgcli). Re-pass --admin-dsn postgres://… so pgcli can create the role again.
  • A flag / discovery change didn’t take effect — --extra-arg and target/URL changes apply at container creation; reinstall with --force. Only the collector config (--config-file) reloads via SIGHUP.
  • macOS local mode serves nothing — a bridge container can’t reach the host’s 127.0.0.1 PG; use --dsn at a reachable address on Mac.
  • Port already allocated — free it with pg addon remove first, or pick another with --port N.

Known limitations

  • No authentication, no TLS, and admin endpoints exposed. pg_exporter serves plain-text /metrics plus /reload, /explain, /stat; the only protection for a 0.0.0.0 bind is the network boundary. Front with nginx or restrict by firewall if it must leave a trusted network.
  • The monitor DSN (with its password) is stored in pg.yaml. That is the low-privilege pg_monitor role’s credential, not an admin one; the --admin-dsn used to create it is never persisted. Protect pg.yaml accordingly.
  • The official image is scratch-based — it carries no system CA bundle, so a TLS (sslmode=require) --dsn to an external server may fail certificate verification; supply trust via the image or connect over a trusted network.
  • Stateless — no data dir, no retention; nothing survives beyond the running process. Reinstall always starts fresh, and the target-side monitor role is never auto-dropped.
  • macOS local-instance mode is not usable (bridge container can’t reach host loopback); remote --dsn mode works there. Linux is the tested platform.
  • pgcli does not validate --extra-arg values; a bad flag surfaces only in the container logs on startup.

33 - influx2tsdb

Run the influx2tsdb proxy as a managed container — InfluxDB 1.x HTTP API (Line Protocol + InfluxQL) on top of PostgreSQL + TimescaleDB, with automatic retention and compression jobs

pg addon install influx2tsdb runs influx2tsdb-proxy 1.3.2 — an InfluxDB 1.x HTTP API adapter (Line Protocol writes and InfluxQL queries) that stores data in PostgreSQL with the TimescaleDB extension — as a managed container from pgcli’s own ghcr.io/mars-base/pgcli/pgcli-influx2tsdb image. Unlike the InfluxDB addon, there is no TSM engine: every point lives in a TimescaleDB hypertable, and the proxy itself is stateless.

The add-on is Linux/amd64 only (the image is single-arch, built from the upstream release binary on debian:12-slim). The proxy container can be recreated at any time; the data survives because PostgreSQL holds it.

The HTTP API has no authentication. The upstream proxy speaks plain HTTP, binds all interfaces, and does not check InfluxDB credentials. Use the nginx addon for TLS and access control, or firewall the port. The endpoint cannot be used safely on an untrusted network.

When to use it — and what you give up

Native InfluxDB 1.x keeps time-series data in its own in-memory index + TSM files and serves InfluxQL directly. influx2tsdb instead translates every request into SQL and stores rows in PostgreSQL/TimescaleDB. That translation and a relational storage engine cost throughput and latency: for pure time-series ingest and query load, native InfluxDB is faster than this proxy. The gap grows on large aggregate scans and high-cardinality workloads.

The trade-off is that time-series data becomes ordinary database data:

  • ACID transactions and consistency. Points land in the same transactional store as relational data; a write batch commits or fails atomically, and time-series can be joined with business tables in one query.
  • SQL ecosystem. TimescaleDB exposes hypertables as tables: joins, views, CTEs, window functions, ORMs and BI tools all work. InfluxQL is only the ingestion/query front end, not a walled garden.
  • Mature backup, PITR, replication and HA. pg_dump/pgBackRest, WAL archiving, streaming replicas, Patroni and the rest of PostgreSQL operations apply unchanged — you do not run a second storage system and a second DR process.
  • One set of operations, auth and audit. Users, roles, TLS, monitoring and compliance controls are PostgreSQL’s; there is no second database to harden.
  • Flexible lifecycle. Retention and compression are native TimescaleDB policies (below), and you can still UPDATE/DELETE arbitrary rows, migrate schemas and reshape tables like any SQL data.
  • Reuse of existing PostgreSQL infrastructure and DBA skills. If PostgreSQL is already operated professionally, the marginal cost of a time-series workload is low.

Pick the InfluxDB addon when InfluxQL/TSM performance and a faithful InfluxDB 1.x behavior model matter most; pick influx2tsdb when keeping everything in PostgreSQL is the priority.

Prerequisites

  • A PostgreSQL database with the TimescaleDB extension. The proxy tries CREATE EXTENSION IF NOT EXISTS timescaledb on startup, but the extension package must be installed in the instance. On a pgcli instance:

    pg extension install timescaledb -i tsdb --auto-restart
  • The target must be running before the proxy starts. A local target is checked up front (pg start -i tsdb); the proxy exits immediately if PostgreSQL is unreachable.

Install

Local target — the DSN is derived from the pgcli instance on every start, so a changed port or password stays in sync:

pg addon install influx2tsdb --pg-name tsdb
✓ influx2tsdb "influx2tsdb" installed and running
  Version:   1.3.2
  Image:     ghcr.io/mars-base/pgcli/pgcli-influx2tsdb:1.3.2
  Container: pgcli-influx2tsdb-influx2tsdb
  Target:    instance tsdb
  InfluxDB database: tsdb_db
  Endpoint:  http://<host>:8087 (InfluxDB 1.x HTTP API; binds all interfaces, no auth)
  Pool:      10 connections

Remote or unmanaged target — pass the full DSN:

pg addon install influx2tsdb --dsn 'postgres://user:pass@db.example.com:5432/metrics?sslmode=disable' \
  --database metrics --port 8087

The DSN (including its password) is stored in pg.yaml and is part of the container command line, so it is visible via podman inspect; protect the config file and prefer a dedicated least-privilege PostgreSQL role.

Second instances take the next free port from influx2tsdb_start_port (default 8087):

pg addon install influx2tsdb --name metrics2 --pg-name tsdb

Re-running install without --force is a no-op. --force rewrites the target/port settings and recreates the container; data is untouched because the proxy has none.

Parameters

Flag Default Description
--name influx2tsdb Instance name (config map key)
--pg-name — Resolve the target from a locally managed pgcli instance; mutually exclusive with --dsn
--dsn — Explicit PostgreSQL/TimescaleDB DSN for a remote or unmanaged server
--database target DB name Default InfluxDB database (the proxy’s -db); becomes a PostgreSQL schema
--port auto (base 8087) InfluxDB-protocol HTTP host port; 0 = auto-assign
--pool-size 10 PostgreSQL connection pool size (-pool)
--verbose false Log translated SQL and query details (-verbose)
--version 1.3.2 Pinned image release
--force false Rewrite the settings and recreate the stateless container

There is no --data-dir and no --listen: the proxy keeps no local state, uses host networking, and always binds all interfaces.

Data model

Each InfluxDB database maps to a PostgreSQL schema inside the target database:

  • CREATE DATABASE "demo" → CREATE SCHEMA "demo"
  • a measurement becomes a TimescaleDB hypertable in that schema
  • tags become text columns; fields become typed columns; time is the hypertable’s partition column
  • proxy metadata lives in the target’s public schema: _influx_databases, _influx_meta, _retention_policy

Because the data is plain PostgreSQL, you can inspect and join it with pg exec:

pg exec -i tsdb 'SELECT * FROM "tsdb_db"."cpu" ORDER BY time DESC LIMIT 5'
pg exec -i tsdb "SELECT time_bucket('1 minute', time) AS m, avg(value) FROM \"tsdb_db\".\"cpu\" GROUP BY 1 ORDER BY 1 DESC LIMIT 5"

Write and query

The API follows InfluxDB 1.x. Writes return 204; malformed line protocol returns 400.

URL=http://127.0.0.1:8087
DB=tsdb_db

# single point
curl -sS -o /dev/null -w '%{http_code}\n' -XPOST "$URL/write?db=$DB" \
  --data-binary 'cpu,host=web01 value=0.42 1700000000000000000'

# batch
curl -sS -o /dev/null -w '%{http_code}\n' -XPOST "$URL/write?db=$DB" --data-binary '
cpu,host=a value=10.5,ok=true,state="up" 1700000000000000000
cpu,host=b value=20.5,ok=false,state="down" 1700000060000000000'

# InfluxQL
curl -sS -G "$URL/query" --data-urlencode "db=$DB" \
  --data-urlencode 'q=SELECT * FROM "cpu" ORDER BY time DESC LIMIT 5'
curl -sS -G "$URL/query" --data-urlencode "db=$DB" \
  --data-urlencode 'q=SELECT mean("value") FROM "cpu" WHERE time > now() - 1h GROUP BY time(5m), "host"'

Common statements supported by the current release:

Category Statements
Database CREATE DATABASE, DROP DATABASE, SHOW DATABASES
Retention policy CREATE / ALTER / DROP / SHOW RETENTION POLICIES
Write / delete line protocol writes, DELETE FROM, DROP MEASUREMENT
Metadata SHOW MEASUREMENTS / TAG KEYS / TAG VALUES / FIELD KEYS (the last three need FROM <measurement>)
Query SELECT with tag/time filters, mean/sum/min/max/count, first/last, GROUP BY time(...) and tags, subqueries

Using the InfluxDB 1.x command-line client

The official influx CLI (1.13.1) works directly against the proxy. pgcli runs it in a short-lived container; use remote mode with the proxy’s host and port (the proxy has no auth, so no credentials are needed):

CLI="pg influx --host 127.0.0.1 --port 8087"

Databases and retention policies:

$CLI -- -execute "SHOW DATABASES"
$CLI -- -execute "CREATE DATABASE demo"
$CLI --database demo -- -execute \
  "CREATE RETENTION POLICY rp1 ON demo DURATION 1d REPLICATION 1"
$CLI --database demo -- -execute \
  "ALTER RETENTION POLICY rp1 ON demo DURATION 2d DEFAULT"
$CLI --database demo -- -execute "SHOW RETENTION POLICIES ON demo"
# A default policy cannot be dropped directly: set another policy as DEFAULT first
$CLI --database demo -- -execute \
  "ALTER RETENTION POLICY autogen ON demo DURATION INF REPLICATION 1 DEFAULT"
$CLI --database demo -- -execute "DROP RETENTION POLICY rp1 ON demo"
$CLI -- -execute "DROP DATABASE demo"

Writes (line protocol):

$CLI --database tsdb_db -- -execute \
  'INSERT cpu,host=web01 value=42,ok=true 1700000000000000000'
$CLI --database tsdb_db -- -execute \
  'INSERT cpu,host=web02,region=us value=7.5 1700000060000000000'

Queries and metadata:

$CLI --database tsdb_db -- -execute \
  "SELECT * FROM cpu WHERE host = 'web01' AND time >= '2023-11-14 22:13:20'"
$CLI --database tsdb_db -- -execute \
  'SELECT mean(value) FROM cpu GROUP BY time(1m),host'
$CLI --database tsdb_db -- -execute 'SHOW MEASUREMENTS'
$CLI --database tsdb_db -- -execute 'SHOW TAG KEYS FROM cpu'
$CLI --database tsdb_db -- -execute 'SHOW TAG VALUES FROM cpu WITH KEY = host'
$CLI --database tsdb_db -- -execute 'SHOW FIELD KEYS FROM cpu'

Deletes and output formats:

$CLI --database tsdb_db -- -execute "DELETE FROM cpu WHERE host = 'web01'"
$CLI --database tsdb_db -- -execute 'DROP MEASUREMENT cpu'
$CLI --database tsdb_db -- -format json -execute 'SELECT * FROM cpu'
$CLI --database tsdb_db -- -format csv  -execute 'SELECT * FROM cpu'
$CLI --database tsdb_db -- -precision ms -execute 'SELECT * FROM cpu'

Bulk import (influx 1.x import format):

cat >/tmp/influx-import.txt <<'DATA'
# DDL
CREATE DATABASE demo

# DML
# CONTEXT-DATABASE: demo
# CONTEXT-RETENTION-POLICY: autogen
weather,location=us-midwest temperature=82 1700000000000000000
weather,location=us-midwest temperature=83 1700000060000000000
DATA

$CLI -- -import -path /tmp/influx-import.txt

Verified working: database and retention-policy DDL, INSERT (line protocol), SELECT (including GROUP BY time(...), tag/time filters and -format column/csv/json), SHOW MEASUREMENTS, SHOW TAG KEYS / FIELD KEYS / TAG VALUES with FROM, DELETE, DROP MEASUREMENT, and -import.

Differences from native InfluxDB:

  • Metadata commands require FROM <measurement>: SHOW TAG KEYS, SHOW FIELD KEYS and SHOW TAG VALUES without FROM return missing FROM clause (native InfluxDB makes it optional); WITH KEY =~ /regex/ is not supported either.
  • SHOW SERIES is not supported (unsupported query: SHOW SERIES).
  • A default retention policy cannot be dropped directly (same as native InfluxDB); set another policy as DEFAULT first.
  • -precision ns/u/ms/s/m/h all work; rfc3339 does not and still prints nanosecond integers.

Time precision caveats

  • Timestamps are always nanoseconds. In E2E testing the current release ignored the precision= query parameter on /write; send nanosecond timestamps (the InfluxDB default) to avoid shifted data.

  • Both time-literal forms work. In testing, WHERE time ... accepted both 'YYYY-MM-DD HH:MM:SS' and RFC3339 literals ('2023-11-14T22:13:20Z', including milliseconds or a +08:00 offset), and Grafana’s interpolated $timeFilter epoch-millisecond form (for example 1793083539315ms) worked too:

    curl -sS -G "$URL/query" --data-urlencode "db=$DB" \
      --data-urlencode "q=SELECT * FROM \"cpu\" WHERE time >= '2023-11-14 22:13:20' AND time <= '2023-11-14 22:15:20'"
  • now() - 1d-style expressions work.

Known upstream issue: DROP MEASUREMENT metadata cache

After DROP MEASUREMENT, the proxy deletes the measurement’s rows in _influx_meta but keeps its in-memory schema cache. Re-creating the same measurement name then does not reinsert metadata, so SHOW MEASUREMENTS / SHOW TAG KEYS / SHOW FIELD KEYS can go empty for it while SELECT still works. Use unique measurement names in automation, or restart the proxy after dropping and recreating a measurement. The bundled test script does the former.

Grafana integration

Grafana’s built-in InfluxDB data source works directly against this proxy (verified end-to-end on Grafana 13.2.4): choose InfluxDB as the data source type and InfluxQL as the query language (not Flux), point the URL at the proxy, and Grafana reads the underlying TimescaleDB hypertables.

Field Value
Type InfluxDB
Query Language InfluxQL
URL http://<proxy-host>:8087
Database tsdb_db (or your default database)
User / Password empty
HTTP Method GET (default)

The data source’s “Save & test” health check passes; queries generated by the Grafana query editor and panels ($timeFilter, epoch=ms, fill(null), GROUP BY time) returned correct series in testing, and SHOW MEASUREMENTS / TAG KEYS / TAG VALUES / FIELD KEYS are supported, so the measurement/tag/field selectors in the query builder work.

Notes:

  • The proxy has no auth and no TLS; use the nginx addon in front when Grafana and the proxy are not on a trusted network.
  • Only the InfluxQL subset is supported; unsupported expressions may error or return empty results, and Flux is not available (it needs the InfluxDB v2 API).
  • The proxy ignores the write precision= parameter; Grafana reads with epoch=ms, so display is unaffected.

Provisioning through the Grafana HTTP API

You do not need the web UI for automation: Grafana’s HTTP API can create the data source and verify the full “write through the proxy, read through the Grafana API” path (the commands below were verified on Grafana 13.2.4).

GRAFANA_PW=$(pg addon password grafana)   # Grafana admin password
G=http://127.0.0.1:3000

# 1. Create the InfluxDB/InfluxQL data source
curl -sS -u "admin:$GRAFANA_PW" \
  -H 'Content-Type: application/json' \
  -XPOST "$G/api/datasources" -d '{
    "name": "influx2tsdb",
    "type": "influxdb",
    "access": "proxy",
    "url": "http://127.0.0.1:8087",
    "database": "tsdb_db",
    "user": "",
    "password": "",
    "isDefault": true,
    "jsonData": {"httpMode": "GET", "version": "InfluxQL"}
  }'

# Look up the uid by name (or read datasource.uid from the POST response)
UID=$(curl -sS -u "admin:$GRAFANA_PW" \
  "$G/api/datasources/name/influx2tsdb" \
  | python3 -c 'import sys,json; print(json.load(sys.stdin)["uid"])')

# 2. Health check
curl -sS -u "admin:$GRAFANA_PW" \
  "$G/api/datasources/uid/$UID/health"
# {"message":"datasource is working. 0 measurements found","status":"OK"}

# 3. Write one point through the proxy (nanosecond timestamp)
curl -sS -o /dev/null -w '%{http_code}\n' \
  -XPOST "http://127.0.0.1:8087/write?db=tsdb_db" \
  --data-binary "cpu,host=api value=42 $(date +%s%N)"

# 4. Read through Grafana's data source proxy (InfluxQL)
curl -sS -u "admin:$GRAFANA_PW" -G \
  "$G/api/datasources/proxy/uid/$UID/query" \
  --data-urlencode 'db=tsdb_db' \
  --data-urlencode 'epoch=ms' \
  --data-urlencode 'q=SELECT last("value") FROM "cpu" WHERE time >= now() - 1h'

The write returns 204; step 4 returns the last(value) series with the time column in epoch milliseconds, matching epoch=ms.

Notes:

  • access: "proxy" makes Grafana forward the query server-side; the browser never talks to the proxy directly, so CORS does not apply.
  • version: "InfluxQL" and httpMode: "GET" in jsonData match the mode panels use, so set them explicitly at creation time.
  • Delete the data source with curl -u "admin:$GRAFANA_PW" -X DELETE "$G/api/datasources/uid/$UID" (returns 200).

Retention policies, compression and TimescaleDB jobs

CREATE / ALTER / DROP RETENTION POLICY is supported with InfluxDB semantics (per-database, one default policy, minimum duration 15m, INF/0s = infinite). At the storage layer the proxy immediately calls TimescaleDB’s own policy functions for every hypertable in that database’s schema:

SELECT add_retention_policy('"tsdb_db"."cpu"', INTERVAL '86400 seconds',
                            schedule_interval => INTERVAL '1 hour');
SELECT add_compression_policy('"tsdb_db"."cpu"', INTERVAL '6 hours',
                              schedule_interval => INTERVAL '1 hour');
SELECT set_chunk_time_interval('"tsdb_db"."cpu"', INTERVAL '1 hour');

The cleanup itself is automatic and needs no pg_cron. The jobs run inside TimescaleDB’s own background-job scheduler and are visible in timescaledb_information.jobs:

pg exec -i tsdb "
  SELECT job_id, application_name, schedule_interval, proc_name,
         hypertable_schema, hypertable_name, config
  FROM timescaledb_information.jobs
  WHERE hypertable_schema = 'tsdb_db' ORDER BY job_id"

A 1-day policy produces a job like:

 job_id |  application_name        | schedule_interval |    proc_name     | config
--------+--------------------------+-------------------+------------------+-----------------------------------------
   1050 | Retention Policy [1050]  | 01:00:00          | policy_retention | {"drop_after": "24:00:00", ...}
   1051 | Columnstore Policy [1051]| 01:00:00          | policy_compression | {"compress_after": "06:00:00", ...}

Operational details:

  • The proxy is not the scheduler. TimescaleDB executes the jobs; stopping or removing the proxy container does not stop retention while PostgreSQL is running. Conversely, if the proxy is down when a new hypertable is created, its policies are applied on the next sync.
  • Sync cadence. CREATE / ALTER / DROP RETENTION POLICY triggers an immediate sync; a background loop re-applies policies to all hypertables every 5 minutes (for new tables and for DDL skipped on a lock timeout).
  • Job cadence. The proxy requests a schedule interval: retention every 5 minutes when the duration is under 24h, otherwise hourly; compression every minute under 24h, otherwise hourly. Note the upstream 1.3.2 quirk: the interval is chosen by scanning policies across all databases in map order, so with multiple databases the effective interval can differ from the derivation (a 1h retention policy was observed scheduled hourly). Read schedule_interval from timescaledb_information.jobs when exact cadence matters; every sync re-applies the derived interval.
  • Only the default policy is enforced. All hypertables in the schema use the database’s default retention duration (or the first finite policy if none is default). Non-default policies are metadata; the proxy does not split data into per-policy schemas or apply measurement-specific retention. With no finite policy (or an INF default) data grows without bound.
  • Deletion is chunk-granular. TimescaleDB drops whole chunks, so expired data may linger for up to one chunk interval; steady-state size is roughly “retention duration + at most one chunk interval” and stops growing after that. The proxy derives the chunk interval from SHARD DURATION or from the retention duration (1h minimum, retention/24, capped at 1 day).
  • Changing a policy to INF removes the TimescaleDB retention job at the next sync; data then stops expiring.
  • Compression is applied automatically. Tags become compress_segmentby, time descending becomes compress_orderby, and compress_after is derived from the retention duration (retention/4, capped at 1 day; 15m minimum).

Verify from PostgreSQL:

# active policies and last run
pg exec -i tsdb "SELECT application_name, schedule_interval, last_run_started_at, last_successful_finish
                 FROM timescaledb_information.job_stats s
                 JOIN timescaledb_information.jobs j USING (job_id)
                 WHERE proc_name IN ('policy_retention','policy_compression')"

Security and exposure

  • The proxy has no credentials; anyone who can reach the port can read and write every database exposed by the target DSN.
  • Bind it to a trusted network only, or put the nginx addon in front for TLS and IP/basic-auth restrictions. The proxy port itself has no TLS.
  • The PostgreSQL password appears in pg.yaml and in the container’s argv. Use a dedicated role limited to the target database, and protect the config file.

Lifecycle and autostart

pg addon start influx2tsdb --name influx2tsdb
pg addon stop influx2tsdb --name influx2tsdb
pg addon influx2tsdb status --name influx2tsdb
pg logs addon influx2tsdb --name influx2tsdb -f
pg addon remove influx2tsdb --name influx2tsdb          # container + pg.yaml entry

remove never deletes data: it lives in PostgreSQL. --clean-data is accepted for consistency but has nothing to delete.

Autostart recreates the stateless proxy at boot. For a local target, pgcli starts the instance first and then re-derives the DSN:

pg autostart enable --influx2tsdb --name influx2tsdb
pg autostart status
pg autostart disable --influx2tsdb --name influx2tsdb

Backup, restore and HA

There is nothing to back up on the proxy side. Use PostgreSQL’s normal tooling:

  • pg backup <instance> / pgBackRest / pg_dump — all schemas, hypertables and the public._influx_* metadata tables are included.
  • PITR / WAL archiving / streaming replicas / Patroni — work unchanged. On a failover or move, point the proxy at the new primary (--dsn) and recreate it, or, for a local instance, restart it after the instance’s DSN changes.

The proxy container is disposable: pg addon install influx2tsdb --force rebuilds it from the same target.

Test script

test/addon/test_influx2tsdb.sh exercises the common time-series operations: ping, single/batch writes with tags and field types, count, time-range and tag filters, mean/sum/min/max, GROUP BY time() and tags, first/last, SHOW metadata, optional PostgreSQL row-count/hypertable checks, DELETE, DROP MEASUREMENT, database lifecycle, retention-policy CRUD, and malformed-write handling.

# local target; discovers URL and database from pg addon influx2tsdb status
test/addon/test_influx2tsdb.sh --instance tsdb

# explicit endpoint
test/addon/test_influx2tsdb.sh --url http://127.0.0.1:8087 --db tsdb_db

# keep the test measurements/database for inspection
test/addon/test_influx2tsdb.sh --instance tsdb --keep

The script uses unique per-run measurement and database names because of the DROP MEASUREMENT metadata-cache issue described above.

test/addon/test_influx2tsdb_retention.sh focuses on retention automation and covers:

  • the automatic policy_retention / policy_compression jobs, with drop_after / compress_after matching the derived values;
  • CALL run_job(<id>) actually dropping expired chunks while recent data survives;
  • expired rows inserted directly into PostgreSQL while the proxy is stopped still being deleted (proving the schedule does not depend on the proxy);
  • switching the default policy to INF removing the retention job while the compression job stays and falls back to 1 day;
  • DROP DATABASE cleaning up all jobs for that schema;
  • asserting that pg_cron is not installed.
# local target; discovers endpoint, database and instance from
# pg addon influx2tsdb status
test/addon/test_influx2tsdb_retention.sh

# explicit endpoint
test/addon/test_influx2tsdb_retention.sh --instance tsdb \
  --url http://127.0.0.1:8087 --db tsdb_db

# skip the proxy-stop phase (jobs/config only)
test/addon/test_influx2tsdb_retention.sh --skip-proxy-stop

The script reaches PostgreSQL through pg exec, so it needs --instance or --pg-dsn, and it stops and restarts the local proxy during the run (unless --skip-proxy-stop).

Limitations

  • Linux/amd64 only.
  • No authentication and no TLS in the proxy; front it with nginx or isolate it.
  • InfluxQL subset. The release implements the statements listed above, not the full InfluxQL language; for example, SHOW SERIES is not supported and SHOW TAG KEYS / FIELD KEYS / TAG VALUES require FROM. Unsupported constructs return an error or an empty result. Flux is not available.
  • Timestamps in nanoseconds; the precision= write parameter is ignored by the current release. Query output precision follows epoch=ms, which Grafana sends.
  • Per-database retention only. One default policy applies to every hypertable in the schema.
  • Performance is below native InfluxDB for time-series workloads (see above).
  • The proxy stores its metadata tables (_influx_databases, _influx_meta, _retention_policy) in the target database’s public schema.

CLI flag reference

pg addon install influx2tsdb

Flag Default Description
--name NAME influx2tsdb Instance name
--pg-name NAME — Local pgcli instance as the target; exclusive with --dsn
--dsn DSN — postgres://user:pass@host:port/db target; exclusive with --pg-name
--database DB target DB name Default InfluxDB database (-db)
--port N auto (base 8087) HTTP host port; 0 = auto-assign
--pool-size N 10 PostgreSQL pool size
--verbose false Log translated SQL
--version V 1.3.2 Pinned image release
--force false Rewrite settings and recreate the container

pg addon start|stop|remove influx2tsdb

Command Flags Description
pg addon start influx2tsdb --name NAME Start (recreate) the container; checks a local target first
pg addon stop influx2tsdb --name NAME Stop the container
pg addon remove influx2tsdb --name NAME, --clean-data Remove container and config entry; data stays in PostgreSQL

pg addon influx2tsdb status

Flag Default Description
--name NAME influx2tsdb Instance to inspect (state, ping, target, database, port)

pg logs addon influx2tsdb

Flag Default Description
--name NAME influx2tsdb Instance whose container logs to show
-n N, --tail N 50 Number of lines
-f, --follow false Follow

pg autostart enable|disable

Flag Description
--influx2tsdb Select the proxy add-on
--name NAME Instance to toggle (default influx2tsdb)

Global flags

Flag Description
-c, --config FILE Config file (default ~/.pgcli/pg.yaml)
-o, --output FILE Output config path
-i, --instance NAME PostgreSQL instance selector — not used here; use --name

34 - ClickHouse

Run ClickHouse as a managed addon container — single node or one member of a replicated multi-host cluster with ReplicatedMergeTree, Distributed tables and ON CLUSTER DDL; authentication, SQL helpers, users/grants, config overrides and BACKUP/RESTORE

pg addon install clickhouse runs ClickHouse 26.8 LTS — a columnar OLAP database, standalone or as one member of a replicated multi-host cluster — as a managed container from the official docker.io/clickhouse/clickhouse-server multi-arch image. Like VictoriaMetrics and InfluxDB, it is a top-level addon: it does not front a PostgreSQL instance.

ClickHouse speaks two protocols on two ports: HTTP (curl, JDBC/ODBC, many drivers) and the native TCP protocol (clickhouse-client). pgcli runs it with host networking, so both are plain host ports. Authentication is always enabled — the install creates an admin account and stores its password in pg.yaml.

Cluster mode is opt-in with --cluster: pass the cluster name, this member’s --shard/--replica, its --advertise-host, the other members as --peer, and the Keeper endpoints as --keeper. pgcli renders remote_servers, macros and zookeeper, enabling ReplicatedMergeTree, Distributed tables and ON CLUSTER DDL. Coordination comes from the separate ClickHouse Keeper addon. A step-by-step four-host walkthrough lives on the ClickHouse cluster page; the rest of this page documents the single-node behavior and the flags shared by both modes.

The admin password is generated at install time and can be read back at any time with pg addon password clickhouse [--name NAME]. The HTTP and native listeners require authentication on every request; there is no anonymous access. --listen defaults to 127.0.0.1 — pass 0.0.0.0 explicitly when other hosts must connect, and front it with nginx for TLS.

Parameters

Flag Default Description
--name clickhouse Instance name (map key; also the default subcommand name)
--version 26.8.36.3 Upstream image tag, pulled directly from docker.io/clickhouse/clickhouse-server
--data-dir <base_dir>/addon/clickhouse/<name>/data Data directory bind-mounted at /var/lib/clickhouse; must be an absolute path
--listen 127.0.0.1 Bind address for the HTTP and native listeners. 0.0.0.0 exposes both on the network
--http-port auto (base 8123) Host HTTP port; 0 = auto-assign from clickhouse_http_start_port
--tcp-port auto (base 9000) Host native-protocol port; 0 = auto-assign from clickhouse_tcp_start_port (shared with the S3 API pool)
--admin-user admin Admin account created by the image entrypoint
--admin-password generated Admin password. On --force the stored password is kept unless this is set
--config-option K=V — Extra server setting as a dotted XML path (logger.level=debug, max_server_memory_usage=2147483648); repeatable; replaces the stored override map
--cluster NAME — Switch on cluster mode: the remote_servers/macros cluster name; same on every member
--shard N — Cluster mode: this member’s 1-based shard number
--replica N — Cluster mode: this member’s 1-based replica number within the shard
--advertise-host IP — Cluster mode: concrete non-loopback address peers dial
--peer S/R@HOST:PORT — Cluster mode: another member; repeatable. List every other member; this host is added automatically
--keeper HOST[:PORT] — Cluster mode: a Keeper client endpoint; repeatable. Pass the full shared list on every member; default port 9181
--interserver-port N 9009 Cluster mode: replica catch-up port; must match across the cluster
--force false Re-render the config and secret, then recreate the container; keeps data, the stored password and the stored overrides. Cluster identity flags stay immutable

--image does not apply to ClickHouse — use --version. The cluster flags require --cluster; on a single-node install they are rejected. Cluster-mode validation is covered in ClickHouse cluster.

The generated config only pins listeners, ports, logging and the backup disk; every other server setting keeps the upstream default. Overrides are stored in pg.yaml under addons.clickhouse.<name>.settings and rendered into the generated XML, so they survive restarts and container recreation.

Install

pg addon install clickhouse --name ch1
✓ ClickHouse "ch1" installed
  Version:   26.8.36.3
  Image:     docker.io/clickhouse/clickhouse-server:26.8.36.3
  Container: pgcli-clickhouse-ch1
  HTTP:      http://127.0.0.1:8123
  TCP:       127.0.0.1:9000
  Admin:     admin
  Password:  <generated>
  Data dir:  /home/you/.pgcli/addon/clickhouse/ch1/data
  Backups:   /home/you/.pgcli/addon/clickhouse/ch1/backups
  Config:    /home/you/.pgcli/addon/clickhouse/ch1/config.d/zz-pgcli.xml

A second instance takes the next free HTTP/TCP ports from its pools (for example 8124/9001) and can use a custom data dir:

pg addon install clickhouse --name analytics --data-dir /srv/clickhouse-data --listen 0.0.0.0

Re-running install without --force is a no-op that reports the current state. --force re-renders the config, recreates the container and keeps the data dir, the stored admin password and the stored settings; pass --config-option only when you want to replace the override map.

The image is pulled directly from Docker Hub; no pgcli-built image is involved. --version accepts any safe upstream tag, but the tag must exist in the registry — the pull fails otherwise. pgcli pins the current LTS line (26.8.36.3) by default.

For a replicated cluster, install ClickHouse Keeper first, then run the install on every member with --cluster, the local --shard/--replica/--advertise-host, the other members as --peer, the Keeper endpoints as --keeper, and the same explicit --admin-password. The complete four-host procedure, including the exact peer lists, is in ClickHouse cluster.

Ports

Endpoint Default Protocol Pool
HTTP 8123 HTTP (queries, /ping, many drivers) clickhouse_http_start_port, default 8123
Native 9000 ClickHouse native TCP (clickhouse-client) clickhouse_tcp_start_port, default 9000, shared with the S3 API pool
Interserver 9009 Replica catch-up (interserver_http_port), cluster mode only Fixed; no pool, reserved across all addons

Both HTTP/TCP pools share one “already assigned” set, so an explicit port in one pool cannot collide with an auto-assigned port in the other. --http-port and --tcp-port must differ, and every HTTP/TCP port must be unique across all ClickHouse instances. Ports already listening on the host are skipped during auto-assignment.

In cluster mode the fixed 9009 interserver port and the Keeper ports (9181 client, 9234 Raft) are reserved by pgcli’s cross-addon port checks. --interserver-port and (in cluster mode) --tcp-port are immutable after install because other members embed them in their peer lists; --http-port can still move.

When --listen is a wildcard (0.0.0.0, ::), pgcli’s own client commands dial 127.0.0.1; the printed endpoints follow the same rule. A LAN --listen bind also keeps loopback enabled inside the container so the in-container clickhouse-client always works.

What pgcli creates

Everything for one instance lives under <base_dir>/addon/clickhouse/<name>/:

Host path Container path Notes
config.d/ /etc/clickhouse-server/config.d Read-only; replaces the image’s stock config.d (which would otherwise bind every interface). zz-pgcli.xml is the generated override; zz-pgcli-cluster.xml is added only in cluster mode
data/ /var/lib/clickhouse Database data and system tables
logs/ /var/log/clickhouse-server clickhouse-server.log and clickhouse-server.err.log (also visible via podman logs)
backups/ /var/lib/clickhouse-backups The managed backups disk used by backup/restore
secrets/admin_password /run/secrets/admin_password Mode 0600, read by the entrypoint via CLICKHOUSE_PASSWORD_FILE

The generated zz-pgcli.xml sets:

  • listen_host (exactly what --listen chose) plus listen_try
  • http_port / tcp_port
  • logger.level, logger.log, logger.errorlog, logger.console, rotation (size, count)
  • a local disk named backups at /var/lib/clickhouse-backups, allowed for BACKUP/RESTORE

Cluster mode adds a second file, config.d/zz-pgcli-cluster.xml, holding remote_servers, macros, zookeeper, distributed_ddl, the interserver endpoint and the default replica path. It is rendered on every member and removed automatically if that instance is later reinstalled as a single node. See ClickHouse cluster.

The container runs with --network host, --restart unless-stopped, a 30-second stop timeout and nofile=262144. Data ownership inside the container is uid/gid 101 (the image drops privileges after its root entrypoint chowns the mounts).

Credentials

pg addon password clickhouse --name ch1   # print the admin password
pg addon list                             # shows the Analytics add-ons section

The image entrypoint creates admin (or the name given with --admin-user) with full privileges and access management enabled (CLICKHOUSE_DEFAULT_ACCESS_MANAGEMENT=1), so CREATE USER / GRANT issued by this CLI work. The password is stored in pg.yaml (mode 0644 by default — protect that file) and duplicated into the 0600 secret file mounted into the container.

Every pgcli command that talks to ClickHouse sends one-shot SQL over the server’s loopback HTTP interface with HTTP basic auth; neither the password nor the statement appears on the podman command line or the host process list. Interactive shells still use podman exec.

Connecting

Use the printed endpoints from any host tool:

# HTTP interface (Basic auth)
curl -sS 'http://127.0.0.1:8123/?query=SELECT%20version()' \
  --user "admin:$(pg addon password clickhouse --name ch1)"

# Native protocol
clickhouse-client --host 127.0.0.1 --port 9000 --user admin --password

clickhouse-client is not installed on the host by pgcli — use the addon’s own query/shell commands below, or point an external client at the native port. /ping answers Ok. without authentication and is what pgcli polls during start.

Shell and query

pg addon clickhouse shell --name ch1                  # bash inside the container
pg addon clickhouse query --name ch1 'SELECT version()'
pg addon clickhouse query --name ch1 --database demo 'SELECT count() FROM events'
pg addon clickhouse query --name ch1 --file schema.sql
echo "SELECT 1" | pg addon clickhouse query --name ch1 -

query runs one statement through the HTTP interface as the admin user and writes the result to stdout, so it can be piped or redirected. The statements are joined from the positional arguments; --file reads a file (mount-free: the host reads it and hands the contents to the server), and - reads from stdin. Multi-statement mode is not enabled, so pass one statement per call.

The instance must be running for query, database, user, grant, backup and restore; shell opens regardless but prints a warning when the container is stopped.

CREATE TABLE demo.events
(
    id   UInt64,
    ts   DateTime,
    name String
)
ENGINE = MergeTree
ORDER BY id;
pg addon clickhouse query --name ch1 --database demo --file events.sql
echo "INSERT INTO demo.events VALUES (1, now(), 'boot')" | \
  pg addon clickhouse query --name ch1 --database demo -
pg addon clickhouse query --name ch1 --database demo 'SELECT * FROM demo.events ORDER BY id'

Databases

pg addon clickhouse database create demo --name ch1
pg addon clickhouse database create logs --engine Atomic --comment 'application logs' --if-not-exists --name ch1
pg addon clickhouse database list --name ch1
pg addon clickhouse database drop demo --name ch1 --yes

create takes a bare engine name (default Atomic; engine parameters are not exposed). drop is destructive — it asks for confirmation unless --yes is given. database list shows name, engine and data_path from system.databases. db is an alias for database.

Users and privileges

# User with an explicit password and default database
pg addon clickhouse user create app --password 'change-me' --default-database demo --name ch1

# Password omitted: generated and printed once
pg addon clickhouse user create reader --default-database demo --readonly --name ch1

# Restrict by source address / host name (repeatable; default is HOST ANY)
pg addon clickhouse user create etl --host-ip 10.0.0.0/8 --host-ip 192.168.1.10 --name ch1
pg addon clickhouse user create svc --host-name app.internal --name ch1
pg addon clickhouse user create localonly --host-local --name ch1

pg addon clickhouse user list --name ch1
pg addon clickhouse user drop app --name ch1 --yes

Users are created with IDENTIFIED WITH sha256_password. --host-any is the default when no host flag is given; --host-local, --host-ip (IP or CIDR) and --host-name add HOST clauses. --readonly appends SETTINGS readonly = 1. A generated password is printed exactly once and is not stored in pg.yaml — save it. --if-not-exists makes user create idempotent.

# Read + write on one database
pg addon clickhouse grant app --read --write --database demo --name ch1

# DDL keywords = CREATE, ALTER, DROP, TRUNCATE, OPTIMIZE
pg addon clickhouse grant app --ddl --database demo --name ch1

# Table scope (requires an explicit database)
pg addon clickhouse grant reader --read --database demo --table events --name ch1

# Explicit list, wildcard scope, grant option
pg addon clickhouse grant app --privileges 'SELECT,INSERT' --name ch1
pg addon clickhouse grant app --all --with-grant-option --name ch1

pg addon clickhouse grant list app --name ch1
pg addon clickhouse grant app --read --database demo --revoke --name ch1

--read is SELECT, --write is INSERT, --ddl expands to CREATE, ALTER, DROP, TRUNCATE, OPTIMIZE, --all grants ALL, and --privileges takes a comma-separated list (uppercased and de-duplicated with the flag selections). Without --database the grant targets * (all databases); --table requires an explicit database. --revoke emits REVOKE ... FROM. grant list runs SHOW GRANTS FOR.

All of these run as the instance’s admin account; the CLI never stores per-user passwords or credentials.

Configuration

Server settings are addressed by dotted XML paths; the leaf value is the text of that element in the generated zz-pgcli.xml.

# At install time
pg addon install clickhouse --name ch1 \
  --config-option max_server_memory_usage=2147483648 \
  --config-option logger.level=warning

# On a live instance
pg addon clickhouse config list --name ch1
pg addon clickhouse config get max_server_memory_usage --name ch1
pg addon clickhouse config set max_server_memory_usage=2147483648 --name ch1
pg addon clickhouse config set logger.level=debug query_log.flush_interval_milliseconds=1000 --name ch1
pg addon clickhouse config unset logger.level --name ch1
pg addon clickhouse config show --name ch1        # full generated XML
  • config set KEY=VALUE ... accepts one or more pairs, validates them, rewrites the XML and pg.yaml, then restarts a running container so the change takes effect. Pass --no-restart to defer it to the next start.
  • config unset KEY ... removes overrides (one or more) and follows the same restart rule. Unsetting an unknown key is an error.
  • config get prints the effective value of a custom override or a managed setting; config list shows managed settings first, then the custom overrides sorted by key.
  • config show renders the same XML that is written to config.d/zz-pgcli.xml; it does not touch the file or the container.
  • --config-option at install time replaces the whole override map; omit it to keep the stored one.

logger.level is special-cased: it folds into the managed <logger> block instead of producing a second <level> element. Valid levels are trace, debug, information, warning, error, fatal and none.

pgcli-managed keys are rejected, because overriding them would duplicate generated XML or silently contradict the stored paths/ports: listen_host, listen_try, http_port, https_port, tcp_port, interserver_http_port, interserver_http_host, mysql_port, postgresql_port, path, tmp_path, user_files_path, format_schema_path, access_control_path, backups.*, user_directories, profiles, users, storage_configuration.disks, storage_configuration.policies, and every logger.* key except logger.level. Keys containing spaces or values containing control characters are rejected too.

In cluster mode the topology keys are additionally managed: remote_servers, macros, zookeeper, distributed_ddl, default_replica_path and default_replica_name cannot be set through config set. A single-node instance may still define its own zookeeper/macros block — useful when connecting to an external coordination service.

Typical settings:

pg addon clickhouse config set max_server_memory_usage=2147483648 --name ch1
pg addon clickhouse config set background_pool_size=8 max_concurrent_queries=100 --name ch1
pg addon clickhouse config set query_log.flush_interval_milliseconds=1000 --name ch1
pg addon clickhouse config set merge_tree.max_suspicious=0 --name ch1

Server settings cannot be changed with a hot reload by this CLI; every effective change recreates or restarts the container (ClickHouse reads this generated file at startup).

pgcli validates only the key shape and the managed-key rules — the value is checked by ClickHouse itself at startup. A value it rejects (for example a background_pool_size below what the merge/mutation sanity check allows) aborts startup, and the container’s unless-stopped policy turns that into a restart loop. Recover without losing data:

pg addon stop clickhouse --name ch1
pg addon clickhouse config unset background_pool_size --no-restart --name ch1
pg addon start clickhouse --name ch1

Backup and restore

Backups use ClickHouse’s SQL BACKUP command against the local backups disk (/var/lib/clickhouse-backups). They run online and the instance must be running. Only the managed local disk is exposed — S3 destinations are not configured.

pg addon clickhouse backup --name ch1 --database demo
# ✓ backup written: <instance dir>/backups/demo-20261027-120000.zip (… bytes)

# Explicit name or nested path inside the backups dir
pg addon clickhouse backup --name ch1 --database demo --out nightly.zip
pg addon clickhouse backup --name ch1 --database demo --out archive/2026-q4.zip

pg addon clickhouse backups --name ch1
pg addon clickhouse restore demo-20261027-120000.zip --name ch1 --database demo
pg addon clickhouse restore demo-20261027-120000.zip --name ch1 --database demo --as demo_restored
  • --database is required for both commands: it names the database recorded in the backup (there is no “all databases” form in v1).
  • --out is relative to the backups dir unless absolute; absolute paths must stay inside that dir, and the file must end in .zip. The default name is <database>-YYYYMMDD-HHMMSS.zip (UTC).
  • restore takes a file inside the backups dir, plus the recorded database name. Restoring into a database that already exists fails (ClickHouse refuses to overwrite); use --as NEW to restore alongside it.
  • Restore itself is online, but it needs free space and a running instance; backups lists .zip files sorted newest first.

The backups directory is a normal host directory — copy the .zip files off-host for real disaster recovery. There is no scheduled backup; wire pg addon clickhouse backup into your own timer if you need one.

# Off-host copy
rsync -a /home/you/.pgcli/addon/clickhouse/ch1/backups/ backup-host:/backups/clickhouse-ch1/

Lifecycle

pg addon start clickhouse --name ch1      # create if missing, then wait for /ping
pg addon stop clickhouse --name ch1
pg addon clickhouse status --name ch1     # state, ping, endpoints, version, paths, override count
pg logs addon clickhouse --name ch1 -f    # container logs (stdout/stderr)
pg addon remove clickhouse --name ch1     # remove container + pg.yaml entry, keep data
pg addon remove clickhouse --name ch1 --clean-data   # also delete the instance dir and a custom data dir

start re-renders the generated config and password file from pg.yaml before starting, so a stopped instance picks up config set --no-restart changes and a changed admin password. status reports running (ping ok) when the HTTP /ping endpoint answers.

Without --clean-data, remove leaves <instance dir> (data, config, logs, backups, secret) and a custom --data-dir on disk; reinstalling under the same name revives the data and reuses the kept admin password (pass --admin-password to override). --clean-data deletes both the instance dir and a custom data dir (files owned by uid 101 are removed through podman unshare), but never removes the pulled image.

Auto-start after reboot:

pg autostart enable --clickhouse --name ch1
pg autostart status
pg autostart disable --clickhouse --name ch1

Boot start also re-renders the config and secret first, then starts the existing container. pg start starts every autostart-enabled Keeper member first, then ClickHouse instances, then nginx, so both replication coordination and an nginx backend pointing at ClickHouse’s HTTP port are up in dependency order. Enable Keeper boot start separately with pg autostart enable --clickhouse-keeper --name keeper.

Production notes

  • Single node or static cluster member. Without --cluster, this addon has no replication or sharding; backups are the disaster-recovery path. With --cluster, it becomes one member of a 2×2 (or larger) replicated cluster coordinated by ClickHouse Keeper; see ClickHouse cluster for topology, replicated tables, failure behavior and the warning that production Keeper belongs on dedicated servers.
  • TLS terminates at a proxy. The HTTP and native ports are plaintext, and cluster interserver traffic is plaintext too. To expose ClickHouse over the network with TLS, put the nginx addon in front of the HTTP port (or use an external proxy); do not expose the native, interserver or Keeper ports directly to untrusted networks.
  • Loopback by default. --listen defaults to 127.0.0.1; cluster members require 0.0.0.0. Authentication is always on, but a network bind still widens the attack surface; use 0.0.0.0 only on trusted networks.
  • Password storage. The admin password lives in pg.yaml (0644 by default); protect that file and prefer pg addon password clickhouse over copying it around. In a cluster, every member must use the same admin password — pgcli cannot synchronize or verify it across hosts.
  • Resource use. The container has no CPU/memory limit from pgcli; ClickHouse’s own memory budget and the recommended settings are covered in Memory limits below. Cluster members also compete with Keeper for RAM and I/O when co-located.
  • Upgrades. --force --version <new> pulls a new tag and recreates the container on the same data dir. ClickHouse supports forward upgrades only — never start an older server against data written by a newer version. In a cluster, upgrade one replica at a time and wait for catch-up. Take a backup before upgrading.
  • Data ownership. Data files are owned by uid 101. Use --clean-data rather than deleting the directory by hand; pgcli handles the permission fallback.
  • Platform. Linux only (host networking); the official image is multi-arch (amd64/arm64).

Memory limits

pgcli never passes --memory/--cpus to podman, so the container has no cgroup memory cap; ClickHouse enforces its own budget instead:

  • Server-wide. max_server_memory_usage is the process-wide limit in bytes. Its default 0 keeps ClickHouse’s ratio rule, max_server_memory_usage_to_ram_ratio (default 0.9 of host RAM). That is fine on a dedicated host and risky on a shared one. On a shared host set the absolute value explicitly and leave headroom for the OS page cache and other services; on a dedicated host 50–70% of RAM is a common starting point.
  • Concurrency. max_concurrent_queries and background_pool_size are also server-level settings and work with config set. The server-wide limit covers all concurrent queries together, so plan for peak per-query memory × concurrency inside that budget.
  • Query-level. max_memory_usage, max_bytes_before_external_group_by, max_bytes_before_external_sort and max_threads are user/profile settings, not server XML, so config set does not apply them. Set them for one session with SET in a clickhouse-client started from pg addon clickhouse shell (one-shot query calls do not share session state), or define them on a SQL-created user with CREATE USER ... SETTINGS ....
  • Spill instead of OOM. max_bytes_before_external_group_by / max_bytes_before_external_sort let heavy aggregations and sorts spill to disk above the threshold, trading latency for a lower memory ceiling. JOIN is usually the biggest consumer — size for the right-hand table or avoid large joins.

Check the live value:

pg addon clickhouse query --name ch1 "SELECT name, value, changed FROM system.server_settings WHERE name = 'max_server_memory_usage'"

Example — cap the whole server at 8 GiB and allow 20 concurrent queries:

pg addon clickhouse config set max_server_memory_usage=8589934592 max_concurrent_queries=20 --name ch1

Values are bytes; config set restarts a running container unless --no-restart is passed. For reference, a 2 vCPU / ~2 GiB test VM handles small OLAP workloads with max_server_memory_usage=805306368 (768 MiB); JOIN-heavy or high-cardinality aggregation workloads over large data need proportionally more memory.

CLI flag reference

pg addon install clickhouse

Flag Default Description
--name NAME clickhouse Instance name (map key); [A-Za-z0-9][A-Za-z0-9_-]*, max 48 chars
--version TAG 26.8.36.3 Upstream image tag from docker.io/clickhouse/clickhouse-server
--data-dir DIR <base_dir>/addon/clickhouse/<name>/data Absolute host data dir bind-mounted at /var/lib/clickhouse
--listen ADDR 127.0.0.1 Bind address for both listeners
--http-port N auto (base 8123) HTTP host port; 0 = auto-assign
--tcp-port N auto (base 9000) Native host port; 0 = auto-assign; must differ from --http-port
--admin-user USER admin Admin account name; [A-Za-z0-9_.-]{1,64}
--admin-password PW generated Admin password; on --force the stored value is kept unless supplied. Required (and never generated) in cluster mode
--config-option K=V — Dotted XML path setting; repeatable; replaces the stored override map
--cluster NAME — Cluster mode; the shared cluster name
--shard N — Cluster mode; 1-based shard number
--replica N — Cluster mode; 1-based replica number within the shard
--advertise-host IP — Cluster mode; concrete non-loopback address for peers
--peer S/R@HOST:PORT — Cluster mode; repeatable; every other member
--keeper HOST[:PORT] — Cluster mode; repeatable; the full Keeper client list (default port 9181)
--interserver-port N 9009 Cluster mode; replica catch-up port
--force false Re-render config/secret and recreate the container, keeping data, password and settings; cluster identity flags remain immutable

Cluster identity (--cluster, --shard, --replica, --advertise-host, --peer, --keeper, --interserver-port, and --tcp-port in cluster mode) cannot be changed with --force. Full workflow: ClickHouse cluster.

pg addon clickhouse cluster status

Argument/flag Default Description
--name NAME clickhouse Cluster member to inspect; must be running

Reports system.clusters, system.replicas and Keeper endpoint reachability; exits non-zero when the topology does not match pg.yaml or a replica is read-only.

pg addon clickhouse status / shell / query [SQL...]

Argument/flag Default Description
--name NAME clickhouse Instance to operate on
SQL... — query only: SQL joined from positional arguments
--database DB — query only: adds --database DB
--file FILE — query only: read SQL from a host file (- = stdin)
- (argument) — query only: read SQL from stdin

pg addon clickhouse database create|list|drop

Argument/flag Default Description
NAME — Database name (create/drop, positional)
--engine NAME Atomic Bare engine name (no parameters)
--comment TEXT — Database comment
--if-not-exists false create only
--if-exists false drop only
--yes false drop only: skip the confirmation prompt

db is an accepted alias for database.

pg addon clickhouse user create|list|drop

Argument/flag Default Description
NAME — User name (create/drop, positional)
--password PW generated Password; generated and printed once when omitted
--default-database DB — DEFAULT DATABASE clause
--host-any implied Allow any host (applied when no host flag is given)
--host-local false LOCAL (loopback) only
--host-ip IP|CIDR — Repeatable IP host clause
--host-name NAME — Repeatable NAME host clause
--readonly false Add SETTINGS readonly = 1
--if-not-exists false create only
--if-exists false drop only
--yes false drop only: skip the confirmation prompt

pg addon clickhouse grant USER / grant list USER

Argument/flag Default Description
USER — Target user (positional)
--read false Grant SELECT
--write false Grant INSERT
--ddl false Grant CREATE, ALTER, DROP, TRUNCATE, OPTIMIZE
--all false Grant ALL
--privileges LIST — Extra comma-separated privileges, merged with the flags above
--database DB all (*) Scope to a database
--table TABLE all tables Scope to a table; requires --database
--revoke false Emit REVOKE ... FROM instead of GRANT ... TO
--with-grant-option false Append WITH GRANT OPTION (grant only)

pg addon clickhouse backup / restore FILE / backups

Argument/flag Default Description
FILE — restore only: .zip file inside the backups dir
--database DB required Database to back up / the database name recorded in the backup
--out NAME <db>-<UTC timestamp>.zip backup only: output path inside the backups dir
--as NEW — restore only: restore under a new database name

pg addon clickhouse config list|get|set|unset|show

Argument/flag Default Description
KEY=VALUE... — set only: one or more dotted XML settings
KEY... — get/unset: one setting key (get takes exactly one)
--name NAME clickhouse Instance to inspect or modify
--no-restart false set/unset only: apply on the next start instead of restarting now

Lifecycle, credentials, logs, autostart

Command Flags Description
pg addon start clickhouse --name NAME Start (create if missing), wait for /ping
pg addon stop clickhouse --name NAME Stop the container, keep data
pg addon clickhouse cluster status --name NAME Cluster member only: topology, replica health and Keeper reachability
pg addon remove clickhouse --name NAME, --clean-data Remove container and config entry; --clean-data also deletes the instance dir and a custom data dir
pg addon password clickhouse --name NAME Print the admin password
pg logs addon clickhouse --name NAME, -n N (default 50), -f Container logs
pg autostart enable|disable --clickhouse, --name NAME Toggle boot start for one instance

Global flags

Flag Description
-c, --config FILE Config file (default ~/.pgcli/pg.yaml)
-o, --output FILE Output config path (default the same file)
-i, --instance NAME PostgreSQL instance selector — not used by ClickHouse; use --name instead

35 - ClickHouse Cluster

Run a replicated ClickHouse cluster across hosts — 2 shards × 2 replicas, ReplicatedMergeTree, Distributed tables and ON CLUSTER DDL — coordinated by a standalone ClickHouse Keeper addon

pg addon install clickhouse --cluster ... turns the ClickHouse addon into one member of a static multi-host cluster. Each host runs its own ClickHouse container and keeps its own pg.yaml; pgcli never SSHes between hosts and never creates cluster members for you. You install the same cluster on every member and pass the shared topology explicitly.

Coordinated replication is provided by ClickHouse Keeper — a separate top-level addon that must be installed and healthy before the ClickHouse members. Keeper is not embedded in the ClickHouse container.

Production uses three dedicated Keeper servers. The four-VM layout below is a test topology that co-locates Keeper with ClickHouse to save machines. In production, run the Keeper quorum on its own 3 (or 5) servers with separate disks and failure domains — see Production notes.

Topology

A cluster is defined by a name plus a set of shard / replica positions. This guide uses the reference test layout:

Host IP Keeper ClickHouse
host01 192.0.2.11 server id 1 shard 1 / replica 1
host02 192.0.2.12 server id 2 shard 1 / replica 2
host03 192.0.2.13 server id 3 shard 2 / replica 1
host04 192.0.2.14 — shard 2 / replica 2

Substitute your own addresses; the --peer lists below are built from this table.

Shards and replicas

  • A shard is a horizontal partition: different shards hold different rows.
  • A replica is a full copy of a shard, kept in sync through Keeper. Every replica in a shard accepts reads and writes; replication is asynchronous.
  • With 2 shards × 2 replicas, every row exists twice and one ClickHouse host per shard can fail without losing data or write availability.
  • v1 requires every shard to have the same replica count, numbered 1..N without gaps, and every member must be listed on every host. Membership is static: there is no add/remove-node command.

v1 supports concrete IPv4/IPv6 addresses only (no DNS names), one ClickHouse instance per host, and one Keeper per host.

Before you start

  1. A running Keeper quorum. Follow ClickHouse Keeper and install three members. pg addon clickhouse-keeper status should show 3/3 client endpoints reachable.
  2. The same admin password on every member. Every ClickHouse member must use the identical --admin-password; pgcli cannot read or synchronize it across hosts. A fresh cluster install therefore requires the flag explicitly — the generated-password path is disabled in cluster mode.
  3. Free ports. HTTP 8123, native TCP 9000, interserver 9009; Keeper uses client 9181 and Raft 9234.
  4. The pgcli binary on every host and a config file per host (default ~/.pgcli/pg.yaml). Use the same --name everywhere; namespaces still isolate unrelated deployments on the same machine.

Install

The reference Keeper commands (details on the Keeper page):

# host01
pg addon install clickhouse-keeper --name keeper \
  --server-id 1 --advertise-host 192.0.2.11 --listen 0.0.0.0 \
  --peer 2@192.0.2.12 --peer 3@192.0.2.13

# host02
pg addon install clickhouse-keeper --name keeper \
  --server-id 2 --advertise-host 192.0.2.12 --listen 0.0.0.0 \
  --peer 1@192.0.2.11 --peer 3@192.0.2.13

# host03
pg addon install clickhouse-keeper --name keeper \
  --server-id 3 --advertise-host 192.0.2.13 --listen 0.0.0.0 \
  --peer 1@192.0.2.11 --peer 2@192.0.2.12

Then install one ClickHouse member per host. The full command for host01:

pg addon install clickhouse --name clickhouse \
  --cluster chcluster \
  --shard 1 --replica 1 \
  --advertise-host 192.0.2.11 --listen 0.0.0.0 \
  --admin-password "$CH_ADMIN_PASSWORD" \
  --peer 1/2@192.0.2.12:9000 \
  --peer 2/1@192.0.2.13:9000 \
  --peer 2/2@192.0.2.14:9000 \
  --keeper 192.0.2.11:9181 \
  --keeper 192.0.2.12:9181 \
  --keeper 192.0.2.13:9181 \
  --interserver-port 9009

The other three members differ only in the local identity and in which peer they omit:

Host --shard --replica --advertise-host --peer entries (the other three)
host01 1 1 192.0.2.11 1/2@192.0.2.12:9000, 2/1@192.0.2.13:9000, 2/2@192.0.2.14:9000
host02 1 2 192.0.2.12 1/1@192.0.2.11:9000, 2/1@192.0.2.13:9000, 2/2@192.0.2.14:9000
host03 2 1 192.0.2.13 1/1@192.0.2.11:9000, 1/2@192.0.2.12:9000, 2/2@192.0.2.14:9000
host04 2 2 192.0.2.14 1/1@192.0.2.11:9000, 1/2@192.0.2.12:9000, 2/1@192.0.2.13:9000

The shares that must be identical on every host are --cluster, the three --keeper endpoints, --interserver-port and --admin-password.

--peer lists only the other members — this host is folded in from --shard, --replica, --advertise-host and its TCP port. The --keeper list, on the other hand, is the complete Keeper client endpoint list on every host (Keeper has no self-folding for ClickHouse). The default Keeper client port is 9181, so --keeper 192.0.2.11 is accepted; write the port explicitly when it is not the default.

A fresh cluster install requires explicit --cluster, --shard, --replica, --advertise-host, at least one --peer, at least one --keeper, --listen (non-loopback, either 0.0.0.0 or this node’s advertised address) and --admin-password. A missing piece is reported as an error listing every missing flag.

What cluster mode renders

Standard server config still lives in config.d/zz-pgcli.xml. Cluster mode adds a second managed file, config.d/zz-pgcli-cluster.xml:

<?xml version="1.0"?>
<clickhouse>
    <remote_servers>
        <chcluster>
            <shard>
                <internal_replication>true</internal_replication>
                <replica>
                    <host>192.0.2.11</host>
                    <port>9000</port>
                    <user>admin</user>
                    <password from_env="PGCLI_CLICKHOUSE_ADMIN_PASSWORD"></password>
                </replica>
                <replica>
                    <host>192.0.2.12</host>
                    <port>9000</port>
                    <user>admin</user>
                    <password from_env="PGCLI_CLICKHOUSE_ADMIN_PASSWORD"></password>
                </replica>
            </shard>
            <shard>
                <internal_replication>true</internal_replication>
                <replica>
                    <host>192.0.2.13</host>
                    <port>9000</port>
                    <user>admin</user>
                    <password from_env="PGCLI_CLICKHOUSE_ADMIN_PASSWORD"></password>
                </replica>
                <replica>
                    <host>192.0.2.14</host>
                    <port>9000</port>
                    <user>admin</user>
                    <password from_env="PGCLI_CLICKHOUSE_ADMIN_PASSWORD"></password>
                </replica>
            </shard>
        </chcluster>
    </remote_servers>
    <macros>
        <cluster>chcluster</cluster>
        <shard>1</shard>
        <replica>1</replica>
    </macros>
    <zookeeper>
        <node>
            <host>192.0.2.11</host>
            <port>9181</port>
        </node>
        <node>
            <host>192.0.2.12</host>
            <port>9181</port>
        </node>
        <node>
            <host>192.0.2.13</host>
            <port>9181</port>
        </node>
        <session_timeout_ms>30000</session_timeout_ms>
        <operation_timeout_ms>10000</operation_timeout_ms>
    </zookeeper>
    <distributed_ddl>
        <path>/clickhouse/chcluster/task_queue/ddl</path>
    </distributed_ddl>
    <interserver_http_host>192.0.2.11</interserver_http_host>
    <interserver_http_port>9009</interserver_http_port>
    <default_replica_path>/clickhouse/chcluster/tables/{uuid}/{shard}</default_replica_path>
    <default_replica_name>{replica}</default_replica_name>
</clickhouse>
  • remote_servers declares the full topology under the cluster name; internal_replication=true makes a write to a replicated table replicate through Keeper instead of the Distributed engine writing to every replica itself. Each replica entry also carries the admin user so cross-shard Distributed queries authenticate on the remote member — the image’s entrypoint removes the password-less default user when a dedicated admin account is configured. The password is referenced as from_env; the container entrypoint wrapper exports it from the mounted secret at startup, so the 0644 cluster file contains only the variable name, never the password.
  • macros fill {shard} and {replica} in ReplicatedMergeTree paths on this node.
  • zookeeper points at the Keeper client endpoints (Keeper speaks the ZooKeeper protocol).
  • distributed_ddl places ON CLUSTER DDL tasks under a cluster-specific path.
  • interserver_http_host / _port is the replica-to-replica catch-up endpoint.
  • default_replica_path / default_replica_name let ReplicatedMergeTree with no explicit arguments derive its Keeper path from the macros.

The cluster file contains no listeners, logger or backup settings — those stay in the base file. Its only user entry is the from_env credential reference above. In cluster mode, config set rejects keys that would contradict the managed topology (remote_servers, macros, zookeeper, distributed_ddl, default_replica_path, default_replica_name). A single-node instance may still set an external zookeeper/macros block of its own.

The cluster file is removed automatically if an instance is reinstalled as a single node (for example after remove without --clean-data), so a stale remote_servers block cannot leak into standalone mode.

Verify

pg addon clickhouse cluster status --name clickhouse

The command queries system.clusters and system.replicas on the local member, compares the topology with pg.yaml and probes every Keeper client endpoint:

clickhouse "clickhouse" — cluster "chcluster", this node shard 1 / replica 1
  Cluster config: /home/you/.pgcli/addon/clickhouse/clickhouse/config.d/zz-pgcli-cluster.xml
  system.clusters: 4 member(s), expected 4
    shard 1 replica 1  192.0.2.11:9000  local
    shard 1 replica 2  192.0.2.12:9000
    shard 2 replica 1  192.0.2.13:9000
    shard 2 replica 2  192.0.2.14:9000
  system.replicas: 1 replicated table(s)
    demo.events replica 1 — ok, delay 0s, queue 0
  [OK] Keeper client endpoints reachable: 3/3 (quorum 2; reachability is not a Raft quorum proof)

It exits non-zero if system.clusters does not match the stored topology or a replica is read-only. Keeper reachability is reported separately: a TCP-reachable client port is not proof of a Raft quorum.

Direct SQL equivalents:

pg addon clickhouse query --name clickhouse \
  "SELECT cluster, shard_num, replica_num, host_name, port, is_local FROM system.clusters WHERE cluster = 'chcluster'"

pg addon clickhouse query --name clickhouse \
  "SELECT database, table, replica_name, is_readonly, absolute_delay, queue_size FROM system.replicas"

pg addon clickhouse query --name clickhouse \
  "SELECT count() FROM system.zookeeper WHERE path = '/clickhouse/chcluster'"

Create replicated tables

Create the database and tables once with ON CLUSTER; ClickHouse expands the statement onto every member. Because default_replica_path / default_replica_name are rendered, ReplicatedMergeTree needs no explicit path argument:

CREATE DATABASE IF NOT EXISTS demo ON CLUSTER chcluster;

CREATE TABLE demo.events ON CLUSTER chcluster
(
    id   UInt64,
    ts   DateTime,
    name String
)
ENGINE = ReplicatedMergeTree
ORDER BY id;

CREATE TABLE demo.events_dist ON CLUSTER chcluster
AS demo.events
ENGINE = Distributed(chcluster, demo, events, rand());

Run these one statement at a time through pg addon clickhouse query (multi-statement mode is not enabled), or pipe a file through shell with clickhouse-client --multiquery.

Local table (demo.events) and distributed table (demo.events_dist) have different jobs:

  • demo.events holds this shard’s rows and replicates them to the sibling replica.
  • demo.events_dist is a routing view: it fans writes across shards and merges reads from all shards. It stores no data.

Insert locally and verify replication on the sibling:

# On host01: insert into shard 1
pg addon clickhouse query --name clickhouse \
  "INSERT INTO demo.events VALUES (1, now(), 'host01')"

# On host02: the sibling replica sees it
pg addon clickhouse query --name clickhouse \
  "SELECT id, name FROM demo.events ORDER BY id"

# Read across both shards through the Distributed table (run on any member)
pg addon clickhouse query --name clickhouse \
  "SELECT id, name FROM demo.events_dist ORDER BY id"

If you prefer explicit paths (for example to give each table its own Keeper layout), pass them yourself and keep the macros in their placeholders:

ENGINE = ReplicatedMergeTree('/clickhouse/chcluster/tables/{shard}/events', '{replica}')

{shard} and {replica} come from the rendered macros, so the expression expands differently on each member.

Failure behavior

  • One ClickHouse replica stops. Its sibling in the same shard keeps serving reads and writes. When it returns, it catches up through Keeper and the interserver endpoint; check system.replicas.queue_size until it drains.
  • Both replicas of a shard stop. That shard’s data is unavailable, but other shards keep working. Distributed reads return partial results / errors depending on the engine settings; do not treat the cluster as available.
  • One Keeper of three stops. A quorum of 2/3 remains; ON CLUSTER DDL and replication continue.
  • Two Keepers of three stop. There is no quorum. New replicated tables and DDL fail, and existing replicated tables go read-only once the ClickHouse-to-Keeper session expires (30 s in the rendered config). Treat Keeper quorum loss as an outage and restore a member before writing.

Keeper data is small but critical: it holds the replication log and table metadata. Losing the whole Keeper quorum does not lose the table data on disk, but the replication state cannot be reconstructed automatically.

Operations

  • Identity is immutable. After install, --force rejects changes to --cluster, --shard, --replica, --advertise-host, --peer, --keeper, --interserver-port and (in cluster mode) --tcp-port. Every other member has this node baked into its configuration, so changing one node’s identity requires a coordinated rebuild.
  • Growth is manual. Adding members requires a rolling rebuild; see Horizontal scaling. v1 does not automate rebalancing or shard splitting.
  • backup / restore are per-node. They operate on the local instance’s local tables. Backing up one replica does not back up the other shards. Replicated tables restored into a cluster need their Keeper paths considered.
  • config set affects only the local member and restarts it by default. A cluster-wide change must be repeated on every host; the CLI does not distribute configuration. Pass --no-restart to write the value without restarting, so it applies on the next start. Roll members one at a time; never restart both replicas of a shard together.
  • user / grant are per-node unless issued with ON CLUSTER. Users and grants created by the CLI run against the local member only.
  • Autostart order. pg start starts autostart-enabled Keeper members first, then ClickHouse members, then nginx. Enable both with pg autostart enable --clickhouse-keeper --name keeper and pg autostart enable --clickhouse --name clickhouse.

Setting memory

ClickHouse has no cluster-wide memory limit. Memory is enforced per server process, so every member needs its own configuration — there is no command that pushes a value to the whole cluster.

Server memory

Set max_server_memory_usage at install time with --config-option:

pg addon install clickhouse --name clickhouse \
  --cluster chcluster --shard 1 --replica 1 \
  --advertise-host 192.0.2.11 --listen 0.0.0.0 \
  --admin-password "$CH_ADMIN_PASSWORD" \
  --peer 1/2@192.0.2.12:9000 \
  --peer 2/1@192.0.2.13:9000 \
  --peer 2/2@192.0.2.14:9000 \
  --keeper 192.0.2.11:9181 \
  --keeper 192.0.2.12:9181 \
  --keeper 192.0.2.13:9181 \
  --interserver-port 9009 \
  --config-option max_server_memory_usage=2147483648

On an existing member, use config set (it restarts the local container by default; --no-restart defers the change to the next start):

# Run on every member separately
pg addon clickhouse config set max_server_memory_usage=2147483648 --name clickhouse

Roll members one at a time: wait until system.replicas shows is_readonly=0 with an empty queue before moving on, and never restart both replicas of a shard together.

The default 0 keeps ClickHouse’s ratio rule (max_server_memory_usage_to_ram_ratio, 0.9 of host RAM). That is risky on shared hosts — always set an absolute value explicitly when Keeper or other services share the machine.

Query memory

max_memory_usage, max_bytes_before_external_group_by and max_bytes_before_external_sort are user/profile settings, not server XML, so config set does not apply them. Define them on a user with ON CLUSTER, or set them per session:

CREATE USER app IDENTIFIED WITH sha256_password BY '...'
SETTINGS max_memory_usage = 5000000000,
         max_bytes_before_external_group_by = 2000000000
ON CLUSTER chcluster;
SET max_memory_usage = 5000000000;

Clients can also pass them per request (HTTP query parameters, or the driver’s settings map). A query-level value cannot exceed the server-wide max_server_memory_usage.

Memory across a Distributed query

Each participating shard executes its local part and is bounded by its own max_server_memory_usage; the initiating node additionally holds memory for result merging and aggregation. There is no shared cluster memory pool. Size for per-node peak × concurrency, and leave headroom for the initiating node and for Keeper. See Memory limits for the general ClickHouse guidance.

Setting CPU

pgcli applies no container-level CPU quota: it never passes --cpus or --cpuset-cpus to podman, so a container may use every host core. ClickHouse also parallelizes queries across the available cores by default — saturating the host’s cores is the default behavior.

Query threads

max_threads (default: available cores) and max_insert_threads are user/session/request settings, not server XML, so config set does not apply them. Define them on a user with ON CLUSTER, or set them per session:

CREATE USER app IDENTIFIED WITH sha256_password BY '...'
SETTINGS max_threads = 4, max_insert_threads = 2
ON CLUSTER chcluster;
SET max_threads = 4;

Clients can also pass them per request (HTTP query parameters, or the driver’s settings map).

Server concurrency

max_concurrent_queries and background_pool_size are server XML settings. Run config set on every member separately (it restarts the local container by default; --no-restart defers the change):

# Run on every member separately
pg addon clickhouse config set max_concurrent_queries=20 background_pool_size=8 --name clickhouse

Cluster semantics

Each node is independent — there is no cluster-wide CPU quota. A Distributed query starts threads on every participating shard, and the initiating node also pays the merge cost. Size for per-node peak × concurrency, and tune it together with max_server_memory_usage. Hard cgroup isolation is outside pgcli’s scope: any --cpus you add to the container manually disappears when pgcli recreates it.

Horizontal scaling

v1 membership is static: there is no online add-node command. Scaling means installing the new members first, then rewriting every existing member’s remote_servers block in a rolling rebuild.

  • Every shard keeps the same replica count, numbered consecutively from 1. Adding one replica means adding it to every shard.
  • --peer is part of the immutable identity, so an existing member cannot be changed in place with --force. Remove it without --clean-data and reinstall under the same --name with the extended peer list. The default data directory is reused and replicated tables reconnect to their Keeper paths. If the original install used a custom --data-dir, pass the same path again.
  • Keep --cluster, --admin-password, --interserver-port and --tcp-port unchanged. Keeper membership does not change unless you are scaling Keeper separately.
  • Roll one member at a time, never take both replicas of a shard down together, wait until system.replicas shows is_readonly=0 and an empty queue, and pause ON CLUSTER DDL during the rollout.

Add replicas

Add one replica to every shard. Going from 2 shards × 2 replicas to 2 × 3 uses two new hosts:

Host --shard --replica --advertise-host
host05 1 3 192.0.2.15
host06 2 3 192.0.2.16

Install each new member with the full six-member peer list, listing every other member and never the node itself:

# host05 — shard 1 / replica 3
pg addon install clickhouse --name clickhouse \
  --cluster chcluster --shard 1 --replica 3 \
  --advertise-host 192.0.2.15 --listen 0.0.0.0 \
  --admin-password "$CH_ADMIN_PASSWORD" \
  --peer 1/1@192.0.2.11:9000 --peer 1/2@192.0.2.12:9000 \
  --peer 2/1@192.0.2.13:9000 --peer 2/2@192.0.2.14:9000 \
  --peer 2/3@192.0.2.16:9000 \
  --keeper 192.0.2.11:9181 --keeper 192.0.2.12:9181 \
  --keeper 192.0.2.13:9181 \
  --interserver-port 9009

host06 uses --shard 2 --replica 3 --advertise-host 192.0.2.16 with the matching peer list.

Then roll the four existing members. On each host, remove without --clean-data and reinstall with the same identity and the extended peer list:

# On host01; repeat on host02–host04 with their own identity
pg addon remove clickhouse --name clickhouse     # keeps data, config and logs
pg addon install clickhouse --name clickhouse \
  --cluster chcluster --shard 1 --replica 1 \
  --advertise-host 192.0.2.11 --listen 0.0.0.0 \
  --admin-password "$CH_ADMIN_PASSWORD" \
  --peer 1/2@192.0.2.12:9000 --peer 2/1@192.0.2.13:9000 \
  --peer 2/2@192.0.2.14:9000 \
  --peer 1/3@192.0.2.15:9000 --peer 2/3@192.0.2.16:9000 \
  --keeper 192.0.2.11:9181 --keeper 192.0.2.12:9181 \
  --keeper 192.0.2.13:9181 \
  --interserver-port 9009

New replicas fetch existing parts from their shard siblings automatically — there is no manual data rebalance. Verify with pg addon clickhouse cluster status --name clickhouse: system.clusters should list six members (2 shards × 3 replicas) and system.replicas should be healthy.

Add shards

A new shard starts empty and needs the same replica count as the existing shards. Going from 2 × 2 to 3 × 2 uses two new hosts:

Host --shard --replica --advertise-host
host05 3 1 192.0.2.15
host06 3 2 192.0.2.16

Install them the same way; host05’s command differs from the replica example only in identity and peer list:

# host05 — shard 3 / replica 1
pg addon install clickhouse --name clickhouse \
  --cluster chcluster --shard 3 --replica 1 \
  --advertise-host 192.0.2.15 --listen 0.0.0.0 \
  --admin-password "$CH_ADMIN_PASSWORD" \
  --peer 1/1@192.0.2.11:9000 --peer 1/2@192.0.2.12:9000 \
  --peer 2/1@192.0.2.13:9000 --peer 2/2@192.0.2.14:9000 \
  --peer 3/2@192.0.2.16:9000 \
  --keeper 192.0.2.11:9181 --keeper 192.0.2.12:9181 \
  --keeper 192.0.2.13:9181 \
  --interserver-port 9009

host06 uses --shard 3 --replica 2 --advertise-host 192.0.2.16. Then roll host01–host04 exactly as above, replacing the two new peer entries with 3/1@192.0.2.15:9000 and 3/2@192.0.2.16:9000.

Historical rows are not redistributed: the Distributed table only routes new writes to the new shard. If existing data must move, plan a reshard separately (for example clickhouse-copier, or a new table populated with INSERT … SELECT or dual writes); pgcli v1 does not automate this. Verify system.clusters lists six members (3 shards × 2 replicas).

Production notes

  • Run Keeper on dedicated servers. The co-located layout in this guide exists to fit a four-VM test lab. Production should use three (or five) independent Keeper servers with separate disks, power and failure domains. Keeper and ClickHouse compete for the same RAM and I/O, and co-location turns a ClickHouse failure into a quorum risk.
  • Trusted network only. Keeper has no authentication and no TLS; ClickHouse interserver traffic is plaintext too. Do not expose Keeper ports (9181, 9234) or the interserver port beyond a trusted network.
  • No TLS. The HTTP and native listeners are plaintext. Front the HTTP port with the nginx addon when remote clients need TLS; never expose the native or interserver ports to untrusted networks.
  • Asynchronous replication. A write acknowledged by one replica is not yet on the sibling. Do not treat a successful insert as durable on two nodes; use system.replicas for health and SYSTEM SYNC REPLICA when a test must wait for catch-up.
  • Shared admin password. Every member must use the same --admin-password; pgcli cannot enforce this across hosts. A mismatch shows up as inconsistent client access, not as an install error.
  • Memory. Small VMs need an explicit max_server_memory_usage on each ClickHouse member, and Keeper needs headroom too. Pass --config-option max_server_memory_usage=2147483648 at install time, or set it later with pg addon clickhouse config set; there is no cluster-wide push, so repeat it on every member. The 2 GiB test VMs use a few hundred MiB per ClickHouse container; see Memory limits.
  • Upgrades. Upgrade one replica at a time (stop, install --force --version <new>, start), wait for replication to catch up, then move to the sibling. Never run a newer on-disk format under an older server.

Limits

  • Static membership: no online add/remove, no automatic rebalance, no shard splitting.
  • Uniform topology only: all shards must have the same replica count.
  • Concrete IP addresses only; no DNS names.
  • One ClickHouse instance and one Keeper per host.
  • No cross-host orchestration: every command addresses this host’s pg.yaml.
  • No TLS, no Keeper authentication, no mixed-version guarantees.
  • Replication is asynchronous.

CLI flag reference

Shared ClickHouse flags (--name, --version, --data-dir, ports, users, config, backup, lifecycle) are documented on the ClickHouse page. The cluster-specific additions:

pg addon install clickhouse --cluster

Flag Default Description
--cluster NAME — (required) Cluster name; also becomes the remote_servers element, macros entry and DDL path component. [A-Za-z_][A-Za-z0-9_-]*, max 48 chars
--shard N — (required) This member’s 1-based shard number
--replica N — (required) This member’s 1-based replica number within the shard
--advertise-host IP — (required) Concrete non-loopback address peers and clients use for this member
--peer S/R@HOST:PORT — (required, repeatable) Another member as shard/replica@host:tcp_port. List the other members on every host; this host is added automatically
--keeper HOST[:PORT] — (required, repeatable) Keeper client endpoint. Pass the full shared list on every host; default port 9181
--interserver-port N 9009 Replica catch-up port; must match across the cluster and is immutable after install
--listen ADDR required in cluster mode Must be 0.0.0.0 or this node’s --advertise-host; loopback is rejected
--admin-password PW required in cluster mode Must be identical on every member; the generated-password path is disabled
--tcp-port N auto (base 9000) Native port; used by every peer’s --peer entry and immutable after install

Cluster identity flags are immutable with --force: --cluster, --shard, --replica, --advertise-host, --peer, --keeper, --interserver-port, and --tcp-port in cluster mode. Re-running install without --force compares every explicit flag with the stored value and reports drift instead of silently applying it.

pg addon clickhouse cluster status

Argument/flag Default Description
--name NAME clickhouse Cluster member to inspect; must be running

The command fails on a single-node instance, when system.clusters disagrees with the stored topology, or when a replicated table is read-only. Keeper reachability is informational.

Verification

Verified on 2026-11-03 with clickhouse/clickhouse-server:26.8.36.3 on a four-host topology matching the table above: all 103 assertions in test/addon/test_clickhouse_cluster.sh passed, covering replicated writes, cross-shard Distributed reads and writes, one Keeper member down, one ClickHouse replica down and catch-up, identity immutability and path isolation.

36 - ClickHouse Keeper

Run a standalone ClickHouse Keeper quorum as a top-level addon — the ZooKeeper-compatible coordination service behind ReplicatedMergeTree and ON CLUSTER DDL

pg addon install clickhouse-keeper runs ClickHouse Keeper as its own managed container from the official docker.io/clickhouse/clickhouse-keeper image. Keeper is the ZooKeeper-compatible coordination service used by ClickHouse replicated clusters: it stores the replicated-table metadata, the replication log and the ON CLUSTER DDL task queue.

Keeper is a separate top-level addon, never a process inside the ClickHouse container:

  • Its config, data and log directories are independent of every ClickHouse instance (pgcli rejects overlapping paths).
  • It has its own lifecycle: install, start, stop, remove and autostart are all addressed as pg addon ... clickhouse-keeper.
  • pg start starts autostart-enabled Keeper members before ClickHouse members, so ClickHouse never boots against a Keeper quorum that is still down.

This addon is only useful with ClickHouse in cluster mode. A single-node ClickHouse does not need Keeper.

Production runs Keeper on dedicated servers. The examples below co-locate Keeper with ClickHouse on a test lab’s VMs. Production should use 3 (or 5) independent servers with separate disks and failure domains — see Production notes.

Parameters

Flag Default Description
--name clickhouse-keeper Instance name (map key; also the default subcommand name)
--version 26.8.36.3 Upstream image tag from docker.io/clickhouse/clickhouse-keeper
--server-id — (required on fresh install) This member’s 1-based Raft server id; unique within the quorum
--advertise-host — (required on fresh install) Concrete non-loopback address Raft peers use for this member
--peer ID@HOST[:RAFT_PORT] — Another member; repeatable. List every other member on every host; this host is added automatically. Default Raft port 9234
--client-port 9181 ZooKeeper-protocol client port (ClickHouse connects here)
--raft-port 9234 Raft peer port between Keeper members
--listen 127.0.0.1 Bind address. Multi-member installs require a non-loopback value (0.0.0.0 or the advertised address)
--data-dir <base_dir>/addon/clickhouse-keeper/<name>/data Raft log and snapshot storage; absolute path
--log-dir <base_dir>/addon/clickhouse-keeper/<name>/logs clickhouse-keeper.log and .err.log; absolute path
--config-dir <base_dir>/addon/clickhouse-keeper/<name>/config Directory that receives keeper_config.xml; absolute path
--force false Rewrite the config and recreate the container, keeping data and identity
--clean-data false (remove) Also delete the instance dir plus any custom data/log dirs

--cluster is rejected: Keeper membership is expressed entirely by --server-id, --advertise-host and --peer. --image does not apply either — use --version.

Install a three-member quorum

Install one member on each host. Only the local identity and the omitted peer differ:

# host01
pg addon install clickhouse-keeper --name keeper \
  --server-id 1 --advertise-host 192.0.2.11 --listen 0.0.0.0 \
  --peer 2@192.0.2.12 --peer 3@192.0.2.13

# host02
pg addon install clickhouse-keeper --name keeper \
  --server-id 2 --advertise-host 192.0.2.12 --listen 0.0.0.0 \
  --peer 1@192.0.2.11 --peer 3@192.0.2.13

# host03
pg addon install clickhouse-keeper --name keeper \
  --server-id 3 --advertise-host 192.0.2.13 --listen 0.0.0.0 \
  --peer 1@192.0.2.11 --peer 2@192.0.2.12

The rendered config on each host contains the complete Raft membership (the two peers plus this member folded in from its own identity), sorted by server id. Installs can run in any order: a member whose peers are not up yet starts without listening on the client port and reports a warning instead of failing the install. It joins as soon as a quorum forms, so continue with the remaining members. pg addon clickhouse-keeper status warns but does not fail when quorum is not reached yet.

A fresh install requires explicit --server-id and --advertise-host — Keeper cannot derive either safely. A multi-member install also requires non-loopback --listen, because peers cannot reach 127.0.0.1. Quorums smaller than three members are accepted for development with a warning; use 3 or 5 members in production.

The install summary:

✓ ClickHouse Keeper "keeper" installed
  Version:     26.8.36.3
  Image:       docker.io/clickhouse/clickhouse-keeper:26.8.36.3
  Container:   pgcli-clickhouse-keeper-keeper
  Server ID:   1
  Client:      0.0.0.0:9181
  Raft:        192.0.2.11:9234
  Members:     1@192.0.2.11:9234, 2@192.0.2.12:9234, 3@192.0.2.13:9234
  Data dir:    /home/you/.pgcli/addon/clickhouse-keeper/keeper/data
  Logs dir:    /home/you/.pgcli/addon/clickhouse-keeper/keeper/logs
  Config:      /home/you/.pgcli/addon/clickhouse-keeper/keeper/config/keeper_config.xml

Quorum

Keeper replicates its state with Raft. A quorum is floor(n/2)+1 members:

Members Quorum Failures tolerated
1 1 0 (development only)
2 2 0 — either member’s loss stops the quorum
3 2 1
5 3 2

Three members is the smallest configuration that survives a host failure. Even numbers are not useful: four members still need three for quorum. Run 3 or 5.

  • One member down (3-member quorum). ClickHouse keeps creating replicated tables and running ON CLUSTER DDL.
  • Two members down. No quorum. Replication stops, new replicated tables and DDL fail, and existing replicated tables go read-only after the session timeout. Restore a member before writing.
  • Loss of the whole quorum. Table data on ClickHouse disks is not deleted, but replication and DDL state cannot be rebuilt automatically. Back up the Keeper data directories along with ClickHouse data.

Keeper’s own client port is intentionally unauthenticated, like ZooKeeper. Keep 9181 and 9234 on a trusted network.

Status

pg addon clickhouse-keeper status --name keeper

The command reports the container state, the rendered membership and a local mntr probe:

clickhouse-keeper "keeper" — running (ruok ok)
  Version:    26.8.36.3
  Image:      docker.io/clickhouse/clickhouse-keeper:26.8.36.3
  Container:  pgcli-clickhouse-keeper-keeper
  Server ID:  1
  Client:     0.0.0.0:9181
  Raft:       192.0.2.11:9234
  Members:    1@192.0.2.11:9234, 2@192.0.2.12:9234, 3@192.0.2.13:9234
  Local state: leader
  Reachability:
    server 1  127.0.0.1:9181  reachable (leader)
    server 2  192.0.2.12:9181  reachable
    server 3  192.0.2.13:9181  reachable
  [OK] 3/3 client endpoints reachable (quorum 2; client reachability is not a Raft quorum proof)

The local member is probed over loopback, so it shows 127.0.0.1; remote members are probed at their advertised addresses. Only the local member’s Raft role is known (from mntr), so remote members have no role suffix. Reachability probes every member’s client port with the ruok four-letter word; the local member also answers mntr, which provides zk_server_state (leader / follower / standalone). A reachable client port is not a quorum proof — the output says so explicitly. Combine mntr state with the reachable count to judge health.

What pgcli creates

Everything for one instance lives under <base_dir>/addon/clickhouse-keeper/<name>/:

Host path Container path Notes
config/keeper_config.xml /etc/pgcli-clickhouse-keeper/keeper_config.xml Read-only managed config
data/ /var/lib/clickhouse-keeper Raft log under coordination/log, snapshots under coordination/snapshots
logs/ /var/log/clickhouse-keeper clickhouse-keeper.log / .err.log, rotated at 100 MB × 3

All three paths can be overridden independently (--config-dir controls the directory that holds keeper_config.xml). pgcli validates at install time that the Keeper config/data/log paths do not overlap each other or any ClickHouse config/data/log/backup/secret path.

The generated XML sets:

<?xml version="1.0"?>
<clickhouse>
    <logger>
        <level>information</level>
        <log>/var/log/clickhouse-keeper/clickhouse-keeper.log</log>
        <errorlog>/var/log/clickhouse-keeper/clickhouse-keeper.err.log</errorlog>
        <size>100M</size>
        <count>3</count>
        <console>1</console>
    </logger>
    <listen_host>0.0.0.0</listen_host>
    <keeper_server>
        <tcp_port>9181</tcp_port>
        <server_id>1</server_id>
        <log_storage_path>/var/lib/clickhouse-keeper/coordination/log</log_storage_path>
        <snapshot_storage_path>/var/lib/clickhouse-keeper/coordination/snapshots</snapshot_storage_path>
        <coordination_settings>
            <operation_timeout_ms>10000</operation_timeout_ms>
            <session_timeout_ms>30000</session_timeout_ms>
            <raft_logs_level>information</raft_logs_level>
        </coordination_settings>
        <raft_configuration>
            <server><id>1</id><hostname>192.0.2.11</hostname><port>9234</port></server>
            <server><id>2</id><hostname>192.0.2.12</hostname><port>9234</port></server>
            <server><id>3</id><hostname>192.0.2.13</hostname><port>9234</port></server>
        </raft_configuration>
    </keeper_server>
</clickhouse>

The container uses --network host, --restart unless-stopped, a 30-second stop timeout and nofile=262144. The official entrypoint chowns the data and log mounts before dropping privileges. There is no secret: Keeper configuration contains no credentials.

Lifecycle

pg addon start clickhouse-keeper --name keeper      # create if missing, wait briefly for local ruok; a pending quorum only warns
pg addon stop clickhouse-keeper --name keeper
pg addon clickhouse-keeper status --name keeper
pg addon clickhouse-keeper shell --name keeper      # bash inside the container
pg addon clickhouse-keeper config show --name keeper
pg logs addon clickhouse-keeper --name keeper -f
pg addon remove clickhouse-keeper --name keeper     # remove container + pg.yaml entry, keep data
pg addon remove clickhouse-keeper --name keeper --clean-data

remove prints a quorum warning and reminds you that the remaining members still reference the removed server id in their raft_configuration. v1 has no online membership change: replacing a member means reinstalling the affected members with updated peer lists. --clean-data deletes only the Keeper instance directory and any custom --data-dir/--log-dir outside it; ClickHouse data is never touched.

config show prints the rendered XML; Keeper has no config set in v1 and no password subcommand.

Autostart:

pg autostart enable --clickhouse-keeper --name keeper
pg autostart status
pg autostart disable --clickhouse-keeper --name keeper

pg start starts autostart-enabled Keeper members first, then ClickHouse members, then nginx.

Production notes

  • Dedicated servers. Run the quorum on 3 (or 5) servers that do not also run ClickHouse. Separate disks and failure domains matter more than CPU: a lost Keeper quorum makes the whole ClickHouse cluster read-only, so co-location couples unrelated failures.
  • Trusted network only. No authentication, no TLS. Any client that can reach 9181 can read and modify coordination state.
  • Back up the data directory. Keeper’s data is small and changes frequently; a filesystem snapshot of data/ on one healthy member is enough for recovery, but a consistent backup is easier with the quorum stopped or one member stopped at a time.
  • One Keeper per host. v1 enforces one Keeper member per host.
  • Static membership. No online add/remove/replace; plan the quorum size up front.
  • Resource use. Keeper is lightweight (hundreds of MiB) but not free on a 2 GiB test VM; leave headroom for ClickHouse’s max_server_memory_usage.

Limits

  • No authentication and no TLS.
  • No online membership change; --server-id, --advertise-host, --peer, --client-port and --raft-port are immutable after install, even with --force.
  • No config set; edit the generated XML only through a full reinstall.
  • IP addresses only (no DNS names).
  • One Keeper per host.
  • The addon manages one container per config entry; multi-member setups are one config entry per host.

CLI flag reference

pg addon install clickhouse-keeper

Flag Default Description
--name NAME clickhouse-keeper Instance name; [A-Za-z0-9][A-Za-z0-9_-]*, max 48 chars
--version TAG 26.8.36.3 Upstream image tag from docker.io/clickhouse/clickhouse-keeper
--server-id N required on fresh install 1-based Raft server id, unique in the quorum
--advertise-host IP required on fresh install Concrete non-loopback address peers dial
--peer ID@HOST[:RAFT_PORT] — Repeatable; list every other member on every host
--client-port N 9181 ZooKeeper-protocol client port
--raft-port N 9234 Raft peer port
--listen ADDR 127.0.0.1 Bind address; non-loopback required with peers
--data-dir DIR <instance>/data Absolute path; mounted at /var/lib/clickhouse-keeper
--log-dir DIR <instance>/logs Absolute path; mounted at /var/log/clickhouse-keeper
--config-dir DIR <instance>/config Absolute path; receives keeper_config.xml
--force false Rewrite config and recreate the container; identity flags stay immutable

Re-running install without --force compares every explicit flag with the stored value and reports drift instead of applying it.

pg addon clickhouse-keeper status / shell / config show

Argument/flag Default Description
--name NAME clickhouse-keeper Instance to operate on

Lifecycle, logs, autostart

Command Flags Description
pg addon start clickhouse-keeper --name NAME Start (create if missing); wait briefly for local ruok, warning when the quorum is still pending
pg addon stop clickhouse-keeper --name NAME Stop the container, keep data
pg addon remove clickhouse-keeper --name NAME, --clean-data Remove container and config entry; --clean-data deletes the Keeper instance/data/log paths
pg logs addon clickhouse-keeper --name NAME, -n N (default 50), -f Container logs
pg autostart enable|disable --clickhouse-keeper, --name NAME Toggle boot start for one member

Global flags

Flag Description
-c, --config FILE Config file (default ~/.pgcli/pg.yaml)
-o, --output FILE Output config path (default the same file)
-i, --instance NAME PostgreSQL instance selector — not used by Keeper; use --name instead

Verification

Verified on 2026-11-03 with clickhouse/clickhouse-keeper:26.8.36.3: the Keeper assertions in test/addon/test_clickhouse_cluster.sh passed on a three-member quorum, including leader/follower state, 2/3 quorum with one member stopped, and ON CLUSTER DDL while degraded.

37 - Kafka

Run Apache Kafka 4.x brokers in KRaft mode (no ZooKeeper) as a managed addon — single-node or a multi-host static controller quorum, with topic management, rendered server.properties and host networking

pg addon install kafka runs Apache Kafka 4.4.0 as a managed container from the official docker.io/apache/kafka multi-arch image. Kafka 4.x is KRaft-only: the metadata controller is built into the broker process (process.roles=broker,controller, combined mode) and ZooKeeper is not installed or used.

Like ClickHouse, Kafka is a top-level addon — it does not front a PostgreSQL instance. pgcli renders server.properties, pins a KRaft cluster id, bind-mounts the data directory and runs the container on the host network. A single command installs a single combined node; adding --cluster, --node-id and --peer installs one node of a multi-host static controller quorum, with every host running its own pg addon install kafka (pgcli never SSHes). See Multi-host cluster.

There is no authentication. Kafka listens with PLAINTEXT by default, and --listen defaults to 127.0.0.1. TLS is opt-in (--tls) and encrypts traffic, but it does not authenticate clients (ssl.client.auth=none), and the plaintext listener stays enabled for compatibility. Expose it only on a trusted private network or behind a firewall/proxy. Anyone who can reach either listener can read and write every topic.

Parameters

Flag Default Description
--name kafka Instance name (map key; also the default subcommand name)
--version 4.4.0 Upstream image tag, pulled directly from docker.io/apache/kafka
--data-dir <base_dir>/addon/kafka/<name>/data Data directory bind-mounted at /var/lib/kafka/data; must be an absolute path
--listen 127.0.0.1 Bind address for the PLAINTEXT, SSL (when --tls) and CONTROLLER listeners. 0.0.0.0 exposes all enabled listeners on the network; in cluster mode it must be 0.0.0.0 or the advertised address
--advertise-host 127.0.0.1 Host clients are told to use. Must be a concrete IP (never 0.0.0.0); in single-node mode it is also the controller voter address. In cluster mode it is this node’s controller voter address too, so it must be a concrete non-loopback IP and is required on a fresh cluster install
--broker-port auto (base 9092) Host broker port; 0 = auto-assign from kafka_broker_start_port
--controller-port auto (base 19093) Host KRaft controller port; 0 = auto-assign from kafka_controller_start_port. Cluster installs must pass it explicitly: every peer embeds it in its voter list
--cluster NAME — Join a multi-host cluster with this name. Every host must use the same name; the KRaft cluster id is derived from it deterministically
--node-id N 1 single-node This node’s 1-based KRaft node id. Required on a fresh cluster install, unique within the cluster; rejected in single-node mode
--peer ID@HOST:PORT — Another controller voter. Repeat once per other node (this node is folded in automatically); pass the full peer list on every host. The host must be an IP and the port must match that node’s --controller-port
--tls false Add an SSL listener next to the plaintext broker, using a certificate from pgcli’s self-signed CA. The PLAINTEXT listener stays enabled
--tls-pem — Serve TLS with this combined PEM (certificate chain + private key) instead of the generated certificate. Implies --tls; the file is validated and copied to config/tls/server.pem. PKCS#8, PKCS#1 and SEC1 keys are accepted. In cluster mode the certificate must cover this node’s --advertise-host
--tls-port auto (base 9093) Host SSL listener port; 0 = auto-assign from kafka_tls_start_port; requires --tls
--cluster-id derived (cluster) / generated In cluster mode the id is derived from --cluster and an explicit value must equal it; in single-node mode it adopts an explicit 22-character KRaft cluster id, else adopts meta.properties or generates one
--config-option K=V — Extra server.properties setting (num.partitions=3, log.retention.hours=168); repeatable; replaces the stored override map
--force false Re-render server.properties and recreate the container; keeps data, the stored cluster id and node id; required to add or remove TLS. Cluster identity fields (cluster, node id, cluster id, peers, advertise host, controller port) cannot be changed even with --force

--image does not apply to Kafka — use --version.

The controller default is 19093, not 9093, because 9093 belongs to the Alertmanager pool (the TLS pool starts at 9093 but skips ports owned by other addons). pgcli renders the topology keys itself; --config-option can only add settings outside the managed set (roles, node id, listeners, advertised listeners, protocol map, controller listeners/voters, log.dirs, the SSL keystore/client-auth keys, internal-topic replication factors, default.replication.factor and min.insync.replicas are rejected).

Install

pg addon install kafka --name k1
✓ Kafka "k1" installed
  Version:     4.4.0
  Image:       docker.io/apache/kafka:4.4.0
  Container:   pgcli-kafka-k1
  Broker:      127.0.0.1:9092
  Controller:  127.0.0.1:19093
  Node ID:     1
  Cluster ID:  <22-character id>
  Data dir:    /home/you/.pgcli/addon/kafka/k1/data
  Config:      /home/you/.pgcli/addon/kafka/k1/config/server.properties

A second instance takes the next free broker/controller ports from their pools (for example 9093/19094, unless those ports are in use):

pg addon install kafka --name k2 --data-dir /srv/kafka-data --listen 0.0.0.0 --advertise-host 192.0.2.10

Re-running install without --force is a no-op that reports the current state. --force re-renders the config and recreates the container, keeping the data dir, the stored cluster id and node id. Changing --cluster-id on an instance whose data dir is already formatted is refused — the data belongs to the original cluster id.

The image is pulled directly from Docker Hub; no pgcli-built image is involved. --version accepts any safe upstream tag, but the tag must exist in the registry — the pull fails otherwise.

Multi-host cluster

A cluster is a static KRaft quorum: every node carries the complete controller.quorum.voters list, and membership cannot be changed online. Install one node per host with the same --cluster name, a unique --node-id, this host’s --advertise-host, an explicit --controller-port, and a --peer entry for every other node. Run the command on each host yourself; pgcli does not fan out over SSH.

For three hosts 192.0.2.11, 192.0.2.12 and 192.0.2.13:

# node 1 on 192.0.2.11
pg addon install kafka --name prod --cluster prod --node-id 1 \
  --listen 0.0.0.0 --advertise-host 192.0.2.11 \
  --broker-port 9092 --controller-port 19093 \
  --peer 2@192.0.2.12:19093 --peer 3@192.0.2.13:19093

# node 2 on 192.0.2.12
pg addon install kafka --name prod --cluster prod --node-id 2 \
  --listen 0.0.0.0 --advertise-host 192.0.2.12 \
  --broker-port 9092 --controller-port 19093 \
  --peer 1@192.0.2.11:19093 --peer 3@192.0.2.13:19093

# node 3 on 192.0.2.13
pg addon install kafka --name prod --cluster prod --node-id 3 \
  --listen 0.0.0.0 --advertise-host 192.0.2.13 \
  --broker-port 9092 --controller-port 19093 \
  --peer 1@192.0.2.11:19093 --peer 2@192.0.2.12:19093

How the identity is assembled:

  • Cluster ID. Derived from --cluster with a deterministic hash, so every host computes the same value without passing --cluster-id. If you pass --cluster-id it must equal the derived value.
  • Voters. ID@HOST:PORT entries are sorted by node id; this node’s entry comes from --node-id, --advertise-host and --controller-port, and peers supply the rest. Two voters may not share a controller endpoint.
  • Controller port. It is part of every peer’s voter list, so a fresh cluster install requires an explicit --controller-port (default and recommended value: 19093). Auto-assignment could pick a different port on another host.
  • Ports and addresses. All nodes may use the same broker/controller ports because they are different hosts. --listen must be 0.0.0.0 (or this node’s advertised address); loopback is rejected.

The first two installs print a warning that the controller quorum is not ready yet — that is expected until the last voter is installed. The readiness wait is 15 seconds in cluster mode instead of 90. Once all nodes are up:

pg addon kafka cluster status --name prod    # leader + 3 voters
pg addon kafka status --name prod            # cluster, node x of N, voter, voters, RF/minISR
pg addon list                                # shows "cluster prod" and the voter list

Topic defaults follow the quorum size: --replication-factor 0 means min(3, voters) (3 for three nodes), with min.insync.replicas = min(2, RF). A two-voter cluster is allowed but has zero fault tolerance — losing either node loses the metadata quorum — so pgcli prints a warning. Use three or another odd number for HA.

Cluster identity is immutable after install, even with --force: --cluster, --node-id, --cluster-id, the --peer set, --advertise-host and --controller-port are all rejected if they change. Ports, TLS, version, --data-dir and --config-option remain mutable with --force. To change the topology, remove the node (on that host) and reinstall; there is no online controller add/remove in this addon.

Ports

Endpoint Default Protocol Pool
Broker 9092 Kafka client protocol (PLAINTEXT) kafka_broker_start_port, default 9092
Controller 19093 KRaft metadata quorum (PLAINTEXT) kafka_controller_start_port, default 19093
SSL (TLS) 9093 (when --tls) Kafka client protocol over TLS kafka_tls_start_port, default 9093

All three pools share one “already assigned” set with each other and pre-mark explicit ports from the other streaming addons (Prometheus, ClickHouse, InfluxDB, influx2tsdb and the object stores), so neither side can steal the other’s port. Explicit Alertmanager ports are also pre-marked by the Kafka allocator (and Kafka’s ports by the Alertmanager pool), because both default near 9093. Broker, controller and TLS ports must differ and must be unique across all Kafka instances. Ports already listening on the host are skipped during auto-assignment.

When --listen is a wildcard, pgcli’s own topic/health commands dial 127.0.0.1; the printed local controller endpoint follows the same rule. In single-node mode the static voter is AdvertiseHost:ControllerPort, so if you set a LAN --advertise-host you must also set --listen to 0.0.0.0 (or that same LAN address) or the controller cannot reach itself.

In cluster mode the controller port is not just a local bind — it is the address every other host writes into its controller.quorum.voters. Use the same --controller-port on every node (unless you deliberately give each node a different one, in which case every --peer entry must carry the correct port for that node) and make sure the port is free on all hosts before you start. A mismatch means the voter lists differ and the quorum never forms. The broker port is advertised per node, so it may differ between hosts, but the same 9092 everywhere keeps client bootstrap lists simple.

Replication defaults

Replication follows the number of static voters, so neither mode needs manual server.properties edits:

Voters Topic default RF min.insync.replicas Tolerates (with acks=all)
1 1 1 no broker failure
2 2 2 no broker failure (both replicas must stay in sync)
3+ 3 2 one broker down
  • The same values set default.replication.factor, min.insync.replicas and the internal topics (offsets, transaction.state.log, share coordinator), so a new cluster can commit offsets and transactions before any user topic exists.
  • pg addon kafka topic create NAME uses the topic default; override it per topic with --replication-factor N. The RF cannot exceed the number of brokers holding the data.
  • RF stays capped at 3 in larger clusters: extra replicas add write cost and latency without improving the failure budget that min.insync.replicas=2 allows.
  • With min.insync.replicas=2, a partition whose ISR drops below 2 rejects acks=all writes (the producer default since Kafka 3.0). pg addon kafka topic describe NAME shows the ISR.

TLS

Enable the SSL listener with --tls:

pg addon install kafka --name k1 --tls                 # SSL on the first free port from 9093
pg addon install kafka --name k1 --tls --tls-port 9093

install and status then print both endpoints and the CA path:

  Broker:      127.0.0.1:9092
  TLS:         127.0.0.1:9093 (CA .../addon/kafka/k1/config/tls/ca.crt)
  Controller:  127.0.0.1:19093

The plaintext listener stays enabled, so existing clients keep working. TLS only takes effect on creation or with --force; --tls-port without --tls is rejected. Disable it again with --tls=false --force — the generated files stay under config/tls/ and are reused if you re-enable TLS.

The certificate is issued by pgcli’s self-signed CA (the same helper MinIO/silo/rustfs use) for localhost, every host NIC address and --advertise-host. Clients must trust config/tls/ca.crt.

Cluster TLS

Every node issues its own CA and leaf, so a client that may connect to any broker needs all of them in one trust file:

# On each host, copy out that node's CA, then concatenate them on the client.
for v in vm01 vm02 vm03; do
  ssh $v 'cat ~/.pgcli/addon/kafka/prod/config/tls/ca.crt'
done > kafka-ca-bundle.pem

The SSL listener is per node: enable --tls on all nodes for a uniform SSL bootstrap list. If only some nodes have TLS, those nodes advertise an SSL://... endpoint while the others advertise only PLAINTEXT://...; clients using security.protocol=SSL can still reach the TLS nodes, but the plaintext-only nodes remain plaintext. Enable TLS one node at a time (--tls --force) so the controller quorum keeps two of three voters.

--tls only adds a client-facing SSL listener. The CONTROLLER quorum and inter-broker traffic stay on PLAINTEXT, so enabling or disabling TLS never breaks quorum.

Bring your own certificate (pg cert)

Kafka’s PEM keystore reads one file containing the certificate chain followed by the private key. pg cert writes the two parts separately, so merge them before installing:

# 1. Issue the server certificate. Include every address clients dial,
#    especially --advertise-host.
pg cert --host 127.0.0.1,192.0.2.11 \
  --cert-file kafka.crt --key-file kafka.key

# 2. Merge certificate (chain) + private key into one PEM.
cat kafka.crt kafka.key > kafka-server.pem

# 3. Install with the merged file — --tls is implied.
pg addon install kafka --name k1 --tls-pem ./kafka-server.pem

With an intermediate chain, put the leaf first: cat leaf.crt intermediate.crt key.key > kafka-server.pem.

At install time pgcli checks that the file contains a certificate and exactly one unencrypted key, that the key matches the certificate, that the certificate is currently valid, allows server authentication and is not a CA certificate. It also checks the SANs against --advertise-host: in cluster mode a certificate that does not cover this node’s advertised IP is a hard error (the other voters and clients reach this node by that address); in single-node mode it is only a warning. PKCS#8 (BEGIN PRIVATE KEY, what pg cert writes), PKCS#1 (BEGIN RSA PRIVATE KEY) and SEC1 (BEGIN EC PRIVATE KEY) keys are accepted; encrypted keys are rejected.

pgcli copies the merged file to config/tls/server.pem (mode 0600, owned by uid 1000) and does not generate ca.crt or public.crt/private.key. The source file is left untouched. Automatic renewal does not apply: replace the source PEM and re-run the install with --force to put the new certificate into a fresh container.

For a self-signed pg cert certificate, the certificate file itself is what clients trust — use kafka.crt wherever the examples below say ca.crt. If the certificate is signed by a public or private CA, point clients at that CA chain instead, and include any intermediate certificates in kafka-server.pem.

In a cluster, issue a separate certificate per node that covers that node’s advertised IP, and pass it only to that node’s install:

# On node 1, whose --advertise-host is 192.0.2.11:
pg cert --host 192.0.2.11 --cert-file kafka-node1.crt --key-file kafka-node1.key
cat kafka-node1.crt kafka-node1.key > kafka-node1.pem
pg addon install kafka --name prod --cluster prod --node-id 1 --force ... --tls-pem ./kafka-node1.pem

# Clients trust every node: concatenate the per-node certificates (or CAs).
cat kafka-node1.crt kafka-node2.crt kafka-node3.crt > kafka-ca-bundle.pem

If a node’s certificate does not cover its --advertise-host, the cluster install is refused before the container is recreated.

To switch an instance back to pgcli’s generated certificate, reinstall with --tls --tls-pem '' --force; an empty --tls-pem clears the stored path.

Java client (client.properties):

security.protocol=SSL
ssl.truststore.type=PEM
ssl.truststore.location=/path/to/addon/kafka/k1/config/tls/ca.crt

librdkafka-based clients:

security.protocol=SSL
ssl.ca.location=/path/to/addon/kafka/k1/config/tls/ca.crt

Verify the listener with OpenSSL:

openssl s_client -connect 127.0.0.1:9093 \
  -CAfile <base_dir>/addon/kafka/k1/config/tls/ca.crt -verify_return_error </dev/null

Produce and consume over TLS from inside the container (the TLS dir is mounted read-only with the config dir):

pg addon kafka shell --name k1 -- bash -lc \
  'printf "security.protocol=SSL\nssl.truststore.type=PEM\nssl.truststore.location=/mnt/shared/config/tls/ca.crt\n" > /tmp/client.properties
   printf "hello\n" | /opt/kafka/bin/kafka-console-producer.sh --bootstrap-server 127.0.0.1:9093 --producer.config /tmp/client.properties --topic demo'

pg addon kafka shell --name k1 -- bash -lc \
  'printf "security.protocol=SSL\nssl.truststore.type=PEM\nssl.truststore.location=/mnt/shared/config/tls/ca.crt\n" > /tmp/client.properties
   /opt/kafka/bin/kafka-console-consumer.sh --bootstrap-server 127.0.0.1:9093 --consumer.config /tmp/client.properties --topic demo --from-beginning --max-messages 1'
  • TLS encrypts the connection only: ssl.client.auth=none, so clients present no certificate and anyone who can reach the SSL port can still connect. The listen address remains the only security boundary.
  • Connect by IP (or a name present in the certificate). A DNS name that is not a host NIC address is not in the SAN list and fails verification.
  • The leaf certificate is regenerated when it is within 30 days of expiry (on install, start or --force). The CA is kept, so clients do not need a new trust file. This applies only to pgcli-generated certificates; with --tls-pem you own renewal.

What pgcli creates

Everything for one instance lives under <base_dir>/addon/kafka/<name>/:

Host path Container path Notes
config/server.properties /mnt/shared/config (directory, read-only) Generated topology; the image entrypoint merges it into the runtime config
config/tls/ /mnt/shared/config/tls (read-only) Only with --tls: server.pem (cert chain + key, 0600, owned by uid 1000), plus ca.crt (0644), public.crt and private.key when pgcli generated the certificate. With --tls-pem, only server.pem is written — a normalized copy of your combined PEM
data/ /var/lib/kafka/data Log segments, meta.properties and KRaft metadata

The generated server.properties sets:

process.roles=broker,controller
node.id=1
listeners=PLAINTEXT://127.0.0.1:9092,CONTROLLER://127.0.0.1:19093
advertised.listeners=PLAINTEXT://127.0.0.1:9092
inter.broker.listener.name=PLAINTEXT
controller.listener.names=CONTROLLER
listener.security.protocol.map=CONTROLLER:PLAINTEXT,PLAINTEXT:PLAINTEXT
controller.quorum.voters=1@127.0.0.1:19093
log.dirs=/var/lib/kafka/data

With --tls the listener lines and security section become:

listeners=PLAINTEXT://127.0.0.1:9092,SSL://127.0.0.1:9093,CONTROLLER://127.0.0.1:19093
advertised.listeners=PLAINTEXT://127.0.0.1:9092,SSL://127.0.0.1:9093
listener.security.protocol.map=CONTROLLER:PLAINTEXT,PLAINTEXT:PLAINTEXT,SSL:SSL
ssl.keystore.type=PEM
ssl.keystore.location=/mnt/shared/config/tls/server.pem
ssl.client.auth=none

For a three-node cluster (node 2 of prod shown; --listen 0.0.0.0):

process.roles=broker,controller
node.id=2
listeners=PLAINTEXT://0.0.0.0:9092,CONTROLLER://0.0.0.0:19093
advertised.listeners=PLAINTEXT://192.0.2.12:9092
inter.broker.listener.name=PLAINTEXT
controller.listener.names=CONTROLLER
listener.security.protocol.map=CONTROLLER:PLAINTEXT,PLAINTEXT:PLAINTEXT
controller.quorum.voters=1@192.0.2.11:19093,2@192.0.2.12:19093,3@192.0.2.13:19093
log.dirs=/var/lib/kafka/data
offsets.topic.replication.factor=3
transaction.state.log.replication.factor=3
transaction.state.log.min.isr=2
default.replication.factor=3
min.insync.replicas=2

The voter list is identical on all three hosts and sorted by node id; this node’s node.id is the only line that differs. Replication factors are min(3, voters) and ISR is min(2, RF).

plus replication settings for the internal topics and auto-created topics: with one voter, offsets.topic.replication.factor=1, transaction.state.log.replication.factor=1, transaction.state.log.min.isr=1, the share-coordinator equivalents, default.replication.factor=1 and min.insync.replicas=1. Overrides are appended after the managed block in sorted key order.

The container runs with --network host, --restart unless-stopped and a 30-second stop timeout, and is started with -e CLUSTER_ID=<id> so the image formats the data dir with exactly the stored id (the image would otherwise inject its own fixed default).

The official image runs as uid/gid 1000 (appuser). Before the first boot pgcli hands the data directory to that id with a one-time podman unshare chown -R 1000:1000. Once meta.properties exists the storage is already owned correctly, so later starts and --force re-creations do not recurse over the log tree. With --tls, only the combined config/tls/server.pem is chowned to uid/gid 1000 (the PEM keystore is read as appuser); the config dir, CA and raw private key stay host-owned, and the directory remains traversable for the read-only mount.

Topics

pg addon kafka topic create demo --name k1
pg addon kafka topic create events --partitions 3 --replication-factor 1 --name k1
pg addon kafka topic create logs --config retention.ms=604800000 --name k1
pg addon kafka topic list --name k1
pg addon kafka topic list --exclude-internal --name k1
pg addon kafka topic describe demo --name k1
pg addon kafka topic delete demo --name k1 --yes
pg addon kafka topic retention demo 7d --name k1   # set retention.ms
pg addon kafka topic retention demo --name k1      # show current overrides
  • --partitions defaults to the broker’s num.partitions (upstream default 1). --replication-factor 0 (the default) means “the instance’s RF” — 1 on a single node, min(3, voters) in a cluster (so 3 on a three-node cluster).
  • --config KEY=VALUE is repeatable and passes topic-level settings through to kafka-topics.sh.
  • delete asks for confirmation unless --yes is given; deleting a topic deletes all of its messages.
  • retention NAME [DURATION] shows or sets retention.ms. Durations accept ms/s/m/h/d/w suffixes (30m, 12h, 7d, 4w), plain milliseconds, or -1 / infinite / forever to keep messages indefinitely. Without a duration it prints the topic’s dynamic overrides; an empty result means the broker default applies. Retention is time-based and deletes old segments even if they were never consumed.
  • The instance must be running for every topic command.

Produce and consume with the Kafka scripts inside the container (the image keeps them in /opt/kafka/bin, which is not on PATH):

pg addon kafka shell --name k1 -- bash -lc \
  'printf "hello\nworld\n" | /opt/kafka/bin/kafka-console-producer.sh --bootstrap-server 127.0.0.1:9092 --topic demo'

pg addon kafka shell --name k1 -- bash -lc \
  '/opt/kafka/bin/kafka-console-consumer.sh --bootstrap-server 127.0.0.1:9092 --topic demo --from-beginning --max-messages 2'

--bootstrap-server is what external clients use with the printed broker endpoint. For a host-side client against the default loopback listener, 127.0.0.1:9092 is enough.

In a cluster, every broker advertises its own host, so a client can bootstrap from any node and is redirected to the partition leader. Producers and consumers may run on different hosts:

pg addon kafka topic create e2e --partitions 3 --replication-factor 3 --name prod

# Produce on node 1 through the local broker:
pg addon kafka shell --name prod -- bash -lc \
  'printf "alpha\nbeta\n" | /opt/kafka/bin/kafka-console-producer.sh --bootstrap-server 192.0.2.11:9092 --topic e2e'

# Consume on node 3 from node 2's broker:
pg addon kafka shell --name prod -- bash -lc \
  '/opt/kafka/bin/kafka-console-consumer.sh --bootstrap-server 192.0.2.12:9092 --topic e2e --from-beginning --max-messages 2'

Testing from a host with kcat

kcat is a small native producer/consumer that is convenient for smoke tests from outside the container (apt install kcat on Debian/Ubuntu, brew install kcat on macOS). Bootstrap from any node — the client follows the advertised leaders. The examples use the e2e topic created above (3 partitions, RF=3):

# PLAINTEXT
printf 'alpha\nbeta\n' | kcat -P -b 192.0.2.11:9092 -t e2e
kcat -C -q -b 192.0.2.12:9092 -t e2e -o beginning -e -c 2   # first two messages
kcat -C -q -b 192.0.2.13:9092 -t e2e -o -1 -e -c 1         # the last message

For TLS, point kcat at the CA bundle from Cluster TLS and select the SSL protocol (the TLS listener is on port 9093):

printf 'gamma\n' | kcat -P -b 192.0.2.11:9093 -t e2e \
  -X security.protocol=SSL -X ssl.ca.location=kafka-ca-bundle.pem
kcat -C -q -b 192.0.2.12:9093 -t e2e -o -1 -e -c 1 \
  -X security.protocol=SSL -X ssl.ca.location=kafka-ca-bundle.pem
  • -o beginning / -o -1 start at the first / last message; -e exits at EOF and -c N stops after N messages; -q prints only message bodies.
  • With -b, use the advertised broker address; the client is redirected to the partition leader, so there is no per-partition configuration.
  • These examples do not use a consumer group: kcat reads the partitions directly and commits no offsets, so nothing appears in pg addon kafka group list. Add -G NAME to consume as a group (topics become positional arguments) — see Consumer groups.

Consumer groups

kafka-consumer-groups.sh is wrapped for the two everyday queries:

pg addon kafka group list --name k1
pg addon kafka group describe demo-group --name k1
  • list prints the group ids that have committed offsets on this cluster.
  • describe prints the group state, its members and per-partition CURRENT-OFFSET / LOG-END-OFFSET / LAG, plus the consumer id and host. A lag that keeps growing means the consumers are not keeping up.
  • A group only appears after its first offset commit; group.id is set by the client, not by pgcli. To create one for a smoke test, consume with --group:
pg addon kafka shell --name prod -- bash -lc \
  '/opt/kafka/bin/kafka-console-consumer.sh --bootstrap-server 192.0.2.11:9092 --topic e2e --group demo-group --from-beginning --max-messages 2'
pg addon kafka group list --name prod
pg addon kafka group describe demo-group --name prod

From a host, the same thing with kcat uses -G; in group mode topics are positional arguments, not -t:

kcat -C -q -G demo-group -b 192.0.2.11:9092 \
  -X auto.offset.reset=earliest -c 2 e2e
pg addon kafka group list --name prod
pg addon kafka group describe demo-group --name prod

The console-consumer and kcat examples in the sections above omit the group on purpose (read-and-exit smoke tests), so they never create one.

  • The instance must be running for both commands. A consumer that stops without committing leaves the group behind in the Empty state; its offsets and lag are still visible until the offsets expire.

Status and quorum

pg addon kafka status --name k1          # container state, endpoints, ids, paths
pg addon kafka cluster status --name k1  # KRaft metadata quorum leader and voters
pg logs addon kafka --name k1 -f         # broker logs (stdout/stderr)

cluster status runs kafka-metadata-quorum.sh --bootstrap-controller <local controller> describe --status; on a healthy single node it prints the cluster id, a leader and one voter. In a cluster it reports the leader and every voter with its log lag and whether it is caught up — run it on any node:

ClusterId:              <derived id>
LeaderId:               1
CurrentVoters:          [{"id": 1, ...}, {"id": 2, ...}, {"id": 3, ...}]

N voters tolerate (N-1)/2 stopped nodes — three nodes tolerate one, two nodes tolerate none. Stopping a majority loses the metadata quorum: brokers keep their existing partitions readable/writable only as far as min.insync.replicas allows, but no leader election or metadata change is possible until quorum returns.

install and start wait up to 90 seconds for kafka-broker-api-versions.sh to answer on the local broker endpoint (15 seconds in cluster mode, where the full quorum only forms after the last voter is installed). A broker that never becomes ready fails the command and prints the last log lines; data is preserved.

Configuration

Extra server.properties entries can be set at install time:

pg addon install kafka --name k1 \
  --config-option num.partitions=3 \
  --config-option log.retention.hours=168

--config-option replaces the stored override map (it does not merge). The overrides are persisted in pg.yaml under addons.kafka.<name>.settings and re-rendered on every start, so they survive restarts and container recreation. There is no separate config set command in this release; change an override by re-installing with --force and the complete map you want.

Keys may contain letters, digits, dots, underscores and hyphens. Values must not contain NUL, CR or LF. pgcli-managed keys are rejected rather than silently overridden.

Lifecycle

pg addon start kafka --name k1            # start, create if missing, wait for readiness
pg addon stop kafka --name k1
pg addon remove kafka --name k1           # remove container + pg.yaml entry, keep data/config
pg addon remove kafka --name k1 --clean-data   # also delete the instance dir and a custom data dir

Without --clean-data, remove leaves <instance dir> (config + data) and a custom --data-dir on disk. Reinstalling under the same name adopts the formatted storage: the cluster.id and node.id in meta.properties are reused automatically instead of generating a new cluster. This is why a reinstall can revive the existing log.

--clean-data deletes the instance directory and a distinct custom data dir (files owned by uid 1000 are removed through podman unshare), but never removes the pulled image. Pointing an instance at a data dir that belongs to a different cluster id or node id is refused before the container is created.

In a cluster, remove only affects this host — pgcli never contacts the other nodes, and their static voter lists still reference this node. pg addon remove prints the quorum impact first. With three voters, removing (or stopping) one leaves the cluster available; removing a second loses quorum. Re-adding the node later requires the same --cluster, --node-id and --peer list; after --clean-data the data dir is empty and the broker formats it again with the same derived cluster id.

Auto-start after reboot is also per host — enable it on every node:

pg autostart enable --kafka --name prod   # run on each host
pg autostart status
pg autostart disable --kafka --name prod

Boot start re-renders server.properties first and is idempotent (pg start also brings up autostart-enabled Kafka instances).

Production notes

  • Static quorum, no online resize. --cluster installs one node of a fixed KRaft quorum. There is no online controller add/remove: to grow or shrink the cluster you must reinstall nodes with a new voter list. Use three (or another odd number ≥ 3) voters for HA; two voters are allowed but tolerate no failure.
  • Single node is still the default. Without --cluster there is no replication and no HA: a stopped broker means no reads or writes for that instance.
  • KRaft combined mode. Broker and controller share one process. This is fine for development and small deployments; the upstream project recommends isolated controller/broker roles for larger critical clusters, which this addon does not provide.
  • No authentication; TLS is transport-only. The plaintext listener is always enabled; --tls adds an encrypted listener but ssl.client.auth=none means clients are not authenticated. Anyone who can reach either port can read and write every topic. In cluster mode the CONTROLLER quorum and inter-broker traffic are also PLAINTEXT — --tls only covers client connections. Keep the default loopback bind, or expose the cluster only on a trusted private network. Put real authentication (SASL/mTLS) in front of Kafka with your own proxy/gateway if needed.
  • No ZooKeeper. Kafka 4.x is KRaft-only; there is no ZooKeeper container to manage, and zookeeper.connect is rejected as a managed key.
  • Copies are not backups. Topic replication protects availability, not against accidental deletion or corruption. Stop the instance and copy the data dir for an offline backup of one node; there is no backup/restore command in this release, and an offline copy of a single cluster node is not a complete cluster backup.
  • Upgrades. --force --version <new> pulls a new tag and recreates the container on the same data dir. Kafka does not guarantee downgrading data written by a newer version — take an offline copy before upgrading. --version must be a real upstream tag.
  • JVM heap. The image default is -Xms1G -Xmx1G. Raise it with --heap when a node handles many partitions/connections, but leave most RAM to the OS page cache — Kafka reads mostly from page cache, and heaps above roughly 6–8 GB usually hurt more than they help. In a cluster each node takes its own --heap; changing it recreates that node’s container (--force), one node at a time.
  • Data ownership. Data files are owned by uid/gid 1000. Use --clean-data instead of deleting the directory by hand; pgcli handles the permission fallback.
  • Ports. Broker defaults to 9092; the controller defaults to 19093 to avoid the Alertmanager default 9093. Both are ordinary host ports under host networking.
  • Platform. Linux (host networking); the official image is multi-arch (amd64/arm64).

CLI flag reference

pg addon install kafka

Flag Default Description
--name NAME kafka Instance name; [A-Za-z0-9][A-Za-z0-9_-]*, max 48 chars
--version TAG 4.4.0 Upstream docker.io/apache/kafka tag
--data-dir DIR <base_dir>/addon/kafka/<name>/data Absolute host data dir bind-mounted at /var/lib/kafka/data
--listen ADDR 127.0.0.1 Bind address for the broker, SSL (when enabled) and controller listeners; cluster mode requires 0.0.0.0 or the advertised address
--advertise-host IP 127.0.0.1 Advertised broker host (and this node’s controller voter host); never a wildcard; required explicitly on a fresh cluster install
--broker-port N auto (base 9092) Broker host port; 0 = auto-assign
--controller-port N auto (base 19093) Controller host port; 0 = auto-assign; must be explicit on a fresh cluster install because every peer embeds it
--cluster NAME — Multi-host cluster name; identical on every host; derives the KRaft cluster id
--node-id N 1 single-node 1-based node id, unique within the cluster; required on a fresh cluster install; rejected in single-node mode
--peer ID@HOST:PORT — Another node’s controller voter; repeat for every other node; same peer list on every host
--tls false Add an SSL listener; the plaintext listener stays enabled
--tls-pem FILE — Combined PEM (chain + key) for the SSL listener; implies --tls; relative paths are resolved to absolute; must cover --advertise-host in cluster mode
--tls-port N auto (base 9093) SSL listener host port; 0 = auto-assign; requires --tls
--cluster-id ID derived (cluster) / generated KRaft cluster id; in cluster mode it must equal the id derived from --cluster
--heap SIZE image default (1G) JVM heap, passed as KAFKA_HEAP_OPTS=-XmsSIZE -XmxSIZE (512m, 2g, 4g); per node in a cluster; changing it needs --force
--config-option K=V — Extra server.properties setting; repeatable; replaces the stored override map
--force false Re-render config and recreate the container, keeping data and ids; required to add or remove --tls; cannot change cluster identity fields

pg addon kafka status / shell

Argument/flag Default Description
--name NAME kafka Instance to operate on
-- COMMAND... /bin/bash shell only: run a command instead of an interactive shell

pg addon kafka topic create|list|describe|delete|retention

Argument/flag Default Description
NAME — Topic name (create/describe/delete/retention, positional)
DURATION — retention only: new retention.ms (30m, 12h, 7d, 4w, plain milliseconds, or -1/infinite); omit it to show the current overrides
--partitions N broker default (1) create only: partition count
--replication-factor N 0 = instance RF (1 single-node, min(3, voters) in a cluster) create only: replication factor
--config K=V — create only: topic config; repeatable
--exclude-internal false list only: hide Kafka’s internal topics
--yes false delete only: skip the confirmation prompt

pg addon kafka group list|describe

Argument/flag Default Description
GROUP — Consumer group id (describe only, positional)
--name NAME kafka Instance whose local broker is queried

pg addon kafka cluster status

Argument/flag Default Description
--name NAME kafka Instance whose local controller is queried

Lifecycle, logs, autostart

Command Flags Description
pg addon start kafka --name NAME Start (create if missing), wait for readiness
pg addon stop kafka --name NAME Stop the container, keep data
pg addon remove kafka --name NAME, --clean-data Remove container and config entry; --clean-data also deletes the instance dir and a custom data dir
pg logs addon kafka --name NAME, -n N (default 50), -f Container logs
pg autostart enable|disable --kafka, --name NAME Toggle boot start for one instance

Global flags

Flag Description
-c, --config FILE Config file (default ~/.pgcli/pg.yaml)
-o, --output FILE Output config path (default the same file)
-i, --instance NAME PostgreSQL instance selector — not used by Kafka; use --name instead

38 - DocumentDB Gateway

Run the official DocumentDB MongoDB wire-protocol gateway as a managed pgcli addon, connected to a local PostgreSQL 18 instance over a shared Unix socket.

pg addon install documentdb runs the official DocumentDB gateway — the Rust service that speaks the MongoDB wire protocol in front of the DocumentDB PostgreSQL extension — as a managed container.

MongoDB clients (pymongo, mongosh, …)
        │  port 10260
        ▼
DocumentDB gateway container
        │  Unix socket (shared volume)
        ▼
PostgreSQL 18 container with documentdb / documentdb_core /
documentdb_extended_rum / pg_cron

Install the extension first. The gateway refuses to start unless the target instance is running, exports /var/run/postgresql, and has all four extensions. See DocumentDB extension.

Local instances only. The official gateway .deb supports passwordless authentication over a Unix socket and refuses PGPASSWORD, passwords in the URL, and PostgresDataUserPassword. pgcli therefore connects the gateway through a shared socket volume and rejects --dsn/--admin-dsn. A remote PostgreSQL cannot be used as the target.

Access model. The gateway connects to PostgreSQL as the dedicated role docdb_gateway (LOGIN SUPERUSER, no password) through local … trust in pg_hba.conf. MongoDB clients authenticate as a DocumentDB user (default docdb_admin) with the built-in roles readWriteAnyDatabase + clusterAdmin — broad by design. Use a distinct --username per application if you need finer separation later; v1 does not expose per-collection roles.

No telemetry. pgcli does not use the upstream all-in-one image or its usage_telemetry.sh. It runs the vendor gateway binary directly and renders SetupConfiguration.json with TelemetryOptions.Metrics.Enabled and Tracing.Enabled set to false; no OTLP endpoint is injected.

Parameters

Flag Default Description
--name documentdb Add-on name (map key and container suffix)
--pg-name — Required. Target pgcli instance (must be PG 18, standalone, with the DocumentDB extension)
--database target instance’s database Database containing the DocumentDB extension
--username docdb_admin MongoDB client user, created through documentdb_api.create_user. Prefixes documentdb, citus, pg, internal_role are rejected
--password generated Client password. Printed once when generated; retrieve later with pg addon password documentdb
--tls-mode allow allow = plaintext and TLS; require = TLS only
--image ghcr.io/mars-base/pgcli/pgcli-documentdb-gateway:1.0.0 Gateway image override
--port auto (base 10260) MongoDB wire-protocol port
--listen 0.0.0.0 Bind address (0.0.0.0, 127.0.0.1 or ::1)
--force false Recreate even when running, applying changed flags

--dsn and --admin-dsn are rejected for this add-on.

Install

pg extension install documentdb -i demo --auto-restart
pg addon install documentdb --pg-name demo

The install prints the one-time password and the endpoint:

✓ DocumentDB gateway installed: "documentdb"
  Container:  pgcli-documentdb-documentdb
  Image:      ghcr.io/mars-base/pgcli/pgcli-documentdb-gateway:1.0.0
  Endpoint:   mongodb://docdb_admin@127.0.0.1:10260/demo_db?directConnection=true
  Target:     instance demo (database demo_db)
  Client:     docdb_admin (DocumentDB native user)
  TLS mode:   allow

  Client password: n7Qv2Kd9Xa4Tb8Rm3Lc6Wf1Z
  (printed once — retrieve it later with `pg addon password documentdb --name documentdb`)

During install pgcli also:

  1. Prepares the target — ensures docdb_gateway exists with LOGIN SUPERUSER, and adds a managed local all docdb_gateway trust rule at the top of pg_hba.conf only if no matching local trust rule is present (pgcli’s default HBA already has one).
  2. Creates or rotates the client user through documentdb_api.create_user / update_user. The JSON document travels over psql stdin — never argv or PostgreSQL logs — after SET log_statement='none'.
  3. Renders pg-url and SetupConfiguration.json under <base-dir>/addon/documentdb/<name>/ and mounts the target’s socket volume read-only.
  4. Starts the gateway container with --restart unless-stopped.

Re-running the same install while the container is running is a no-op unless --force is passed.

Client Test with Python (uv + pymongo)

pgcli’s repository uses uv for ad-hoc Python dependencies. This is the end-to-end connection and CRUD test used during development:

export MONGO_PASSWORD="$(pg addon password documentdb --name documentdb)"

uv run --with pymongo python - <<'PY'
import os
from urllib.parse import quote
from pymongo import MongoClient

host = os.environ.get("MONGO_HOST", "127.0.0.1")
port = os.environ.get("MONGO_PORT", "10260")
user = os.environ.get("MONGO_USER", "docdb_admin")
password = quote(os.environ["MONGO_PASSWORD"], safe="")

# Set MONGO_TLS=true to connect over TLS.
use_tls = os.environ.get("MONGO_TLS", "").lower() in ("1", "true", "yes")
params = "directConnection=true"
if use_tls:
    params += "&tls=true&tlsAllowInvalidCertificates=true"

uri = f"mongodb://{user}:{password}@{host}:{port}/?{params}"
client = MongoClient(uri, serverSelectionTimeoutMS=10000)
print("ping:", client.admin.command("ping"))

col = client["pgcli_e2e"]["smoke"]
col.drop()
print("inserted:", col.insert_one({"name": "alpha", "value": 1}).inserted_id)
print("found:   ", col.find_one({"name": "alpha"}))

print("updated: ", col.update_one({"name": "alpha"}, {"$set": {"value": 2}}).modified_count)
print("index:   ", col.create_index([("value", 1)]))
print("count:   ", col.count_documents({}))
print("deleted: ", col.delete_one({"name": "alpha"}).deleted_count)

client.drop_database("pgcli_e2e")
client.close()
print("OK")
PY

Run it on the host where the add-on listens; from another machine set MONGO_HOST to the gateway host. TLS is off by default in the script: run with MONGO_TLS=true to enable it. This works in both allow and require modes (plaintext is rejected in require anyway). tlsAllowInvalidCertificates is needed only because the auto-generated certificate is self-signed; with a certificate you trust, use tlsCAFile="/path/to/ca.pem" instead.

Management CLI (mongosh)

pgcli can connect to and inspect a managed or remote gateway with mongosh without installing it on the host and without adding a MongoDB driver to the pgcli binary. The client runs from a separate mongosh-only image — the official mongosh 2.14.1 binary on debian:13-slim, no MongoDB server — which is pulled on first use and runs as a throwaway container. The pgcli binary does not grow.

pg addon documentdb shell
pg addon documentdb shell --database app
pg addon documentdb shell -- --eval 'db.version()'

pg addon documentdb databases list
pg addon documentdb collections list --database app
pg addon documentdb indexes list --database app --collection orders

All subcommands accept the same persistent flags:

Flag Default Description
--name documentdb Gateway add-on to connect to (explicit --name forces local mode and ignores DOCDB_URI)
--dsn $DOCDB_URI Full MongoDB connection string — recommended for a gateway on another host
--uri — Alias for --dsn
--host / --port — / 10260 Alternative to --dsn
--username / --password $DOCDB_USERNAME / $DOCDB_PASSWORD Credentials with --host; prefer the environment over --password, which is visible in ps
--tls false Force TLS. Enabled automatically when a managed gateway’s --tls-mode is require
--image ghcr.io/mars-base/pgcli/pgcli-mongosh:2.14.1 Client image override (private registry or offline)

shell opens an interactive session; --database selects the initial database (the gateway’s target database or the URI’s database by default), and arguments after -- are forwarded to mongosh verbatim. databases list, collections list, and indexes list run read-only queries and print one name (or one JSON index document) per line; indexes list requires --collection.

Remote Gateways

No local add-on entry is needed to drive a gateway on another host. Export the connection string once so the commands stay short:

export DOCDB_PASSWORD='...'   # from the gateway host: pg addon password documentdb
export DOCDB_URI='mongodb://docdb_admin@10.0.0.5:10260/demo_db?authSource=admin&directConnection=true'

pg addon documentdb databases list
pg addon documentdb collections list --database demo_db
pg addon documentdb shell -- --eval 'db.version()'

Use --dsn (or its alias --uri) for one-off commands:

pg addon documentdb collections list \
  --dsn 'mongodb://docdb_admin@10.0.0.5:10260/demo_db'

Rules:

  • A password missing from the URI is filled from DOCDB_PASSWORD; missing userinfo is filled from DOCDB_USERNAME. Prefer these environment variables over --password, whose value appears in ps.
  • pgcli adds authSource=admin, directConnection=true, and serverSelectionTimeoutMS=10000 when the URI omits them. Values already in the URI, including its database path, win.
  • --tls forces TLS by adding tls=true&tlsAllowInvalidCertificates=true. Use it with a gateway in require mode, or put the TLS parameters in the URI yourself.
  • --dsn/--uri cannot be combined with --host/--port/--username/--password, and --name cannot be combined with any remote flag. Explicit remote flags take precedence over DOCDB_URI.
  • --host HOST --port PORT --username USER remains available as an alternative; the password comes from DOCDB_PASSWORD.
  • The client host needs podman and the mongosh image, pulled from GHCR on first use (--image overrides it). The gateway must listen on an address reachable from the client: the default --listen 0.0.0.0 works; 127.0.0.1 restricts it to the gateway host.

Remote mode only changes where the mongosh client connects — the gateway itself still targets a local PostgreSQL instance on its own host.

Common mongosh Operations

shell forwards everything after -- to mongosh. Everyday commands:

// inventory
db                       // current database
show dbs                 // DocumentDB lists a database only after it has a collection
show collections
use demo_db              // switch (creates the database implicitly on first write)

// write and read
db.users.insertOne({name: "alice", age: 30})
db.users.insertMany([{name: "bob"}, {name: "carol", age: 41}])
db.users.findOne({name: "alice"})
db.users.find({age: {$gte: 30}}).forEach(printjson)
db.users.countDocuments({age: {$gte: 30}})

// update and delete
db.users.updateOne({name: "alice"}, {$set: {age: 31}})
db.users.updateMany({}, {$inc: {visits: 1}})
db.users.deleteOne({name: "bob"})
db.users.deleteMany({age: {$lt: 18}})

// indexes: 1 = ascending, -1 = descending
db.users.createIndex({name: 1})
db.users.createIndex({tenant: 1, createdAt: -1})   // compound: tenant asc, createdAt desc
db.users.find({tenant: "acme"}).sort({tenant: 1, createdAt: -1})  // matches the compound index
db.users.getIndexes()                              // key shows direction, e.g. {"name":1}
db.users.dropIndex("name_1")

// remove data
db.users.drop()
db.dropDatabase()

Run a single command without entering the shell:

pg addon documentdb shell -- --quiet --eval 'db.getSiblingDB("demo_db").users.countDocuments({})'
pg addon documentdb shell --dsn 'mongodb://docdb_admin@10.0.0.5:10260/demo_db' \
  -- --quiet --eval 'db.users.find({age: {$gte: 30}}).forEach(printjson)'
  • find() shows the first 20 documents in an interactive session; type it for more, or .forEach(printjson) to print all.
  • _id is unique per collection, indexed automatically, and generated when omitted. Queries on _id do not need another index.
  • drop() and dropDatabase() delete data irreversibly. The read-only CLI helpers (databases list, collections list, indexes list) never write; use shell for document queries and writes.
  • DocumentDB does not implement every MongoDB command or query operator; check the upstream compatibility notes when a feature is missing.

Notes:

  • The connection string is built from the add-on’s pg.yaml entry (client user, password, port, TLS mode) in local mode, or from --dsn/DOCDB_URI in remote mode. The password reaches the container through an environment variable passed by name only, so it does not appear in podman’s argv (podman inspect’s Config.Cmd).
  • DocumentDB reports only databases that contain collections. When a list is empty, pgcli prints an explanatory note on stderr and leaves stdout empty, so scripts can keep treating stdout as data.
  • The inspection subcommands are intentionally read-only. Create/drop database, collection, index, and user operations are not exposed yet; use shell (or a MongoDB driver) for writes.
  • The image sets mongosh’s telemetry opt-out (/home/mongosh/.mongodb/mongosh/config, {"enableTelemetry":false}). mongosh 2.14.1 may still print its telemetry notice at startup.

TLS

The daemon always generates a self-signed certificate on first start and persists it in the named volume pgcli-documentdb-tls-<name>, so the certificate survives container recreation.

  • --tls-mode allow (default): the same port accepts plaintext and TLS.
  • --tls-mode require: EnforceTls=true in SetupConfiguration.json; plaintext handshakes are rejected.

Switch modes with a recreate:

pg addon install documentdb --pg-name demo --tls-mode require --force

With require, enable TLS on the client as in the test code (MONGO_TLS=true), or use tlsCAFile when you want certificate validation.

Lifecycle

pg addon list                    # DocumentDB section: status/endpoint/target/TLS
pg addon start documentdb --name documentdb
pg addon stop  documentdb --name documentdb
pg logs addon documentdb         # follows the gateway container logs
pg addon password documentdb --name documentdb
pg addon remove documentdb --name documentdb [--clean-data]

remove deletes the container; --clean-data also deletes the TLS state volume and the rendered config directory. PostgreSQL-side state is kept: DocumentDB data, the client user, the docdb_gateway role and the HBA rule survive removal. The command prints the DROP ROLE statements if you want to clean them up manually.

Autostart is supported; the gateway starts after the instances in pg start --autostart and verifies the target instance is up first:

pg autostart enable --documentdb --name documentdb

Multiple Gateways

Each gateway gets its own name, container, port and TLS volume:

pg addon install documentdb --name analytics --pg-name demo --port 10261 --username docdb_analytics

Use a distinct --username when several gateways share the same target database. DocumentDB users are PostgreSQL roles, so a second install with the same username rotates that role’s password — invalidating the credential stored by the first gateway.

Impact on the Shared PostgreSQL Instance

Multiple gateways may target one instance, but they are not isolated from it or from each other:

Area Impact
Connections Each gateway holds at least one client backend as docdb_gateway (one idle connection per gateway was observed on a running install). Under load the gateway may open more. Count the total against max_connections; v1 has no pooling layer between the gateway and PostgreSQL.
CPU / memory / I/O / locks Every gateway’s queries, writes and foreground index builds (indexBuildsScheduledOnBgWorker=false) compete on the same instance. Adding gateways adds load, not capacity.
Data visibility A distinct --username separates credentials, not data. Each DocumentDB user is created with readWriteAnyDatabase + clusterAdmin by default, so all gateways pointing at the same database read and write the same collections. Use separate databases or separate instances when applications need isolation; v1 exposes no per-collection roles.
Roles PostgreSQL roles are cluster-wide. Client usernames must therefore be unique across gateways. pg addon remove keeps each gateway’s client role (drop it manually), while the shared docdb_gateway role must remain for the surviving gateways.
Background workers / pg_cron Configured once per instance, not per gateway. Extra gateways do not start duplicate workers or cron jobs.

Monitor actual usage with:

pg exec -i demo "SELECT usename, state, count(*) FROM pg_stat_activity WHERE backend_type = 'client backend' GROUP BY 1, 2 ORDER BY 3 DESC"

Limitations

  • Local PG 18 instances only; standalone (not Patroni/HA); --dsn is unsupported. (The pg addon documentdb --dsn client flag is unrelated — it points mongosh at a gateway running elsewhere.)
  • macOS is code-complete but untested.
  • TLS uses the auto-generated self-signed certificate only; custom certificates are not exposed yet.
  • pg destroy deletes the instance’s socket volume. Remove the gateway before destroying its target instance.
  • The gateway connects as a superuser over local trust; the security boundary is the host/container boundary. Keep --listen 127.0.0.1 when clients are local.

Troubleshooting

WARN … Host Config file not able to be loaded: No such file or directory

Expected on a standalone gateway: no dynamic host-configuration file is configured. It is logged once at startup and does not affect operation.

If the gateway cannot connect, verify the target mount and extensions:

podman inspect <pg container> --format '{{range .Mounts}}{{.Destination}}{{"\n"}}{{end}}'
pg exec -i demo "SELECT extname FROM pg_extension WHERE extname LIKE 'documentdb%' OR extname = 'pg_cron'"

39 - RabbitMQ

Run a RabbitMQ broker as a managed addon — single node or a multi-host cluster formed by etcd peer discovery, AMQP plus the management web UI/API, optional TLS (generated CA or bring your own certificate), and queue management (list/declare/inspect, publish/get, bind/unbind, purge/delete)

pg addon install rabbitmq runs RabbitMQ 4.4.0 as a managed container from the official docker.io/library/rabbitmq image (the -management variant, which bundles the web UI and HTTP API). Like Kafka and ClickHouse, RabbitMQ is a top-level addon: pgcli renders rabbitmq.conf, owns the administrator account, bind-mounts the data directory and runs the container on the host network.

The addon runs either a single node or one member of a multi-host cluster. Clustering uses etcd peer discovery (rabbitmq_peer_discovery_etcd): you install one member per host with the same --cluster name and the list of etcd endpoints, and the members find each other on first boot — no static peer list and no manual join_cluster. Federation, shovel, MQTT and STOMP are not configured; advanced administration (vhosts, users, permissions, policies and exchanges) is done through the management UI or pg addon rabbitmq shell + rabbitmqctl. Common queue operations are wrapped by pg addon rabbitmq queue (see Queues and messages). In cluster mode declare creates quorum queues by default (see Clustering).

Authentication is always on. AMQP and the management UI require the administrator account pgcli creates (default admin, generated 20-character password). --listen defaults to 127.0.0.1. When you expose it on a network, treat the password as the security boundary: TLS encrypts traffic but does not authenticate clients (verify_none, fail_if_no_peer_cert = false).

Parameters

Flag Default Description
--name rabbitmq Instance name (map key; also the default subcommand name)
--version 4.4.0 Upstream image tag, pulled directly as docker.io/library/rabbitmq:<version>-management
--admin-user admin Administrator account created on first boot and reconciled on every start
--admin-password generated (20 chars) Administrator password; stored in pg.yaml and in a 0600 secret file. Rejected in cluster mode — use --secrets-from-etcd or --admin-password-file
--admin-password-file FILE — Read the administrator password from FILE (one line). Required for the first install of a cluster member unless --secrets-from-etcd is used; also accepted for standalone instances
--data-dir <base_dir>/addon/rabbitmq/<name>/data Data directory bind-mounted at /var/lib/rabbitmq; must be an absolute path
--listen 127.0.0.1 standalone, 0.0.0.0 cluster Bind address shared by AMQP, AMQPS (when --tls) and the management listeners. 0.0.0.0 exposes all enabled listeners. Must not be loopback in cluster mode
--cluster NAME — Join/create the RabbitMQ cluster NAME. Empty = standalone. All members must use the same name
--node-name NODE@HOST — This member’s Erlang node name (for example rabbit@192.0.2.11). Required for the first install of a cluster member; must be unique. An IP host needs no name resolution; a hostname must resolve on every member
--etcd m1,m2 — Local etcd addon member name(s) to use as discovery endpoints. Mutually exclusive with --etcd-endpoints (which wins)
--etcd-endpoints host:port,... — External etcd endpoints for discovery; repeatable or comma-separated. Plain HTTP only; http:// is accepted and stripped
--erlang-cookie-file FILE — Read the shared Erlang cookie from FILE. Required for the first install of a cluster member unless --secrets-from-etcd is used; the value is stored and cannot change afterwards
--secrets-from-etcd false Read both shared secrets from the etcd keys written by pg addon rabbitmq secret generate (recommended; no file copying between hosts). Cannot be combined with --erlang-cookie-file or --admin-password-file
--amqp-port auto (base 5672) Plaintext AMQP port; 0 = auto-assign from rabbitmq_start_port
--management-port auto (base 15672) Management HTTP UI/API port; 0 = auto-assign from rabbitmq_management_start_port
--tls false Add AMQPS and management HTTPS next to the plaintext listeners, using a certificate from pgcli’s self-signed CA
--tls-cert FILE — Bring-your-own server certificate (PEM chain). Must be passed together with --tls-key; implies --tls. Must cover --listen unless the listen address is 0.0.0.0
--tls-key FILE — Bring-your-own private key (PKCS#8/PKCS#1/SEC1), paired with --tls-cert
--tls-port auto (base 5671) AMQPS port; 0 = auto-assign from rabbitmq_tls_start_port; requires --tls
--config-option K=V — Extra rabbitmq.conf setting (heartbeat=60, log.file.level=debug); repeatable; replaces the stored override map
--force false Re-render the config and recreate the container, keeping data and the stored password. In cluster mode --cluster, --node-name and the Erlang cookie are immutable; --etcd-endpoints may change

--image does not apply to RabbitMQ — use --version. --version accepts any safe upstream tag, but the tag must exist in the registry; the image reference is always docker.io/library/rabbitmq:<version>-management.

Install

pg addon install rabbitmq --name rmq
✓ RabbitMQ "rmq" installed
  Version:    4.4.0
  Image:      docker.io/library/rabbitmq:4.4.0-management
  Container:  pgcli-rabbitmq-default-rmq
  AMQP:       amqp://127.0.0.1:5672
  Management: http://127.0.0.1:15672
  Admin:      admin
  Password:   <generated>
  Data dir:   /home/you/.pgcli/addon/rabbitmq/rmq/data
  Config:     /home/you/.pgcli/addon/rabbitmq/rmq/config/rabbitmq.conf

⚠️ A standalone instance declares durable classic queues, but their messages are not persistent by default. Classic message persistence is a per-message property that the publisher must set on every publish (--property delivery_mode=2 with pg addon rabbitmq queue publish, or delivery_mode=2 in the application’s AMQP client); there is no queue argument or policy that enables it. Without it, a broker restart keeps the queue but drops its messages. Cluster mode uses quorum queues, which persist every message automatically.

A second instance takes the next free port from every pool (for example AMQP 5673, management 15673, EPMD 4370, distribution 25673):

pg addon install rabbitmq --name rmq2 --data-dir /srv/rabbitmq-data --listen 0.0.0.0

Re-running install without --force is a no-op that reports the current state. With --force, pgcli re-renders rabbitmq.conf, rewrites enabled_plugins, recreates the container and re-applies the administrator credentials; the data directory and password are kept.

The password is printed once at install time and can be read back at any time:

pg addon password rabbitmq --name rmq

Management UI and API

The management web UI is served on the management port:

standalone: http://127.0.0.1:15672      (default --listen 127.0.0.1)
cluster:    http://<member-ip>:15672    (any member, e.g. http://192.0.2.11:15672)

Run pg addon rabbitmq status --name rmq to print the exact Management: URL for the instance — it follows --listen and --management-port. Open that URL and sign in with the admin account; retrieve the password with pg addon password rabbitmq --name rmq. In cluster mode every member serves the same UI, and Overview → Nodes shows the whole cluster.

The same endpoint serves the HTTP API:

pw="$(pg addon password rabbitmq --name rmq)"
curl -fsS -u "admin:$pw" http://127.0.0.1:15672/api/overview

The UI is the supported path for everything the CLI does not wrap: vhosts, users, permissions, policies and exchange definitions. Common queue operations are available as pg addon rabbitmq queue ... commands (see Queues and messages).

Ports

Endpoint Default Pool
AMQP (plaintext) 5672 rabbitmq_start_port, default 5672
AMQPS (TLS) 5671 (when --tls) rabbitmq_tls_start_port, default 5671
Management HTTP UI/API 15672 rabbitmq_management_start_port, default 15672
Management HTTPS 15671 (when --tls) rabbitmq_management_tls_start_port, default 15671
Erlang EPMD 4369 rabbitmq_epmd_start_port, default 4369
Erlang distribution 25672 rabbitmq_dist_start_port, default 25672

Each pool is allocated independently: instances are sorted by name, an explicit port is never overwritten, and a port already listening on the host is skipped. Ports must be unique across all RabbitMQ instances.

EPMD and distribution are infrastructure ports, not client endpoints. A standalone instance runs with RABBITMQ_NODENAME=rabbit@localhost, ERL_EPMD_ADDRESS=127.0.0.1 and its own EPMD/distribution ports, and rabbitmq.conf pins distribution.listener.interface = 127.0.0.1 — Erlang distribution is never exposed on the network, and multiple standalone instances coexist on one host without colliding with a host Erlang installation.

A cluster member is different: every member uses the fixed EPMD port 4369 and distribution port 25672, and distribution listens on --listen (default 0.0.0.0). As a consequence, at most one clustered RabbitMQ instance can run per host, and 4369, 25672 must be reachable from the other members (see Clustering).

The rabbitmq_prometheus plugin is not enabled. pgcli mounts its own enabled_plugins file containing only rabbitmq_management (rabbitmq_management and rabbitmq_peer_discovery_etcd in cluster mode), so every instance behaves the same and none opens a second unauthenticated metrics listener.

Clustering

A cluster is formed by etcd peer discovery, not by a static peer list. Each host runs one member with the same --cluster name and an etcd endpoint list; on first boot the member registers itself in etcd and joins whichever nodes are already registered.

Prerequisites:

  • etcd 3.4+ reachable from every member on plain HTTP. A single-member etcd is enough to test, but a production discovery store should itself be redundant. pgcli does not manage TLS or authentication for this etcd connection in this release — keep it on a trusted network. You can run it as the pgcli etcd addon (pg addon install etcd ...) or use an external etcd with --etcd-endpoints.
  • Unique node names. --node-name rabbit@host must be unique in the cluster. The host part may be a hostname or an IPv4 address; loopback and IPv6 are rejected. With an IP the members connect directly and need no name resolution at all — recommended when there is no internal DNS. With a hostname every member must resolve it (DNS or /etc/hosts): etcd discovery registers only rabbit@host, it does not provide addresses. FQDNs and IPs make RabbitMQ use Erlang long names automatically.
  • Shared secrets. All members need the same Erlang cookie and the same administrator password. Generate them once with pg addon rabbitmq secret generate; it writes local 0600 files and publishes their contents to etcd, and every member then installs with --secrets-from-etcd. pgcli stores both values in pg.yaml and the 0600 secret file, so start and autostart do not need etcd or the original files. The older --erlang-cookie-file / --admin-password-file pair still works when you prefer to distribute files yourself. These are cluster-level secrets: AMQP clients need neither.
  • Same version. Use the same --version on every member.
  • Same cluster name. A different --cluster value creates a separate cluster sharing the etcd store; pgcli isolates them with cluster_formation.etcd.cluster_name.

On the management host, generate and publish the shared secrets once:

pg addon rabbitmq secret generate --cluster pgcli-lab \
  --etcd-endpoints 192.0.2.10:2379

The values are never printed. The command writes /tmp/rmq.cookie and /tmp/rmq.admin (mode 0600) and stores the same contents at these etcd keys (not files):

/pgcli/rabbitmq/clusters/pgcli-lab/secrets/erlang_cookie
/pgcli/rabbitmq/clusters/pgcli-lab/secrets/admin_password

The two local files have distinct purposes:

File Purpose
/tmp/rmq.cookie The shared Erlang cookie. Cluster nodes use it only for the Erlang distribution handshake between members (EPMD 4369, distribution 25672). AMQP and management clients never use it.
/tmp/rmq.admin The shared broker administrator password, used to create/reconcile the admin account. It is an installation input, not a client-side credential: applications should connect with their own RabbitMQ users. To sign in as the administrator interactively, read the stored value with pg addon password rabbitmq --name mq instead of keeping the file.

Both files are bootstrap/distribution artifacts. Each member stores the values in pg.yaml and its own 0600 secret file during installation, and start/autostart never read the /tmp files, so they can be deleted once every member is installed. When you distribute secrets manually instead of using --secrets-from-etcd, these are the files you copy to each host (contents must be identical) and pass as --erlang-cookie-file / --admin-password-file; the paths may differ per host. Never generate a new Erlang cookie after members are installed — it is immutable and members with mismatched cookies cannot join.

Install three members from the member hosts (only --node-name differs; using each host’s IP avoids /etc/hosts/DNS):

# on 192.0.2.11
pg addon install rabbitmq --name mq --cluster pgcli-lab \
  --node-name rabbit@192.0.2.11 \
  --etcd-endpoints 192.0.2.10:2379 \
  --secrets-from-etcd

# on 192.0.2.12
pg addon install rabbitmq --name mq --cluster pgcli-lab \
  --node-name rabbit@192.0.2.12 \
  --etcd-endpoints 192.0.2.10:2379 \
  --secrets-from-etcd

# on 192.0.2.13
pg addon install rabbitmq --name mq --cluster pgcli-lab \
  --node-name rabbit@192.0.2.13 \
  --etcd-endpoints 192.0.2.10:2379 \
  --secrets-from-etcd

Every member reads the same values, so no file copying is required. If you prefer manual distribution, skip secret generate and pass the two --*-file flags instead.

Etcd stores these values as plaintext. Anyone who can reach the etcd client port can read the cluster credentials, so restrict port 2379 to the member hosts and the management host. Do not put the secrets in a shared etcd that other tenants can read.

The first member starts a cluster of one and prints a hint; the others discover it through etcd and join automatically. Discovery runs only while Mnesia is empty — an already-joined member restarts by contacting its last-seen peers.

Discovery keys live under

/rabbitmq/discovery/rabbitmq/clusters/<cluster-name>/nodes/<node-name>

so several clusters can share one etcd as long as their --cluster names differ.

Queue semantics

  • In cluster mode pg addon rabbitmq queue declare defaults to --type quorum. Quorum queues are replicated on every member (the default quorum size is 3, capped by the number of members) and are the only replicated queue type in RabbitMQ 4.x.
  • --type classic still works but classic queues are not replicated: a classic queue lives on the node where it was declared and is unavailable if that node is down. Use classic only for non-critical or transient workloads.
  • --durable=false and quorum + --auto-delete remain rejected (see Queues and messages).
  • Every node can serve clients and the management API shows the whole cluster, so clients may connect to any member. For production, configure several endpoints or put a TCP load balancer in front.

Inspect and retire members

pg addon rabbitmq cluster status --name mq
pg addon rabbitmq cluster forget rabbit@192.0.2.13 --name mq --yes

cluster status prints rabbitmqctl cluster_status, including every running node. cluster forget removes a stopped, permanently retired member from the cluster metadata; it refuses to forget the local node. After forgetting a member, rebalance quorum queues so their replicas are spread over the remaining nodes:

pg addon rabbitmq shell --name mq
rabbitmq-queues rebalance quorum

A member that is only temporarily down needs no action: restart it and it rejoins from its last-seen peers. Do not call cluster forget while the node is still meant to come back — the old node will not be able to rejoin and must be wiped (or forgotten from the other side and re-added with a fresh data directory).

Cluster constraints

  • --cluster, --node-name and the Erlang cookie are immutable. Re-running install --force with any of them changed fails; --etcd-endpoints can be updated.
  • A standalone instance cannot be converted to a cluster member (or vice versa): remove it with --clean-data and install again. First-time cluster installation also requires an empty data directory.
  • --advertise-host, --node-id, --peer and --join do not apply to RabbitMQ; the node identity is --node-name. Plaintext --admin-password is rejected in cluster mode.
  • The administrator password is a cluster-wide credential. All members must store the same value. To rotate it, publish a new one with pg addon rabbitmq secret generate --force --keep-cookie ... (or use --admin-password-file ...) and rerun install --force --secrets-from-etcd (or --admin-password-file ...) on every member. Never regenerate the Erlang cookie after members are installed: it is immutable and a changed value makes install --force fail.
  • The etcd secret keys under /pgcli/rabbitmq/clusters/<name>/secrets/ are plaintext. Restrict the etcd client port to the member and management hosts. These secrets are for the cluster, not for application clients; AMQP clients need neither the cookie nor the administrator password (create separate RabbitMQ users for applications).
  • Cluster interconnect traffic (Erlang distribution on 25672) is not encrypted. --tls protects client listeners only. Keep 4369 and 25672 on a private network, and allow them only between members.

TLS

TLS is additive: --tls keeps the plaintext AMQP and management listeners and adds AMQPS plus management HTTPS.

pg addon install rabbitmq --name rmq --tls
pg addon install rabbitmq --name rmq --tls --tls-port 5671

install and status then print both sets of endpoints and the CA path:

  AMQP:       amqp://127.0.0.1:5672
  Management: http://127.0.0.1:15672
  AMQPS:      amqps://127.0.0.1:5671
  Mgmt TLS:   https://127.0.0.1:15671
  CA cert:    /home/you/.pgcli/addon/rabbitmq/rmq/config/tls/ca.crt

The generated certificate is issued by pgcli’s self-signed CA (the same helper MinIO/silo/rustfs and Kafka use) and covers localhost, 127.0.0.1, ::1, every host NIC address and a concrete --listen address. Clients must trust config/tls/ca.crt:

openssl s_client -connect 127.0.0.1:5671 \
  -CAfile "$HOME/.pgcli/addon/rabbitmq/rmq/config/tls/ca.crt" \
  -verify_ip 127.0.0.1 -verify_return_error </dev/null

pw="$(pg addon password rabbitmq --name rmq)"
curl -fsS --cacert "$HOME/.pgcli/addon/rabbitmq/rmq/config/tls/ca.crt" \
  -u "admin:$pw" https://127.0.0.1:15671/api/overview

AMQP URL with TLS (e.g. for Python/pika or Go clients):

amqps://admin:<password>@127.0.0.1:5671/
  • TLS is transport-only. ssl_options.verify = verify_none and fail_if_no_peer_cert = false mean clients do not present certificates; anyone who can reach an enabled port and knows the password still gets in. The listen address and password remain the security boundary.
  • The leaf certificate is regenerated when it is within 30 days of expiry (on install, start or --force). The CA is kept, so clients do not need a new trust file. This applies only to pgcli-generated certificates.
  • --tls-port without --tls is rejected. Disable TLS with --tls=false --force; the generated files stay under config/tls/ and are reused if TLS is re-enabled.

Bring your own certificate (pg cert)

pg cert --host localhost,127.0.0.1,192.0.2.10 \
  --cert-file rmq.crt --key-file rmq.key

pg addon install rabbitmq --name rmq \
  --tls-cert rmq.crt --tls-key rmq.key

--tls-cert and --tls-key must be supplied together and imply --tls. Before any image pull or container work, pgcli validates that:

  • the certificate parses and is currently valid;
  • it allows server authentication and is not a CA certificate;
  • the private key matches the certificate and is unencrypted;
  • the certificate covers a concrete --listen address (a mismatch is a hard error; use --listen 0.0.0.0 or add the address as a SAN).

The files are copied into the instance’s config/tls/ as public.crt and private.key, and the certificate copy also serves as ca.crt. A self-signed pg cert leaf is its own trust anchor, so clients can trust rmq.crt directly. If the certificate is signed by another CA, trust that CA’s chain instead: ca.crt contains only what you supplied, which may not include the root.

With BYO TLS the source files are left untouched and pgcli does not renew the certificate — replace the source files and re-run install --force (or --tls=false --force to go back to plaintext).

Queues and messages

queue list, purge and delete run rabbitmqctl inside the container and do not need the management HTTP password. The other queue commands — declare, info, publish, get, bind, unbind, bindings — use the management HTTP API with the stored administrator credentials; the instance must be running and the management port must be reachable from the host.

# declare and inspect
pg addon rabbitmq queue list --name rmq
pg addon rabbitmq queue declare orders --name rmq
pg addon rabbitmq queue info orders --name rmq
pg addon rabbitmq queue info orders --name rmq --json

# publish and consume
pg addon rabbitmq queue publish orders --payload '{"id":1}' --name rmq
echo '{"id":2}' | pg addon rabbitmq queue publish orders --payload-file - --name rmq
# standalone classic queue: persist the message across a broker restart
pg addon rabbitmq queue publish orders --payload '{"id":3}' --property delivery_mode=2 --name rmq
pg addon rabbitmq queue get orders --count 10             # peek: messages stay queued
pg addon rabbitmq queue get orders --count 10 --consume   # ack: remove them
pg addon rabbitmq queue get orders --json

# bindings (a real exchange is required; the default exchange cannot be bound)
pg addon rabbitmq queue bind orders --exchange amq.topic --routing-key 'order.*' --name rmq
pg addon rabbitmq queue bindings orders --name rmq
pg addon rabbitmq queue unbind orders --exchange amq.topic --routing-key 'order.*' --name rmq

# cleanup
pg addon rabbitmq queue purge orders --name rmq --yes
pg addon rabbitmq queue delete orders --name rmq --yes
pg addon rabbitmq queue delete orders --name rmq --if-empty --if-unused
  • list prints name, type, messages, ready, unacked and consumers; an empty vhost prints no queues.
  • declare creates a durable classic queue by default on a standalone instance, and a durable quorum queue by default on a cluster member (see Clustering). RabbitMQ 4.x removed transient (non-durable, non-exclusive) queues, so --durable=false is rejected before the request is sent. --type classic or --type quorum overrides the default explicitly; quorum queues must be durable and cannot be auto-delete. Repeatable --argument KEY=VALUE sets queue arguments; values that parse as JSON keep their JSON type (--argument x-max-priority=10).
  • Message retention. --message-ttl 30m (or a number of milliseconds) sets x-message-ttl: a message that waits in the queue longer is dropped, or dead-lettered when the queue has x-dead-letter-exchange. A single message can carry its own TTL with --property 'expiration="60000"'.
  • Automatic deletion. --auto-delete deletes the queue when its last consumer disconnects. --expires 24h sets x-expires: the queue itself — including any messages still in it — is deleted once it has been unused for that long. A queue counts as used only when it has a consumer, is redeclared, or is accessed with basic.get; publishing alone does not reset the timer. The value must be positive (0 is rejected by RabbitMQ). Both can also be set with --argument.
  • info shows type, state, durable, auto-delete, message counters, consumers, memory, policy, arguments and node. --json prints the raw management API document. Counters are updated by RabbitMQ’s stats collector, so they can lag a few seconds behind publish/get.
  • publish sends one message. Exactly one of --payload or --payload-file is required (use - to read stdin). --exchange defaults to amq.default (the default exchange, which routes to the queue named by the routing key); --routing-key defaults to the queue name. Repeatable --property KEY=VALUE sets message properties, e.g. --property delivery_mode=2 --property 'content_type="application/json"'. An unroutable message prints a warning but is not an error.
  • Standalone persistence. A standalone instance declares a durable classic queue (not replicated), but durability applies to the queue, not its messages. Classic message persistence is a per-message property set by the publisher on every publish: pass --property delivery_mode=2 to queue publish, or set delivery_mode=2 in the application’s AMQP client. No queue argument or policy can enable it (--argument delivery_mode=2 has no effect). Without it, a broker restart (stop/start, container recreation or a host reboot) keeps the queue but drops the messages. With it, messages survive as long as the instance data dir is kept (never remove --clean-data); a lost disk is unrecoverable. Cluster quorum queues persist and replicate every message regardless of delivery mode.
  • get peeks by default (ack_requeue_true); --consume acknowledges and removes the returned messages (ack_requeue_false). --count defaults to 1; --json prints the raw API response.
  • bind / unbind require --exchange and refuse amq.default (the default exchange is bound implicitly). --routing-key defaults to the queue name. Repeatable --argument supports argument-based (headers) bindings. unbind without --argument removes every binding from that exchange with the given routing key; with --argument it removes only the exactly matching binding.
  • bindings lists a queue’s bindings and their arguments (--json for the raw document).
  • purge removes every message but keeps the queue; delete removes the queue itself. Both ask for confirmation unless --yes is given. --if-empty / --if-unused (delete only) forward RabbitMQ’s conditional checks: the delete fails instead of removing a non-empty queue or one with consumers.
  • Every queue command accepts --name and --vhost (default /) and requires the instance to be running.

Retention examples

A queue declared without retention flags keeps messages indefinitely: there is no default TTL. Messages leave the queue only when they are consumed, purged, dead-lettered, or the queue itself is deleted. Concrete limits:

# Queue-level TTL: every message expires 24 hours after it was published
pg addon rabbitmq queue declare orders --message-ttl 24h --name rmq

# Per-message TTL: this message expires 60 seconds after publishing
# (`expiration` is a string property in milliseconds)
pg addon rabbitmq queue publish orders --payload '{"id":1}' \
  --property 'expiration="60000"' --name rmq

# Idle queue deletion (not a message TTL): the queue itself and its
# messages are removed after 1 hour without consumers, redeclare or basic.get
pg addon rabbitmq queue declare scratch --expires 1h --name rmq

# Capacity cap instead of a time limit: keep at most 10000 messages
pg addon rabbitmq queue declare backlog --argument x-max-length=10000 --name rmq

# Route expired messages to a dead-letter exchange instead of dropping them
pg addon rabbitmq queue declare dlq-demo --message-ttl 24h \
  --argument x-dead-letter-exchange=dlx --name rmq

--message-ttl and --expires only apply when the queue is first declared. To change retention on an existing queue without deleting it, use a policy:

pg addon rabbitmq shell --name rmq
rabbitmqctl set_policy orders-ttl '^orders$' \
  '{"message-ttl":86400000,"max-length":10000}' --apply-to queues
rabbitmqctl list_policies

Policies match queue names by regular expression, apply to new and existing queues, and take precedence over the equivalent x-* queue arguments. A policy can also be created in the management UI under Admin → Policies.

The same retention limits can be applied without redeclaring a queue through a RabbitMQ policy (message-ttl, expires, max-length, max-length-bytes); pgcli does not wrap policies yet — use the management UI or rabbitmqctl set_policy.

pg addon rabbitmq shell opens /bin/bash in the container; rabbitmqctl and rabbitmq-diagnostics are available there for everything the CLI and API do not cover.

Status and lifecycle

pg addon rabbitmq status --name rmq       # state, endpoints, TLS, admin, EPMD/dist, paths
pg addon start rabbitmq --name rmq        # start (create if missing), wait for readiness
pg addon stop rabbitmq --name rmq
pg addon remove rabbitmq --name rmq       # remove container + pg.yaml entry, keep data/config/secrets
pg addon remove rabbitmq --name rmq --clean-data   # also delete the instance dir and a custom data dir
pg logs addon rabbitmq --name rmq -f

install, start and --force wait up to 90 seconds for rabbitmqctl -q await_startup on a standalone instance. A cluster member waits up to 180 seconds, which also covers the initial peer-discovery and Mnesia bootstrap; each attempt is capped at 10 seconds because with peers present the command can succeed silently and still never exit. If the idle watchdog ends such an attempt, pgcli probes the AMQP port instead — the listener opens at the end of boot, so a reachable port means ready. After readiness pgcli reconciles the administrator account with rabbitmqctl change_password / add_user / set_user_tags administrator / set_permissions.

In cluster mode status additionally prints the cluster name, the Erlang node name and the etcd endpoints; pg addon rabbitmq cluster status shows the live view from rabbitmqctl cluster_status.

Without --clean-data, remove keeps the data dir, the generated config and the 0600 password secret. Reinstalling under the same name reuses that password, so clients keep working after a remove/reinstall cycle.

Auto-start after reboot:

pg autostart enable --rabbitmq --name rmq
pg autostart status
pg autostart disable --rabbitmq --name rmq

Boot start re-renders rabbitmq.conf, starts the container and re-applies the admin credentials. pg start also brings up autostart-enabled RabbitMQ instances.

What pgcli creates

Everything for one instance lives under <base_dir>/addon/rabbitmq/<name>/:

Host path Container path Notes
config/rabbitmq.conf /etc/rabbitmq/rabbitmq.conf (read-only) Rendered listeners, management, admin tags/permissions and distribution settings
config/enabled_plugins /etc/rabbitmq/enabled_plugins (read-only) [rabbitmq_management]. standalone, [rabbitmq_management,rabbitmq_peer_discovery_etcd]. in cluster mode
config/tls/ /etc/rabbitmq/tls (read-only, only with --tls) ca.crt (0644), public.crt (chain, 0644), private.key (0600, chowned to uid 999); ca.key stays host-side and is not mounted
data/ /var/lib/rabbitmq Mnesia, message store, definitions and logs; cluster mode adds .erlang.cookie (0400, chowned to uid 999)
secrets/admin_password not mounted 0600, reused by reinstall

The generated rabbitmq.conf for a plaintext instance:

listeners.tcp.default = 127.0.0.1:5672

management.tcp.ip = 127.0.0.1
management.tcp.port = 15672

default_user_tags.administrator = true
default_permissions.configure = .*
default_permissions.read = .*
default_permissions.write = .*

distribution.listener.interface = 127.0.0.1
distribution.listener.port_range.min = 25672
distribution.listener.port_range.max = 25672

With --tls the file additionally carries listeners.ssl.default, the ssl_options.* block and the management.ssl.* block. A cluster member instead binds to 0.0.0.0 (or the explicit --listen address) and appends the discovery block:

cluster_formation.peer_discovery_backend = etcd
cluster_formation.etcd.endpoints.1 = 192.0.2.10:2379
cluster_formation.etcd.cluster_name = pgcli-lab

No secret is written into rabbitmq.conf. The administrator password travels in the container environment (RABBITMQ_DEFAULT_USER / RABBITMQ_DEFAULT_PASS, which only seed an empty Mnesia; pgcli reconciles it with rabbitmqctl on every start), as do RABBITMQ_NODENAME and RABBITMQ_USE_LONGNAME. In cluster mode pgcli additionally writes the shared Erlang cookie to data/.erlang.cookie before the container starts (mode 0400, owned by uid 999): the official 4.4 image ignores RABBITMQ_ERLANG_COOKIE, and a node left to generate its own random cookie cannot complete the distribution handshake with its peers.

The container runs with --network host, --restart unless-stopped and a 30-second stop timeout. It runs as the image’s uid/gid 999 (rabbitmq); pgcli hands only the TLS private key and the cluster cookie file to that uid (through podman unshare on rootless, os.Chown when running as root). The data directory is chowned by the image entrypoint itself.

Configuration

Extra rabbitmq.conf entries can be set at install time:

pg addon install rabbitmq --name rmq --force \
  --config-option heartbeat=60 \
  --config-option log.file.level=debug

--config-option replaces the stored override map (it does not merge). Overrides are persisted in pg.yaml under addons.rabbitmq.<name>.settings and re-rendered on every start. Keys may contain letters, digits, dots, underscores and hyphens; values must not contain NUL, CR or LF.

pgcli-managed keys are rejected rather than silently overridden: listeners.*, ssl_options.*, management.*, prometheus.*, cluster_formation.*, default_user, default_pass, default_user_tags.*, default_permissions.*, loopback_users.* and distribution.listener.*.

Password and account semantics

  • RABBITMQ_DEFAULT_USER / RABBITMQ_DEFAULT_PASS only seed an empty Mnesia database on first boot. That is why pgcli reconciles the account on every start with rabbitmqctl change_password (falling back to add_user when the user does not exist), then sets the administrator tag and full .* / .* / .* permissions on vhost /.
  • Changing --admin-user on an existing instance creates/reconciles the new account but does not delete the previous one. Remove stale accounts in the management UI or with rabbitmqctl delete_user.
  • Changing --admin-password (or reviving a stored secret) is applied on the next install --force or start. In a cluster the password is shared: every member must store the same value, so rotate it on all members.
  • In cluster mode the shared secrets come either from --secrets-from-etcd (recommended; keys written by pg addon rabbitmq secret generate) or from --admin-password-file plus --erlang-cookie-file. Plaintext --admin-password is rejected. Both values are then persisted in pg.yaml and the 0600 secret file.
  • Passwords are stored both in pg.yaml and in the 0600 secret file; pg addon password rabbitmq --name NAME prints the stored value.

Production notes

  • Single node or one cluster member. A standalone instance has no HA: one stopped container means the broker is down. In cluster mode availability comes from quorum queues replicated across members; classic queues are not replicated and disappear with their node. Federation, shovel, MQTT and STOMP are not configured.
  • Cluster networking. Open 4369 (EPMD) and 25672 (Erlang distribution) only between members on a private network. Distribution traffic is not encrypted even with --tls; TLS covers client listeners only. One clustered instance per host.
  • Discovery is plaintext. etcd endpoints are contacted over plain HTTP without authentication. Anyone who can reach etcd can register a node in the cluster or read the shared secret keys written by pg addon rabbitmq secret generate; isolate it on a trusted network. etcd TLS/auth is not supported in this release.
  • No Prometheus plugin. enabled_plugins is pinned to management (plus etcd discovery in cluster mode). Scrape metrics through the management API or enable a plugin manually in the container if you really need it — but note that every instance would then want the same default metrics port.
  • TLS is not client authentication. Use --listen 127.0.0.1 or a private network/firewall in front of the broker. The management UI is a full administrative surface; do not expose it casually.
  • TLS is additive. Plaintext amqp:// and http:// stay enabled when --tls is on; clients that need encryption must select the amqps:// / https:// endpoints explicitly.
  • Upgrades. --force --version <new> pulls a new tag and recreates the container on the same data dir. RabbitMQ does not guarantee downgrading data written by a newer version — take an offline copy before upgrading. --version must be a real upstream tag.
  • Backups. Copy the data directory while the container is stopped, or use the management API’s definitions export for users/vhosts/policies. There is no pg addon rabbitmq backup command in this release.
  • Data ownership. Data files are owned by uid/gid 999. Use --clean-data instead of deleting the directory by hand; pgcli handles the permission fallback through podman unshare.
  • Platform. Linux (host networking); the official image is multi-arch (amd64/arm64). On a rootful host, run pgcli as root so it can hand the TLS private key to uid 999; on rootless it uses podman unshare.

CLI flag reference

pg addon install rabbitmq

Flag Default Description
--name NAME rabbitmq Instance name; [A-Za-z0-9][A-Za-z0-9_-]*, max 48 chars
--version TAG 4.4.0 Upstream docker.io/library/rabbitmq tag; the -management suffix is added automatically
--admin-user USER admin Administrator account; [A-Za-z0-9_.-]{1,64}
--admin-password PASS generated Administrator password (no NUL/CR/LF); rejected in cluster mode
--admin-password-file FILE — Read the password from FILE; required for the first install of a cluster member unless --secrets-from-etcd is used
--data-dir DIR <base_dir>/addon/rabbitmq/<name>/data Absolute host data dir bind-mounted at /var/lib/rabbitmq
--listen ADDR 127.0.0.1 (0.0.0.0 in cluster mode) Bind address for AMQP, AMQPS, management HTTP and management HTTPS; must not be loopback in cluster mode
--cluster NAME — Cluster name; empty = standalone
--node-name NODE@HOST — Erlang node name for this cluster member; required on first install
--etcd M1,M2 — Local etcd addon members used for discovery
--etcd-endpoints HOST:PORT,... — External etcd endpoints used for discovery; takes precedence over --etcd
--erlang-cookie-file FILE — Read the shared Erlang cookie from FILE; required on first install of a cluster member unless --secrets-from-etcd is used
--secrets-from-etcd false Read both shared secrets from the etcd keys written by secret generate; excludes the two --*-file flags
--amqp-port N auto (base 5672) Plaintext AMQP port; 0 = auto-assign
--management-port N auto (base 15672) Management HTTP port; 0 = auto-assign
--tls false Add AMQPS and management HTTPS; plaintext listeners stay enabled
--tls-cert FILE — BYO certificate chain (PEM); must be paired with --tls-key; implies --tls
--tls-key FILE — BYO private key; must be paired with --tls-cert
--tls-port N auto (base 5671) AMQPS port; 0 = auto-assign; requires --tls
--config-option K=V — Extra rabbitmq.conf setting; repeatable; replaces the stored override map
--force false Re-render config and recreate the container, keeping data and password; cluster/node/cookie are immutable

pg addon rabbitmq status / shell / cluster ...

Argument/flag Default Description
status --name NAME rabbitmq Show state, endpoints, TLS, admin, EPMD/dist, paths; cluster name/node/etcd when clustered
shell --name NAME rabbitmq Open /bin/bash in the container
cluster status --name NAME rabbitmq Print rabbitmqctl cluster_status
cluster forget NODE --name NAME [--yes] — Forget a stopped, retired member; refuses the local node and asks for confirmation unless --yes

pg addon rabbitmq secret generate

Flag Default Description
--cluster NAME — Cluster whose secrets are published (required)
--etcd M1,M2 — Local etcd addon members holding the secrets
--etcd-endpoints HOST:PORT,... — External etcd endpoints holding the secrets; takes precedence over --etcd
--cookie-file FILE /tmp/rmq.cookie Local copy of the Erlang cookie (0600); used by cluster nodes only, clients do not need it
--admin-password-file FILE /tmp/rmq.admin Local copy of the administrator password (0600); an installation input, not a client credential
--force false Overwrite existing files and etcd keys
--keep-cookie false With --force: keep the existing Erlang cookie and rotate only the admin password (used after members are installed)

pg addon rabbitmq queue ...

Every queue subcommand accepts --name NAME (default rabbitmq) and --vhost VHOST (default /).

Command Argument/flag Default Description
list — — Show queues with message and consumer counts
declare QUEUE --durable true Declare a durable queue (false is rejected by RabbitMQ 4.x)
--auto-delete false Delete the queue when its last consumer disconnects
--type TYPE classic standalone, quorum cluster classic or quorum
--message-ttl DURATION — Set x-message-ttl (e.g. 30m, 24h, or milliseconds)
--expires DURATION — Set x-expires: delete the queue after this much idle time (must be > 0)
--argument K=V — Extra queue argument; repeatable; JSON values keep their type
info QUEUE --json false Print the raw management API document
publish QUEUE --payload TEXT — Message body (mutually exclusive with --payload-file)
--payload-file FILE — Read the body from a file; - reads stdin
--exchange NAME amq.default Target exchange
--routing-key KEY queue name Routing key
--property K=V — Message property; repeatable; a standalone classic message needs delivery_mode=2 set on every publish to survive a broker restart (no queue-level switch exists); JSON values keep their type
get QUEUE --count N 1 Maximum messages to fetch
--consume false Ack and remove the messages (default: peek and requeue)
--json false Print the raw management API response
bind QUEUE --exchange NAME — Source exchange (required; amq.default rejected)
--routing-key KEY queue name Routing key
--argument K=V — Binding argument; repeatable
unbind QUEUE --exchange NAME — Source exchange (required)
--routing-key KEY queue name Routing key
--argument K=V — Remove only the exactly matching binding; omit to remove all matches
bindings QUEUE --json false Print the raw management API document
purge QUEUE --yes false Skip the confirmation prompt
delete QUEUE --yes false Skip the confirmation prompt
--if-empty false Fail instead of deleting a queue with messages
--if-unused false Fail instead of deleting a queue with consumers

Lifecycle, logs, autostart

Command Flags Description
pg addon start rabbitmq --name NAME Start (create if missing), wait for readiness, reconcile the admin account
pg addon stop rabbitmq --name NAME Stop the container, keep data
pg addon remove rabbitmq --name NAME, --clean-data Remove container and config entry; --clean-data also deletes the instance dir and a custom data dir
pg logs addon rabbitmq --name NAME, -n N (default 50), -f Container logs
pg autostart enable|disable --rabbitmq, --name NAME Toggle boot start for one instance
pg addon password rabbitmq --name NAME Print the stored administrator password

Global flags

Flag Description
-c, --config FILE Config file (default ~/.pgcli/pg.yaml)
-o, --output FILE Output config path (default the same file)
-i, --instance NAME PostgreSQL instance selector — not used by RabbitMQ; use --name instead

40 - RocketMQ

Run Apache RocketMQ 5.x as a managed addon — three containers (NameServer + broker + proxy), standalone or a multi-host controller-mode cluster with automatic broker failover, topic and message helpers, rendered configs and host networking

pg addon install rocketmq runs Apache RocketMQ 5.x as a managed addon from the official docker.io/apache/rocketmq image. Like Kafka, ClickHouse and RabbitMQ it is a top-level addon that does not front a PostgreSQL instance.

Each instance is three containers on the host network: a NameServer, a broker and a proxy. The same shape is used in both modes, so ports, commands, logs and lifecycle behave identically:

  • Standalone — one NameServer with no controller, one async master broker with no replicas, and a proxy. This is the quickest way to send and receive messages. The 4.x master/slave and DLedger broker deployment modes are not used.
  • Multi-host cluster — every NameServer embeds a DLedger (Raft) controller, the brokers run in controller mode, and one broker is elected master while another takes over automatically when it fails. The proxy is the client entry point. This is RocketMQ 5.x’s auto-failover deployment mode.

There is no authentication and no TLS. RocketMQ listens on host networking, and cluster ports are fixed. Anyone who can reach the NameServer, broker or proxy ports can read and write every topic. Run it only on a trusted private network or behind a firewall that restricts 9876, 9877, 10911, 10912, 8080 and 8081. There is also no web UI and no ACL in this addon.

Parameters

Flag Default Description
--name rocketmq Instance name (map key; also the default subcommand name)
--version 5.5.0 Upstream image tag, pulled as docker.io/apache/rocketmq:<version>. Only 5.x releases are accepted
--data-dir <base_dir>/addon/rocketmq/<name>/data Instance data root: the broker store is <dir>/broker and, in cluster mode, the controller store is <dir>/controller. Must be absolute except for base_dir-relative paths
--advertise-host 127.0.0.1 standalone; required cluster Host advertised to clients and peers. Cluster mode requires a concrete non-loopback IPv4 address; hostnames, IPv6 and 0.0.0.0 are rejected. Set it to the host’s LAN IP for standalone instances that remote clients use
--cluster NAME — Switch on multi-host cluster mode. Every host must use the same name; it becomes the DLedger controller group and the broker cluster/group name. Cluster identity is immutable after install
--controller-id ID — This node’s controller member id (n0, n1, …). Required on a fresh cluster install; must be unique in the group and match [A-Za-z][A-Za-z0-9]{0,31}. Rejected in standalone mode
--peer ID@HOST — Another controller member. Repeat once per other node, with a bare non-loopback IPv4 host and no port (the controller port is fixed at 9877). Pass the full list of the other members on every host; the local peer is added automatically. Rejected in standalone mode
--namesrv-port auto (9876) standalone NameServer host port. 0 = auto-assign from the RocketMQ pool. Standalone only; cluster members are fixed at 9876
--broker-port auto (10911) standalone Broker listen port; HA is broker_port + 1 and the VIP port is broker_port - 2. Standalone only; cluster members are fixed at 10911
--proxy-port auto (8080) standalone Proxy remoting port. Standalone only; cluster members are fixed at 8080
--grpc-port auto (8081) standalone Proxy gRPC port for 5.x SDKs. Standalone only; cluster members are fixed at 8081
--controller-port — Embedded controller port. Not accepted in standalone mode; cluster members are fixed at 9877
--heap 512m Broker JVM heap, applied as JAVA_OPT_EXT=-Xms<size> -Xmx<size>
--namesrv-heap 256m NameServer JVM heap
--proxy-heap 256m Proxy JVM heap
--config-option K=V — Extra broker.conf setting (flushDiskType=SYNC_FLUSH, brokerPermission=4); repeatable and replaces the stored override list. pgcli-managed keys are rejected (identity, listeners, store paths, controller settings, replication settings, autoCreateTopicEnable)
--force false Re-render the three configs and recreate the three containers, keeping the broker store and controller store. Cluster identity and fixed ports cannot be changed even with --force

--image, --listen, --tls, --tls-pem, --tls-cert, --tls-key, --node-id, --cluster-id and --join do not apply to RocketMQ and are rejected. Use --version to select the image.

Install a standalone instance

pg addon install rocketmq --name rmq

The install pulls the image if needed, renders the configs, creates the directories, starts namesrv → broker → proxy, and waits for the NameServer, broker registration and both proxy listeners:

✓ RocketMQ "rmq" installed
  Version:     5.5.0
  Image:       docker.io/apache/rocketmq:5.5.0
  Containers:  pgcli-rocketmq-rmq-namesrv, pgcli-rocketmq-rmq-broker, pgcli-rocketmq-rmq-proxy
  Namesrv:     127.0.0.1:9876
  Broker:      127.0.0.1:10911 (HA 10912, VIP 10909)
  Proxy:       127.0.0.1:8080 (remoting), 127.0.0.1:8081 (gRPC)
  Mode:        single-node (no controller, no replicas)
  JVM heap:    broker 512m, namesrv 256m, proxy 256m
  Data dir:    /home/you/.pgcli/addon/rocketmq/rmq/data
  Config:      /home/you/.pgcli/addon/rocketmq/rmq/config

To let clients on other hosts connect, advertise the host’s LAN address (the proxy config and broker both use it):

pg addon install rocketmq --name rmq --advertise-host 10.0.0.11

A second standalone instance takes the next free port from each pool; it does not reuse the first instance’s ports:

pg addon install rocketmq --name rmq2 --data-dir /srv/rocketmq-data

On a small VM, lower all three heaps to keep the three JVMs inside memory:

pg addon install rocketmq --name rmq \
  --heap 384m --namesrv-heap 192m --proxy-heap 192m

Re-running install without --force is a no-op that reports the current state. With --force, pgcli rewrites namesrv.conf, broker.conf and rmq-proxy.json, recreates the three containers and keeps the broker and controller stores.

Multi-host cluster

Cluster mode uses RocketMQ 5.x’s controller mode: the controller is embedded in every NameServer as a DLedger (Raft) group, and controller-mode brokers elect a master and fail over automatically. Every host runs its own pg addon install rocketmq; pgcli never SSHes to other hosts.

Requirements:

  • The same --cluster name on every host.
  • A unique --controller-id per host (n0, n1, n2, …).
  • That host’s --advertise-host as a concrete non-loopback IPv4 address.
  • --peer ID@HOST entries for the other controller members. Pass the full peer set on every host; the local peer is added automatically.
  • The fixed cluster ports free on every host: 9876, 9877, 10911, 10912, 8080 and 8081. One clustered RocketMQ instance per host.
  • At least 3 members for fault tolerance. The DLedger quorum is the majority, so 2 members tolerate no failure; pgcli prints a warning for a 2-member cluster.

Install the members one host at a time. For three hosts 10.0.0.11, 10.0.0.12 and 10.0.0.13:

# on 10.0.0.11 (controller n0)
pg addon install rocketmq --name rmq --cluster prod --controller-id n0 \
  --advertise-host 10.0.0.11 \
  --peer n1@10.0.0.12 --peer n2@10.0.0.13

# on 10.0.0.12 (controller n1)
pg addon install rocketmq --name rmq --cluster prod --controller-id n1 \
  --advertise-host 10.0.0.12 \
  --peer n0@10.0.0.11 --peer n2@10.0.0.13

# on 10.0.0.13 (controller n2)
pg addon install rocketmq --name rmq --cluster prod --controller-id n2 \
  --advertise-host 10.0.0.13 \
  --peer n0@10.0.0.11 --peer n1@10.0.0.12

The first two installs are expected to finish with a warning such as:

[!] RocketMQ broker is running, but it has not registered with the controller yet
(broker not listed in clusterList) — install the remaining nodes with the same
--cluster and --peer values ...

This is normal: the controller quorum only forms once a majority of NameServers is up. The install still exits successfully and leaves the containers running. After the third member is installed, the controller elects the broker master and the broker registers.

Check every member:

pg addon rocketmq status --name rmq
pg addon rocketmq cluster status --name rmq

status shows the three container states, the controller id, the full peer list and — when the cluster is reachable — how many brokers are registered and how many are masters. cluster status prints the raw clusterList table; the controller’s BID column (labelled BrokerId in older clients) is 0 for the current master and non-zero for replicas:

rocketmq "rmq" — cluster prod: 3 broker(s), 1 master(s)
#Cluster Name  #Broker Name  #BID  #Addr             #Version  #InTPS(LOAD)  #OutTPS(LOAD)
prod           prod          0     10.0.0.13:10911   V5_5_0    0.00(0,0ms)   0.00(0,0ms)
prod           prod          1     10.0.0.11:10911   V5_5_0    0.00(0,0ms)   0.00(0,0ms)
prod           prod          2     10.0.0.12:10911   V5_5_0    0.00(0,0ms)   0.00(0,0ms)

The column layout and row order are produced by mqadmin and may differ slightly between 5.x releases; pgcli only relies on the cluster name and broker id columns.

Failover

When the master broker stops, the controller elects another in-sync replica after a heartbeat timeout. Clients that connect through the proxy or NameServer retry automatically. To watch a failover:

# find the master (BID 0) in cluster status, then on that host:
pg addon stop rocketmq --name rmq

# on any member, poll until another BID 0 appears:
pg addon rocketmq cluster status --name rmq

# start the old broker again; it rejoins as a replica:
pg addon start rocketmq --name rmq

enableElectUncleanMaster=false is rendered, so a replica that is not in the in-sync state set is not elected. If the controller quorum itself loses its majority (for example two of three NameServers are down), no master can be elected and writes stop until the quorum returns. Stopping or removing a member does not rewrite the peer lists on the remaining hosts; pgcli never contacts the other nodes.

Ports

Port Role Standalone Cluster
9876 NameServer client/RPC auto, base 9876 fixed
9877 Embedded DLedger controller not used fixed
10911 Broker listen auto, base 10911 fixed
10912 Broker HA replication broker_port + 1 fixed
10909 Broker VIP broker_port - 2 fixed
8080 Proxy remoting auto, base 8080 fixed
8081 Proxy gRPC auto, base 8081 fixed

Standalone instances can coexist on one host because every port is drawn from a pool and reserved together with the derived HA/VIP ports. In cluster mode all of these ports are fixed because the controller membership and broker addresses are baked into every node’s config.

Clients

The proxy is the single client entry point in both modes and runs in CLUSTER mode:

  • 5.x gRPC SDK (the recommended 5.x client): connect to <advertise-host>:8081.
  • Remoting SDK (4.x-style clients): connect to <advertise-host>:8080, or directly to the broker on <advertise-host>:10911.
  • NameServer addresses (9876, controller 9877) are internal cluster plumbing. Do not expose them to remote clients.

A standalone instance defaults to 127.0.0.1, so a client on another host needs an install with --advertise-host set to the host’s reachable IP. In cluster mode every member requires a non-loopback IPv4 --advertise-host and the proxy on each host advertises that host.

Topics and messages

Topic auto-creation is enabled (autoCreateTopicEnable=true) for compatibility, but explicit creation is recommended so queue counts are deterministic:

pg addon rocketmq topic create surge --queues 3 --name rmq
pg addon rocketmq topic list --name rmq
pg addon rocketmq topic describe surge --name rmq

topic create creates the topic across the cluster (-c <cluster-or-name>) with --queues read and write queues (default 3). topic list hides RocketMQ’s internal topics (%RETRY%…, %DLQ%…, TBW102, SELF_TEST_TOPIC, transaction/schedule/trace topics, the 5.x rmq_sys_* / RMQ_SYS_* topics, *_REPLY_TOPIC and the topic named after the cluster); pass --system to show everything. topic describe prints the per-broker queue and offset table from topicStatus.

Send a message and look it up by key:

pg addon rocketmq send surge "hello" --key k1 --tags demo --name rmq

pg addon rocketmq shell --service namesrv --name rmq -- \
  sh mqadmin queryMsgByKey -t surge -k k1 -n 127.0.0.1:9876

send prints the sendMessage result, including the message id, send status and queue. Pull messages back with a bounded debug consumer:

pg addon rocketmq consume surge --count 10 --timeout 30s --name rmq

# one queue, from the start
pg addon rocketmq consume surge --queue 0 --offset 0 --count 50 --name rmq

# messages in a time window (epoch milliseconds or yyyy-MM-dd#HH:mm:ss:SSS)
pg addon rocketmq consume surge --begin 1793264528000 --end 1793264535000 \
  --count 0 --name rmq

consume runs mqadmin consumeMessage in a throwaway container and prints messages to the terminal. It drains the topic’s queues and exits; --timeout (default 30s) is a hard safety limit enforced inside the container, and Ctrl-C stops early. It is a pull-only debug viewer: it does not delete messages and does not commit consumer offsets.

--count is mqadmin’s message budget (default 10); mqadmin accounts it per queue, so a run can print slightly fewer messages than requested. --count 0 removes the budget. --queue/--offset read one queue and use the instance’s broker name (--broker overrides it). --begin/--end accept epoch milliseconds or yyyy-MM-dd#HH:mm:ss:SSS; mqadmin converts the boundaries to queue offsets, so the end of the window can include the first message at or after it.

Deleting a topic removes all of its messages and asks for confirmation unless --yes is passed:

pg addon rocketmq topic delete surge --name rmq --yes

Message retention

Consumption never deletes messages. The broker removes whole commitlog segments (the storage unit shared by all topics on that broker) when a segment is older than fileReservedTime hours and the clock reaches one of the deleteWhen hours, or earlier when disk usage exceeds diskMaxUsedSpaceRatio percent. Retention is broker-wide, not per topic.

Show the running broker’s effective values and change them:

pg addon rocketmq retention show --name rmq

pg addon rocketmq retention set --hours 24 --delete-when "04;16" \
  --disk-ratio 80 --name rmq

Defaults are 72 hours, 04 o’clock and 75 percent. set requires at least one of --hours (1–8760), --delete-when (one or more hours 0–23 separated by ;) and --disk-ratio (1–100). It applies the change to the running broker with updateBrokerConfig and writes the same values to pg.yaml and the rendered broker.conf, so the setting survives pg addon stop/start without a recreate. An expired segment is not deleted at the exact hour; the broker removes it during the next scheduled cleanup. Raising the ratio above the current disk usage stops disk-pressure deletions.

Retention is stored per broker. In a cluster, run the command on every member host; each broker cleans only its own commitlog.

Delivery and durability

Standalone. The broker is the only node (brokerId=0, brokerRole=ASYNC_MASTER) with no replicas. Messages are written to the broker store under data/broker, so a graceful stop/start keeps them. The rendered disk flush policy is RocketMQ’s default ASYNC_FLUSH; a host power loss can therefore lose the most recent writes. For stronger durability, render SYNC_FLUSH (at the cost of throughput):

pg addon install rocketmq --name rmq --force \
  --config-option flushDiskType=SYNC_FLUSH

Cluster. Brokers replicate in controller mode. pgcli renders allAckInSyncStateSet=true and minInSyncReplicas=2 for 3 or more members (1 for a 2-member cluster), so a produce succeeds only when every in-sync replica has accepted the message. Disk flush is still ASYNC by default; use flushDiskType=SYNC_FLUSH when a power loss must not lose acknowledged writes across all replicas.

Replication protects against a broker failure while the controller quorum is healthy. It does not make the controller store disposable: data/controller holds the DLedger state and epoch files. Deleting it, wiping a member, or reinstalling with --clean-data destroys that member’s controller state and can break the quorum. A member that is removed and rejoined must start with a fresh data directory and the same cluster/controller/peer identity.

pg addon remove rocketmq --clean-data deletes the instance directory (configs, broker store, controller store and logs) and a distinct custom data directory. Without --clean-data, the data and config directories are kept.

Configuration, upgrades and immutability

  • Mutable with --force: version, JVM heaps, broker.conf overrides and, for standalone instances, the listener ports. --config-option replaces the stored override map, so pass every override again on a forced reinstall.
  • Immutable even with --force: in cluster mode --cluster, --controller-id, --advertise-host, --peer and the fixed ports. These values are embedded in every peer’s configuration; changing them in place is rejected.
  • Topology changes require a rebuild: standalone ↔ cluster is not an in-place change. Remove the instance with --clean-data and install it again in the desired mode.
  • Custom data directory: pointing --data-dir at a new path makes the instance use a new, empty store; pgcli does not migrate existing data.

Managed broker.conf keys (rejected in --config-option) include brokerClusterName, brokerName, brokerId, brokerRole, brokerIP1/brokerIP2, listenPort, haListenPort, namesrvAddr, enableControllerMode, controllerAddr, every controller* key, storePathRootDir, storePathCommitLog, storePathEpochFile, autoCreateTopicEnable, allAckInSyncStateSet, minInSyncReplicas, enableControllerInNamesrv, enableElectUncleanMaster and notifyBrokerRoleChanged.

Lifecycle, logs and autostart

pg addon start rocketmq --name rmq
pg addon stop rocketmq --name rmq
pg addon remove rocketmq --name rmq --clean-data

pg logs addon rocketmq --name rmq --service broker -f
pg logs addon rocketmq --name rmq --service namesrv
pg logs addon rocketmq --name rmq --service proxy

Stopping walks the containers in reverse (proxy → broker → namesrv); starting walks them forward (namesrv → broker → proxy). In cluster mode, start does not wait for the full controller quorum: when a majority is not yet reachable the broker stays in its waiting state and the command still succeeds. Check pg addon rocketmq status and cluster status after the other members are up.

Autostart is available like the other top-level addons:

pg autostart enable --rocketmq --name rmq
pg autostart status

It re-renders the three configs and starts the containers in order. For a cluster member, autostart does not wait for the controller quorum, so members can boot in any order. pg addon start (the global autostart starter) behaves the same way.

Limitations

  • No authentication, TLS or ACL. Restrict the network; the proxy and NameServer are open to anyone who can reach them.
  • No web UI. Use pg addon rocketmq status, cluster status, topic commands and the logs.
  • No online scaling or rolling upgrade. Cluster membership and fixed ports are immutable; member changes require a planned rebuild. The controller store must not be deleted while the member participates in a quorum.
  • 2-member clusters have no fault tolerance. Use 3 or more members for production.
  • Linux only. The addon relies on host networking and the official image’s uid/gid 3000.
  • No message migration, consumer-group management or broker/storage rebalancing. Use the standard RocketMQ administration tools through pg addon rocketmq shell.