pg_upgrade toolbox: PostgreSQL 8.2-18 binaries (with extensions) in one image
1.7K
epicmorg/pg-upgrade-toolA one-shot toolbox for major PostgreSQL upgrades with pg_upgrade: every PostgreSQL major from
8.2 to 18 (PGDG packages on epicmorg/debian:trixie) is installed side by side in
/usr/lib/postgresql/<major>/bin, together with the same extension set as
epicmorg/postgres
(PostGIS, TimescaleDB, system_stats, ...) so that pg_upgrade --check finds the extensions on both
sides, plus pgloader.
Example: upgrade an 11 cluster to 16.
Stop the old container itself (docker compose stop -t 120 postgres), not pg_ctl inside it: with
restart: always the server comes straight back, and pg_upgrade needs a clean shutdown.
docker run --rm -it \
-v /path/to/pgdata:/var/lib/postgresql/upgrade \
-u postgres -w /tmp \
epicmorg/pg-upgrade-tool:latest
with /path/to/pgdata/11 (old cluster) and /path/to/pgdata/16 (new, empty) on the host. One mount
holding both clusters matters for --link / --clone: across two bind mounts they fail with
EXDEV, only the default copy mode works. -w /tmp: pg_upgrade puts its sockets in the working
directory.
pg_upgrade --check refuses a new cluster whose data checksums, encoding or locale differ from the
old one. Encoding and locale: docker exec postgres psql -U postgres -l before step 0; checksums:
/usr/lib/postgresql/11/bin/pg_controldata /var/lib/postgresql/upgrade/11 | grep -i checksum
and repeat them in initdb (-k when the old cluster has checksums; 18 enables them by default, so
there --no-data-checksums when it has none):
/usr/lib/postgresql/16/bin/initdb -D /var/lib/postgresql/upgrade/16 \
-U postgres -E UTF8 --locale=en_US.UTF-8 -k -A scram-sha-256 --pwprompt
Alternative: start epicmorg/postgres:16 once on the empty new directory with the same
POSTGRES_INITDB_ARGS (and user) as the old container, then stop it - same checksums / locale, and the
image's network pg_hba.conf instead of initdb's local-only one.
/usr/lib/postgresql/16/bin/pg_upgrade \
-b /usr/lib/postgresql/11/bin \
-B /usr/lib/postgresql/16/bin \
-d /var/lib/postgresql/upgrade/11 \
-D /var/lib/postgresql/upgrade/16 \
--check
/usr/lib/postgresql/16/bin/pg_upgrade \
-b /usr/lib/postgresql/11/bin \
-B /usr/lib/postgresql/16/bin \
-d /var/lib/postgresql/upgrade/11 \
-D /var/lib/postgresql/upgrade/16
Default copy mode keeps the old cluster usable. --link (or --clone on a reflink filesystem) is much
faster but needs both clusters on one filesystem (step 1), and after --link the old cluster must not
be started again.
epicmorg/postgres:16 containerCopy your postgresql.conf / pg_hba.conf changes to the new cluster before starting it, then:
docker exec -d postgres-16 vacuumdb --all --analyze-in-stages -U postgres
| Tags | Dockerfile |
|---|---|
latest | . |
Every tag is pushed to docker.io, quay.io and ghcr.io (epicmorg/pg-upgrade-tool:<tag> on each) - same digest everywhere.
docker pull epicmorg/pg-upgrade-tool:latest