Friday 19 April 2013

Find Start Time of SQL Server

There are several ways to find out when your SQL Server instance has been started.
One of the Server Standard Reports shows the SQL Server instance startup time:
Connect to SQL Server Instance -> Right Click on instance name -> Click Reports -> Click Standard Reports -> Choose Server Dashboard Report:
sql server start time from dashboard report
For details what other Standars Reports are there in SQL Server and how to open them, read previous blog post:
Standard Reports in SQL Server Management Studio
In Windows Event Viewer you can find the startup time of SQL Server service. Filter the Aplication Event Sources by instance name, and Event ID 17162:

sql server start time in event viewer
To find out the SQL Server instance start time in the current SQL Server error log in SQL Server Management Studio:
Management -> SQL Server Logs
Find the “SQL Server is starting” line at the bottom of the log. If the log was cycled, open previous logs until you find the SQL Server start time:
sql server start time in error log
You can query sys.dm_exec_sessions Dynamic Management View that shows information about all active connections and find out the login time of the Session Id 1, that is created when the SQL Server is started:
SELECT login_time
FROM sys.dm_exec_sessions WHERE session_id=1


The tempdb system database is re-created every time SQL Server starts, so by finding out the creation time of tempdb, you can find out the start time of SQL Server instance (database ID of tempdb database is always 2):
SELECT create_date
FROM sys.databases where database_id=2

sql server start time tempdb create time
If the Default Trace is not explicitly disabled on your SQL Server instance, you can find out the start time of SQL Server instance by finding out the start time of the Default Trace, because the Default Trace is started when the SQL Server is started:

SELECT start_time FROM sys.traces
WHERE is_default = 1

sql server start time default trace
In SQL Server 2008 and SQL Server 2012 you can query sys.dm_os_sys_info Dynamic Management View, but it requires VIEW SERVER STATE permission on the server:
SELECT sqlserver_start_time
FROM sys.dm_os_sys_info

sql server start time dmv
There is a small time difference between the results, depending on the method you used to determine the SQL Server start time.

No comments:

Post a Comment