7

I'm trying to connect to Azure Postgresql using psql from my local machine and get the following error:

$ psql "host=username.postgres.database.azure.com port=5432 dbname=postgres user=username@domain password=mypassword sslmode=require"
psql: error: could not connect to server: server closed the connection unexpectedly
    This probably means the server terminated abnormally
    before or while processing the request.

Local Postgres version: 12.1, Azure Postgres database version: 10, macOS Majove.

This issue only recently started after I reinstalled Postgres using Homebrew. I have no issues running $ psql --host=localhost.

I've tried installing postgresql@10 with homebrew so that when I run psql I get the message psql (12.1, server 10.11). But when I attempt to log into Azure Postgres I get the same error as above.

I'm fairly new to Postgres and Azure and would appreciate any suggestions.

Update:

Thanks for the comments and feedback.

I properly installed Postgres 10 with Homebrew and linked it to fix the problem.

$ brew services stop postgresql
$ brew install postgresql@10
$ brew services start postgresql@10
$ brew link --overwrite --force postgresql@10

I can now access the Azure database as expected.

3
  • have you tried a retry logic? Commented Jan 1, 2020 at 1:49
  • Try to install the PostgreSQL Client for macOS with Homebrew referring to this again? Commented Jan 1, 2020 at 8:20
  • 1
    I encounter the same issue that you have right now. I can connect to the database using GUI client but not psql. Commented Jan 2, 2020 at 16:06

1 Answer 1

5

In this case, you could install the PostgreSQL Client for macOS with Homebrew properly then link it as it will symlink all the tools into the /usr/local/bin directory.

To fix this issue, run the following commands:

$ brew services stop postgresql
$ brew install postgresql@10
$ brew services start postgresql@10
$ brew link --overwrite --force postgresql@10

Ref: https://www.compose.com/articles/postgresql-tips-installing-the-postgresql-client/

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

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.