Postgres for logeverylift¶
logeverylift keeps its data in a CloudNativePG Cluster in the logeverylift namespace.
Authentik runs its own Postgres (authentik-postgresql in identity). The Authentik Helm
chart deploys and manages it, and this doc does not cover it. The restore procedure for its
nightly dump is in ../backups/restore.md.
Current setup¶
logeverylift's database is the CloudNativePG Cluster logeverylift-db
(k8s/talos/apps/logeverylift/cnpg-cluster.yaml). It runs two instances of
ghcr.io/cloudnative-pg/postgresql:18.6-minimal-trixie: one primary and one
asynchronous standby. Each instance has its own syno-nfs-csi PVC. When the primary goes
away, the operator promotes the standby. This takes about 10 seconds. Replication is
asynchronous, so a failover can lose the last few seconds of commits.
- The app connects to
logeverylift-db-rwas the owner rolelogeverylift. It uses theurifrom the Secretlogeverylift-db-appthat the operator generates. logeverylift-db-roreaches the standby,logeverylift-db-rany instance.- WAL archiving runs continuously. A base backup runs nightly at 23:15 UTC. Both go to
Garage under
s3://cnpg-logeverylift/logeverylift-db/and stay for 30 days. Garage and the operator:cloudnative-pg.md. - The nightly
pg_dumpCronJob ink8s/talos/apps/logeverylift/db-backup.yamldumps fromlogeverylift-db-rwto the NAS as before. The monthly restore test loads the newest dump (../backups/README.md). - Metrics come from each instance's built-in exporter through the PodMonitor
logeverylift-db, plus the per-table query in the ConfigMaplogeverylift-db-monitoring. They feed the Grafana Postgres dashboard. - Alerts:
PostgresWalArchivingFailingandPostgresBaseBackupStalepage.PostgresDownwarns when no instance is primary.
Recreating the Cluster¶
The manifest bootstraps with a plain initdb. A Cluster recreated from it starts empty.
To get the data back, bootstrap from the archive as in
../backups/restore.md, or load a dump.
Why a major is not a tag bump¶
A Postgres major cannot read the previous major's data directory. Backups from before the
upgrade cannot recover past it. For this reason renovate.json disables Postgres major
updates repo-wide and points here.
Major upgrade procedure (N to N+1)¶
CloudNativePG upgrades in place with pg_upgrade when imageName moves to a higher major.
All instances are down while it runs. The standby is re-cloned afterwards. Images must
stay on the same OS distribution. The upstream
upgrade guide covers failure
handling. Read it first: this procedure has not yet run on this Cluster.
- Take a fresh dump:
kubectl -n logeverylift create job --from=cronjob/logeverylift-db-backup logeverylift-db-backup-pre-upgrade. - Prepare one PR with all of these.
pg_dumprefuses a newer server, and the Barman plugin does not separate archives by major: imageNameincnpg-cluster.yaml, andserverNamein itspluginsto a new value such aslogeverylift-db-<N+1>. This leaves the old archive intact.- The image in
db-backup.yamland the logeverylift container ink8s/talos/infra/backup-check/restore-test.yaml. serverNameindb-restore-test.yamland in the example inrestore.md.- Merge it and wait for the Cluster to report healthy.
- Take a base backup at once. Nothing from before the upgrade can recover past it:
kubectl -n logeverylift create -f - <<EOF
apiVersion: postgresql.cnpg.io/v1
kind: Backup
metadata:
name: logeverylift-db-post-upgrade
spec:
cluster:
name: logeverylift-db
method: plugin
pluginConfiguration:
name: barman-cloud.cloudnative-pg.io
EOF
- Check real workout history on logeverylift.com. One hour after the base backup, run
logeverylift-db-restore-testand the backup restore test by hand.