Skip to content

Instantly share code, notes, and snippets.

@auxcoder
Forked from joho/gist:3735740
Last active July 20, 2017 13:30
Show Gist options
  • Select an option

  • Save auxcoder/8d9c3f3d400ed5e37e084ec462df7582 to your computer and use it in GitHub Desktop.

Select an option

Save auxcoder/8d9c3f3d400ed5e37e084ec462df7582 to your computer and use it in GitHub Desktop.
PostgreSQL upgrade steps and common commands

Steps to install and run PostgreSQL using Homebrew (Mac OS X)

launchctl unload -w ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist

Rename the old version and update PostgreSQL

mv /usr/local/var/postgres /usr/local/var/postgres91
brew update
brew upgrade postgresql

Init PostgreSQL

initdb /usr/local/var/postgres -E utf8

Update old DBs

pg_upgrade -b /usr/local/Cellar/postgresql/<old.version>/bin -B /usr/local/Cellar/postgresql/<new.version>/bin -d /usr/local/var/postgres91 -D /usr/local/var/postgres

Copy Homebrew agent and start server

cp /usr/local/Cellar/postgresql/<version>/homebrew.mxcl.postgresql.plist ~/Library/LaunchAgents/
pg_ctl -D /usr/local/var/postgres -l /usr/local/var/postgres/server.log start

Stop it manually

pg_ctl -D /usr/local/var/postgres stop -s -m fast

Start/Stop via launchd configuration

launchctl unload ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist
launchctl load ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist

Create new DB

createdb mydb

More Info

How to start PostgreSQL server on Mac OS X?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment