I was unable to access a remote AWS postgres database via things like psql -h *EC2ExternalIP* -U *me*. I would get:

psql -h *EC2ExternalIP* -U *me*
psql: could not connect to server: Operation timed out
Is the server running on host *EC2ExternalIP* and accepting
TCP/IP connections on port 5432?

same thing trying a simple telnet connection to this port:

curl telnet://*EC2ExternalIP*:5434
curl: (7) Failed to connect to *EC2ExternalIP* port 5434:
Operation timed out

and even though i could access other services (eg, apache) on this same EC2ExternalIP.

So I poked around at threads like these:

and they helped me to ensure I'd made appropriate modifications to postgresql.conf and pg_hba.conf; the right settings for you will depend on your instance's security concerns. But it is still not working.

What should I do to make this DB accessible?


1 Answer 1


(self-answering in case someone else has these same symptoms!)

Then I stumbled upond Shubham Dipt's post on "PostgreSQL on EC2 (Ubuntu) in AWS", making me aware of the "Security group" layer AWS maintains. It's easy to specify a new one via the AWS console, specifically adding Custom TCP: 5432, Source: Anywhere and SSH TCP:22, Source: Anywhere rules for Inbound:

EC2 console editing Security group

Then, added this security group to the instance, and it worked for me.

  • 1
    FYI terrible idea to open this up if you use password security for production. Use AWS VPC or if you just need to admin use a keypair and SSH to the EC2 instance instead. Commented Aug 15, 2019 at 13:19
  • 2
    @mattdlockyer TOTALLY CORRECT!! this was from a year ago, and i've learned a lot about AWS since. i've un-checked my self-answer, but for anyone else stumbling by this way, use VPC's!!
    – rikb
    Commented Aug 16, 2019 at 15:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.