Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save adamli/5ce4c13b8729cda4d324f24c73d1fc5c to your computer and use it in GitHub Desktop.

Select an option

Save adamli/5ce4c13b8729cda4d324f24c73d1fc5c to your computer and use it in GitHub Desktop.
Upgrade Postgres 9.3 to 9.4 on Ubuntu
# Be sure to save your config files. Optional but I do:
sudo cp /etc/postgresql/9.3/main/postgresql.conf ~
sudo cp /etc/postgresql/9.3/main/pg_hba.conf ~
# Package repo (for apt-get)
wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -
sudo sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt/ precise-pgdg main" >> /etc/apt/sources.list.d/postgresql.list'
# Also probably optional but I like to update sources and upgrade
sudo apt-get update
# Install postgres 9.4
sudo apt-get install postgresql-9.4 postgresql-server-dev-9.4 postgresql-contrib-9.4
# dump your data
/usr/lib/postgresql/9.4/bin/pg_dumpall > ~/pre_upgrade_from_9.3_to_9.4.dump
# Make a data dir for Postgres 9.4 (on your EBS if this is EC2)
sudo mkdir -p /data/postgres/9.4/main
sudo chown -R postgres:postgres /data/postgres
# Change the 9.4 conf file's data dir to point to /data/postgres/9.4/main
sudo nano /etc/postgresql/9.4/main/postgresql.conf
# Install 9.4 cluster
sudo /etc/init.d/postgresql stop
sudo pg_dropcluster 9.4 main
sudo pg_createcluster -d /data/postgres/9.4/main 9.4 main
# start 9.4 explicitly
sudo /etc/init.d/postgresql start 9.4
# Restore: Make sure to use the 9.4 version of psql
sudo -u postgres psql -d postgres -p 5433 -f ~/pre_upgrade_from_9.3_to_9.4.dump
# Change port back to 5432 (optional) and the confs back to what they were! (reference previously copied files)
sudo nano /etc/postgresql/9.4/main/postgresql.conf
sudo nano /etc/postgresql/9.4/main/pg_hba.conf
sudo service postgresql restart 9.4
# Verify your data was properly imported
# Drop old cluster
sudo pg_dropcluster --stop 9.3 main
# Analyze
sudo service postgresql start
psql
>\c your_database
> ANALYZE;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment