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

DataNotes
Organizations, people, teams, roles and grantsPeople and sessions are in the web app's sign-in tables, in the same database.
Clusters, sources, apps, deployments, environmentsAnd their settings.
Snapshots and stored objectsWith 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 storeRepository and registry credentials, encrypted with keys that the master key (WARDN_SECRET_MASTER_KEY) wraps. The database alone cannot decrypt them.
ActivityThe audit log, with its hash chain.
TimelinesKept for WARDN_TIMELINE_RETENTION (30 days by default). Old months are dropped whole.
Work queue, leases, live eventsHow 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-tiny is 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_statements for 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=require or stricter for a database across a network. The charts default postgres.external.sslMode to require; the bundled database uses disable because 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 with postgres.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.

InstallServer replicasConnections to plan for
Compose, wardn-tiny1about 30
wardn-standard, no pooler3about 70 to 100
wardn-standard, with a pooler3the 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:

SettingPoints atUsed for
POSTGRES_URLThe poolerAPI requests and other request-path queries
POSTGRES_DIRECT_URLThe database itselfLISTEN, 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.

SettingDefaultWhat it does
POSTGRES_REPLICA_URLunsetThe standby. Unset, every read goes to the primary.
POSTGRES_REPLICA_MAX_CONNS10Connections in the replica pool, per server replica.
POSTGRES_REPLICA_MAX_LAG5sHow 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_LAG ago. 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

On this page