如何发现数据库连接泄露

如何发现数据库连接泄露,第1张

1. 根据日志查找;

首先,翻看系统日志,找到连接池溢出的时刻。然后,对应这个时间,查找用户正在进行的 *** 作。

这种方法适合于不启动任何监控程序或进程,不改变系统设置,就能人为的缩小可能泄露连接的代码范围。

2. 利用连接池本身的utility设施;比如C3P0,以下是需要用到的两个参数(推荐):

unreturnedConnectionTimeout

Default: 0

Seconds. If set, if an application checks out but then fails to check-in [i.e. close()] a Connection within the specified period of time, the pool will unceremoniously destroy() the Connection. This permits applications with occasional Connection leaks to survive, rather than eventually exhausting the Connection pool. And that's a shame. Zero means no timeout, applications are expected to close() their own Connections. Obviously, if a non-zero value is set, it should be to a value longer than any Connection should reasonably be checked-out. Otherwise, the pool will occasionally kill Connections in active use, which is bad. This is basically a bad idea, but it's a commonly requested feature. Fix your $%!@% applications so they don't leak Connections! Use this temporarily in combination with debugUnreturnedConnectionStackTraces to figure out where Connections are being checked-out that don't make it back into the pool!

debugUnreturnedConnectionStackTraces

Default: false

If true, and if unreturnedConnectionTimeout is set to a positive value, then the pool will capture the stack trace (via an Exception) of all Connection checkouts, and the stack traces will be printed when unreturned checked-out Connections timeout. This is intended to debug applications with Connection leaks, that is applications that occasionally fail to return Connections, leading to pool growth, and eventually exhaustion (when the pool hits maxPoolSize with all Connections checked-out and lost). This parameter should only be set while debugging, as capturing the stack trace will slow down every Connection check-out.

  当我们同时使用这两个参数时,比如unreturnedConnectionTimeout设为5秒,debugUnreturnedConnectionStackTraces设为true。那么,当一个连接被check out 5秒,还没有被check in的时候,连接池会抛出一个错误堆栈。有了堆栈,那我们就可以精确定位出现问题的代码位置了。

当然,这个方法中的参数并不是C3P0特有的,其他连接池配置中,应该也有类似的参数。

网站上的隐私泄露可以从各个方面,从浏览网页、网上发帖、转发,现在就连朋友圈点赞都有可能造成信息泄露。在下载APP的时候,都会让你选择是否授权,有的如果不授权无法使用这个软件。这类强制性要求公开搜集个人信息的都会造成你的隐私泄露的,如果真的有不法分子想要获取你的信息,通过上述的行为都可以查到你的所有信息,包括:身份z号、手机号码、家庭地址、父母的联系方式等,都是可以被搜到的。所以中国数据安全防护专家亿赛通提醒广大手机党们,上网要谨慎,严格防护信息泄露。


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/sjk/6803546.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-03-28
下一篇 2023-03-28

发表评论

登录后才能评论

评论列表(0条)

保存