Postgres
What Wardn keeps in Postgres, how many connections it needs, poolers, TLS and migrations.
Postgres is the only service Wardn requires. Everything lives in it, and the server replicas use it to coordinate, so its health is Wardn's health. This page is for the person who runs the database. Self-hosting explains the other parts.
What Wardn keeps there
| Data | Notes |
|---|---|
| Organizations, people, teams, roles and grants | People and sessions are in the web app's sign-in tables, in the same database. |
| Clusters, sources, apps, deployments, environments | And their settings. |
| Snapshots and stored objects | With the default object store, rendered snapshots and recordings are rows, not files. With the s3 or gcs object store, their bytes are in a bucket and only their index is here. |
| The secret store | Repository and registry credentials, encrypted with keys that the master key (WARDN_SECRET_MASTER_KEY) wraps. The database alone cannot decrypt them. |
| Activity | The audit log, with its hash chain. |
| Timelines | Kept for WARDN_TIMELINE_RETENTION (30 days by default). Old months are dropped whole. |
| Work queue, leases, live events | How replicas share work and pass events to each other. |
With the default object store, a database backup is a complete backup of Wardn's data; with a bucket store, back up the bucket too. The keys that sit outside it are covered in Backup and restore.
Requirements
- Postgres 14 or newer. The bundled database in Compose and
wardn-tinyis Postgres 18. - A database and a user that can create tables, schemas and indexes in it. The server runs its migrations at start.
- No extensions are required. Compose's development setup loads
pg_stat_statementsfor measuring, which is useful but optional.
Connection URL
The server reads POSTGRES_URL, a standard Postgres connection URL:
postgres://wardn:[email protected]:5432/wardn?sslmode=require- TLS. Use
sslmode=requireor stricter for a database across a network. The charts defaultpostgres.external.sslModetorequire; the bundled database usesdisablebecause it never leaves the namespace. - Special characters. In a URL,
@ : / ? #in the password must be percent-encoded. The charts build the URL from a password Secret without encoding it, so for such a password give a whole URL withpostgres.external.urlSecretRef. - The web app connects with the same URL. It creates its own sign-in tables on start.
Connections and sizing
Each server process keeps a pool of up to POSTGRES_MAX_CONNS connections (20 by default). With a pooler, it keeps a second, direct pool of up to POSTGRES_DIRECT_MAX_CONNS (10 by default). The web app opens a few more.
| Install | Server replicas | Connections to plan for |
|---|---|---|
Compose, wardn-tiny | 1 | about 30 |
wardn-standard, no pooler | 3 | about 70 to 100 |
wardn-standard, with a pooler | 3 | the pooler's own pool size, plus 3 × 10 direct |
Count connections per replica: the database sees replicas times the pool size. Set the pool sizes with postgres.maxConns and postgres.directMaxConns in the charts. The metrics wardn_db_pool_acquired_connections and wardn_db_pool_wait_total show whether a pool is too small (Monitoring).
Every read runs in a short read-only transaction, because Wardn scopes each query to one organization with row-level security, set inside the transaction. That costs a few round trips per read, so keep the database close to the server: the same region, and preferably the same network.
Poolers
A transaction-mode pooler such as PgBouncer can serve the request path, but not everything Wardn does needs only transactions. LISTEN for live events and queued work, the leader leases and the migrations need a session that stays open. So Wardn takes two URLs:
| Setting | Points at | Used for |
|---|---|---|
POSTGRES_URL | The pooler | API requests and other request-path queries |
POSTGRES_DIRECT_URL | The database itself | LISTEN, leader leases, migrations and the background providers |
Without POSTGRES_DIRECT_URL, POSTGRES_URL serves everything and there is one pool. In the charts, postgres.pooler.enabled=true with postgres.pooler.host sets both: the pooled URL goes to the pooler, and the direct URL to postgres.external.host. Run the pooler yourself; the charts do not deploy one. Use transaction mode.
Read replicas
A hot standby of the database can take the lists off the primary: environments, clusters, deployments, apps, releases, pipelines, teams, members, guardrails, freezes, incidents, integrations, test runs and Activity. Everything else, every write and the live event stream stay on the primary.
| Setting | Default | What it does |
|---|---|---|
POSTGRES_REPLICA_URL | unset | The standby. Unset, every read goes to the primary. |
POSTGRES_REPLICA_MAX_CONNS | 10 | Connections in the replica pool, per server replica. |
POSTGRES_REPLICA_MAX_LAG | 5s | How far behind the standby may be. Further behind, every read goes to the primary until it catches up. |
A standby replays the primary's changes a moment late, so two rules keep what it serves right:
- You always see your own changes. After you change something, your lists come from the primary until the standby has replayed that change. Each server replica remembers this for the people it served, and your browser carries it to the next request in a short-lived cookie (
wardn_read_after, a log position, nothing secret), so it holds when your next request reaches another server replica. A command-line client keeps no cookies: across server replicas it can see another list a moment before its own change shows. - Lag has a limit. Each server replica checks every second how far the standby has replayed against where the primary was
POSTGRES_REPLICA_MAX_LAGago. A standby that falls further behind, stops replaying or does not answer serves nothing until it is back within the limit, and the server logs a warning.
What it costs: one extra statement on the primary after each of your changes (to read the log position), and two small statements a second per server replica for the check. The standby must accept the same user and password, and must be a standby: a URL that points at a primary serves nothing and logs that it reports no replay position.
In the charts, set postgres.readReplica.enabled=true and postgres.readReplica.host (same user, password and database as the primary), or postgres.readReplica.urlSecretRef when the primary is given as a whole URL. The bundled Postgres has no standby. If the standby sits behind a pooler, use transaction mode, as for the primary.
Migrations
The server migrates the schema when it starts, before it serves. Several replicas starting together take a lock in the database, so exactly one applies the migrations and the others find nothing left to do. Migrations only go forward: there is no command to undo one. To go back to an earlier version, restore the backup you took before the upgrade (Upgrading).
While a migration is pending, /api/v1/ready answers 503 and lists it under the migrations check.
Backups
Wardn has no backup tool of its own. Use your database's: a managed service's automated backups and point-in-time recovery, or pg_dump and pg_restore. Backup and restore lists what else to keep and the restore order.
Next
Install without internet access
Copy a release into one archive with wardn bundle create, load it into a private registry with wardn bundle push, and install the charts from there.
Object storage
Keep rendered snapshots and other blobs in S3 or Cloud Storage instead of Postgres, and move an install's blobs there without downtime.