ConnectionPoolExhausted cloud resource_error ai_generated true

RDSProxy: Connection pool exhausted for database 'mydb'

ID: cloud/aws-rds-proxy-connection-pool-exhausted

Also available as: JSON · Markdown · 中文
85%Fix Rate
87%Confidence
1Evidence
2024-05-12First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
RDS Proxy 1.0 active
Aurora MySQL 8.0 active
Aurora PostgreSQL 15 active
RDS for MySQL 8.0 active

Root Cause

RDS Proxy's maximum connection pool size for the target database is reached, often due to too many concurrent connections or long-running queries holding connections open.

generic

中文

RDS Proxy针对目标数据库的最大连接池大小已满,通常是由于并发连接过多或长时间运行的查询占用连接未释放。

Official Documentation

https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/rds-proxy.html#rds-proxy-connection-pool

Workarounds

  1. 85% success Increase RDS Proxy's MaxConnectionsPercent and SessionPinningFilters in the proxy target group: `aws rds modify-db-proxy-target-group --db-proxy-name my-proxy --target-group-name default --connection-pool-config MaxConnectionsPercent=90,SessionPinningFilters=["EXCLUDE_VARIABLE_SETS"]`. Also increase database max_connections: `aws rds modify-db-instance --db-instance-identifier my-db --db-parameter-group-name custom-params` with max_connections=500.
    Increase RDS Proxy's MaxConnectionsPercent and SessionPinningFilters in the proxy target group: `aws rds modify-db-proxy-target-group --db-proxy-name my-proxy --target-group-name default --connection-pool-config MaxConnectionsPercent=90,SessionPinningFilters=["EXCLUDE_VARIABLE_SETS"]`. Also increase database max_connections: `aws rds modify-db-instance --db-instance-identifier my-db --db-parameter-group-name custom-params` with max_connections=500.
  2. 90% success Optimize application code to close connections promptly using connection pooling libraries (e.g., HikariCP with maxLifetime=300000 and idleTimeout=600000). Set connection timeout in AWS Lambda: `import pymysql; conn = pymysql.connect(..., connect_timeout=5, read_timeout=30)`.
    Optimize application code to close connections promptly using connection pooling libraries (e.g., HikariCP with maxLifetime=300000 and idleTimeout=600000). Set connection timeout in AWS Lambda: `import pymysql; conn = pymysql.connect(..., connect_timeout=5, read_timeout=30)`.

中文步骤

  1. Increase RDS Proxy's MaxConnectionsPercent and SessionPinningFilters in the proxy target group: `aws rds modify-db-proxy-target-group --db-proxy-name my-proxy --target-group-name default --connection-pool-config MaxConnectionsPercent=90,SessionPinningFilters=["EXCLUDE_VARIABLE_SETS"]`. Also increase database max_connections: `aws rds modify-db-instance --db-instance-identifier my-db --db-parameter-group-name custom-params` with max_connections=500.
  2. Optimize application code to close connections promptly using connection pooling libraries (e.g., HikariCP with maxLifetime=300000 and idleTimeout=600000). Set connection timeout in AWS Lambda: `import pymysql; conn = pymysql.connect(..., connect_timeout=5, read_timeout=30)`.

Dead Ends

Common approaches that don't work:

  1. 80% fail

    RDS Proxy pool size is limited by the database's max_connections; increasing proxy percent alone does not help if the database limit is reached.

  2. 90% fail

    Restarting clears the pool temporarily, but the application will quickly exhaust it again if connections are not closed properly.

  3. 75% fail

    Multiple proxy endpoints share the same underlying database connection limit; this only distributes load but does not increase total pool size.