# RDSProxy：数据库'mydb'的连接池已耗尽

- **ID:** `cloud/aws-rds-proxy-connection-pool-exhausted`
- **领域:** cloud
- **类别:** resource_error
- **错误码:** `ConnectionPoolExhausted`
- **验证级别:** ai_generated
- **修复率:** 85%

## 根因

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

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| RDS Proxy 1.0 | active | — | — |
| Aurora MySQL 8.0 | active | — | — |
| Aurora PostgreSQL 15 | active | — | — |
| RDS for MySQL 8.0 | active | — | — |

## 解决方案

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)`.
   ```

## 无效尝试

- **** — 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. (80% 失败率)
- **** — Restarting clears the pool temporarily, but the application will quickly exhaust it again if connections are not closed properly. (90% 失败率)
- **** — Multiple proxy endpoints share the same underlying database connection limit; this only distributes load but does not increase total pool size. (75% 失败率)
