Verified Commit e10f2893 authored by Evangelos Foutras's avatar Evangelos Foutras 🐱
Browse files

Merge branch 'pg_upgrade-tweaks' into master

parents 58c8c86e fd6d8a83
......@@ -5,7 +5,7 @@ set -e
TO_VERSION=$(pacman -Q postgresql | grep -Po '(?<=postgresql )[0-9]+\.[0-9]')
to_major=${TO_VERSION%%.*}
if (( $to_major != 13 )); then
if (( $to_major != 14 )); then
# NOTE: When this happens you should check the changelog and add any
# necessary changes here. Then bump the version check.
echo "ERROR: major upgrade detected, aborting..."
......@@ -30,6 +30,8 @@ if [[ -d /var/lib/postgres/data-$FROM_VERSION ]]; then
exit 3
fi
pacman -S --needed "postgresql-old-upgrade>=$FROM_VERSION"
# mask postgresql.service to make sure that other services with
# Wants=postgresql.service and Restart=on-failure will not start
# it again during the upgrade
......@@ -37,23 +39,25 @@ systemctl mask postgresql.service
systemctl daemon-reload
systemctl stop postgresql.service
pacman -S --needed postgresql-old-upgrade
chown postgres:postgres /var/lib/postgres/
su - postgres -c "mv /var/lib/postgres/data /var/lib/postgres/data-$FROM_VERSION"
su - postgres -c 'mkdir /var/lib/postgres/data'
su - postgres -c 'chattr -f +C /var/lib/postgres/data' || :
# rename the old cluster and create a new empty 'data' directory for initdb
mv /var/lib/postgres/{data,data-$FROM_VERSION}
mkdir /var/lib/postgres/data
chown postgres: /var/lib/postgres/data
chattr -f +C /var/lib/postgres/data || :
# initialize the new cluster
su - postgres -c 'initdb --locale en_US.UTF-8 -E UTF8 -D /var/lib/postgres/data'
vimdiff /var/lib/postgres/{data,data-$FROM_VERSION}/pg_hba.conf
vimdiff /var/lib/postgres/{data,data-$FROM_VERSION}/postgresql.conf
# copy existing SSL certs from data-$FROM_VERSION to data
for f in {fullchain,chain,privkey}.pem; do
# copy existing configuration and SSL certs from the old cluster
for f in pg_hba.conf postgresql.conf {fullchain,chain,privkey}.pem; do
if [[ -e /var/lib/postgres/data-$FROM_VERSION/$f ]]; then
cp -avx /var/lib/postgres/{data-$FROM_VERSION,data}/$f
cp -av /var/lib/postgres/{data-$FROM_VERSION,data}/$f
fi
done
su - postgres -c "pg_upgrade -b /opt/pgsql-$FROM_VERSION/bin/ -B /usr/bin/ \
# running pg_upgrade from /tmp so it can create pg_upgrade_internal.log
su - postgres -c "cd /tmp && \
pg_upgrade -b /opt/pgsql-$FROM_VERSION/bin/ -B /usr/bin/ \
-d /var/lib/postgres/data-$FROM_VERSION -D /var/lib/postgres/data"
# unmask and start postgresql.service
......@@ -61,7 +65,4 @@ systemctl unmask postgresql.service
systemctl daemon-reload
systemctl start postgresql.service
su - postgres -c /var/lib/postgres/analyze_new_cluster.sh
# We probably want to manually delete things for now in case this script misses
# some stuff
#su - postgres -c /var/lib/postgres/delete_old_cluster.sh
su - postgres -c 'vacuumdb --all --analyze-in-stages'
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment