Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Postgresql pg_upgrade on Ubuntu for pgsql 9.3 to 9.4
# Add postgresql repo and update apt listing
echo "deb http://apt.postgresql.org/pub/repos/apt/ squeeze-pgdg main" > /etc/apt/sources.list.d/pgdg.
wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -
sudo apt-get update
sudo apt-get upgrade
# Stop all running postgresql servers -- needed for migration of 9.3 data to 9.4 (pg_upgrade execution)
sudo /etc/init.d/postgresql stop
# 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.3/main/postgresql.conf /var/lib/postgresql/9.3/main/postgresql.conf
ln -s /etc/postgresql/9.4/main/postgresql.conf /var/lib/postgresql/9.4/main/postgresql.conf
# Run the pg_upgrade, but as the postgres user instead of root.
su postgres
cd ~postgres
/usr/lib/postgresql/9.4/bin/pg_upgrade -d /var/lib/postgresql/9.3/main -D /var/lib/postgresql/9.4/main -b /usr/lib/postgresql/9.3/bin -B /usr/lib/postgresql/9.4/bin -k -v
# Hopefully upgrade finished without error! In which case, we can start up PostgreSQL...
/etc/init.d/postgresql start
# We can now run, but make sure it works first!
#sudo sh /var/lib/postgresql/analyze_new_cluster.sh
#sudo sh /var/lib/postgresql/delete_old_cluster.sh
#sudo apt-get remove postgresql-9.3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.