python
network_error
ai_generated
true
sqlalchemy.exc.OperationalError:(psycopg2.OperationalError) SSL 连接意外关闭
sqlalchemy.exc.OperationalError: (psycopg2.OperationalError) SSL connection has been closed unexpectedly
ID: python/sqlalchemy-connection-pool-recycle
80%修复率
85%置信度
0证据数
2025-09-01首次发现
版本兼容性
| 版本 | 状态 | 引入 | 弃用 | 备注 |
|---|---|---|---|---|
| 3.x | active | — | — | — |
根因分析
数据库服务器因超时关闭了空闲连接;连接池仍持有过时连接。
English
Database server closed idle connections due to timeout; pool still holds stale connections.
解决方案
-
95% 成功率 Set pool_recycle to a value less than server idle timeout.
engine = create_engine(url, pool_recycle=3600) # Recycle connections every hour
-
90% 成功率 Enable pool_pre_ping to check connection health.
engine = create_engine(url, pool_pre_ping=True)
无效尝试
常见但无效的做法:
-
Disabling SSL entirely.
50% 失败
Security risk; may not be allowed by policy.
-
Increasing pool_timeout.
70% 失败
Does not refresh stale connections.