postgresql npgsql 泄漏 Postgres 数据库连接:监视连接的方法?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2775489/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-20 00:07:05  来源:igfitidea点击:

npgsql Leaking Postgres DB Connections: Way to monitor connections?

c#postgresqlconnection-poolingpoolingnpgsql

提问by Alan

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.

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

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.

我正在尝试诊断 npgsql 中泄漏的 postgres 连接。

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.

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

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

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

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).

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

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

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

采纳答案by Francisco Junior

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.htmlI hope it helps.

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

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.

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

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...

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

I hope it helps.

我希望它有帮助。

Please, let me know what do you get.

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