Skip to content

Instantly share code, notes, and snippets.

@databyte
Created November 29, 2011 03:29
Show Gist options
  • Save databyte/1403261 to your computer and use it in GitHub Desktop.
Save databyte/1403261 to your computer and use it in GitHub Desktop.
Upgrade PostgreSQL from 9.0 to 9.1
#!/bin/sh
#
# Upgrade PostgreSQL from 9.0 to 9.1
#
# by David Sommers
#
brew update postgres
# stop postgres
launchctl unload -w ~/Library/LaunchAgents/org.postgresql.postgres.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
# 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.1/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
launchctl load -w ~/Library/LaunchAgents/org.postgresql.postgres.plist
# vacuum it
vacuumdb --all --analyze-only
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment