JusDB
Free DB Audit
Cloud Databases

Mastering AWS RDS Max Connections for MySQL & PostgreSQL

Master AWS RDS connection limits for MySQL and PostgreSQL. Learn max_connections calculation, connection pooling strategies, and optimization techniques.

JusDB Team
Published April 11, 2023
Updated November 28, 2026
15 min read

Short answer: Amazon RDS sets max_connections from instance memory. The default is {DBInstanceClassMemory/12582880} for RDS for MySQL (about one connection per 12 MiB; RDS for MariaDB 10.5 and later uses LEAST({DBInstanceClassMemory/25165760}, 12000), about one per 24 MiB) and LEAST({DBInstanceClassMemory/9531392}, 5000) for RDS for PostgreSQL (about one per 9 MiB, capped at 5,000). A db.t4g.medium or db.t3.medium (4 GiB) therefore tops out at roughly 341 connections on MySQL and roughly 450 on PostgreSQL, and the live value is a little lower because DBInstanceClassMemory excludes memory reserved for the operating system and RDS processes. Run SHOW max_connections; (PostgreSQL) or SHOW VARIABLES LIKE 'max_connections'; (MySQL) to read the exact number for your instance.

The ceiling is rarely the real constraint. On a db.r6g.large (16 GiB) the MySQL default is about 1,365 connections, but opening anywhere near that many concurrent, active connections will degrade performance long before you hit the limit: every connection costs memory (per-thread buffers in MySQL, a backend process in PostgreSQL), and hundreds of active sessions on two vCPUs spend their time on lock and CPU contention. This guide covers what RDS max connections actually means, the per-instance-type limits, how to change the value, how to size a connection pool, and when to add RDS Proxy.

Understanding Database Connection Limits

When architecting applications on AWS RDS, one of the most critical yet often overlooked parameters is the maximum number of concurrent database connections. This seemingly simple constraint can make or break your application's ability to scale under load. Whether you're running MySQL, PostgreSQL, MariaDB, Oracle, or SQL Server on RDS, understanding connection limits is fundamental to building robust, scalable database systems.

A database connection represents a session between your application and the database server. Each connection consumes memory and computational resources on the database instance. When your application opens a connection to query data, execute transactions, or perform administrative tasks, it occupies one of these precious connection slots until the connection is closed or times out.

What Happens When You Hit the Limit?

When your application attempts to establish a connection beyond the maximum allowed limit, the database server refuses the connection request. This typically manifests as the infamous error message: "ERROR 1040 (08004): Too many connections" in MySQL and MariaDB. PostgreSQL returns "FATAL: sorry, too many clients already", or a message that the remaining connection slots are reserved for superuser or rds_superuser roles. This error can cascade through your application stack, causing:

  • Application failures: Users encounter timeout errors or inability to complete transactions
  • Service degradation: Parts of your application become unresponsive
  • Lost revenue: E-commerce transactions fail, impacting your bottom line
  • Poor user experience: Page load times increase dramatically or features stop working
  • Cascading failures: Connection pool exhaustion can trigger failures across microservices

How AWS RDS Calculates Max Connections

Unlike traditional on-premises databases where you might set a fixed connection limit, AWS RDS dynamically calculates the maximum connections based on the available memory of your instance type. This approach ensures that the connection limit scales proportionally with the resources available on your database instance.

The Formula Behind the Numbers

For each database engine, AWS applies a specific formula to determine the default maximum connections:

text
MySQL (and MariaDB 10.4):
max_connections = {DBInstanceClassMemory/12582880}

MariaDB 10.5 and later:
max_connections = LEAST({DBInstanceClassMemory/25165760}, 12000)

PostgreSQL:
max_connections = LEAST({DBInstanceClassMemory/9531392}, 5000)

Oracle:
processes = LEAST({DBInstanceClassMemory/9868951}, 20000)

SQL Server:
Maximum concurrent connections = 0 (unlimited, constrained by memory)

The divisors are bytes of memory per connection: 12,582,880 bytes is about 12 MiB for MySQL (MariaDB 10.5 and later use 25,165,760 bytes, about 24 MiB, with a 12,000 cap), and 9,531,392 bytes is about 9.1 MiB for PostgreSQL. The PostgreSQL formula, LEAST({DBInstanceClassMemory/9531392}, 5000), also caps the default at 5,000, so every PostgreSQL instance class with roughly 45 GiB of memory or more gets 5,000. Oracle's processes default is capped at 20,000. For SQL Server, 0 means the engine's own maximum of 32,767 user connections. Amazon Aurora MySQL uses a different default formula, and AWS publishes a per-class table for Aurora, so check the Aurora documentation rather than this table for Aurora clusters.

Let's break down the MySQL/MariaDB calculation with a practical example. If you're using a db.t3.medium instance with 4 GiB of memory:

text
Memory in bytes = 4 × 1024 × 1024 × 1024 = 4,294,967,296 bytes
max_connections = 4,294,967,296 / 12,582,880
max_connections ≈ 341 concurrent connections

PostgreSQL on the same 4 GiB instance:
max_connections = LEAST(4,294,967,296 / 9,531,392, 5000)
max_connections ≈ 450 concurrent connections

Both results are upper bounds. DBInstanceClassMemory is the instance memory minus what RDS reserves for the operating system and its management processes, so the value you read from a live db.t3.medium or db.t4g.medium is somewhat lower than 341 or 450. A few PostgreSQL slots are also held back for administrators by superuser_reserved_connections and, on RDS, rds.rds_superuser_reserved_connections, so your application can open slightly fewer than max_connections.

Comprehensive Instance Type Connection Limits

The tables below list the default RDS max connections per instance type, organized by instance family. Each row shows the MySQL default (which also applies to MariaDB 10.4; for MariaDB 10.5 and later, halve it and cap it at 12,000) and the PostgreSQL default, both calculated from the class's nominal memory with the formulas above. Treat them as upper bounds: the live value is a little lower because of the reserved-memory deduction, and not every class is offered for every engine and Region. MySQL's own maximum for max_connections is 100,000, so formula results above that are shown as 100,000.

T-Series: Burstable Performance Instances

The T-series instances are designed for workloads that don't consistently use the full CPU but occasionally need to burst. These are cost-effective options for development, testing, and small production workloads:

Instance Type Memory vCPUs MySQL / MariaDB 10.4 default PostgreSQL default
db.t2.micro 1 GiB 1 85 112
db.t3.micro 1 GiB 2 85 112
db.t3.small 2 GiB 2 171 225
db.t3.medium 4 GiB 2 341 450
db.t3.large 8 GiB 2 683 901
db.t3.xlarge 16 GiB 4 1,365 1,802
db.t3.2xlarge 32 GiB 8 2,731 3,604
db.t4g.micro 1 GiB 2 85 112
db.t4g.small 2 GiB 2 171 225
db.t4g.medium 4 GiB 2 341 450
db.t4g.large 8 GiB 2 683 901
db.t4g.xlarge 16 GiB 4 1,365 1,802
db.t4g.2xlarge 32 GiB 8 2,731 3,604

M-Series: General Purpose Instances

M-series instances provide a balanced mix of compute, memory, and networking resources. They're ideal for most production database workloads:

Instance Type Memory vCPUs MySQL / MariaDB 10.4 default PostgreSQL default
db.m5.large 8 GiB 2 683 901
db.m5.xlarge 16 GiB 4 1,365 1,802
db.m5.2xlarge 32 GiB 8 2,731 3,604
db.m5.4xlarge 64 GiB 16 5,461 5,000
db.m5.8xlarge 128 GiB 32 10,923 5,000
db.m5.12xlarge 192 GiB 48 16,384 5,000
db.m5.16xlarge 256 GiB 64 21,845 5,000
db.m5.24xlarge 384 GiB 96 32,768 5,000
db.m6g.large 8 GiB 2 683 901
db.m6g.xlarge 16 GiB 4 1,365 1,802
db.m6g.2xlarge 32 GiB 8 2,731 3,604
db.m6g.4xlarge 64 GiB 16 5,461 5,000
db.m6g.8xlarge 128 GiB 32 10,923 5,000
db.m6g.12xlarge 192 GiB 48 16,384 5,000
db.m6g.16xlarge 256 GiB 64 21,845 5,000
db.m6i.large 8 GiB 2 683 901
db.m6i.xlarge 16 GiB 4 1,365 1,802
db.m6i.2xlarge 32 GiB 8 2,731 3,604
db.m6i.4xlarge 64 GiB 16 5,461 5,000
db.m6i.8xlarge 128 GiB 32 10,923 5,000
db.m6i.12xlarge 192 GiB 48 16,384 5,000
db.m6i.16xlarge 256 GiB 64 21,845 5,000
db.m6i.24xlarge 384 GiB 96 32,768 5,000
db.m6i.32xlarge 512 GiB 128 43,690 5,000
db.m7g.large 8 GiB 2 683 901
db.m7g.xlarge 16 GiB 4 1,365 1,802
db.m7g.2xlarge 32 GiB 8 2,731 3,604
db.m7g.4xlarge 64 GiB 16 5,461 5,000
db.m7g.8xlarge 128 GiB 32 10,923 5,000
db.m7g.12xlarge 192 GiB 48 16,384 5,000
db.m7g.16xlarge 256 GiB 64 21,845 5,000

R-Series: Memory-Optimized Instances

R-series instances are optimized for memory-intensive applications. They offer higher memory-to-vCPU ratios and are perfect for applications requiring many concurrent connections:

Instance Type Memory vCPUs MySQL / MariaDB 10.4 default PostgreSQL default
db.r5.large 16 GiB 2 1,365 1,802
db.r5.xlarge 32 GiB 4 2,731 3,604
db.r5.2xlarge 64 GiB 8 5,461 5,000
db.r5.4xlarge 128 GiB 16 10,923 5,000
db.r5.8xlarge 256 GiB 32 21,845 5,000
db.r5.12xlarge 384 GiB 48 32,768 5,000
db.r5.16xlarge 512 GiB 64 43,690 5,000
db.r5.24xlarge 768 GiB 96 65,536 5,000
db.r5b.large 16 GiB 2 1,365 1,802
db.r5b.xlarge 32 GiB 4 2,731 3,604
db.r5b.2xlarge 64 GiB 8 5,461 5,000
db.r5b.4xlarge 128 GiB 16 10,923 5,000
db.r5b.8xlarge 256 GiB 32 21,845 5,000
db.r5b.12xlarge 384 GiB 48 32,768 5,000
db.r5b.16xlarge 512 GiB 64 43,690 5,000
db.r5b.24xlarge 768 GiB 96 65,536 5,000
db.r6g.large 16 GiB 2 1,365 1,802
db.r6g.xlarge 32 GiB 4 2,731 3,604
db.r6g.2xlarge 64 GiB 8 5,461 5,000
db.r6g.4xlarge 128 GiB 16 10,923 5,000
db.r6g.8xlarge 256 GiB 32 21,845 5,000
db.r6g.12xlarge 384 GiB 48 32,768 5,000
db.r6g.16xlarge 512 GiB 64 43,690 5,000
db.r6i.large 16 GiB 2 1,365 1,802
db.r6i.xlarge 32 GiB 4 2,731 3,604
db.r6i.2xlarge 64 GiB 8 5,461 5,000
db.r6i.4xlarge 128 GiB 16 10,923 5,000
db.r6i.8xlarge 256 GiB 32 21,845 5,000
db.r6i.12xlarge 384 GiB 48 32,768 5,000
db.r6i.16xlarge 512 GiB 64 43,690 5,000
db.r6i.24xlarge 768 GiB 96 65,536 5,000
db.r6i.32xlarge 1024 GiB 128 87,381 5,000
db.r7g.large 16 GiB 2 1,365 1,802
db.r7g.xlarge 32 GiB 4 2,731 3,604
db.r7g.2xlarge 64 GiB 8 5,461 5,000
db.r7g.4xlarge 128 GiB 16 10,923 5,000
db.r7g.8xlarge 256 GiB 32 21,845 5,000
db.r7g.12xlarge 384 GiB 48 32,768 5,000
db.r7g.16xlarge 512 GiB 64 43,690 5,000

X-Series: Extreme Memory Instances

For applications requiring massive memory capacity and extremely high connection counts, X-series instances deliver enterprise-grade performance:

