SqlAlchemy“已有太多客户端”错误
我对 python 和金字塔框架相当陌生。最近我被介绍使用 SQLSoup 来满足我的数据库 (postgres) 需求。
dbEngine1 = SqlSoup(settings['sqlalchemy.db1.url'])
users = dbEngine1.users.fetchall()
一切都运行良好,但是在使用金字塔应用程序一段时间后,我收到此错误消息。我必须杀死金字塔才能释放postgres中的所有空闲连接(在抛出以下异常之前大约有50个空闲连接)
sorry, too many clients already
我的问题是,如何关闭这个空闲连接,我尝试添加一行代码,如下所示,但它没有帮助。
dbEngine1 = SqlSoup(settings['sqlalchemy.db1.url'])
users = dbEngine1.users.fetchall()
dbEngine1.engine.connect().close()
SQLAlchemy 专家有什么指点吗?
I'm fairly new to python and pyramid framework. Recently I was introduced to SQLSoup to take care of my database (postgres) needs.
dbEngine1 = SqlSoup(settings['sqlalchemy.db1.url'])
users = dbEngine1.users.fetchall()
Everything is working great, however after a short period of using the pyramid app, I'm getting this error message. I have to kill pyramid to release all idling connections in postgres (about 50 idling connection before throwing below exception)
sorry, too many clients already
My question is, how do I close this idling connection, I tried adding a line of code as shown below, but it does not help.
dbEngine1 = SqlSoup(settings['sqlalchemy.db1.url'])
users = dbEngine1.users.fetchall()
dbEngine1.engine.connect().close()
Any pointer from SQLAlchemy gurus?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
似乎您对 Pyramid 应用程序的每个请求都创建了
dbEngine1
。为了在 web 应用程序中正确使用 SqlSoup,您必须使用 SA 会话。
请参阅本页上的“访问会话”部分。
SqlSoup例如原始SA使用连接池,池中的每个连接在空闲状态util查询执行。该连接池必须创建一次。
Seems like you create
dbEngine1
on each request to yours Pyramid app.For proper usage SqlSoup in webapp you must use SA Sessions.
See section "Accessing the Session" on this page.
SqlSoup such as raw SA use the connection pool, each connection in pool at idle status util query executes. This connection pool must be created once.