SQL:如何获得每个数据库或小时或......的执行查询数?

时间:2022-12-04 00:52:58

Is there any way to see how many queries are executed in like every hour, or per database / hour, or average number of queries on a day, or ...whatever is interesting?

是否有任何方法可以查看每小时,每个数据库/小时执行的查询数量,或一天中的平均查询数,或者......有趣的是什么?

Just for statistics.. I like numbers. I can't just start a trace with Sql Server Profiler, because the UI will crash when too many queries come by.

仅供统计......我喜欢数字。我不能只使用Sql Server Profiler启动跟踪,因为当查询过多时,UI将崩溃。

Does SQL keep track of some basic 'executed queries statistics' somewhere, or are there any tools I can use to get this information?

SQL是否在某处跟踪某些基本的“已执行查询统计信息”,或者我是否可以使用任何工具来获取此信息?

(I use SQL Server 2008 R2)

(我使用的是SQL Server 2008 R2)

2 个解决方案

#1


5  

This should work:

这应该工作:

select * 
from sys.dm_os_performance_counters
where counter_name = 'Batch Requests/sec'

It actually returns the total Batch Requests. You poll this number periodically and then use this calculation:

它实际上返回总批量请求。您定期轮询此数字,然后使用此计算:

ReqsPerSec = (curr.Value - prev.Value) / (curr.time - prev.time)

#2


0  

I am actually just learning about this in my Microsoft Certification.

我实际上只是在我的Microsoft认证中了解这一点。

Though I can't answer your question directly yet, I can send you in the right direction with a couple things:

虽然我不能直接回答你的问题,但我可以向你发送一些正确的方向:

  1. Have a look at the views inside the Server > Databases > System Databases > MSDB > Views > System Views. MSDN Systsem Views
  2. 查看服务器>数据库>系统数据库> MSDB>视图>系统视图中的视图。 MSDN Systsem视图

  3. Have a look at the views inside the Server > Databases > System Databases > Master > Views > System Views.
  4. 查看服务器>数据库>系统数据库>主服务器>视图>系统视图中的视图。

  5. Take a peak at the trace tools available to SQL Server.
  6. 在SQL Server可用的跟踪工具上占据一席之地。

In the views note that you may actually have to join a couple of the views together or get at the underlying tables to get specifically what you are after.

在视图中请注意,您实际上可能必须将几个视图连接在一起,或者获取基础表以获得具体的内容。

#1


5  

This should work:

这应该工作:

select * 
from sys.dm_os_performance_counters
where counter_name = 'Batch Requests/sec'

It actually returns the total Batch Requests. You poll this number periodically and then use this calculation:

它实际上返回总批量请求。您定期轮询此数字,然后使用此计算:

ReqsPerSec = (curr.Value - prev.Value) / (curr.time - prev.time)

#2


0  

I am actually just learning about this in my Microsoft Certification.

我实际上只是在我的Microsoft认证中了解这一点。

Though I can't answer your question directly yet, I can send you in the right direction with a couple things:

虽然我不能直接回答你的问题,但我可以向你发送一些正确的方向:

  1. Have a look at the views inside the Server > Databases > System Databases > MSDB > Views > System Views. MSDN Systsem Views
  2. 查看服务器>数据库>系统数据库> MSDB>视图>系统视图中的视图。 MSDN Systsem视图

  3. Have a look at the views inside the Server > Databases > System Databases > Master > Views > System Views.
  4. 查看服务器>数据库>系统数据库>主服务器>视图>系统视图中的视图。

  5. Take a peak at the trace tools available to SQL Server.
  6. 在SQL Server可用的跟踪工具上占据一席之地。

In the views note that you may actually have to join a couple of the views together or get at the underlying tables to get specifically what you are after.

在视图中请注意,您实际上可能必须将几个视图连接在一起,或者获取基础表以获得具体的内容。