python
network_error
ai_generated
true
sqlalchemy.exc.OperationalError: (psycopg2.OperationalError) SSL connection has been closed unexpectedly
ID: python/sqlalchemy-connection-pool-recycle
80%Fix Rate
85%Confidence
0Evidence
2025-09-01First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| 3.x | active | — | — | — |
Root Cause
Database server closed idle connections due to timeout; pool still holds stale connections.
generic中文
数据库服务器因超时关闭了空闲连接;连接池仍持有过时连接。
Workarounds
-
95% success Set pool_recycle to a value less than server idle timeout.
engine = create_engine(url, pool_recycle=3600) # Recycle connections every hour
-
90% success Enable pool_pre_ping to check connection health.
engine = create_engine(url, pool_pre_ping=True)
Dead Ends
Common approaches that don't work:
-
Disabling SSL entirely.
50% fail
Security risk; may not be allowed by policy.
-
Increasing pool_timeout.
70% fail
Does not refresh stale connections.