Lost data during PostgreSQL minor version upgrade
Indeed, you should not have uninstalled it and re-installed it, as PostgreSQL initdb starts a new database store from scratch, hence empty.

BTW it may happen that your data is still there, but in another old directory. See for example this article (https://keita.blog/2016/01/09/homebrew-and-postgresql-9-5/) that shows an upgrade between 9.4 and 9.5 but it may apply in the same way in your case.

If you look at the PostgreSQL formula you can see:

def post_install
    (var/"log").mkpath
    (var/name).mkpath
    unless File.exist? "#{var}/#{name}/PG_VERSION"
      system "#{bin}/initdb", "#{var}/#{name}"
    end
end


so initdb should be called only if directory is not already populated, so in your case the database just got initialized in a new directory, empty, while your data is still in another directory.

But things have changed recently.

Homebrew 1.5, released on January 19th 2018 has this in its changelog:


  brew postgresql-upgrade-database is a new command to simplify upgrading PostgreSQL databases between major versions.


It is a wrapper around PostgreSQL pg_upgrade tool, that can be used to upgrade a database in place, hence not loosing anything, including between major versions.

This article (https://olivierlacan.com/posts/migrating-homebrew-postgres-to-a-new-version/) can give you a lot of information on how to upgrade PostgreSQL, and what happens when you use brew upgrade.