LiCongMingDeShujuku / 4-Ways-To-Check-Boot-Time-With-TSQL

4种用SQL检查启动时间的方法

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

CLEVER DATA GIT REPO

4种用SQL检查启动时间的方法

发布-日期: 2017年11月10日 (评论)

Check Boot Time With SQL

Contents

中文

很多时候我们需要检查服务器或者数据库的启动时间。参照下面的例子,有一个快速的脚本可以让你用4种有效的数据方式返回去检测包括sql服务器以及它的操作系统的启动时间。通过下面的例子我们可以清楚地看到当服务器重新启动的时候数据库是最后重启的。

English

Often times you’ll need to check server or database server start times. In this example; there is a quick script that will show you 4 valid types of date types that can be returned to detect the start time both of sql server, and the operating system. Here you can easily see that the database service was last restarted at the time when the server was rebooted.


Logic

use master;
set nocount on
 
declare @last_boot table ([os_boot] datetime, [first_session] datetime, [default_trace_start] datetime, [tempdb_created] datetime)
insert into @last_boot
select
    (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 create_date from sys.databases where name = 'tempdb')
 
select
    'boot_time'     		= left([os_boot], 19)
,   'days_since_boot'   	= datediff(day, [os_boot], getdate())
,   'sql__start'        	= left([tempdb_created], 19)
,   'days_since_sql_start'  = datediff(day, [os_boot], getdate())
,   'default_trace_start'   = left([default_trace_start], 19)
,   'first_session'     	= left([first_session], 19)
from
    @last_boot

WorksEveryTime

Build-Info

Build Quality Build History
Build-Status
Coverage
Nuget
Build history

Author

  • 李聪明的数据库 Lee's Clever Data
  • Mike的数据库宝典 Mikes Database Collection
  • 李聪明的数据库 "Lee Songming"

Gist Twitter Wordpress


License

LicenseCCSA

Lee Songming

About

4种用SQL检查启动时间的方法


Languages

Language:TSQL 100.0%