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.

alex-b1729
  • 83
  • 1
  • 5

1 Answers1

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/

Nancy
  • 26,865
  • 3
  • 18
  • 34