npgsql 泄漏 Postgres DB 连接:监视连接的方法?

发布于 2024-08-31 10:01:37 字数 486 浏览 7 评论 0原文

背景:我正在将我的应用程序从 npgsql v1 移动到 npgsql v2.0.9。运行应用程序几分钟后,我收到 System.Exception:从池中获取连接时超时。

网络声称这是由于连接泄漏(打开数据库连接,但未正确关闭它们)造成的。

所以

我试图诊断 npgsql 中泄漏的 postgres 连接。

来自各地的各种网络文献;诊断泄漏连接的一种方法是在 npgsql 上设置日志记录,并在日志中查找泄漏连接警告消息。问题是,我在任何地方的日志中都没有看到此消息。

我还发现了监视 npgsql 连接的实用程序,但它不稳定并且崩溃。

所以我只能手动检查代码。对于每个创建 npgsql 连接的地方,都有一个 finally 块对其进行处理。对于打开数据读取器的每个地方,都会使用 CommandBehavior.CloseConnection(并且释放数据读取器)。

还有其他地方可以检查吗?或者有人可以推荐一种方法来查找泄漏的池连接吗?

Background: I'm moving my application from npgsql v1 to npgsql v2.0.9. After a few minutes of running my application, I get a System.Exception: Timeout while getting a connection from the pool.

The web claims that this is due to leaking connections (opening a db connection, but not properly closing them).

So

I'm trying to diagnose leaking postgres connections in npgsql.

From the various web literature around; one way to diagnose leaking connections is to setup logging on npgsql, and look for the leaking connection warning message in the log. Problem is, I'm not seeing this message in the logs anywhere.

I also found utility that monitors npgsql connections, but it's unstable and crashes.

So I'm left manually inspecting code. For everyplace that creates an npgsql connection, there is a finally block disposing of it. For everyplace that opens a datareader, CommandBehavior.CloseConnection is used (and the datareader is disposed).

Any other places to check or can someone recommend a way to look for leaking pool connections?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

不如归去 2024-09-07 10:01:37

更新:我正在以更好的方式检查这些泄漏连接的分配位置。请检查我的帖子:http:// fxjr.blogspot.com/2012/11/better-tracing-of-npgsql-connection.html
我希望它有帮助。

编辑:您可能想尝试我们最新的测试版 2.0.11.91。我们添加了更多代码来改进连接池,这可以帮助您。

嗯,这很奇怪......您应该会收到一些消息。

这些消息仅在 ms.net 运行时完成对象时才会出现。您是否有可能同时使用超过默认最大连接数?我的意思是,您的峰值使用量可能超过 20 个最大连接数...

我希望它有所帮助。

请让我知道你得到了什么。

UPDATE: I'm working in a better way to check where those leak connections were allocated. Please, check my post about that: http://fxjr.blogspot.com/2012/11/better-tracing-of-npgsql-connection.html
I hope it helps.

EDIT: You may want to try our latest beta version 2.0.11.91. We added some more code to improve connection pool which can help you.

Hmmmm, this is very strange.... You should be getting some messages.

Those messages only appear when ms.net runtime finalizes the object though. Would it be possible that you are using more than default max connections at same time? I mean, your peak usage may be more than the 20 max number connections...

I hope it helps.

Please, let me know what do you get.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文