July 18, 2017 at 6:29 am
Though there are different ways to find when sql server was rebooted couple of times earlier. But is there any query we can use to find the last 5/6 occurrences when sql was restarted?
Thanks.
July 18, 2017 at 6:45 am
The SQL Error Log has what you are looking for
Every time an instance is restarted, the previous log is closed and marked as archived, and the new one is started; the default is ten log files.
Lowell
July 18, 2017 at 6:48 am
Or look in the Windows Event log for the Windows events around shutdown and restart.
Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability
July 18, 2017 at 6:57 am
Lowell - Tuesday, July 18, 2017 6:45 AMThe SQL Error Log has what you are looking for
Every time an instance is restarted, the previous log is closed and marked as archived, and the new one is started; the default is ten log files.
Thanks Lowell. In this approach the problem is, if someone runs (sp_cycle_errorlog) that also will come here as a new file.
Thanks.
July 18, 2017 at 7:02 am
You can use PowerShell for the machine
Get-EventLog -LogName system | where {$_.eventid -eq 6006}
will show the Event Log Service was stopped
Get-EventLog -LogName system | where {$_.eventid -eq 6005}
shows when the event log service was started
Get-EventLog -LogName system | where {$_.eventid -eq 1074}
will show the process X has initiated a restart/shutdown etc
You can add a -ComputerName paramter if you are querying a remote server
Get-EventLog -ComputerName SERVER -LogName system | where {$_.eventid -eq 6006}
https://blog.robsewell.com Its where I blog
SQL Community Slack Channel https://sqlps.io/slack
The Best PowerShell Module for the Modern SQL DBA https://dbatools.io
Data South West User Group http://sqlsouthwest.co.uk/[/url]
July 18, 2017 at 7:15 am
Thank you everyone!!
Getting the results back using the Powershell.
Thanks.
July 18, 2017 at 7:22 am
SQL-DBA-01 - Tuesday, July 18, 2017 6:57 AMThanks Lowell. In this approach the problem is, if someone runs (sp_cycle_errorlog) that also will come here as a new file.
This is true, but there is no other way (Gail lists one too, but it's also subject to purging) to determine this. Control your logs so that you know when they're being recycled. If you have to have a perfect record of something, then don't rely on built-in processes. Set up your own to capture this information over time to something more persistant.
"The credit belongs to the man who is actually in the arena, whose face is marred by dust and sweat and blood"
- Theodore Roosevelt
Author of:
SQL Server Execution Plans
SQL Server Query Performance Tuning
July 18, 2017 at 7:31 am
Grant Fritchey - Tuesday, July 18, 2017 7:22 AMSQL-DBA-01 - Tuesday, July 18, 2017 6:57 AMThanks Lowell. In this approach the problem is, if someone runs (sp_cycle_errorlog) that also will come here as a new file.This is true, but there is no other way (Gail lists one too, but it's also subject to purging) to determine this. Control your logs so that you know when they're being recycled. If you have to have a perfect record of something, then don't rely on built-in processes. Set up your own to capture this information over time to something more persistant.
Doing this should be pretty straightforward. I'd create a stored procedure to write a row to a table only the DBAs can access. Then create a job that runs when SQL Server starts up to execute the procedure. You can add steps to do anything else you want to do when the instance starts up.
July 18, 2017 at 7:31 am
Thanks Grant. However we dont need a complete tracking. Just for few adhoc cases to monitor we needed sometimes the complete log. That helps a lot to write the investigation report. Thanks for the advise anyways.
Thanks.
July 18, 2017 at 7:40 am
Of course if I read the question carefully and see SQL and not Server then what you can do is
$Instance = 'DAVE'
$Server = ''
if($Instance -eq 'MSSQLSERVER' -or $Instance -eq 'DEFAULT'){ $Source = 'MSSQLSERVER' }else{ $Source = "MSSQL*$Instance"}
Get-EventLog -LogName Application -ComnputerName $server | Where-Object {$_.EntryType -eq 'Information' -and $_.Source -like $Source -and $_.Message -like "*Starting up database 'master'*" }
Then this will show when SQL was started by identifying the master database starting from the Application Event Log
https://blog.robsewell.com Its where I blog
SQL Community Slack Channel https://sqlps.io/slack
The Best PowerShell Module for the Modern SQL DBA https://dbatools.io
Data South West User Group http://sqlsouthwest.co.uk/[/url]
Viewing 10 posts - 1 through 9 (of 9 total)
You must be logged in to reply to this topic. Login to reply