Upgrading major version of bitnami postgresql instances
##
Upgrading major version of bitnami postgresql instances.
#
All credit goes to: https://github.com/bitnami/charts/issues/8025#issuecomment-964906018
#
Please note that I switched to using cloudnative-pg.io, which handles this much better - so I don’t keep this guide up to date.
##
This example is from upgrading from postgresql14 to 15.
- Update the helm-release
Update to the new major-version-image, set
primary.containerSecurityContext.runAsUser=0anddiagnosticMode.enabled=true. - Once the pod has restarted, exec into it, ensure the new version is active
postgres --version. . /opt/bitnami/scripts/libos.shensure_group_exists postgres -i 1001ensure_user_exists postgres -i 1001 -g postgresmv /bitnami/postgresql/data /bitnami/postgresql/olddatamkdir -p /bitnami/postgresql/data; mkdir -p /bitnami/postgresql/oldbincd /tmp/- Download the application-package from the previous release you upgraded from, check upstream Dockerfile.
apt update && apt install curl -y && curl --remote-name https://downloads.bitnami.com/files/stacksmith/postgresql-14.5.0-17-linux-${OS_ARCH}-debian-11.tar.gz cd /bitnami/postgresql/oldbintar --extract --directory . --file /tmp/postgresql-14.5.0-17-linux-${OS_ARCH}-debian-11.tar.gzmv postgresql-14.5.0-linux-${OS_ARCH}-debian-11/files/postgresql/bin/* .chown -R postgres:postgres /bitnami/postgresql/data /bitnami/postgresql/olddatagosu postgres initdb -E UTF8 -D /bitnami/postgresql/data -U postgrescd /tmp; rm /bitnami/postgresql/olddata/postmaster.pidcp /bitnami/postgresql/data/postgresql.conf /bitnami/postgresql/olddata/; cp /bitnami/postgresql/data/pg_hba.conf /bitnami/postgresql/olddata/; chown -R postgres:postgres /bitnami/postgresql/data /bitnami/postgresql/olddata- Start the “old” server:
gosu postgres /bitnami/postgresql/oldbin/pg_ctl start -w -D /bitnami/postgresql/olddata/ - After successfull start, stop it:
gosu postgres /bitnami/postgresql/oldbin/pg_ctl stop -w -D /bitnami/postgresql/olddata/ gosu postgres pg_upgrade -b /bitnami/postgresql/oldbin -B /opt/bitnami/postgresql/bin -d /bitnami/postgresql/olddata -D /bitnami/postgresql/data --socketdir=/tmp./delete_old_cluster.sh- Remove
primary.containerSecurityContext.runAsUser=0anddiagnosticMode.enabled=truefrom your helm-release.