Skip to content

Instantly share code, notes, and snippets.

@warmwaffles
Forked from cjolly/pg.sh
Last active August 29, 2015 14:11
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 warmwaffles/8095bec00ad664214382 to your computer and use it in GitHub Desktop.
Save warmwaffles/8095bec00ad664214382 to your computer and use it in GitHub Desktop.
newpg=9.3.2
oldpg=9.2.4 # set this to your current PG version
# Stop current Postgres server
launchctl unload ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist
# Backup current db
mv /usr/local/var/postgres/ /usr/local/var/postgres-$oldpg
# Homebrew
# Check here if you have issues with either of these https://github.com/Homebrew/homebrew/wiki#troubleshooting
brew update
brew upgrade postgresql
# OS X launch agents for PG, so it starts on boot automatically
cp /usr/local/Cellar/postgresql/$newpg/homebrew.mxcl.postgresql.plist ~/Library/LaunchAgents/
# These settings may or may not be necessary, investigate on your own
# http://www.postgresql.org/docs/9.3/static/kernel-resources.html
sudo sysctl -w kern.sysv.shmall=65536
sudo sysctl -w kern.sysv.shmmax=16777216
# Create new DB
initdb /usr/local/var/postgres
# Upgrade old DB to new DB
mkdir -p /tmp/pgupgrade && cd $_
pg_upgrade -d /usr/local/var/postgres-$oldpg/ \
-D /usr/local/var/postgres \
-b /usr/local/Cellar/postgresql/$oldpg/bin \
-B /usr/local/Cellar/postgresql/$newpg/bin
# Start new Postgres server
launchctl load -w ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist
# Clean new DB
./analyze_new_cluster.sh
# After determining upgrade successful you can remove old DB.
./delete_old_cluster.sh
# Go home
cd ~
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment