Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save SemVerTsar/ba846b32ee9efae5e6306446e7213380 to your computer and use it in GitHub Desktop.
Save SemVerTsar/ba846b32ee9efae5e6306446e7213380 to your computer and use it in GitHub Desktop.
Upgrading PostgreSQL from 9.3 to 9.4

First, check the version of Ubuntu:

lsb_release -sc

You need to add the latest PostgreSQL repository for the latest version, otherwise It will install PostgreSQL 9.3. This is for trusty version.

sudo add-apt-repository "deb https://apt.postgresql.org/pub/repos/apt/ trusty-pgdg main"

Update and Install PostgreSQL 9.4:

sudo apt-get update

sudo apt-get install postgresql-9.4

List the current Clusters

pg_lsclusters

Stop the 9.4 cluster and drop it.

sudo pg_dropcluster 9.4 main --stop

Upgrade the 9.3 cluster to the latest version.

sudo pg_upgradecluster 9.3 main

Your 9.3 cluster should now be "down".

pg_lsclusters 
Ver Cluster Port Status Owner    Data directory               Log file
9.3 main    5433 down   postgres /var/lib/postgresql/9.3/main /var/log/postgresql/postgresql-9.3-main.log
9.4 main    5432 online postgres /var/lib/postgresql/9.4/main /var/log/postgresql/postgresql-9.4-main.log

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

sudo pg_dropcluster 9.3 main

Adapted from:

http://www.dbrnd.com/2016/04/postgresql-how-to-install-postgresql-9-4-on-ubuntu-14-04/ https://gist.github.com/dideler/60c9ce184198666e5ab4

@kevinetienne
Copy link

kevinetienne commented Sep 1, 2016

Thanks worked smoothly for me but I had the following error after running update:

W: GPG error: https://apt.postgresql.org trusty-pgdg InRelease: The following signatures couldn't be verified because the public key is not available: NO_PUBKEY KEYHASH

which can be resolved by running:

sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys KEYHASH

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment