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.
pg_close() closes the non-persistent connection to a PostgreSQL database associated with the given connection instance.
To access Azure Database for PostgreSQL from your local computer, ensure that the firewall on your network and local computer allow outgoing communication on TCP port 5432.
“Could not connect to server: Connection refused” To be sure that PostgreSQL is running, you can also restart it with systemctl restart postgresql. If this does not fix the problem, the most likely cause of this error is that PostgreSQL is not configured to allow TCP/IP connections.
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/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With