So…
I’ll preface this by saying I am only going by the provided documentation…
But first you want postgresql-old-upgrade
which will provide the pg_upgrade
from the previous version (14).
First stop the service if it is somehow running:
systemctl stop postgresql
Now because you are going to use the same path for the new db you want to move the current one out of the way (again note I am using the docs … if you have a different path then use that):
sudo mv /var/lib/postgres/data /var/lib/postgres/olddata
Then we make the new directories we will use:
sudo mkdir /var/lib/postgres/data /var/lib/postgres/tmp
Set the ownership:
sudo chown postgres:postgres /var/lib/postgres/data /var/lib/postgres/tmp
And lets change to the postgres user:
sudo -iu postgres
Move to path
cd /var/lib/postgres/tmp
Now create the thing using the same flags and options you did before (again this is only an example):
initdb --locale=C.UTF-8 --encoding=UTF8 -D /var/lib/postgres/data --data-checksums
Now you can do the pg_upgrade:
pg_upgrade -b /opt/pgsql-14/bin -B /usr/bin -d /var/lib/postgres/olddata -D /var/lib/postgres/data
You may want to check and/or edit the configuration files pg_hba.conf
and postgresql.conf
, though it is not necessarily required.
Now you can try starting the service again:
systemctl start postgresql
You may optionally (as postgres user) run the vaccuum:
vacuumdb --all --analyze-in-stages
Hope that helps.