Instance Type Memory vCPUs MySQL / MariaDB 10.4 default PostgreSQL default
db.x2g.large 32 GiB 2 2,731 3,604
db.x2g.xlarge 64 GiB 4 5,461 5,000
db.x2g.2xlarge 128 GiB 8 10,923 5,000
db.x2g.4xlarge 256 GiB 16 21,845 5,000
db.x2g.8xlarge 512 GiB 32 43,690 5,000
db.x2g.12xlarge 768 GiB 48 65,536 5,000
db.x2g.16xlarge 1024 GiB 64 87,381 5,000
db.x2iedn.xlarge 128 GiB 4 10,923 5,000
db.x2iedn.2xlarge 256 GiB 8 21,845 5,000
db.x2iedn.4xlarge 512 GiB 16 43,690 5,000
db.x2iedn.8xlarge 1024 GiB 32 87,381 5,000
db.x2iedn.16xlarge 2048 GiB 64 100,000 (MySQL max) 5,000
db.x2iedn.24xlarge 3072 GiB 96 100,000 (MySQL max) 5,000
db.x2iedn.32xlarge 4096 GiB 128 100,000 (MySQL max) 5,000
db.x2idn.16xlarge 1024 GiB 64 87,381 5,000
db.x2idn.24xlarge 1536 GiB 96 100,000 (MySQL max) 5,000
db.x2idn.32xlarge 2048 GiB 128 100,000 (MySQL max) 5,000

I-Series: Storage Optimized Instances

Amazon RDS does not offer I-series DB instance classes: i3 and i4i are EC2 instance types, and there is no db.i3 or db.i4i class to select for RDS for MySQL, MariaDB or PostgreSQL. The rows below only show what the default formulas would give for those memory sizes. For local NVMe storage on RDS, use an Optimized Reads class such as db.r6gd, db.r6id or db.r8gd.

Instance Type Memory vCPUs MySQL / MariaDB 10.4 default PostgreSQL default
db.i3.large 15.25 GiB 2 1,301 1,717
db.i3.xlarge 30.5 GiB 4 2,603 3,435
db.i3.2xlarge 61 GiB 8 5,205 5,000
db.i3.4xlarge 122 GiB 16 10,411 5,000
db.i3.8xlarge 244 GiB 32 20,821 5,000
db.i3.16xlarge 488 GiB 64 41,643 5,000
db.i4i.large 16 GiB 2 1,365 1,802
db.i4i.xlarge 32 GiB 4 2,731 3,604
db.i4i.2xlarge 64 GiB 8 5,461 5,000
db.i4i.4xlarge 128 GiB 16 10,923 5,000
db.i4i.8xlarge 256 GiB 32 21,845 5,000
db.i4i.16xlarge 512 GiB 64 43,690 5,000
db.i4i.24xlarge 768 GiB 96 65,536 5,000
db.i4i.32xlarge 1024 GiB 128 87,381 5,000

Z-Series: High Frequency Instances

Z-series instances feature sustained all-core frequency with high single-threaded performance:

Instance Type Memory vCPUs MySQL / MariaDB 10.4 default PostgreSQL default
db.z1d.large 16 GiB 2 1,365 1,802
db.z1d.xlarge 32 GiB 4 2,731 3,604
db.z1d.2xlarge 64 GiB 8 5,461 5,000
db.z1d.3xlarge 96 GiB 12 8,192 5,000
db.z1d.6xlarge 192 GiB 24 16,384 5,000
db.z1d.12xlarge 384 GiB 48 32,768 5,000

Important Note: Having a high maximum connection limit doesn't automatically mean better performance. Each connection consumes memory and CPU resources. It's crucial to balance connection availability with overall system performance.

New Generation Benefits: The newer generation instances (T4g, M6g/M7g, R6g/R7g, etc.) are powered by AWS Graviton processors, which AWS markets as offering better price-performance than comparable x86 classes. They maintain the same connection limits based on memory while providing better overall efficiency.

Modifying Max Connections in AWS RDS

While AWS provides sensible defaults for max connections, there are legitimate scenarios where you might need to adjust this parameter. Perhaps you have a specific application architecture that requires more connections than the default formula provides, or you want to impose stricter limits for security reasons.

Why You Can't Modify Default Parameter Groups

AWS RDS uses parameter groups to manage database engine configurations. The default parameter group that comes with every RDS instance is immutable—you cannot modify it. This design ensures that AWS can maintain consistency and reliability across its infrastructure. If you attempt to modify a default parameter group, you'll encounter an error like:

text
ERROR: Cannot modify a default parameter group. (Service: AmazonRDS; Status Code: 400; Error Code: InvalidParameterValue)

Step-by-Step: Creating a Custom Parameter Group

To modify max_connections, you need to create a custom parameter group. Here's the comprehensive process:

Step 1: Access the RDS Console

Log into your AWS Management Console and navigate to the RDS service. Look for "Parameter groups" in the left-hand navigation menu under the "Configuration" section.

Step 2: Create New Parameter Group

Click the "Create parameter group" button. You'll need to provide:

  • Parameter group family: Select the database engine family that matches your RDS instance (e.g., mysql8.0, postgres14, mariadb10.6)
  • Group name: Choose a descriptive name like "production-mysql-high-connections"
  • Description: Add context about the purpose, such as "Custom parameter group with increased max_connections for production workload"

Step 3: Locate the max_connections Parameter

Once your parameter group is created, click on it to view all parameters. Use the search box to filter for "max_connections". You'll see the current formula, which might look like:

text
{DBInstanceClassMemory/12582880}

Step 4: Modify the max_connections Value

Click "Edit parameters" and locate max_connections. You have two options:

  • Set a specific value: Enter a fixed number based on your requirements (e.g., 500, 1000, 2000)
  • Modify the formula: Adjust the divisor to change the calculation (e.g., {DBInstanceClassMemory/20000000} for fewer connections)

Save your changes. Whether a reboot is needed depends on the engine. In RDS for MySQL and MariaDB, max_connections is a dynamic parameter, so a change to a parameter group the instance already uses applies without a restart. In RDS for PostgreSQL, max_connections is a static parameter: the instance shows pending-reboot until you reboot it. Either way, the first time you attach a new custom parameter group to an instance, the instance must be rebooted before that group takes effect.

Step 5: Apply the Parameter Group to Your RDS Instance

Navigate back to your RDS instances and select the instance you want to modify. Click "Modify" and scroll to the "Database options" section. Under "DB parameter group," select your newly created parameter group from the dropdown menu.

You'll be asked when to apply the changes:

  • Apply immediately: The instance is associated with the new group as soon as possible, potentially causing a brief interruption
  • Apply during maintenance window: Changes are queued for your next scheduled maintenance window

In both cases the parameter group status reads pending-reboot until the instance is rebooted. Plan the reboot for a quiet period, or use a Multi-AZ reboot with failover to shorten the interruption.

text
## Same change with the AWS CLI (PostgreSQL example; max_connections is static)
aws rds create-db-parameter-group \
  --db-parameter-group-name prod-postgres16-conn \
  --db-parameter-group-family postgres16 \
  --description "Custom max_connections"

aws rds modify-db-parameter-group \
  --db-parameter-group-name prod-postgres16-conn \
  --parameters "ParameterName=max_connections,ParameterValue=800,ApplyMethod=pending-reboot"

aws rds modify-db-instance \
  --db-instance-identifier my-db \
  --db-parameter-group-name prod-postgres16-conn \
  --apply-immediately

aws rds reboot-db-instance --db-instance-identifier my-db

Step 6: Verify the Changes

After the parameter group is applied, connect to your database and verify the new setting:

text
## For MySQL/MariaDB:
SHOW VARIABLES LIKE 'max_connections';

## For PostgreSQL:
SHOW max_connections;

How to Estimate Concurrent User Capacity on a Low-Cost RDS Instance

Concurrent users are not the same as database connections. With a connection pool, one connection serves many users one after another, so the number that matters is how many queries are running at the same moment. A simple way to estimate it is Little's law:

text
busy connections ≈ queries per second × average query time (seconds)

Example (illustrative numbers):
  300 requests/second, 2 queries per request, 5 ms per query
  = 600 queries/second × 0.005 s
  ≈ 3 connections busy on average

In this example a pool of 10 to 20 connections leaves room for bursts, far below the roughly 341 (MySQL) or 450 (PostgreSQL) ceiling of a db.t4g.medium. On small burstable classes (db.t3, db.t4g) the limit you usually hit first is CPU credits or memory, not max_connections. To estimate capacity for your own workload:

  1. Measure queries per request and the average and p95 query time (Performance Insights, pg_stat_statements, or the MySQL slow query log).
  2. Multiply peak queries per second by average query time to get busy connections, then size the pool at two to four times that number.
  3. Load test on the same instance class while watching CPUUtilization, CPUCreditBalance, FreeableMemory and DatabaseConnections in CloudWatch.
  4. Raise the request rate until latency or CPU credits degrade. That point, not max_connections, is your capacity on that instance.

Connection Management Best Practices

Simply increasing the max_connections parameter isn't always the solution to connection problems. In fact, poorly managed connections can lead to worse performance than running out of connections. Here are proven strategies for optimal connection management.

1. Implement Connection Pooling

