Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sql Server - how to get last server restart (DMV reset date/time)

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

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.

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?

Thanks! -D

like image 645
dhartford Avatar asked Apr 05 '12 15:04

dhartford


3 Answers

SELECT sqlserver_start_time FROM sys.dm_os_sys_info
like image 111
user1318325 Avatar answered Oct 20 '22 04:10

user1318325


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'

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

like image 21
dhartford Avatar answered Oct 20 '22 02:10

dhartford


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

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.

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

like image 24
Conrad Frix Avatar answered Oct 20 '22 03:10

Conrad Frix