Upgrading PostgreSQL from version 10 to 11 on Ubuntu 19.04 (Disco Dingo)
Tags: database, debian, postgres, ubuntu
Published: 2019-05-28 08:42:49

---
title: Upgrading PostgreSQL from version 10 to 11 on Ubuntu 19.04 (Disco Dingo)
published: true
description: Howto guide for upgrading PostgreSQL from version 10 to 11 on Ubuntu, after its upgrade from version 18.10 to 19.04.
tags: databases,debian,postgresql,ubuntu
cover_image: https://thepracticaldev.s3.amazonaws.com/i/0r7vwi3q198mpi4idu7q.png
canonical_url: https://www.paulox.net/2019/05/28/upgrading-postgresql-from-version-10-to-11-on-ubuntu-19-04-disco-dingo/
series: PauLoX's Howto
---

> Howto guide for upgrading PostgreSQL from version 10 to 11 on Ubuntu, after its upgrade from version 18.10 to 19.04.

# TL;DR

After upgrade to Ubuntu 19.04:

```console
$ sudo pg_dropcluster 11 main --stop
$ sudo pg_upgradecluster 10 main
$ sudo pg_dropcluster 10 main
```

# Upgrade PostgreSQL

During Ubuntu updgrade to 19.04 you receive this message "Configuring postgresql-common":

> Obsolete major version 10
> 
> The PostgreSQL version 10 is obsolete, but the server or client packages are still installed.
> Please install the latest packages (postgresql-11 and postgresql-client-11) and upgrade the existing clusters with pg_upgradecluster (see manpage).
> 
> Please be aware that the installation of postgresql-11 will automatically create a default cluster 11/main.
> If you want to upgrade the 10/main cluster, you need to remove the already existing 11 cluster (pg_dropcluster --stop 11 main, see manpage for details).
> 
> The old server and client packages are no longer supported.
> After the existing clusters are upgraded, the postgresql-10 and postgresql-client-10 packages should be removed.
> 
>  Please see /usr/share/doc/postgresql-common/README.Debian.gz for details.

Use `dpkg -l | grep postgresql` to check which versions of postgres are installed:

```console
ii  postgresql                                 11+199                               all          object-relational SQL database (supported version)
ii  postgresql-10                              10.8-0ubuntu0.18.10.1                amd64        object-relational SQL database, version 10 server
ii  postgresql-11                              11.3-0ubuntu0.19.04.1                amd64        object-relational SQL database, version 11 server
ii  postgresql-client                          11+199                               all          front-end programs for PostgreSQL (supported version)
ii  postgresql-client-10                       10.8-0ubuntu0.18.10.1                amd64        front-end programs for PostgreSQL 10
ii  postgresql-client-11                       11.3-0ubuntu0.19.04.1                amd64        front-end programs for PostgreSQL 11
ii  postgresql-client-common                   199                                  all          manager for multiple PostgreSQL client versions
ii  postgresql-common                          199                                  all          PostgreSQL database-cluster manager
```

Run `pg_lsclusters`, your 10 and 11 main clusters should be "online".

```psql
Ver Cluster Port Status Owner    Data directory               Log file
10  main    5432 online postgres /var/lib/postgresql/10/main /var/log/postgresql/postgresql-10-main.log
11  main    5433 online postgres /var/lib/postgresql/11/main /var/log/postgresql/postgresql-11-main.log
```

There already is a cluster "main" for 11 (since this is created by default on package installation). This is done so that a fresh installation works out of the box without the need to create a cluster first, but of course it clashes when you try to upgrade 10/main when 11/main also exists. The recommended procedure is to remove the 11 cluster with `pg_dropcluster` and then upgrade with `pg_upgradecluster`.

Stop the 11 cluster and drop it.

```console
$ sudo pg_dropcluster 11 main --stop
```

Upgrade the 10 cluster to the latest version.

```console
$ sudo pg_upgradecluster 10 main
```

Your 10 cluster should now be "down" and you can verifity running `pg_lsclusters`

```console
Ver Cluster Port Status Owner    Data directory              Log file
10  main    5433 down   postgres /var/lib/postgresql/10/main /var/log/postgresql/postgresql-10-main.log
11  main    5432 online postgres /var/lib/postgresql/11/main /var/log/postgresql/postgresql-11-main.log
```

Check that the upgraded cluster works, then remove the 10 cluster.

```console
$ sudo pg_dropcluster 10 main
```

After all your data check you can remove your old packages.

```console
$ sudo apt purge \
postgresql-10 postgresql-client-10 postgresql-contrib-10
```

# Disclaimer of Warranty.

THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.


# Reference

Originially published on [www.paulox.net](https://www.paulox.net/2019/05/28/upgrading-postgresql-from-version-10-to-11-on-ubuntu-19-04-disco-dingo/)