Connection pooling is perhaps the most important technique for managing database connections efficiently. Instead of creating a new connection for every database operation, your application maintains a pool of reusable connections. Popular connection pooling solutions include:

  • HikariCP (Java): High-performance JDBC connection pool known for speed and reliability
  • PgBouncer (PostgreSQL): Lightweight connection pooler that can handle thousands of connections
  • ProxySQL (MySQL): Advanced proxy with connection pooling, load balancing, and query caching
  • Amazon RDS Proxy: AWS-managed service that pools and shares database connections
  • SQLAlchemy (Python): ORM with built-in connection pooling capabilities
  • Database driver pools: Many modern database drivers include pooling (node-postgres, mysql2, etc.)

JusDB Pro Tip: Configure your connection pool size to be significantly smaller than your database's max_connections. A common starting point, popularized by the HikariCP project, is: pool size = ((core_count × 2) + effective_spindle_count). For a 4-core system, this typically means 10-20 connections per application instance.

2. Set Appropriate Connection Timeouts

Stale connections can accumulate and consume your connection limit. Implement aggressive timeout policies:

  • Connection timeout: Maximum time to wait when establishing a connection (5-10 seconds)
  • Idle timeout: Close connections that haven't been used (30-60 seconds)
  • Max lifetime: Recycle connections after a certain age (30-60 minutes)
  • Query timeout: Cancel queries that run too long (30-60 seconds for OLTP)

3. Monitor Connection Usage Continuously

You can't manage what you don't measure. Implement comprehensive monitoring for connection metrics:

Key Metrics to Track:

  • DatabaseConnections: Current number of active connections
  • Connection utilization percentage: Active connections / max_connections
  • Failed connection attempts: Indicates when you're hitting limits
  • Average connection duration: Helps identify connection leaks
  • Connections by user/application: Identify which services are consuming connections
  • Wait events: Shows contention and resource bottlenecks

4. Implement Read Replicas for Read-Heavy Workloads

If your application is read-heavy, distributing read traffic across multiple read replicas can dramatically reduce connection pressure on your primary database. Each read replica has its own connection limit, effectively multiplying your available connections. This approach works particularly well for:

  • Reporting and analytics queries
  • Search functionality
  • API read endpoints
  • Background job queries
  • Dashboard and monitoring systems

5. Use Amazon RDS Proxy

Amazon RDS Proxy is a fully managed database proxy service that sits between your application and RDS database. It provides several connection management benefits:

  • Connection pooling at scale: Maintains a warm pool of connections, reducing connection overhead
  • Improved application resilience: Keeps client connections open during a Multi-AZ failover and routes them to the new primary, which shortens the impact of the failover
  • Enhanced security: Integrates with IAM and Secrets Manager for authentication
  • Reduced connection churn: Applications can aggressively create and close connections without impacting the database
  • Better serverless support: Essential for AWS Lambda and other serverless architectures

Troubleshooting Connection Issues

Even with proper planning, connection issues can arise. Here's how to diagnose and resolve common problems.

Diagnosing "Too Many Connections" Errors

When you encounter connection limit errors, follow this diagnostic process:

text
1. Check current connections (MySQL/MariaDB):
SHOW PROCESSLIST;
SELECT COUNT(*) FROM information_schema.PROCESSLIST;

2. Identify connections by user:
SELECT user, host, COUNT(*) as connection_count
FROM information_schema.PROCESSLIST
GROUP BY user, host
ORDER BY connection_count DESC;

3. Find long-running connections:
SELECT id, user, host, db, command, time, state, info
FROM information_schema.PROCESSLIST
WHERE command != 'Sleep'
ORDER BY time DESC
LIMIT 20;

4. Check for idle connections:
SELECT COUNT(*) as idle_connections
FROM information_schema.PROCESSLIST
WHERE command = 'Sleep'
AND time > 300;

For RDS for PostgreSQL, the same checks use pg_stat_activity:

text
1. Connections by user, application and state:
SELECT usename, application_name, state, COUNT(*) AS connections
FROM pg_stat_activity
WHERE backend_type = 'client backend'
GROUP BY usename, application_name, state
ORDER BY connections DESC;

2. How close you are to the limit:
SELECT COUNT(*) AS used,
       current_setting('max_connections')::int AS max_connections
FROM pg_stat_activity
WHERE backend_type = 'client backend';

3. Sessions idle in a transaction (they hold locks and a slot):
SELECT pid, usename, now() - state_change AS idle_for, query
FROM pg_stat_activity
WHERE state = 'idle in transaction'
ORDER BY idle_for DESC;

