Connecting to Azure PostgreSQL server from python psycopg2 client

Petr Svec 101 Reputation points
2020-07-23T14:47:58.76+00:00

Hello,
I have trouble connecting to the Azure postgres database from python. I am following the guide here - https://learn.microsoft.com/cs-cz/azure/postgresql/connect-python
But the psycopg2 and SQLalchemy throw me the same error:

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

I am able to connect to the instance by other client tools like dbeaver but from python it does not work.

When I investigate in Postgres logs I can see that the server actually authorized the connection but the next line says

could not receive data from client: An existing connection was forcibly closed by the remote host.  

psycopg's version is 2.8.5
Azure Postgres region is in West Europe

Do you have any suggestion on what to try to debug this?

Thank you!

Azure Database for PostgreSQL
{count} vote

Accepted answer
  1. Petr Svec 101 Reputation points
    2020-07-27T13:11:12.11+00:00

    The issue resolved itself. Guess there must have something happened on the Azure West Europe side because when I tried the same setup again a few days later it started working.

    @KalyanChanumolu-MSFT , @AnuragSharma-MSFT , thank you for commenting.

    P.

    0 comments No comments

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.