Sql Server - 如何重新启动服务器(DMV重置日期/时间)

时间:2021-06-02 10:19:05

I'm using some modifications to Glenn Berry's excellent DMV queries!

我正在对Glenn Berry的优秀DMV查询进行一些修改!

However, I would like to add to the resultset the 'last server restart', or to be more specific, the date/time the statistics for (all, the specific) DMV was reset.

但是,我想在结果集中添加“上次服务器重启”,或者更具体地说,重置(全部,特定)DMV的统计信息的日期/时间。

Since it would be quite important to know last reset when looking at the statistics, I want to make absolutely sure the date/time is accurate and shown.

因为在查看统计数据时知道上次重置非常重要,所以我想确保日期/时间准确并显示出来。

Question: How can you get the most accurate date/time of when a/all DMV statistic was reset?

问题:如何获得重置/全部DMV统计数据的最准确日期/时间?

Thanks! -D

谢谢! -D

4 个解决方案

#1


9  

SELECT sqlserver_start_time FROM sys.dm_os_sys_info

#2


7  

Using a prior question (different key words), I ended up using this approach. As always, up to the individual what would be 'best' for them!

使用先前的问题(不同的关键词),我最终使用这种方法。一如既往,取决于个人对他们来说“最好”的东西!

SELECT create_date FROM sys.databases WHERE name = 'tempdb'

SELECT create_date FROM sys.databases WHERE name ='tempdb'

source: Find out how long the sql server service has been running, from t-sql

source:从t-sql中查找sql​​ server服务运行了多长时间

#3


2  

This will work but you have to know the service name also its only available with R2 and later

这将有效,但您必须知道服务名称,它仅适用于R2及更高版本

SELECT last_startup_time 
FROM   sys.dm_server_services 
WHERE  servicename = "Your Service name" 

Although this won't be totally accurate since you can also reset the DB specific views via a DB detach or a DB close.

虽然这不完全准确,因为您还可以通过DB分离或DB关闭来重置DB特定视图。

Also there are two views that can be reset on a live db sys.dm_os_latch_stats and sys.dm_os_wait_stats

还有两个视图可以在实时db sys.dm_os_latch_stats和sys.dm_os_wait_stats上重置

#4


0  

There are many ways to check when was SQL server restarted last time.

有很多方法可以检查上次重启SQL Server的时间。

Below mentioned SQL queries can be used to quickly find out the server restart date time.

下面提到的SQL查询可用于快速找出服务器重启日期时间。

 SELECT sqlserver_start_time FROM sys.dm_os_sys_info;  



SELECT login_time FROM sys.dm_exec_sessions WHERE session_id = 1;  



 select start_time from sys.traces where is_default = 1  ;



 SELECT crdate FROM sysdatabases WHERE name='tempdb'  ;



 SELECT create_date FROM sys.databases WHERE name = 'tempdb' ;

#1


9  

SELECT sqlserver_start_time FROM sys.dm_os_sys_info

#2


7  

Using a prior question (different key words), I ended up using this approach. As always, up to the individual what would be 'best' for them!

使用先前的问题(不同的关键词),我最终使用这种方法。一如既往,取决于个人对他们来说“最好”的东西!

SELECT create_date FROM sys.databases WHERE name = 'tempdb'

SELECT create_date FROM sys.databases WHERE name ='tempdb'

source: Find out how long the sql server service has been running, from t-sql

source:从t-sql中查找sql​​ server服务运行了多长时间

#3


2  

This will work but you have to know the service name also its only available with R2 and later

这将有效,但您必须知道服务名称,它仅适用于R2及更高版本

SELECT last_startup_time 
FROM   sys.dm_server_services 
WHERE  servicename = "Your Service name" 

Although this won't be totally accurate since you can also reset the DB specific views via a DB detach or a DB close.

虽然这不完全准确,因为您还可以通过DB分离或DB关闭来重置DB特定视图。

Also there are two views that can be reset on a live db sys.dm_os_latch_stats and sys.dm_os_wait_stats

还有两个视图可以在实时db sys.dm_os_latch_stats和sys.dm_os_wait_stats上重置

#4


0  

There are many ways to check when was SQL server restarted last time.

有很多方法可以检查上次重启SQL Server的时间。

Below mentioned SQL queries can be used to quickly find out the server restart date time.

下面提到的SQL查询可用于快速找出服务器重启日期时间。

 SELECT sqlserver_start_time FROM sys.dm_os_sys_info;  



SELECT login_time FROM sys.dm_exec_sessions WHERE session_id = 1;  



 select start_time from sys.traces where is_default = 1  ;



 SELECT crdate FROM sysdatabases WHERE name='tempdb'  ;



 SELECT create_date FROM sys.databases WHERE name = 'tempdb' ;