Skip to content

Instantly share code, notes, and snippets.

@rubysolo
Forked from ibussieres/upgrade_pg.sh
Last active October 21, 2015 12:29
Show Gist options
  • Save rubysolo/b1e4f5c838d739aafe7a to your computer and use it in GitHub Desktop.
Save rubysolo/b1e4f5c838d739aafe7a to your computer and use it in GitHub Desktop.
PG_OLD=9.1
PG_NEW=9.4
echo "deb http://apt.postgresql.org/pub/repos/apt/ `lsb_release -cs`-pgdg main" | sudo tee /etc/apt/sources.list.d/pgdg.list
wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -
sudo apt-get update
sudo apt-get install postgresql-$PG_NEW postgresql-server-dev-$PG_NEW postgresql-contrib-$PG_NEW -y
sudo su - postgres -c "psql template1 -p 5433 -c 'CREATE EXTENSION IF NOT EXISTS hstore;'"
sudo su - postgres -c "psql template1 -p 5433 -c 'CREATE EXTENSION IF NOT EXISTS \"uuid-ossp\";'"
sudo su - postgres -c "service postgresql stop"
sudo su - postgres -c '/usr/lib/postgresql/$PG_NEW/bin/pg_upgrade -b /usr/lib/postgresql/$PG_OLD/bin -B /usr/lib/postgresql/$PG_NEW/bin -d /var/lib/postgresql/$PG_OLD/main/ -D /var/lib/postgresql/$PG_NEW/main/ -O " -c config_file=/etc/postgresql/$PG_NEW/main/postgresql.conf" -o " -c config_file=/etc/postgresql/$PG_OLD/main/postgresql.conf"'
sudo apt-get remove postgresql-$PG_OLD -y
sudo sed -i "s:5433:5432:g" /etc/postgresql/$PG_NEW/main/postgresql.conf
sudo service postgresql restart
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment