Skip to content

Instantly share code, notes, and snippets.

@deepakputhraya
Last active March 4, 2017 08:34
Show Gist options
  • Save deepakputhraya/2cc4628a0048da1558c468b23c078ed0 to your computer and use it in GitHub Desktop.
Save deepakputhraya/2cc4628a0048da1558c468b23c078ed0 to your computer and use it in GitHub Desktop.
Migrating from Postgreql from 9.4 to 9.6 with very simple commands. This technique will work if anyone wants to migrate to different versions. This requires down time

Postgresql backup before migrating

pg_dumpall > backup.out

Install Postgresql 9.6

For Ubuntu 14.04

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

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

sudo apt-get update

sudo apt-get install postgresql-9.6

Stop the running postgresql instance

sudo service postgresql stop

Use PgUpgrade to upgrade from Postgresql 9.4 to 9.6

sudo -k -u  postgres /usr/lib/postgresql/9.6/bin/pg_upgrade \
   -b /usr/lib/postgresql/9.4/bin \
   -B /usr/lib/postgresql/9.6/bin \
   -d /var/lib/postgresql/9.4/main \
   -D /var/lib/postgresql/9.6/main \
   -o ' -c config_file=/etc/postgresql/9.4/main/postgresql.conf' \
   -O ' -c config_file=/etc/postgresql/9.6/main/postgresql.conf'

Test if both 9.4 and 9.6 are starting up

Before you run the below command change the ports of both 9.4 and 9.6 if required.

sudo service postgresql start

Stop Postgresql 9.4

sudo pg_ctlcluster 9.4 main stop

Drop Postgreql 9.4

The below will permanently remove the 9.4 instance. So make sure that everything working as desired before doing this.

sudo pg_dropcluster 9.4 main

Change the configuration of the Postgresql 9.6 in postgresql.conf and pg_hba.conf files and reload.

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