57 lines
2.2 KiB
Bash
57 lines
2.2 KiB
Bash
#!/bin/sh
|
|
|
|
set -euo pipefail
|
|
|
|
if [ -z "${PG_FROM}" ]; then
|
|
echo "You must set PG_FROM env var to the source version"
|
|
exit 1
|
|
elif [ -z "${PG_TO}" ]; then
|
|
echo "You must set PG_TO env var to the destination version"
|
|
exit 1
|
|
elif [ ! -d "${PG_BASE_DATA}/${PG_FROM}" ]; then
|
|
echo "Source data dir ${PG_BASE_DATA}/${PG_FROM} must already exist"
|
|
exit 1
|
|
fi
|
|
|
|
if [ -z "${DO_PG_UPGRADE}" -o "${DO_PG_UPGRADE}" != "1" ]; then
|
|
echo "Not running the upgrade. Please set DO_PG_UPGRADE=1"
|
|
fi
|
|
|
|
cd ${PG_BASE_DATA}
|
|
|
|
echo "Creating new data dir for version ${PG_TO}"
|
|
mkdir -p ${PG_BASE_DATA}/${PG_TO}
|
|
chmod 700 ${PG_BASE_DATA}/${PG_TO}
|
|
|
|
echo "Commenting SSL directives (SSL cert not available, nor needed in the upgrade context)"
|
|
cp ${PG_BASE_DATA}/${PG_FROM}/postgresql.conf ${PG_BASE_DATA}/${PG_FROM}/postgresql.conf.old
|
|
sed -i -r 's/^(ssl.*)/#\1/g' ${PG_BASE_DATA}/${PG_FROM}/postgresql.conf
|
|
|
|
echo "Replacing pg_hba with a custom one"
|
|
cp ${PG_BASE_DATA}/${PG_FROM}/pg_hba.conf ${PG_BASE_DATA}/${PG_FROM}/pg_hba.conf.old
|
|
cat <<_EOF > ${PG_BASE_DATA}/${PG_FROM}/pg_hba.conf
|
|
local all postgres peer
|
|
_EOF
|
|
|
|
echo "Initializing new PG cluster"
|
|
/usr/libexec/postgresql${PG_TO}/bin/initdb --pgdata=${PG_BASE_DATA}/${PG_TO} --auth-host=scram-sha-256 --auth-local=peer --icu-locale=${LANG} --data-checksums --encoding=UTF8 --locale-provider=icu
|
|
|
|
echo "Upgrading PG data from ${PG_BASE_DATA}/${PG_FROM} to ${PG_BASE_DATA}/${PG_TO}"
|
|
/usr/libexec/postgresql${PG_TO}/bin/pg_upgrade \
|
|
--clone \
|
|
--old-datadir ${PG_BASE_DATA}/${PG_FROM} \
|
|
--new-datadir ${PG_BASE_DATA}/${PG_TO} \
|
|
--old-bindir /usr/libexec/postgresql${PG_FROM}/bin \
|
|
--new-bindir /usr/libexec/postgresql${PG_TO}/bin
|
|
|
|
echo "Keep old patroni.dynamic.json config"
|
|
if [ -e "${PG_BASE_DATA}/${PG_FROM}/patroni.dynamic.json" ]; then
|
|
cp ${PG_BASE_DATA}/${PG_FROM}/patroni.dynamic.json ${PG_BASE_DATA}/${PG_TO}/
|
|
fi
|
|
|
|
echo "Restoring configuration"
|
|
cp -f ${PG_BASE_DATA}/${PG_FROM}/pg_hba.conf.old ${PG_BASE_DATA}/${PG_FROM}/pg_hba.conf
|
|
cp -f ${PG_BASE_DATA}/${PG_FROM}/postgresql.conf.old ${PG_BASE_DATA}/${PG_FROM}/postgresql.conf
|
|
cp -f ${PG_BASE_DATA}/${PG_FROM}/pg_hba.conf ${PG_BASE_DATA}/${PG_TO}/pg_hba.conf
|
|
cp -f ${PG_BASE_DATA}/${PG_FROM}/postgresql.conf ${PG_BASE_DATA}/${PG_TO}/postgresql.conf
|