DamonJW
DamonJW

Reputation: 3682

Remote access to an Azure Postgres database

How can I connect to an Azure PostgreSQL database, from a remote machine?

Update 2. I can connect to the database from WSL/Ubuntu using sudo psql, but I can't using plain psql. So it's a permissions issue somewhere...

Update. I've discovered I can connect from the remote machine using PgAdmin4, but I can't connect using psql. So I want to know: how should I connect using psql?

Original question. I can connect to it using psql from a VM inside Azure, so I know the database is up and accepting connections. But when I try to connect from my home machine, using exactly the same psql command, it fails:

psql --user=UUU --host=HHH DB

psql: server closed the connection unexpectedly
        This probably means the server terminated abnormally
        before or while processing the request.

More information... On the Azure database's "Connection Security" blade, I have

My home machine is running Windows+WSL, and I'm trying to connect from WSL / Ubuntu 18.04 using psql version 10.11. I run into the same problem whether I try to connect from home or from work, and I'm not blocking any outgoing ports (that I know of). The database is running PostgreSQL 10. When I connect (successfully) from an Azure VM, using psql 10.10, it looks like this:

psql --user=UUU --host=HHH DB
Password for user UUU:

psql (10.10 (Ubuntu 10.10-0ubuntu0.18.04.1))
SSL connection (protocol: TLSv1.2, cipher: ECDHE-RSA-AES256-GCM-SHA384, bits: 256, compression: off)

Upvotes: 2

Views: 3521

Answers (2)

Serban Cezar
Serban Cezar

Reputation: 535

I had the same issue. The error message sucks and is of 0 help.

You're probably using a different version of psql than your Azure DB. It needs to match whatever is installed in Azure.

So if you provisioned a version 10 DB in Azure, either you install version 10 for the pqsl tool or do a full Postgre version 10 install instead. The point is the major versions need to match between psql and the target database.

Upvotes: 1

Erik de Groot
Erik de Groot

Reputation: 21

Maybe your root user uses a different psql binary than your user. ( You can find out using which psql and sudo which psql )

I Ran into the same connection issue. In my case, the base issue was a postgres major version mismatch.

I was connecting to an Azure Postgresql on version 11 with my local psql on version 12. Downgrading my local machine's Postgres version to 11.6 solved this for me.

Maybe your root user is using psql 10 and your default user is using psql 11 or 12. ( You can check this using psql -V and sudo psql -V )

Upvotes: 2

Related Questions