feat(db): switch to discourse/postgres image (auto-upgrade)
Some checks failed
cc-ci/testme cc-ci: failure

Move the db off the bitnami-era pgvector:pg17 + hand-rolled pg_upgrade entrypoint
to discourse/postgres:pg18 (pgvector + discourse's auto-upgrade layer). The image
runs the in-place major-version pg_upgrade itself on boot; the recipe configures it
via env:

- a small inline entrypoint injects the db password secret into $DB_PASSWORD (the
  image expects it in the env, no *_FILE support)
- POSTGRES_USER (the install user pg_upgrade must match) defaults to 'postgres' --
  correct for fresh installs and bitnami-origin clusters -- overridable from .env
- POSTGRES_INITDB_ARGS=--no-data-checksums so the new pg18 cluster matches pre-18
  clusters (pg18 initdb enables checksums by default; pg_upgrade needs a match)

- mount postgresql_data at /var/lib/postgresql (versioned PGDATA .../18/docker)
- pg_backup.sh uses POSTGRES_USER for the dump/drop/recreate; fix paths
- document the POSTGRES_USER override in .env.sample, README and the release note
- drop entrypoint.postgres.sh.tmpl

Tested on cctest: pg17->pg18 upgrade preserves data and serves over HTTPS; fresh
install works; backup+restore round-trips.
This commit is contained in:
notplants
2026-06-22 19:57:54 +00:00
committed by notplants
parent 0c4539b7ad
commit 1f77af93bd
7 changed files with 76 additions and 95 deletions

View File

@ -63,35 +63,51 @@ services:
start_period: 25m
db:
image: pgvector/pgvector:pg17
# discourse/postgres = pgvector + discourse's postgres management layer, which
# auto-upgrades an older cluster in place on boot (pg_upgrade into the versioned
# PGDATA /var/lib/postgresql/${MAJOR}/docker); everything is driven by the env below.
image: discourse/postgres:pg18
networks:
- internal
secrets:
- db_password
volumes:
- 'postgresql_data:/var/lib/postgresql/data'
# the image expects the whole cluster tree mounted here (not the data subdir);
# an existing pg17 cluster at the volume root is found and upgraded into /18/docker
- 'postgresql_data:/var/lib/postgresql'
configs:
- source: db_entrypoint
target: /docker-entrypoint.sh
mode: 0555
- source: pg_backup
target: /pg_backup.sh
mode: 0555
entrypoint: /docker-entrypoint.sh
entrypoint:
- /bin/bash
- -c
- |
if [ -f /run/secrets/db_password ]; then
DB_PASSWORD="$$(cat /run/secrets/db_password)"
export DB_PASSWORD POSTGRES_PASSWORD="$$DB_PASSWORD"
fi
exec run-postgres.sh postgres
environment:
# internal-only overlay network; keep all-trust so the app and the
# backup/restore hooks connect without juggling the superuser password
- POSTGRES_HOST_AUTH_METHOD=trust
- POSTGRES_USER=discourse
- POSTGRES_DB=discourse
- POSTGRES_PASSWORD_FILE=/run/secrets/db_password
- DB_USER=discourse
# pg_upgrade runs as this role and initdb's the new cluster with it; it must
# match the OLD cluster's bootstrap superuser (oid 10). The image default
# `postgres` matches fresh installs and bitnami-origin clusters. Override in
# the app .env (POSTGRES_USER=...) only for a cluster bootstrapped differently.
- POSTGRES_USER=${POSTGRES_USER:-postgres}
# pg18's initdb enables data checksums by default, but pg13-17 clusters here
# have them off and pg_upgrade requires a match -> initialise without them.
- POSTGRES_INITDB_ARGS=--no-data-checksums
healthcheck:
test: "pg_isready -U discourse -d discourse"
interval: 30s
timeout: 10s
retries: 5
# generous: a postgres major-version upgrade (apt install + pg_upgrade) runs
# in the entrypoint before the server accepts connections — don't let the
# healthcheck kill an in-progress migration
start_period: 10m
start_period: 15m
deploy:
labels:
backupbot.backup: "true"
@ -138,10 +154,6 @@ configs:
app_migrate_uploads:
name: ${STACK_NAME}_app_migrate_uploads_${APP_MIGRATE_UPLOADS_VERSION}
file: migrate-uploads.sh
db_entrypoint:
name: ${STACK_NAME}_db_entrypoint_${DB_ENTRYPOINT_VERSION}
file: entrypoint.postgres.sh.tmpl
template_driver: golang
pg_backup:
name: ${STACK_NAME}_pg_backup_${PG_BACKUP_VERSION}
file: pg_backup.sh