0

I am trying to connect to a PostgreSQL Azure database using libpq on Windows 10. The syntax is as below --

PQinitSSL(1);
PGconn* pConn = PQconnectdb("host=nameofhost.postgres.database.azure.com port=5432 dbname={your_database} user=postgres@nameofhost password={your_password} sslmode=require");
ConnStatusType ist = PQstatus(pConn);

The connection status is CONNECTION_BAD, and the error message is "SSL SYSCALL error: Connection reset by peer (0x00002746/10054)".

Note that I set up the windows firewall rules correctly. And on the same machine, pgAdmin is able to connect to this PostgreSQL Azure database successfully.

Your help/suggestion is greatly appreciated.

Ankit Deshpande
  • 3,476
  • 1
  • 29
  • 42
HongY
  • 1
  • In the code (connection string) I see `sslmode=require` and the error message says `SSL SYSCALL error`, can you verify if SSL is configured correctly ? – Ankit Deshpande Feb 04 '20 at 17:32
  • Thanks for your reply -- according to https://www.postgresql.org/docs/12/libpq-ssl.html, it says "libpq reads the system-wide OpenSSL configuration file. By default, this file is named openssl.cnf and is located in the directory reported by openssl version -d. This default can be overridden by setting environment variable OPENSSL_CONF to the name of the desired configuration file". I downloaded OpenSSL, and there is a openssl.cnf file in the C:\Program Files (x86)\Common Files\SSL folder. My questions are -- do I need to modify this openssl.cnf? If yes, which entries should I modify? Thanks! – HongY Feb 04 '20 at 19:47
  • Check if this helps: https://learn.microsoft.com/en-us/azure/postgresql/concepts-ssl-connection-security#enforcing-ssl-connections – Ankit Deshpande Feb 05 '20 at 08:42
  • Thanks. I can connect with psql using -- psql "sslmode=verify-full sslrootcert=BaltimoreCyberTrustRoot.crt host=mydemoserver.postgres.database.azure.com dbname=postgres user=myusern@mydemoserver" from the above link. However, libpq (v10 for x86, that was downloaded from PostgreSQL webiste) with the same connection string syntax still gives me the same SSL SYSCALL error. From Process Monitor, it seems the TCP Connect/Receive are ok, actually from debugbing, I once saw the connection was made ok, but then something goes wrong and the connection was reset, which I don't understand. – HongY Feb 05 '20 at 14:37
  • Can you check psql cli version and postgres server version ? – Ankit Deshpande Feb 06 '20 at 10:29

0 Answers0