Skip to content

Instantly share code, notes, and snippets.

@ohvitorino
Forked from ibussieres/upgrade_pg.sh
Last active August 29, 2015 14:00
Show Gist options
  • Save ohvitorino/614dd3c316bc5af38ad0 to your computer and use it in GitHub Desktop.
Save ohvitorino/614dd3c316bc5af38ad0 to your computer and use it in GitHub Desktop.
Upgrade PostgreSQL from 9.1 to 9.3
echo "deb http://apt.postgresql.org/pub/repos/apt/ precise-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-9.3 postgresql-server-dev-9.3 postgresql-contrib-9.3 -y
#In case of error on previous step
# sudo update-alternatives --remove postmaster.1.gz /usr/share/postgresql/9.1/man/man1/postmaster.1.gz
# sudo apt-get install -f
# sudo apt-get install --reinstall postgresql-9.1
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 postgres_fdw;'"
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/9.3/bin/pg_upgrade -b /usr/lib/postgresql/9.1/bin -B /usr/lib/postgresql/9.3/bin -d /var/lib/postgresql/9.1/main/ -D /var/lib/postgresql/9.3/main/ -O "-c config_file=/etc/postgresql/9.3/main/postgresql.conf" -o "-c config_file=/etc/postgresql/9.1/main/postgresql.conf"'
sudo apt-get remove postgresql-9.1 -y
sudo sed -i "s:5433:5432:g" /etc/postgresql/9.3/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