Search code examples
heroku-postgresheroku-cli

cannot connect to Heroku Postgres - error "server closed the connection unexpectedly"


I am trying to use the Heroku CLI to connect a Postgres database in the cloud.

heroku pg:info shows the database information, but heroku pg:psql fails with the following error:

$ heroku pg:psql
--> Connecting to postgresql-<database-id>
psql: server closed the connection unexpectedly
        This probably means the server terminated abnormally
        before or while processing the request.

What's wrong?


Solution

  • Port 5432 must be unblocked for psql to work and I was unable to do that. Switching to a different network (e.g. Internet provider at home or mobile Internet) may help.