PostgreSQL Connection to RDS from external server - Connection errors but works from other sources


I have a Lambda Python function connecting via psycopg2 to a PostgreSQL db instance running RDS. The Lambda connects absolutely fine (Lambda and RDS both in EU-West-2 region) I can also connect to the PostgreSQL via PgAdmin4 from a local development system and other developers can also access from other locations/IPs via PGAdmin with no problem. I can also connect a simple psycopg2 connect and query script from my local desktop here. Therefore I know RDS is accepting and responding to externally-sourced psycopg2 connections and queries. HOWEVER, when I upload the same simple connect script to my web server (OVH - based in France if of any relevance), running equivalent Python and psycopg2 etc., the connection fails with the standard psycopg2 error response from the Python:

Error raised: connection to server at "" (ppp.qqq.rrr.ssss), port 5432 failed: Connection refused Is the server running on that host and accepting TCP/IP connections?

I've tweaked the Security Group settings to permit anything from anywhere etc and still no joy. PostgreSQL in the RDS seems to have listening on * which seems necessary to permit connections under certain circumstances. What is the subtlety in the differing sources that means such a connection from the OVH web server won't work; I can't find anything in the docs that seems to link to this issue and there's nothing obvious mis-configured on the server-side.. Any responses gratefully received.

2 Answers

You said "other developers can also access from other locations/IPs via PGAdmin", so you mean e.g. from their homes not just on-prem? So you have connected OK from various places in the internet? It would still be worth checking the RDS subnet's NACL and route table though. Is everything set up properly on your OVH web server to make an outbound connection like this, for example any stateless ACL config open to receive responses on ephemeral ports?

answered 2 years ago

Is the OVH webserver public (and allows outgoing public connections?) and the intent to connect over the internet to the RDS instance publically?

Please review: How can I troubleshoot connectivity to an Amazon RDS DB instance that uses a public or private subnet of a VPC?

answered 2 years ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions