Run Claviger on PostgreSQL, with one or several replicas
Point Claviger at a PostgreSQL database, know what changes from SQLite, back it up, and run several replicas.
Developers and self-hosters who run Claviger and can set its environment variables and reach a PostgreSQL 16 or 17 server.
PostgreSQL is supported but opt-in. SQLite stays the default. On PostgreSQL the zip backups no longer hold the database, so a missing pg_dump schedule means no database backup at all.
What you will do, in one sentence
Set CLAVIGER_DB_URL to an empty database, add CLAVIGER_MULTI_REPLICA=true only if you need several replicas, and back up with pg_dump.
Screens are captured from a seeded test system. Every name, address and number on the screens is invented. Prepared 15 November 2026.
1. Turn PostgreSQL on
Set one environment variable before you start Claviger:
CLAVIGER_DB_URL='postgres://claviger:[email protected]:5432/claviger?sslmode=require'
- Unset, the default, means SQLite with the behavior you already know.
- PostgreSQL 16 or 17 is supported. CI runs the Postgres tests on both.
- Claviger creates its tables in the
publicschema. Use an empty, dedicated database. - The connection string holds the password. Keep it in your secret store.
- The request logs file
auxiliary.dbstays a local SQLite file inpb_data, one for each replica. It is disposable. OTLP log export can ship the logs somewhere durable.
To check which engine runs, call GET /api/health as a superuser. The answer has data.database, which is sqlite or postgres.
2. What differs from SQLite
The same request on the same data gives the same records on both databases. The tests compare about 400 cases. These differences remain:
| Case | On PostgreSQL |
|---|---|
A text field compared with a number, such as title = 5 | Error 400. Postgres does not coerce types. |
A bool field compared with a number, such as active = 1 | Error 400. Use true and false. |
| A multiple select, relation or file field compared as a whole | Matches jsonb text. Use ?= or :each. |
| JSON values | Stored as JSONB. Key order and spacing are not kept. Parsed JSON is the same. |
| Sorting | Text sorts byte by byte. Z sorts before a. |
Your own SQL runs as written, so it must be PostgreSQL SQL:
- View collections. Quote names that have capitals, and give the view an
idcolumn. - The superuser
/api/sqlendpoint and$app.db()in JS hooks. - Raw SQL in your own migrations. Prefer the portable builders where you can.
Claviger does not translate your SQL. Dates stay text in the same format as before.
3. Back up and restore
Zip backups are a SQLite feature. On PostgreSQL a backup still works. It writes the storage files and the local auxiliary.db, but not the database. The archive manifest says so.
- Back up the database with
pg_dump,pg_basebackup, or point-in-time recovery from your provider. Claviger does not run it for you. - Keep the dump and the storage files of the same moment together. The file names are referenced from the records.
- Verifying such an archive reports
skipped: database is Postgres. That is not a failure. - A zip restore is refused with a
400. Restore the database withpg_restoreor point-in-time recovery, then copy the storage files back. - Leave
LITESTREAM_*unset. Litestream and the handover are SQLite machinery.
POST /api/backups/{key}/restore is refused and changes nothing. Plan your restore with pg_restore before you need it.
4. Run several replicas
Several replicas are opt-in and work on PostgreSQL only. Without the flag, run one replica.
CLAVIGER_DB_URL='postgres://...'
CLAVIGER_MULTI_REPLICA=true
Claviger refuses to start with the flag on SQLite. Every replica must have:
- The same version, and the same
pb_hooksandpb_migrations. - The same encryption environment variable and the same key-encryption key (
CLAVIGER_KEK*). - The same shared file storage. Local disk does not work. Configure S3.
Plan your database connections. Each replica uses its pool plus one dedicated LISTEN connection, and a cron job borrows one more. Size max_connections for replicas x (pool + 2).
If you use PgBouncer, run it in session mode for CLAVIGER_DB_URL. In transaction mode LISTEN does not work.
What Claviger shares across replicas:
- Realtime events, through
LISTEN/NOTIFY. Delivery is at most once. - Cron jobs. Each tick runs once across all replicas.
- Webhook deliveries. Each due delivery is claimed by one replica.
- Settings, collections, sessions and field-key caches.
- Passkey ceremonies, so sticky sessions are not needed.
- Rate limits that guard credentials. The generic API limit stays per replica, so the real ceiling is up to N times the setting.
What stays on each replica: request logs, the auxiliary.db clean-up jobs, realtime connections, and some in-memory cooldowns.
The realtime stream and its subscription call must reach the same replica. Use your platform's sticky sessions for /api/realtime. Everything else works behind a plain round-robin load balancer.
- Rolling updates overlap replicas. There is no handover.
- Keep replica clocks within about a second.
/api/healthanswers from the replica you reach.- Anyone who can
LISTENon the database can read the notifications. Do not grant that to other applications.
5. Quick reference card
Turn on
- Empty PostgreSQL 16 or 17 database.
CLAVIGER_DB_URL='postgres://...'.GET /api/healthshowspostgres.
Back up
pg_dumpon your schedule.- Keep the storage files of the same moment.
- Restore with
pg_restore.
Several replicas
CLAVIGER_MULTI_REPLICA=true.- S3 storage, shared keys, same version.
- Sticky sessions for
/api/realtime.
SQLite stays the default. Nothing here applies to it.