feat(db): use POSTGRES_USER in pg_backup; document it in release note
- pg_backup.sh: use the db service's POSTGRES_USER (default postgres) for the dump/drop/recreate instead of detecting the superuser at runtime, since the recipe now sets that env var; one-line the constants comment - release note: explain the in-place pg_upgrade + the POSTGRES_USER override - bump PG_BACKUP_VERSION v4 Verified on cctest: backup + restore via the hooks round-trips with POSTGRES_USER.
This commit is contained in:
16
pg_backup.sh
16
pg_backup.sh
@ -4,23 +4,13 @@
|
||||
|
||||
set -e
|
||||
|
||||
# constants
|
||||
# dump goes at the volume root so backupbot's backup.sql label finds it
|
||||
BACKUP_FILE='/var/lib/postgresql/backup.sql'
|
||||
DATADIR="${PGDATA:-/var/lib/postgresql/18/docker}"
|
||||
DB_NAME="${POSTGRES_DB:-discourse}"
|
||||
|
||||
# The bootstrap superuser (install user, oid 10) differs between deployments
|
||||
# (`postgres` on bitnami-origin clusters, `discourse` on others). Detect it at
|
||||
# runtime over the local trust socket rather than hard-coding a name.
|
||||
detect_superuser() {
|
||||
local u name
|
||||
for u in discourse postgres; do
|
||||
name="$(psql -U "$u" -d "$DB_NAME" -tAc 'select rolname from pg_roles where oid = 10' 2>/dev/null | tr -d '[:space:]')"
|
||||
if [ -n "$name" ]; then echo "$name"; return 0; fi
|
||||
done
|
||||
echo postgres
|
||||
}
|
||||
SU="$(detect_superuser)"
|
||||
# bootstrap superuser for the dump/drop/recreate; same POSTGRES_USER the db service sets
|
||||
SU="${POSTGRES_USER:-postgres}"
|
||||
|
||||
function backup {
|
||||
pg_dump -U "$SU" "$DB_NAME" | gzip > "$BACKUP_FILE"
|
||||
|
||||
Reference in New Issue
Block a user