My Amazon Relational Database Service (Amazon RDS) for PostgreSQL database (DB) instance returns connection timeout errors when I try to connect from other AWS services. I can't establish a connection to my database.
Resolution
To resolve RDS for PostgreSQL connection timeout errors, check your database endpoint configuration, network settings, and security groups. Complete the following resolutions based on your connection setup.
Verify your database access configuration
Make sure that you use the correct endpoint and port for your DB instance. To find endpoint and port information, see Finding the connection information for an Amazon RDS DB instance.
To grant database access, connect to your database as the administrative user of your AWS account. Then, run the following command:
GRANT CONNECT ON DATABASE database_name TO user_name;
Note: Replace database_name with your database name and user_name with the database user who you're granting access to.
Check your network configuration
If your DB instance is publicly accessible, then confirm that you turned on the Public access option and an internet gateway in its route table.
If your DB instance is in a private subnet, then verify that you have a route table with a NAT gateway route for internet access. If you connect from a different virtual private cloud (VPC), then create a VPC peering connection.
To troubleshoot network issues, use Reachability Analyzer.
Review your security settings
Verify that your security group rules allow traffic on your database port from your source IP address or security group. Port 5432 is the default port for RDS for PostgreSQL databases. Check your network access control list (network ACL) rules to confirm that they allow both inbound and outbound traffic on your database port.
Resolve firewall restrictions
If you connect from outside AWS through a forwarded connection, then your firewall might block connections to the database port. Work with your network administrator to allow outbound connections to your DB instance's endpoint and port.
For information about how to modify your database port, see Modifying an Amazon RDS DB instance.
Check for port conflicts
From your local machine or Amazon Elastic Compute Cloud (Amazon EC2) instance, run the following command to check whether the port is in use:
netstat -tuln | grep 5432
Note: If you use a different port, then replace 5432 with your database port number.
If the port is in use, then the output shows the port and process that uses it. You can either stop the local service or modify your DB instance to use a different port.
Run automated troubleshooting
Use AWS Systems Manager Automation to identify connectivity issues between an Amazon EC2 instance and your DB instance. The automation checks your instance status, subnet CIDRs, network ACLs, security groups, and route tables. For more information, see How can I use the AWSSupport-TroubleshootConnectivityToRDS Systems Manager automation runbook to configure TroubleshootConnectivityToRDS between a source Amazon RDS database and an Amazon EC2 target?
Note: The automation doesn't verify ephemeral ports or specific port settings.
Related information
Can't connect to Amazon RDS DB instance
Controlling access with security groups
Error – Could not connect to server: Connection timed out