Skip to content

AWS RDS Instances Disconnects Randomly

0

Hello! I currently have a django backend connected to AWS RDS, but my instances have been failing to disconnect. It has been doing so on and off a couple times a week, but now it's happening 10+ times a day. There are several 499 errors I see before the db disconnects. I've increased the load balancer timeout from 1 minute to 5 minutes, but this doesn't seem to do anything. Below is the error I see before RDS disconnects.

django.db.utils.OperationalError: connection to server at "<ENDPOINT>" , port 5432 failed: Connection timed out

My configurations for AWS RDS: Enter image description here

My configurations for the instance (when it connects): Enter image description here Enter image description here

asked 2 years ago476 views

1 Answer
0

The issue you're experiencing with your AWS RDS instance disconnecting randomly could be due to several factors. Let's explore some potential causes and solutions:

  1. Network Connectivity: The error message suggests a connection timeout, which could be related to network issues. Ensure that your security group rules allow inbound traffic on port 5432 from your application's IP range.

  2. Instance Capacity: Your RDS instance is using a t3.micro instance class, which has limited resources. If your application is experiencing high load, it might be exhausting the available CPU credits, leading to performance degradation and connection timeouts. Consider upgrading to a larger instance type or switching to a non-burstable instance class.

  3. Connection Pooling: Implement connection pooling in your Django application to manage database connections more efficiently. This can help reduce the number of new connections being created and potentially overloading the database.

  4. Max Connections: Check if you're hitting the maximum number of allowed connections. You can view and adjust this in the parameter group settings for your RDS instance.

  5. Monitoring: Enable Enhanced Monitoring for your RDS instance to get more detailed metrics about its performance and resource utilization. This can help identify if you're consistently hitting resource limits.

  6. Multi-AZ Deployment: Consider enabling Multi-AZ deployment for your RDS instance. This provides higher availability and can help mitigate issues caused by infrastructure problems in a single Availability Zone.

  7. DNS Caching: If you're using a Java-based application server, be aware that the JVM caches DNS name lookups. Configure the JVM with a TTL (Time-to-Live) value of no more than 60 seconds to ensure it can use the new IP address if it changes during a failover.

  8. Connection String: Always use the DNS endpoint to connect to your RDS instance, not the IP address. The IP address can change, especially during failover events.

  9. Failover Events: If you're using Multi-AZ, check if these disconnections coincide with failover events. You can view this information in the RDS console or CloudWatch logs.

To further diagnose the issue, review your application logs for any patterns in the disconnections, monitor your RDS instance's performance metrics, and consider enabling query logging to identify any long-running queries that might be causing issues.

If the problem persists after implementing these suggestions, you may need to contact AWS Support for more in-depth troubleshooting specific to your account and setup.
Sources
Troubleshooting connections to your RDS for PostgreSQL instance - Amazon Relational Database Service
Connecting to an Amazon RDS DB instance - Amazon Relational Database Service
Stopping an Amazon RDS DB instance temporarily - Amazon Relational Database Service
Failing over a Multi-AZ DB instance for Amazon RDS - Amazon Relational Database Service

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.