Skip to content

Instantly share code, notes, and snippets.

@michel
Forked from doole/upgrade_postgres_92_93_debian.sh
Last active August 29, 2015 14:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save michel/cada34404b68bd6baf77 to your computer and use it in GitHub Desktop.
Save michel/cada34404b68bd6baf77 to your computer and use it in GitHub Desktop.
#!/bin/bash
# Update and upgrade packages
sudo apt-get update && sudo apt-get upgrade
# Install postgres 9.3
sudo apt-get install postgresql-9.3 postgresql-server-dev-9.3 postgresql-contrib-9.3
# Having Postgres 9.1 already, this will create database instance configured to run on port 5433
sudo service postgresql stop
# For pg_upgrade to work, you must switch to postgres user
sudo su - postgres
/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"
# Start postgres
sudo service postgresql start
# Must link conf file into data directory since it's expected there by pg_upgrade.
# Unfortunately, Ubuntu places it in /etc default (which complicates the upgrade)
ln -s /etc/postgresql/9.1/main/postgresql.conf /var/lib/postgresql/9.1/main/postgresql.conf
ln -s /etc/postgresql/9.3/main/postgresql.conf /var/lib/postgresql/9.3/main/postgresql.conf
# Change user login method from `peer` to `trust`
sudo vim /etc/postgresql/9.1/main/pg_hba.conf
sudo vim /etc/postgresql/9.3/main/pg_hba.conf
# Run the pg_upgrade, but as the postgres user instead of root.
su postgres
cd ~postgres
/usr/lib/postgresql/9.3/bin/pg_upgrade -d /var/lib/postgresql/9.1/main -D /var/lib/postgresql/9.3/main -b /usr/lib/postgresql/9.1/bin -B /usr/lib/postgresql/9.3/bin -k -v
exit
# Change user login method from `trust` to `md5`
sudo vim /etc/postgresql/9.1/main/pg_hba.conf
sudo vim /etc/postgresql/9.3/main/pg_hba.conf
# check if the right port is configured: 5432
sudo vi /etc/postgresql/9.3/main/postgresql.conf
# Hopefully upgrade finished without error! In which case, we can start up PostgreSQL...
sudo /etc/init.d/postgresql start 9.3
# now we can remove postgresql 9.1
sudo apt-get remove postgresql-9.1
# check if everything still works;
sudo /etc/init.d/postgresql restart
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment