If you need to upgrade Postgresql from v12 to v14, you can follow the procedure given below.
NOTE: You should turn off MAAS before performing this upgrade. It doesn’t matter whether it’s installed or not, but it shouldn’t be running during this procedure.
An optional but highly recommended first step is to back up your existing data, like this:
sudo -u postgres pg_dumpall > backup.sql
Next, you’ll want to upgrade the PostgreSQL service:
sudo apt-get update
sudo apt-get install postgresql-14 postgresql-server-dev-14
sudo systemctl stop postgresql.service
sudo -u postgres /usr/lib/postgresql/14/bin/pg_upgrade \
--old-datadir=/var/lib/postgresql/12/main \
--new-datadir=/var/lib/postgresql/14/main \
--old-bindir=/usr/lib/postgresql/12/bin \
--new-bindir=/usr/lib/postgresql/14/bin \
--old-options '-c config_file=/etc/postgresql/12/main/postgresql.conf' \
--new-options '-c config_file=/etc/postgresql/14/main/postgresql.conf'
# change 'port' to 5432
sudo vim /etc/postgresql/14/main/postgresql.conf
# change 'port' to 5433
sudo vim /etc/postgresql/12/main/postgresql.conf
sudo systemctl start postgresql.service
sudo -u postgres psql -c "SELECT version();"
sudo -u postgres ./analyze_new_cluster.sh
Postgresql v14 uses scram-sha-256
as default password hash function. You must redefine all existing passwords
$ sudo -u postgres psql
postgres=# \password $USER
Enter new password for user "$USER":
Enter it again:
Alternatively, you can edit /etc/postgresql/14/main/pg_hba.conf
and revert this change, setting the hash function to md5
and restarting the server. Be aware that future versions of Postgresql might drop the MD5 support, so this is a temporary solution that carries some risk.
Finally, you should clean up the old version:
#uninstalls postgres packages
sudo apt-get remove postgresql-12 postgresql-server-dev-12
#removes the old postgresql directory
sudo rm -rf /etc/postgresql/12/
#delete the old cluster data
sudo -u postgres ./delete_old_cluster.sh