4. End one stuck session:
SELECT pg_terminate_backend(<pid>);

To stop leaks from piling up, set idle_in_transaction_session_timeout in the parameter group (PostgreSQL) or lower wait_timeout (MySQL) so abandoned sessions are closed by the server.

Quick Remediation Steps

If you're experiencing an immediate connection crisis, here are emergency measures:

Immediate Actions:

  1. Kill idle connections: Identify and terminate long-idle connections consuming resources
  2. Identify connection leaks: Look for applications or services creating excessive connections
  3. Scale up temporarily: Upgrade to a larger instance type for immediate relief
  4. Enable RDS Proxy: Set up connection pooling at the infrastructure level
  5. Review application logs: Identify which components are exhausting connections

Long-Term Solutions

Once you've stabilized the situation, implement these architectural improvements:

  • Audit your application code: Ensure all connections are properly closed with try-finally blocks or context managers
  • Implement connection pooling: Use robust pooling libraries appropriate for your stack
  • Optimize query performance: Faster queries mean shorter connection hold times
  • Consider microservices architecture: Distribute connection load across multiple services
  • Use caching strategically: Redis or Memcached can reduce database queries significantly
  • Implement circuit breakers: Prevent cascading failures when connection limits are reached

Conclusion

Understanding and managing AWS RDS max connections is fundamental to building scalable, reliable applications. With the latest generation instances (M7g, R7g, T4g, etc.), you have more options than ever to balance performance, cost, and connection requirements.

Remember that connection limits are dynamic, calculated based on instance memory. As your application grows, regularly reassess your connection strategy. What works for a startup with hundreds of users might not work when you're serving millions. Continuous monitoring, testing, and optimization are key to maintaining optimal database performance.

Key Takeaways:

  • Choose the right instance type based on actual connection requirements
  • Consider newer generation instances (Graviton-based) for better price-performance
  • Implement efficient connection pooling to maximize resource utilization
  • Monitor connection usage to prevent exhaustion before it impacts users
  • Use RDS Proxy for serverless and microservices architectures
  • Balance performance requirements with cost optimization

Quick Reference: Essential Commands

text
Check current max_connections (MySQL/MariaDB):
SHOW VARIABLES LIKE 'max_connections';

View active connections:
SHOW PROCESSLIST;

Count connections by user:
SELECT user, COUNT(*) as total
FROM information_schema.PROCESSLIST
GROUP BY user;

Kill a specific connection:
KILL [connection_id];

PostgreSQL - check max connections:
SHOW max_connections;

PostgreSQL - view active connections:
SELECT * FROM pg_stat_activity;

PostgreSQL - connections by state:
SELECT state, COUNT(*) FROM pg_stat_activity GROUP BY state;

Working with JusDB on RDS Optimization

Connection limit errors are usually a symptom of missing connection pooling or an oversized pool, not a reason to upgrade to a larger instance. We diagnose RDS connection problems and configure PgBouncer, RDS Proxy, or ProxySQL as part of our AWS database consulting work. Request a review if you're hitting connection limits.

Further Reading

For more in-depth information, check out these authoritative resources:

Explore more database insights from JusDB:

Share this article

Database engineering notes

Articles like this one, in your inbox. No spam, unsubscribe anytime.

JusDB Team

Official JusDB content team

Keep reading

How to Migrate PostgreSQL to AWS RDS: Methods, Pre-Flight Checks, and Cutover

Move self-managed PostgreSQL to Amazon RDS: choose pg_dump, logical replication, AWS DMS, or pglogical by downtime budget, then cut over with sequence sync and a rollback path.

PostgreSQL20 minNov 19, 2026
Read

How to Migrate MySQL to AWS RDS: Methods, Pre-Flight Checks, and Cutover

Move self-managed MySQL to Amazon RDS: choose mysqldump, MySQL Shell, XtraBackup from S3, or AWS DMS by downtime budget, then replicate, validate, and cut over with a rollback path.

MySQL19 minNov 18, 2026
Read

AWS RDS High CPU Usage: Find the Cause on MySQL and PostgreSQL

Triage high CPU on Amazon RDS for MySQL and PostgreSQL with CloudWatch, Enhanced Monitoring, CPU credits, and Database Insights, then fix the SQL or resize.

PostgreSQL19 minNov 13, 2026
Read