Rehearse the toposophia PostgreSQL 19 restore
toposophia uses the stock CloudNativePG PostgreSQL 19 trixie image with a read-only extension image containing PGMQ, Supabase Vault and pg_net. The PG18 Barman backup is physical. Recover it on PG18 first, then transfer the application database to a fresh PG19 instance with PostgreSQL’s logical dump tools. The two rehearsal clusters have their own PVCs, namespaces and service names.
Prepare the two clusters
Section titled “Prepare the two clusters”- Select a completed toposophia backup and record its Barman backup ID, source timeline and end LSN. Recover a separate PG18 CNPG cluster with the source’s PG18 base and extension images. Set
bootstrap.recovery.database: supabase,owner: supabase_admin, and arecoveryTargetwith the chosenbackupID,targetImmediate: trueand sourcetargetTLI. Reference the existing backup through an external Barman ObjectStore using the original server name. Give the rehearsal no archive destination or backup schedule. Confirm the recovery job selected the intended backup and the PG18 cluster became ready. - Keep the recovered source quiescent. Preload only Vault, use the same projected root key and executable key script, and limit network access to recovery dependencies. Exclude external applications, cron and the pg_net worker from this source. Keep the rehearsal networks isolated and access the databases via the operator socket.
- Build the extension image. For single-node dev101, import its local tag into the node’s containerd image store and use
pullPolicy: Never. Create a separate PG19 CNPG cluster with a neutral bootstrap database and owner, leavingsupabaseand its application roles available for restore. Configure the following under the new cluster’sspec.postgresql. Supply the original Vault key and executable script throughspec.projectedVolumeTemplate.
extensions: - name: toposophia image: reference: localhost/toposophia-pg19-extensions:rehearsal pullPolicy: Never ld_library_path: [system]shared_preload_libraries: [supabase_vault, pg_net]parameters: vault.getkey_script: /projected/postgresql-custom/pgsodium_getkey.sh pg_net.database_name: rehearsal_bootstrapPointing pg_net at the neutral bootstrap database keeps archived application HTTP requests quiescent. Check the PG19 pod’s actual read-only volume mount at /extensions/toposophia, normal extension control path, preloads and network isolation before importing data.
Stream the restore
Section titled “Stream the restore”Run these Bash commands from the repository root with kubectl configured for the rehearsal cluster. Use the current primary pods for both databases. The commands assume fresh namespaces and the neutral PG19 bootstrap above.
set -euo pipefailstage=(kubectl -n toposophia-pg18-backup-rehearsal exec toposophia-pg18-backup-1 -c postgres --)target=(kubectl -n toposophia-pg19-restore-rehearsal exec -i pg19-target-1 -c postgres --)psql_target=(psql -X -q -U postgres -v ON_ERROR_STOP=1)
test "$("${target[@]}" "${psql_target[@]}" -Atd postgres -c \ "SELECT count(*) FROM pg_database WHERE datname = 'supabase'")" = 0"${stage[@]}" psql -XAt -U postgres -d supabase -c \ "SELECT extname, extversion FROM pg_extension ORDER BY extname"The tested restore profile expects source PGMQ 1.11.1. Compare the two role inventories before transferring globals. Fresh CNPG instances share their built-in manager roles. The chart-managed target also reconciles supabase_admin and its password from supabase-superuser, matching the existing deployment. Omit duplicate CREATE ROLE statements for roles already present on the target, and retain the source role attributes, settings, owners and memberships. Restoring other application passwords from the deployment’s secret store is a separate cutover step. If an earlier rehearsal created an extra app role on the PG18 staging instance, exclude that role’s CREATE and ALTER statements after verifying it was absent from the source database cluster.
existing_roles=$("${target[@]}" "${psql_target[@]}" -At -d postgres -c \ "SELECT rolname FROM pg_roles WHERE rolname !~ '^pg_' ORDER BY rolname")"${stage[@]}" pg_dumpall -U postgres -l supabase --roles-only --no-role-passwords | awk -v existing="$existing_roles" 'BEGIN { split(existing, names, "\n"); for (i in names) roles[names[i]] = 1 } /^CREATE ROLE [[:alnum:]_]+;$/ { role = $3; sub(/;$/, "", role); if (role in roles) next } { print }' | "${target[@]}" "${psql_target[@]}" --single-transaction -d postgres
"${stage[@]}" pg_dump -U postgres -Fc -d supabase | "${target[@]}" env 'PGOPTIONS=-c extension_control_path=/extensions/toposophia/restore/share:$system:/extensions/toposophia/share' \ pg_restore -U postgres --create --exit-on-error --dbname=postgresThe restore connection selects the historical PGMQ control file. --create restores the database owner, locale, database ACLs and database settings from the archive. A failed restore can leave a partially populated destination. Retry on a fresh disposable target.
Run the post-restore SQL in a normal connection. It verifies the historical PGMQ version, runs the upstream upgrade against the restored queues, tests their metrics and privileges as pg_monitor, and clears the old PostgREST role’s supautils, safeupdate login preload. Its transaction rolls back if a check fails.
"${target[@]}" "${psql_target[@]}" -d supabase < infra/utils/cloudnativepg/pg19/finish-restore.sqlVerify before connecting applications
Section titled “Verify before connecting applications”Run the data comparison against both quiescent databases before starting Auth, Storage or application workers. Save results privately. It covers every user heap, including empty tables and partition leaves, both halves of a row fingerprint summed independently, sequence values and large objects. First compare these outputs byte for byte. Then verify owners, grants and row policies, and exercise the service-owned migrations and APIs.
umask 077mkdir -p "$PWD/tmp/agents"checkdir=$(mktemp -d "$PWD/tmp/agents/pg19-compare.XXXXXXXX")kubectl -n toposophia-pg18-backup-rehearsal exec -i toposophia-pg18-backup-1 -c postgres -- \ psql -XqAt -v ON_ERROR_STOP=1 -U postgres -d supabase \ < infra/utils/cloudnativepg/pg19/compare-data.sql > "$checkdir/pg18""${target[@]}" "${psql_target[@]}" -At -d supabase \ < infra/utils/cloudnativepg/pg19/compare-data.sql > "$checkdir/pg19"cmp "$checkdir/pg18" "$checkdir/pg19"Check the erasure restore procedure against receipts newer than the backup before reconnecting any application. A live cutover also needs a final write boundary, a fresh export, application login credentials, the intended pg_net worker database, and a verified backup destination for the new cluster.
November 21 rehearsal
Section titled “November 21 rehearsal”The following sections record the recovery and cutover performed on 2026-11-21 under the platform’s former name.
Recovered Emergent Barman backup 20261121T023000 through end LSN 1/D1000050 (02:31:26 UTC) in an isolated PG18 CNPG cluster on dev101. The destination ran stock CNPG PostgreSQL 19.0 with the local 11 MB extension image mounted read-only. Before and after the PGMQ upgrade, all 323 user tables (2,480,931 rows), 15 sequences and large-object checks matched the recovered source. All 303 row policies matched. All five queues exposed metrics to pg_monitor and denied it access to message contents after the upgrade.
The backup contained zero Vault rows. Encryption and decryption passed with a rolled-back sentinel using the projected key. A separate synthetic PG18 ciphertext fixture verified decryption on PG19 across restart. The check for erasure receipts since the backup started returned zero.
On this restored copy, the chart-pinned Auth and Storage images ran their migrations as their respective nonsuperuser roles. Auth migration records advanced from 77 to 84 and Storage from 61 to 82. All 31 pre-existing Auth and Storage data tables retained their row counts and fingerprints over the original columns. Both health endpoints, the Auth user list and the Storage bucket list returned HTTP 200. Storage used a disposable file backend for this API smoke. The database backup covers bucket and object metadata; Garage object contents have a separate backup lifecycle.
Live dev101 cutover, November 21
Section titled “Live dev101 cutover, November 21”The active primary is emergent/emergent-postgres (PostgreSQL 19.0). Its configuration is in the PostgreSQL chart and dev values. Helmfile reconciles the new database during both the data-only and full app installs. The live chart uses the private registry payload by manifest digest sha256:ac3329b42cd6d2de9af43d2ee33d785619305cc4bb2ea68f385385103f5e4518.
The old and new clusters exchanged ownership of the CNPG-managed supabasedb-svc while its UID and ClusterIP 10.101.5.80 stayed the same. The workstation alias dev-pg-emergent now points to that stable IP. Auth, Storage, Studio, Meta, the Bun API and workers, and Circuits use the stable endpoint. The active cluster reconciles the existing supabase_admin login from supabase-superuser.
| Database | Completed Barman backup (UTC) | End LSN | Barman server path |
|---|---|---|---|
| PG18 before maintenance | 20261121T135900, 14:00:25 |
1/E3000158 |
s3://db-backups-emergent/supabase-cluster |
| PG19 after final restore | 20261121T141137, 14:12:58 |
0/3702DB90 |
s3://db-backups-emergent/pg19/emergent-postgres |
The transfer streamed the final live database after scaling down writers, draining Circuits, rejecting network connections to the source database and acquiring share locks on the source tables. PostgreSQL transferred application role verifiers directly between sockets. The final copy had 329 tables, 2,480,959 rows and 15 sequences. Row fingerprints, sequence states, large objects, application relation ownership and ACLs, and all 303 row policies matched. PGMQ metrics and message-body privileges passed for all five queues.
The first PG19 archive attempt failed because Garage required the S3 region garage. After configuring the Barman sidecar, the unopened target needed an immediate shutdown during a restart because its shutdown checkpoint was waiting on failed archiving. CNPG recovered on the same PVC. The data and policy comparisons passed again after restart, before switching traffic. The replacement backup completed and its end WAL was archived. PG19’s backup schedule is daily at 02:45 UTC.
Circuits retained its durable-streams pod, gracefully stopped the engine, and detected the new PostgreSQL system identifier on restart. Its expected source reset retired 36 cached shapes. The new circuits logical slot became active and a fresh shape backfilled against PG19. Existing clients can re-subscribe. All paused workloads returned to their original replica counts. Live checks covered authenticated Auth and Storage reads, Studio and Meta SQL, the public Bun functions route, content runtime, LRS and worker connections.
Retained PG18 recovery point
Section titled “Retained PG18 recovery point”supabase-cluster is hibernated with its original 10 GiB PVC, supabase has ALLOW_CONNECTIONS false in that cluster, and its ScheduledBackup is suspended. PG18’s former default RW Service is specific to the retained cluster. Use supabasedb-svc for applications and host tools. The PG18 Vault key script ConfigMap still comes from the common-data release; retain that script and the root key when eventually retiring the old resources.
After PG19 accepted writes, the PG18 PVC became a point-in-time recovery option. Switching the Service back directly would lose subsequent writes. Prefer recovery from the PG19 backup plus archived WAL for a PG19 incident. For an intentional recovery onto PG18, first stop writers and plan how to preserve intervening writes. A separately inspected PG18 copy can be rehydrated by removing its cnpg.io/hibernation annotation and enabling database connections from the maintenance database. Keep application routing on the selected primary throughout recovery.
Renamed dev101 database and promotion copy, November 28
Section titled “Renamed dev101 database and promotion copy, November 28”The dev101 database is now toposophia/toposophia-postgres. The read/write Service is toposophia/supabasedb-svc (ClusterIP 10.101.7.223 at cutover). The former primary was fenced for the final backup. Its PVC and the old emergent namespaces on dev101 and mac101 were subsequently removed. Before retiring the old Garage buckets, all 28 retained Barman files and 280 uploads were compared byte-for-byte with their sources. Use the mac101 promotion copy below for staging and production recovery.
The retained promotion copy is on mac101 Garage under s3://db-backups-toposophia/toposophia-cutover/20261128-dev101/. The postgres/ prefix is a Barman source with server name emergent-postgres, backup ID 20261128T052031, timeline 1 and end LSN 0/8C000160. The uploads/ prefix holds the 280 Garage objects corresponding to the paused source. Normal dev backups write to s3://db-backups-toposophia/pg19.
The renamed cluster recovered from that retained copy. Its 336 user tables (2,481,470 rows), 15 sequences and large-object comparison matched the source. The catalog comparison matched 39 roles, 24 role memberships, 312 policies, all six extensions and relation ownership and ACLs. The dev Storage bucket app-storage-toposophia contains the verified uploads.
The renamed primary’s first completed backup is 20261128T052529 under s3://db-backups-toposophia/pg19/toposophia-postgres. Its ending WAL segment 00000002000000000000008F was verified in Garage. The retained promotion prefix also contains promotion.json and the comparison queries and reference outputs in validation/.
The common-cluster release in the toposophia namespace now owns the Garage keys on both local clusters. Dev101 uses infra/s3-storage-toposophia for uploads. Mac101 uses infra/s3-backups-toposophia for its Toposophia buckets, including the promotion copy. The local bootstrap scripts decrypt the corresponding manifests under infra/secrets/ and install matching consumer Secrets on dev101. Garage writes its operator-managed output to separate Secrets with a -managed suffix. After the former keys lost access to the Toposophia buckets, the Supabase Storage API passed an upload/read/delete check and PG19 completed backup 20261128T062214. Its ending WAL segment 000000020000000000000099 was read back from mac101.
Dev PG19 pulls its extension image from reg.delinin.com/toposophia/postgres-extensions using the repository-scoped hosted-registry-pull Secret. The immutable digest is in infra/helmfile/values/dev/postgres-values.yaml. The local bootstrap installs the encrypted pull Secret alongside the application Secrets.
For a fresh staging or production install, copy the retained Barman tree intact to a private archive reachable by the target and verify the copy. Set the target’s bootstrap.recovery before installing PostgreSQL. Use the dev recovery values as the example, keep the source server name and backup ID, and use a separate archive destination for each target. Supply the matching Vault root key, reconcile the service login credentials for that environment, and restore the uploaded objects to its Storage bucket. Compare the restored data before enabling application writers.
After the comparison, set DATABASE_URL to the restored target and run bun run --cwd packages/db db:migrate:url from the application revision being deployed. Do this before starting Circuits. The retained backup predates the session-recording tables that the engine requires at startup. Verify that GET /replication/lsn on the engine reports a healthy epoch and that the circuits slot in pg_replication_slots is active.