服务器空闲几个小时后,sqlalchemy 无法连接到数据库
我有一个相当标准的设置,其中应用程序服务器通过防火墙与数据库服务器分开。我们使用 sqlalchemy 的应用程序和 db 是 postgres。
系统可以正常工作几个小时,但是一旦长时间处于空闲状态,服务器和数据库之间的通信就会失败。错误日志是:
WARNI [sqlalchemy.pool.QueuePool.0x...7310] [worker 26] Error closing cursor: cursor already closed
我将连接池的“pool_recylce”设置设置为 30 分钟,这样就没有连接持续超过 30 分钟。问题仍然存在。
有什么想法吗?
I have a fairly standard setup where the application server is separated by a firewall from the database server. The application us using sqlalchemy and the db is postgres.
The system works fine for a few hours, but once it remains idle for a long period it appears that the communication fails between the server and the db. The error log is:
WARNI [sqlalchemy.pool.QueuePool.0x...7310] [worker 26] Error closing cursor: cursor already closed
I set up the connection pool with the 'pool_recylce' setting set to 30mins, so that there are no connections lingering for more than 30 mins. The problem persists.
any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可能在客户端和服务器之间有一个状态防火墙,它会忘记闲置时间过长的连接。
您需要:
禁用
pool_recycle
,因为恕我直言,它仅在关闭连接时才有效。You probably have a stateful firewall between a client and a server, which is forgetting about connections that are idle for too long.
You need either to:
Which means that if connection is idle for 10 minutes try to send keepalive probes every 30 seconds until response, close connection if 60 probes are ignored (connection is broken for 30 minutes);
Disable
pool_recycle
as IMHO it works only if you close a connection.