Every time I upgrade Postgres major versions, I need to google for these steps. This usually happens after I’ve run brew upgrade and my database stops working. Here are the steps for future reference.

# Step 1
# Rename your posgres database directory
mv /usr/local/var/postgres /usr/local/var/postgres9.6

# Step 2
# Using the latest version of postgresql, initialize a brand new database.
initdb /usr/local/var/postgres -E utf8

# Step 3
# -d Location of the database being copied from
# -D Location of the database being copied to
# -b Location of the psql binary that can read from the 'from' database
# -B Location of the psql binary that can write to the 'to' database
pg_upgrade \
  -d /usr/local/var/postgres9.6 \
  -D /usr/local/var/postgres \
  -b /usr/local/Cellar/postgresql/9.6.5/bin/ \
  -B /usr/local/Cellar/postgresql/10.0/bin/ \
  -v

# Revert if anything went wrong
# mv /usr/local/var/postgres9.6 /usr/local/var/postgres
# brew uninstall postgresql
# brew install postgresql@9.6