Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Postgresql pg_upgrade on Ubuntu Trusty for pgsql 9.3 to 9.4
# Add postgresql repo and update apt listing
echo "deb trusty-pgdg main" | sudo tee /etc/apt/sources.list.d/pgdg.list > /dev/null
wget --quiet -O - | sudo apt-key add -
sudo apt-get update
sudo apt-get upgrade -y
sudo apt-get install postgresql-9.4 -y
# Stop all running postgresql servers -- needed for migration of 9.3 data to 9.4 (pg_upgrade execution)
sudo /etc/init.d/postgresql stop
# Run the pg_upgrade, but as the postgres user instead of root.
sudo su postgres -c "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 \
-o ' -c config_file=/etc/postgresql/9.3/main/postgresql.conf' \
-O ' -c config_file=/etc/postgresql/9.4/main/postgresql.conf'"
# Change the port of the new server from 5433 to 5432, swap old server to 5433
sudo vim /etc/postgresql/9.4/main/postgresql.conf
sudo vim /etc/postgresql/9.3/main/postgresql.conf
# Other changes to the default config go here
# Hopefully upgrade finished without error! In which case, we can start up PostgreSQL...
sudo /etc/init.d/postgresql start
# Analyze cluster
sudo su postgres -c "sh /var/lib/postgresql/"
# Restart app server here
# Remove postgres 9.3 (TEST 9.4 FIRST)
sudo apt-get remove postgresql-9.3 -y
sudo su postgres -c "sh /var/lib/postgresql/"
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.