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=0
anddiagnosticMode.enabled=true
. - Once the pod has restarted, exec into it, ensure the new version is active
postgres --version
. . /opt/bitnami/scripts/libos.sh
ensure_group_exists postgres -i 1001
ensure_user_exists postgres -i 1001 -g postgres
mv /bitnami/postgresql/data /bitnami/postgresql/olddata
mkdir -p /bitnami/postgresql/data; mkdir -p /bitnami/postgresql/oldbin
cd /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/oldbin
tar --extract --directory . --file /tmp/postgresql-14.5.0-17-linux-${OS_ARCH}-debian-11.tar.gz
mv postgresql-14.5.0-linux-${OS_ARCH}-debian-11/files/postgresql/bin/* .
chown -R postgres:postgres /bitnami/postgresql/data /bitnami/postgresql/olddata
gosu postgres initdb -E UTF8 -D /bitnami/postgresql/data -U postgres
cd /tmp; rm /bitnami/postgresql/olddata/postmaster.pid
cp /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=0
anddiagnosticMode.enabled=true
from your helm-release.