致命错误:剩余的连接槽位保留给非复制超级用户连接(RDS Proxy)
FATAL: remaining connection slots are reserved for non-replication superuser connections (RDS Proxy)
ID: aws/rds-proxy-max-connections-exceeded
版本兼容性
| 版本 | 状态 | 引入 | 弃用 | 备注 |
|---|---|---|---|---|
| RDS Proxy (2023-03-15) | active | — | — | — |
| PostgreSQL 13.12 | active | — | — | — |
| MySQL 8.0.35 | active | — | — | — |
根因分析
RDS Proxy 已耗尽最大连接池大小(默认 100),原因是来自应用程序的并发连接过多,并且数据库实例本身也达到了 max_connections 限制。
English
The RDS Proxy has exhausted its maximum connection pool size (default 100) due to too many concurrent connections from applications, and the database instance itself is also at its max_connections limit.
官方文档
https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/rds-proxy.html解决方案
-
通过 AWS 控制台或 CLI 增加 RDS Proxy 的 MaxConnectionsPercent 和 SessionPinningFilters:`aws rds modify-db-proxy --db-proxy-name my-proxy --max-connections-percent 120`。同时确保 RDS 实例的 max_connections 至少是代理限制的 1.5 倍。
-
在应用程序中使用连接池库(如 Java 的 HikariCP 或 PostgreSQL 的 pgBouncer)来减少对代理的并发连接数。例如:在 HikariCP 配置中设置 `maximumPoolSize=10`。
-
使用 RDS Proxy 的 CloudWatch 指标(例如 'DatabaseConnections')监控活动连接,并在需要时将数据库实例扩展到更大的尺寸。
无效尝试
常见但无效的做法:
-
60% 失败
Increasing only the RDS instance's max_connections without adjusting RDS Proxy's MaxConnectionsPercent will still cause the proxy to reject connections.
-
75% 失败
Restarting the RDS Proxy without scaling the instance or reducing application connections will result in the same error immediately after restart.
-
35% 失败
Assuming the error is a database authentication issue and resetting credentials, which does not address the connection limit.