PostgreSQL Version Migration on Arch Linux

Erstellt: 04.12.2025 Bearbeitet: 05.12.2025

After every major PostgreSQL update, you need to migrate the database to the new version. Fortunately, on Arch Linux, this process is quite smooth with these commands.

Workflow

Install Old PostgreSQL

yay postgresql-old-upgrade

Stop Server

systemctl stop postgresql

Upgrade as Root

# Get last DB version
cat /var/lib/postgres/data/PG_VERSION

# Move current data to olddata
mv /var/lib/postgres/data /var/lib/postgres/olddata
mkdir /var/lib/postgres/data /var/lib/postgres/tmp
chown postgres:postgres /var/lib/postgres/data /var/lib/postgres/tmp

# Initialize a new database as the postgres user and migrate the old data to the new database
su postgres
initdb -D /var/lib/postgres/data --locale=C.UTF-8 --encoding=UTF8 --data-checksums
# Replace PG_VERSION with the old version number from the first step
pg_upgrade -b /opt/pgsql-PG_VERSION/bin -B /usr/bin -d /var/lib/postgres/olddata -D /var/lib/postgres/data

# If you get the error: "old cluster does not use data checksums but the new one does", enter the following command and repeat pg_upgrade
pg_checksums --disable --pgdata /var/lib/postgres/data

exit # Exit your su session

Start Server

systemctl stop postgresql

Optimize

su postgres
/usr/bin/vacuumdb --all --analyze-in-stages --missing-stats-only
/usr/bin/vacuumdb --all --analyze-only
exit

Links