如何检查 SQL Server 的当前池大小 [英] How to check current pool size of SQL Server
问题描述
有没有办法在 SQL Server 中检查当前的连接池大小?我不是在谈论最大连接池大小,而是当前池大小.假设最大池大小为 100,并且打开了 49 个连接,它现在应该显示 51 个可用或 49 个已消耗.
Is there a way to check the current connection pool size in SQL Server? I am not talking about the max connection pool size, but the current pool size. Let's say the max pool size is 100 and there are 49 connections open, it should now show me either 51 available or perhaps 49 consumed.
那么,有这样的查询吗?
So, is there such a query?
推荐答案
很多这些东西似乎都在 dmv 可以直接访问的范围之外.我敢肯定,比我更了解情况的人可以为您提供更好的答案.
So much of this stuff seems to be outside of what is directly accessible from dmv's. I'm sure someone more informed than myself can get you better answers.
这是我所能得到的最接近的.
This is as close as I could get.
SELECT des.program_name
, des.login_name
, des.host_name
, COUNT(des.session_id) [Connections]
FROM sys.dm_exec_sessions des
INNER JOIN sys.dm_exec_connections DEC
ON des.session_id = DEC.session_id
WHERE des.is_user_process = 1
AND des.status != 'running'
GROUP BY des.program_name
, des.login_name
, des.host_name
HAVING COUNT(des.session_id) > 2
ORDER BY COUNT(des.session_id) DESC
这将通过登录以及来自每个主机和应用程序来聚合您的连接.这将使您了解您的连接当前是如何汇集的.如果您知道自己的最大数量,则可以从中减去连接数,它可以为您提供每个池中剩余的连接数.
This will aggregate your connections by login and from each host and app. This will give you an idea of how your connections are currently being pooled. If you know your max amount off hand, you can subtract the connections from it and it could give you the number of connections remaining in each pool.
这篇关于如何检查 SQL Server 的当前池大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!