How To Fix Heroku Postgres CLI

I was trying to use the Postgres CLI for a Heroku Postgres database and got an error:

$ heroku pg:psql --app app-name
--> Connecting to postgresql-orbital-02130
dyld: Library not loaded: /usr/local/opt/openssl/lib/libssl.1.0.0.dylib
Referenced from: /usr/local/lib/libpq.5.dylib
Reason: image not found

It turned out to be because there were multiple versions of openssl:

$ brew list --versions
...
openssl 1.0.2s
openssl@1.1 1.1.1g

The solution was to change to an older version:

$ brew switch openssl 1.0.2s

And it worked!

$ heroku pg:psql --app app-name
--> Connecting to postgresql-orbital-02130
tfv::DATABASE=>