Before the server starts, the role finds the cluster in postgres_data, whether it sits in the volume root, in pgdata/ or in <major>/docker, and upgrades an older one major by major into the PGDATA of the pinned image: - builds an upgrade image from the pinned PostgreSQL image with the binaries of every older major on the path and the extension packages the consumers in the host's groups declare - keeps a reflink copy of the whole volume next to it, or stops until services.postgres.upgrade.backup_confirmed is true on a filesystem without reflinks - runs pg_upgrade --check, then --link, with the old cluster's superuser, encoding, locale and checksum setting, and carries pg_hba.conf, pg_ident.conf and postgresql.auto.conf over - after the start, applies the extension updates pg_upgrade wrote, collects statistics, reports databases whose collation version changed and removes the retired clusters, never the reflink copy A cluster newer than the pin, a pinned major outside PGDATA, or a retired cluster without a newer one stops the deploy. Swarm mode only detects and stops on an older cluster. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2.7 KiB
PostgreSQL Major Upgrade ⬆️
Every compose deploy brings the cluster in postgres_data to the pinned major on its own.
Detection 🔍
Before the container starts, the role reads PG_VERSION in the volume root, in data/, in pgdata/ and in every <major>/docker.
A directory counts as a cluster only when it also holds global/pg_control.
When several older clusters exist, the one whose global/pg_control changed last is the active one; the others stay untouched.
| Found | Action |
|---|---|
| Nothing | PostgreSQL initialises <pinned>/docker |
A cluster in <pinned>/docker |
Starts on it |
| An older cluster | Upgrades it, see below |
| A newer cluster | Stops, a downgrade is impossible |
A cluster whose global/pg_control became pg_control.old and no newer cluster |
Stops, an upgrade broke after pg_upgrade --link started; restore the backup |
Upgrade 🛠️
- The role probes whether the filesystem of the volume clones files.
Without reflinks the deploy stops until
applications.svc-db-postgres.services.postgres.upgrade.backup_confirmed: trueis set after a backup. - It builds
postgres-upgrade:<majors>from the pinned image plus the server packages of every older major on the path and the extension packages every deployed consumer declares, for all of these majors. - It stops and removes the running
postgrescontainer. - With reflinks it copies the whole volume to
<volume>.pg<old>-<timestamp>next to it, for example/data/docker/volumes/postgres_data.pg17-20261021T183005Z, and keeps that copy. - Per major step it starts the old cluster once to read its bootstrap superuser, encoding and locale, initialises
<new>/dockerwith them and with the old data checksum setting, runspg_upgrade --checkand thenpg_upgrade --link, and copiespg_hba.conf,pg_ident.confandpostgresql.auto.conf. - The pinned major starts on
<pinned>/docker. - The role applies the
update_extensions.sqlthatpg_upgradewrote, runsvacuumdb --all --analyze-in-stages, lists every database whose collation version differs from the C library of the new image, and removes the retired clusters. A listed database needsREINDEX DATABASEandALTER DATABASE ... REFRESH COLLATION VERSION.
Swarm mode stops on an older cluster; upgrade it on a compose host or restore a dump.
Rollback ↩️
Stop the container and replace the volume content with the reflink copy; it holds the old cluster in the layout of the release that wrote it. The copy shares its blocks with the live cluster only until PostgreSQL rewrites them, so delete it once the upgraded cluster is verified.