Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

When was server last rebooted? Expand / Collapse
Author
Message
Posted Tuesday, November 13, 2012 1:56 PM
Mr or Mrs. 500

Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500

Group: General Forum Members
Last Login: Today @ 10:21 AM
Points: 529, Visits: 1,567
Is there a DMV or function that tells you when the physical server was last rebooted, as opposed to when SQL service was last restarted (which is in sys.dm_os_sys_info)?
Post #1384287
Posted Tuesday, November 13, 2012 2:37 PM


SSC Eights!

SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!

Group: General Forum Members
Last Login: Sunday, July 20, 2014 7:16 AM
Points: 945, Visits: 1,769
For the physical server you can run "net statistics server" and take a look at the time.


For faster help in answering any problems Please read How to post data/code on a forum to get the best help - Jeff Moden for the best way to ask your question.

For performance Issues see how we like them posted here: How to Post Performance Problems - Gail Shaw

Need to Split some strings? Jeff Moden's DelimitedSplit8K
Jeff Moden's Cross tab and Pivots Part 1
Jeff Moden's Cross tab and Pivots Part 2

Jeremy Oursler
Post #1384309
Posted Tuesday, November 13, 2012 2:42 PM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: Today @ 8:24 AM
Points: 12,887, Visits: 31,835
edit; for reference for others , he mentioned he already knows this one, as opposed to when the OS restarted:
select 
sqlserver_start_time
from sys.dm_os_sys_info



Lowell

--There is no spoon, and there's no default ORDER BY in sql server either.
Actually, Common Sense is so rare, it should be considered a Superpower. --my son
Post #1384311
Posted Tuesday, November 13, 2012 2:51 PM
Hall of Fame

Hall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of Fame

Group: General Forum Members
Last Login: Today @ 11:22 AM
Points: 3,122, Visits: 11,406
This code gives the start time for the OS, SQL Server, and SQL Server Agent, and gives the uptime days for the OS, SQL Server, and SQL Server Agent.

select
[OS Start Time] = convert(varchar(23),b.OS_Start,121),
[SQL Server Start Time] = convert(varchar(23),a.SQL_Start,121),
[SQL Agent Start Time] = convert(varchar(23),a.Agent_Start,121),
[OS Uptime] =
convert(varchar(15),
right(10000000+datediff(dd,0,getdate()-b.OS_Start),4)+' '+
convert(varchar(20),getdate()-b.OS_Start,108)),
[SQL Uptime] =
convert(varchar(15),
right(10000000+datediff(dd,0,getdate()-a.SQL_Start),4)+' '+
convert(varchar(20),getdate()-a.SQL_Start,108)) ,
[Agent Uptime] =
convert(varchar(15),
right(10000000+datediff(dd,0,getdate()-a.Agent_Start),4)+' '+
convert(varchar(20),getdate()-a.Agent_Start,108))
from
(
Select
SQL_Start = min(aa.login_time),
Agent_Start =
nullif(min(case when aa.program_name like 'SQLAgent %' then aa.login_time else '99990101' end),
convert(datetime,'99990101'))
from
master.dbo.sysprocesses aa
where
aa.login_time > '20000101'
) a
cross join
(
select
OS_Start = dateadd(ss,bb.[ms_ticks]/-1000,getdate())
from
sys.[dm_os_sys_info] bb
) b

Results:
OS Start Time           SQL Server Start Time   SQL Agent Start Time    OS Uptime       SQL Uptime      Agent Uptime
----------------------- ----------------------- ----------------------- --------------- --------------- ---------------
2012-08-04 22:19:26.317 2012-08-04 23:38:07.163 2012-10-31 11:49:49.063 0100 18:28:38 0100 17:09:57 0013 04:58:15






Post #1384317
Posted Wednesday, November 14, 2012 12:21 AM
Old Hand

Old HandOld HandOld HandOld HandOld HandOld HandOld HandOld Hand

Group: General Forum Members
Last Login: Today @ 2:31 AM
Points: 332, Visits: 1,123
you can get the time by running this query also

Select name,crdate from sys.sysdatabases where name='tempdb'
Post #1384419
Posted Wednesday, November 14, 2012 12:48 AM


SSC-Forever

SSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-Forever

Group: General Forum Members
Last Login: Today @ 4:58 PM
Points: 42,466, Visits: 35,532
yuvipoy (11/14/2012)
you can get the time by running this query also

Select name,crdate from sys.sysdatabases where name='tempdb'


That gets you the time the SQL instance was last started, not the time the server was last rebooted.

sysdatabases is deprecated, should not be used, included only for backward compat with SQL 2000, will be removed in a future version. The replacement is sys.databases



Gail Shaw
Microsoft Certified Master: SQL Server 2008, MVP
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

We walk in the dark places no others will enter
We stand on the bridge and no one may pass

Post #1384426
Posted Wednesday, November 14, 2012 2:52 AM
SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Thursday, April 17, 2014 1:41 AM
Points: 170, Visits: 1,400
Michael Valentine Jones (11/13/2012)
This code gives the start time for the OS, SQL Server, and SQL Server Agent, and gives the uptime days for the OS, SQL Server, and SQL Server Agent.
....


Michael,

Pretty neat query this one - hadn't thought to get OS start time from dm_os_sys_info ticks.
Since it returns just one row, it is also handy for registred-server batch queries. After a powercut, you can tell immediately which servers had Windows interrupted and which one just SQL services.


Cheers,

JohnA

MCM: SQL2008
Post #1384490
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse