Skip to content

Instantly share code, notes, and snippets.

@giannisp
Created November 18, 2016 05:50
Show Gist options
  • Save giannisp/b53a76047b07751ed3ade3c1db1d2c51 to your computer and use it in GitHub Desktop.
Save giannisp/b53a76047b07751ed3ade3c1db1d2c51 to your computer and use it in GitHub Desktop.
Upgrade PostgreSQL 9.5.5 to 9.6.1 using Homebrew (macOS)
After automatically updating Postgres to 9.6.1 via Homebrew, the pg_ctl start command didn't work.
The error was something like "database files are incompatible with server".
Database files have to be updated before starting the server, here are the steps that had to be followed:
# need to have both 9.6.1 and latest 9.5.x installed, and keep 9.6.1 as default
brew unlink postgresql
brew install postgresql95
brew unlink postgresql95
brew link postgresql
# move 9.5.x db files to another directory
mv /usr/local/var/postgres /usr/local/var/postgres95
# init new database using 9.6.1
initdb /usr/local/var/postgres -E utf8
# make timezonesets directory available for 9.5.x installation
mkdir /usr/local/share/postgresql95
cp -r /usr/local/share/postgresql/timezonesets /usr/local/share/postgresql95
# finally the actual upgrade
# -b is the old binary dir, -B is the new binary dir
# -d is the old data dir, -D is the new data dir
pg_upgrade -b /usr/local/Cellar/postgresql95/9.5.5/bin -B /usr/local/Cellar/postgresql/9.6.1/bin -d /usr/local/var/postgres95 -D /usr/local/var/postgres
# start 9.6.1 to check that upgrade works
pg_ctl start -D /usr/local/var/postgres
# cleanup if upgrade was successful
brew uninstall postgresql95
rm -rf /usr/local/var/postgres95
rm -rf /usr/local/share/postgresql95
@golmansax
Copy link

@giannisp Thanks for posting this! One other thing I had to do was copy over the timezone directory: cp -r /usr/local/share/postgresql/timezone /usr/local/share/postgresql95.

@devdude
Copy link

devdude commented Jan 13, 2017

Thank you @giannisp for this gist. FYI, I had to copy over the timezone dir as well, just like @golmansax mentioned.

@jmercedes
Copy link

Thank you very much, this issue was driving me crazy.

@dantormey
Copy link

Thank you, worked like a charm for me.

@giannisp
Copy link
Author

Version 10.0 has just been released today, so here is an updated gist for 9.6.5 => 10.0 migration:
https://gist.github.com/giannisp/ebaca117ac9e44231421f04e7796d5ca

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