Skip to content

Instantly share code, notes, and snippets.

@leesmith
Last active June 2, 2016 04:29
Show Gist options
  • Save leesmith/19445337d2f425ec1551aec59ae2cfe9 to your computer and use it in GitHub Desktop.
Save leesmith/19445337d2f425ec1551aec59ae2cfe9 to your computer and use it in GitHub Desktop.
Upgrade Postgres via Homebrew

http://collectiveidea.com/blog/archives/2016/01/08/postgresql95-upgrade-with-homebrew/

Upgrade Postgres (9.5):

brew update && brew upgrade postgres

Then let’s stop the old installation (but don’t load up the new one yet).

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

Next, we initialize an empty database:

initdb /usr/local/var/postgres9.5 -E utf8

Then we do the upgrade. First, find out exactly which version you had before:

ls /usr/local/Cellar/postgresql/

Which gives you output something like this: 9.4.5_2 9.5.0. If you have more than two, that’s ok, just get the most recent one before 9.5. In my case, that was 9.4.5_2. Remember that version for the next step.

Run pg_upgrade and put the version number we remembered above in the 4th line here.

pg_upgrade \
  -d /usr/local/var/postgres \
  -D /usr/local/var/postgres9.5 \
  -b /usr/local/Cellar/postgresql/9.4.5_2/bin/ \
  -B /usr/local/Cellar/postgresql/9.5.0/bin/ \
  -v

Next, move the new directory to where postgres expects it to be.

mv /usr/local/var/postgres /usr/local/var/postgres-9.4.5_2
mv /usr/local/var/postgres9.5 /usr/local/var/postgres

You could alternately move the old directory to the trash. I don’t like to delete it completely until we’ve made sure our upgrade works.

Finally, start up PostgreSQL again:

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

Test out your application(s) (for me, I fired up a rails console and pulled up a record). You can clean up the directory and run brew cleanup if it all worked.

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