Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AWS RDS for PostgreSQL cannot be connected after several hours

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.

like image 534
Nathalie Avatar asked Sep 14 '18 02:09

Nathalie


People also ask

How do you increase connection timeout on RDS?

Go to Amazon RDS > Parameter Groups > Create a Postgres parameter group > Select the new parameter group > Click edit parameters > Filter for "alive" > Set tcp_keepalives_idle to 60 > Save. I also filtered for "timeout" and set statement_timeout to 3600000, though this might have been unnecessary.

How do I stop RDS for more than 7 days?

To stop your RDS instance for more than seven days without missing the required maintenance updates, do the following: Set up the AWS Identity Access Management (IAM) permissions to allow AWS Lambda to do the following: Start the instance. Stop the instance. Retrieve information on the instance.

Can't connect to server connection timed out Postgres?

A Connection Timed Out error occurs when the database's firewall won't allow you to connect to the database from your local machine or resource. If you are getting this error, check that you have added the machine or resource you are connecting from to the database's list of trusted sources.

What are some of the common causes why you Cannot connect to a DB instance on AWS?

When you can't connect to a DB instance, the following are common causes: Inbound rules – The access rules enforced by your local firewall and the IP addresses authorized to access your DB instance might not match. The problem is most likely the inbound rules in your security group.


1 Answers

Finally, I found the answer for my problem. For the error of "connection timeout", one of the reasons can be from the security settings. Although I set it as public when creating the RDS instance, the instance is attached with a private VPC security group which is not exposed public. We can attach the RDS instance with a public security group inside the 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 (or you can input the port of your RDS instance, usually it is 5432 for Postgres).
  • 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.
like image 109
Nathalie Avatar answered Oct 27 '22 19:10

Nathalie