Suppose you made a brew upgrade and postgres got upgraded. Follow then these steps to upgrade your old DB data to the new version.
Start to move of your old data directory:
mv /usr/local/var/postgres /usr/local/var/postgres_96_20171110
Initialize a new fresh DB with the new version of postgres
initdb /usr/local/var/postgres/
Check which postgres services are running and stop all
brew services list
Stop all postgres services, one command for each:
brew services start postgresql
Run postgres upgrade tool(-b and -B are the bin directories for old and new version, and -d and -D same for data directories):
pg_upgrade -b /usr/local/Cellar/postgresql\@9.6/9.6.6/bin/ -B /usr/local/Cellar/postgresql/10.1/bin/ -d /usr/local/var/postgres_20171110 -D /usr/local/var/postgres
Start the postgres service again:
brew services start postgresql