Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save tommeier/3127176 to your computer and use it in GitHub Desktop.
Save tommeier/3127176 to your computer and use it in GitHub Desktop.
Upgrade PostgreSQL from 9.0.4 to 9.1.4
#!/bin/sh
#
# Upgrade PostgreSQL from 9.0.4 to 9.1.4 via HomeBrew on Mac OSX
#
# by David Sommers (tweaked by me)
#
brew update
brew update postgres
# stop postgres
launchctl unload -w ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist
# backup old data
mv /usr/local/var/postgres /usr/local/var/postgres-9.0
# create new data
# match your settings from previous initdb, such as: --encoding=UTF8 --locale=en_US
initdb /usr/local/var/postgres --encoding=UTF8
# upgrade data
# see: http://www.postgresql.org/docs/current/static/pgupgrade.html
# (-d: --old-datadir; -D: --new-datadir; -b: --old-bindir; -B: --new-bindir
pg_upgrade -d /usr/local/var/postgres-9.0 -D /usr/local/var/postgres -b /usr/local/Cellar/postgresql/9.0.4/bin -B /usr/local/Cellar/postgresql/9.1.4/bin
# problems?
#
# -v (verbose) and -g (debug)
#
# shared memory problem?
# check out: http://willbryant.net/software/mac_os_x/postgres_initdb_fatal_shared_memory_error_on_leopard
# check out: http://www.postgresql.org/docs/current/static/kernel-resources.html#SYSVIPC
# remove old data files
~/delete_old_cluster.sh
rm ~/delete_old_cluster.sh
# restart server
mkdir -p ~/Library/LaunchAgents
cp /usr/local/Cellar/postgresql/9.1.4/homebrew.mxcl.postgresql.plist ~/Library/LaunchAgents/
launchctl load -w ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist
# vacuum it
vacuumdb --all --analyze-only
#Delete old keg
rm -rf /usr/local/Cellar/postgresql/9.0.4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment