top of page
Search

Upgrade Postgres 12 to Postgres 13 in Ubuntu 20.04.3

Writer: Andres Ehrenpreis
Andres Ehrenpreis
Nov 30, 2021
2 min read

Backup

If you have any local databases which you would wish to preserve, then you need to back them up first so you could restore them later (but you'd need to consider PG version differences then as well which might affect you).


You can dump specific databases but you can also dump all the databases you have with just

pg_dumpall -U postgres > all_dbs.sql

See here for more information about how to backup one or all the dbs.


To restore the databases later, it might be good to use

psql -U username --set ON_ERROR_STOP=on -f backupfile

This will stop when any errors should occur, which maybe is something you want if you would like to see if there are any inconsistencies between two major versions of postgres and your dump file. See here for more information about how to restore Postgres database.



Remove all the old Postgres 12 packages

During the removal you will be prompted also if you'd wish to remove also the data directories. Up to you but for the sake of clarity I wanted to start from clean sheet and removed everything.

sudo apt --purge remove postgresql postgresql-*

Install new Postgres 13 server and client:


sudo sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list'
wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -
sudo apt update
sudo apt install postgresql-13

Checking the installation

You can check if the service came up properly with

sudo systemctl status postgresql

When you enter to postgres commandline with

sudo -iu postgres psql

then you should see the greeting already with new postgres client version as well. Something like:

psql (13.5 (Ubuntu 13.5-2.pgdg20.04+1))
Type "help" for help.

postgres=#

Used articles:

  1. https://otodiginet.com/database/how-to-install-postgresql-13-on-ubuntu-20-04-lts/


PS! If you liked the article you can buy me a coffee to support me going! :)




Recent Posts

See All

Comments


bottom of page