Eric Guo's

Hoping writing JS, Ruby & Rails and Go article, but fallback to DevOps note

Upgrading PostgreSQL to 13 in Ubuntu 20.04 for Gitlab 16.0


Changing the apt repository

By default, Ubuntu 20.04 installs PostgreSQL 12. If you want to upgrade to version 13, you need to use the official PostgreSQL repository.

To change the repository, run the following commands in the terminal:

# Create the file repository configuration:
sudo sh -c 'echo "deb $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list'
# Import the repository signing key:
wget --quiet -O - | sudo apt-key add -
# Update the package lists:
sudo apt-get update

Installing PostgreSQL 13

sudo apt-get -y install postgresql-13

Checking if PostgreSQL 13 is available

dpkg --get-selections | grep postgres

Stopping and upgrading the database

sudo service postgresql stop
sudo pg_renamecluster 13 main main_pristine
sudo pg_upgradecluster 12 main

Starting the database

sudo service postgresql start

Stopping the old database

sudo pg_dropcluster 12 main --stop
sudo pg_dropcluster 13 main_pristine --stop

It’s also safe to upgrade directly to version 15. For more information, you can refer to the original reference.