PostgreSQL 9.5 Upgrade with Homebrew
Photo © Vaughan Leiberum https://www.flickr.com/photos/laertes_za/5342495338/. Licensed under a Creative Commons license.
Note: Keita Kobayashi guide to upgrading to 9.4 is a great resource and this post attempts the same for 9.5.
First, install Postgres 9.5:
brew update && brew upgrade postgres
Then let’s stop the old installation (but don’t load up the new one yet).
brew services stop postgresql
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:
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:
brew services start postgresql
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.