Skip to content

Instantly share code, notes, and snippets.

@sebboh
Created November 18, 2016 23:32
Show Gist options
  • Star 13 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save sebboh/c7056e8c4cf32cdd51dd6963be7d5765 to your computer and use it in GitHub Desktop.
Save sebboh/c7056e8c4cf32cdd51dd6963be7d5765 to your computer and use it in GitHub Desktop.
Upgrade to Postgres 9.6

Stop your running postgres server (your plist name may or may not have specified the version in it, mine had 94 in the name)

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

Upgrade to 9.6

brew update && brew upgrade postgresql

Check your version

postgres --version

If that does not give you 9.6.1 you may need this step (My binaries did not get updated, so I had to force brew to relink them to the 9.6 versions)

brew link --overwrite postgres

Now check your version again

postgres --version

Initialize an empty 9.6 database

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

Migrate your existing 9.4 data to the new 9.6 database

pg_upgrade -d /usr/local/var/postgres -D /usr/local/var/postgres9.6 -b /usr/local/Cellar/postgresql/9.4.1/bin/ -B /usr/local/Cellar/postgresql/9.6.1/bin/ -v

Replace the default database with the new 9.6 database

mv /usr/local/var/postgres /usr/local/var/postgres9.4
mv /usr/local/var/postgres9.6 /usr/local/var/postgres

You may or may not need to link the new launch plist file

ln -s /usr/local/opt/postgresql/homebrew.mxcl.postgresql.plist ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist

Start up the database

launchctl load ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist
brew services start postgresql

It was recommended to recompile the postgres gem

gem uninstall pg
gem install pg

Also optionally run the analyze script provided by postgres

./analyze_new_cluster.sh

Remove these files

rm analyze_new_cluster.sh
rm delete_old_cluster.sh
@stoivo
Copy link

stoivo commented Dec 15, 2016

Nice

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