Standbys on PostgreSQL
By default a daemon keeps its state in SQLite on its own disk, and only that daemon can run on it. With the state in PostgreSQL, several daemons on different hosts can point at the same state. One holds it and serves. The others wait as standbys, and one takes over when the holder stops or its host is lost, carrying on from the last commit. Nothing about the Work changes: the same routes, bindings and history apply.
Use it when losing a host for hours isn’t acceptable. One daemon on one host, with scheduled backups and, if you need a recovery point of seconds, Litestream, is simpler and enough for most teams.
What you need
Section titled “What you need”- PostgreSQL 13 or later, managed (RDS, Cloud SQL, Azure Database) or your own. Its availability is yours: a server with a synchronous standby loses nothing committed; one without loses what its last backup or replica didn’t have.
- A schema for the state, and a second schema for archived Events, on that server. The daemon creates them if they don’t exist. The user it connects as needs to create tables in both.
- An artifact store every host reaches, such as the release’s S3-compatible store. The default store is a directory on one host, and a successor elsewhere can’t read what it holds.
- The same packages, policy, config file and secrets on every host. See what each host must have.
Point each host at the database
Section titled “Point each host at the database”The choice of storage lives in storage.json in each host’s state directory (~/.local/state/open-conduit/storage.json by default), not in the config file. Give every host the same file:
{"backend": "postgres", "location": "postgres://oc@db.example:5432/conduit?search_path=oc&sslmode=verify-full&target_session_attrs=read-write", "archive": {"backend": "postgres", "location": "postgres://oc@db.example:5432/conduit?search_path=oc_archive&sslmode=verify-full&target_session_attrs=read-write"}, "artifacts": {"backend": "s3", "command": "/usr/local/bin/open-conduit", "args": ["extension-run", "aws", "artifact-provider"], "location": "s3://my-bucket/open-conduit?region=eu-west-2"}}The location must name the same state from every host and process, so the daemon refuses one that leaves anything to a host’s own environment:
hostanddbnameare required, and so is a port whilePGPORTorPGSERVICEis set. Aserviceis refused, since each host reads its own service file.search_pathnames exactly one schema: lower-case letters, digits and underscores, not starting withpg_. The archive’s schema must differ from the state’s.- With more than one server address, set
target_session_attrs=read-write(orprimary) so each host reaches the writable primary. - A password in the location is refused, because the location is written to files and shown in messages. Give it through
PGPASSWORDor aPGPASSFILEin the daemon’s environment, a password source, or use client certificates.PGSSLMODEand the other libpq variables work as usual. - A loopback host or a Unix socket is accepted, for a per-host proxy such as the Cloud SQL Auth Proxy. Making every host’s proxy reach the same server is up to you.
pool_max_connsbounds each daemon’s connections. It is 8 by default, and at least 2.
There is no conversion from SQLite state: a SQLite bundle restores only to SQLite. Start a PostgreSQL deployment on new state.
Short-lived passwords
Section titled “Short-lived passwords”PGPASSWORD and PGPASSFILE are read once, when the daemon opens the database. For a password that changes, such as an IAM authentication token or a password Vault rotates, name its source in storage.json as password, beside location (and in archive for the archive’s). Open Conduit asks it each time it opens a connection, so a rotated password is picked up with no restart:
{"backend": "postgres", "location": "postgres://oc@db.example:5432/conduit?search_path=oc&sslmode=verify-full", "password": {"command": "/usr/local/bin/aws", "args": ["rds", "generate-db-auth-token", "--hostname", "db.example", "--port", "5432", "--username", "oc", "--region", "eu-west-2"]}}{"command": PATH, "args": [...]}runs an executable (an absolute path) with the daemon’s environment and uses what it prints, less a trailing newline. It has 10 seconds.gcloud sql generate-login-token,az account get-access-token --resource-type oss-rdbms --query accessToken -o tsvandvault read -field=password database/static-creds/ocall fit. The user is still the location’s, so a source must rotate the password of a fixed user: Vault’s dynamic credentials, which mint a new user each time, don’t fit.{"file": PATH}reads a file (an absolute path) on every connection, for a Vault Agent template, a CSI secrets driver or a mounted Kubernetes Secret that rotates it in place.
The password itself is never written to storage.json or shown in messages, and a failing source is reported by what went wrong, not by what it printed. The offline commands (backup create, state check, auth recover) use the same source. A restore into a new location takes the source for it on the command line, connects with it and records it in the restored storage.json, so the daemon starts on it with nothing to add:
open-conduit backup restore BUNDLE --to DIR \ --database-location 'postgres://oc@db.example:5432/conduit?search_path=oc2&sslmode=verify-full' \ --database-password-command /usr/local/bin/aws \ --database-password-arg rds --database-password-arg generate-db-auth-token \ --database-password-arg --hostname --database-password-arg db.example ...--database-password-file PATH names a file instead, and --archive-password-command, --archive-password-arg and --archive-password-file do the same for --archive-location. serve --restore takes them as --restore-database-password-command and so on. The source isn’t carried over from the storage.json the restore replaces, since the new location may be on another server: name it each time.
Start the daemons
Section titled “Start the daemons”Start open-conduit serve on each host as you would one daemon (in the background, or from the image). The first to reach the database takes the instance lease and serves. Each of the others logs that another instance holds the state and waits as a cold standby. A standby starts no package, takes no webhook and opens no management or tunnel listener. Only its probe listener answers: /livez passes and /readyz fails with standby, so an orchestrator neither restarts it nor sends it traffic.
The holder renews its lease every 10 seconds on a 30-second lease, timed on the database server’s clock. When it stops cleanly it releases the lease and a standby takes over at once. When it is killed, cut off or its host disappears, a standby takes over once the lease has expired, after at most about 40 seconds (the lease, plus the 10 seconds after which the server ends a session left idle in a transaction). A holder that has been superseded can’t commit anything, however long it was paused: it stops when it next tries.
At a takeover the successor fences the old host’s runs and the binding’s retry policy applies, so each Work carries on in a new attempt. Workspaces and agent homes are on the old host, so unpushed work is lost and the agent’s next turn starts from its handoff note.
What each host must have
Section titled “What each host must have”Only what is in the database moves with the lease. Each host keeps its own:
| Installed packages | A daemon that can’t validate the stored config, because a package it uses isn’t installed, doesn’t serve, and leaves the shared config alone. Install a package on every standby before a config that uses it is applied. To replace the stored config from one host’s file on purpose, start it with serve --adopt-config GENERATION. |
| The policy file | A daemon whose policy differs from the one the state was last run under doesn’t serve, so a successor can’t quietly run with looser limits. Accept a changed policy with serve --accept-policy sha256:DIGEST (or none), which the audit ledger records. |
Config file, secrets.json, keyring entries and cmd: programs |
The stored config is what runs, and its secret references resolve on whichever host holds the lease. open-conduit portability lists what is tied to one machine. |
| An operator token | A successor that can’t use the token on its disk issues itself a new owner credential. Named operators live in the database and keep working, so give scripts and people their own credentials. |
A drain is stored in the database, so it holds across a takeover until drain end.
Check it
Section titled “Check it”open-conduit doctor on the holder reports, among its checks:
recovery_point: what the server shows of its replication.observedwith no lag when a synchronous standby is streaming and commits wait for it;observedwith a lag for an asynchronous one;unobservedwhen the connecting user can’t see replication (a managed service’s own, or withoutpg_monitor).artifact_reach:artifacts_on_this_hostwhen the artifact store is the default directory, which a successor elsewhere can’t read.event_archive:archive_off_on_shared_statewhen archiving is on and the archive is on one host. Events then stay in the database instead.
Backups
Section titled “Backups”Bundles work as on one host. Keep them at a backup destination such as a bucket, since a host’s own backups/ directory goes with the host. To restore a bundle, name an empty schema for it with backup restore BUNDLE --to DIR --database-location LOC, and an empty archive with --archive postgres --archive-location LOC. A restore never writes over state that is already there, and refuses to swap shared state out of a directory another daemon may be running on.
Losing the database server is the server’s own recovery: fail over to its replica or restore its backup, then point the hosts at it.
What hasn’t been proved
Section titled “What hasn’t been proved”The takeover drills run two real daemons, each with its own state directory and its own network path to one PostgreSQL server: a killed holder, a paused one and a partitioned one (what the drills prove). They run on one machine. A takeover across two cloud machines, a managed database’s own failover and a tunnel moving between hosts haven’t been run. Taking over on another host has the detail, and the storage design how the lease works.