12
votes

I created several instances of RDS with PostgreSQL and get the same problems:

  • I can connect to all of them right after creating the instances.
  • After several hours (I stop working on it, turn off my laptop), I cannot connect to any of them again.
  • I use DBeaver for the connections, the error show is "Connection attempt timed out."

I attached the information of the RDS instances. Hope someone can help me with this problem. Thank you in advance.

3
There seems to be an option under properties to "Connect on query execute". Try ticking that option. Also I see an option to auto refresh (clock symbol), try it with a large value at firstSlumdog

3 Answers

14
votes

I had to add/edit a rule to the VPC to allow connections from All sources.

Steps:

  1. Go to DB > Connectivity & security > click on VPC(vpc-
  2. Under Security > Security Groups > open sg-[something] for which VPC ID matches the DB VPC

  3. Inbound Rules > Edit Rules > Change Source to anywhere

So it seems that even when creating the DB and selecting allow public access, it only includes the traffic from withing the VPC. By doing the above steps you can allow access to all sources.

9
votes

Finally, I found the answer for my problem. For the error of "connection timeout", one of the reasons can be from the privacy settings. Although I set it as public when creating the RDS instance, the instance is attached with a VPC security group which is not public. We can attach the RDS instance with a public VPC (I don't think it is a good setting, just for the beginner in AWS like me) as below:

  • from Services, select EC2, select Security Groups in the left panel.
  • click "Create Security Group" button.
  • in the dialog, enter the name for the Group, e.g "postgres-public-access"
  • in the dialog, click "Add Rule" button.
  • In the "Type" column, select "PostgreSQL" or other types of RDS instances.
  • In the "Source" column, enter "0.0.0.0/0".
  • Click "Save" button.
  • from Services, select RDS, select the RDS instance, click "Modify" button.
  • In "Network & Security", "Security group", select the VPC Security Group you just created, in my case, it is "postgres-public-access".
  • Click "Continue" button. Now you can go ahead and connect with your database everywhere.
4
votes

I just followed the guide: https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/USER_ConnectToPostgreSQLInstance.html

Run through the typical things:

  • Make sure the Database is Public! (Check in the AWS Website Console).

  • Check you have the Firewall port open for the software and the port you're trying to connect through.

  • When you create a dB in RDS a Security Group is created automatically with the Rule All, All:

enter image description here

  • You can add a rule for TCP Port 5432, like I have above.

  • Check Username/Password - sometimes incorrect ones get cached.

  • Try to ping the dB to see if its a internet connection problem.