2

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?

2 Answers 2

3

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.

Sign up to request clarification or add additional context in comments.

2 Comments

what do u mean by switching to a different network?
@Shomaail I updated my answer. As far as I remember, it was not working for me in the office, but worked fine at home.
1

Might not be the issue for everyone, but if you have a computer set up to connect with mTLS by having a ~/.postgresql/postgresql.crt and ~/.postgresql/postgresql.key, psql will automatically send the key up to all databases you connect to, and you will break heroku pg:psql connections to other databases

So just

mv ~/.postgresql{,.bak}

and try again. If that's your issue, you'll want to put your mTLS certs in a different directory and manually pass them as arguments or via config vars

The location of the certificate and key files can be overridden by the connection parameters sslcert and sslkey or the environment variables PGSSLCERT and PGSSLKEY

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.