15

As the title suggests I want to upgrade my postgresql-10 to postgresql-11.

I'm using ubuntu-18.04.

Penny Liu
  • 15,447
  • 5
  • 79
  • 98
nicolom
  • 360
  • 1
  • 3
  • 11

3 Answers3

26

You can follow this blog setup Postgresql-11 on Ubuntu. I found it easy and simple.

Add the PostgreSQL package repository on your Ubuntu machine

echo "deb http://apt.postgresql.org/pub/repos/apt/ $(lsb_release -cs)-pgdg main 11" | sudo tee /etc/apt/sources.list.d/pgsql.list

Add the GPG key of the PostgreSQL package repository:

wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -

Update APT and install postgresql-11

sudo apt update && sudo apt install postgresql-11
adrenalin
  • 1,656
  • 1
  • 15
  • 25
13

Upgrading Postgres to the latest version (currently 13), or to an intermediate version such as 11, should be done by running:

sudo apt install postgresql-common
sudo sh /usr/share/postgresql-common/pgdg/apt.postgresql.org.sh

This is documented on https://wiki.postgresql.org/wiki/Apt
This runs a bash script on your computer. See there if you wish to run the steps manually.

Once you have installed Postgres, the easiest way to upgrade on Ubuntu is with pg_upgradecluster.

  1. Backup your data. You will dropping the database, so no games!
sudo -u postgres pg_dumpall > all.sql
  1. Upgrade.
// Install latest Postgres. Use `postgresql-11` for v11 instead of `postgresql` for latest.   
sudo apt-get install -y postgresql
    
// The install sets up a cluster, which needs then to be removed for the upgrade. 
// Stop and remove the newly installed cluster. Use `11` instead of `13` for v11
sudo pg_dropcluster 13 main --stop
    
// Upgrade the db. Takes the OLD version and OLD schema as required arguments
sudo pg_upgradecluster 10 main
    
// Test. Once you are satisfied, remove OLD cluster.
sudo pg_dropcluster 10 main
SamGoody
  • 13,758
  • 9
  • 81
  • 91
  • Very useful reply! I missed installing some extensions (postgis) of the new version and had many errors in upgrade. Installing the extension package, then running dropcluster followed by upgradecluster again fixed it! – peschü Jun 09 '21 at 08:28
-2

Use this command:

sudo apt update && sudo apt install postgresql-11
zx485
  • 28,498
  • 28
  • 50
  • 59
Andrei
  • 33
  • 3