Solved

Filtering errors in sql error logs

Posted on 2014-11-05
6
181 Views
Last Modified: 2014-11-28
Hello Guys,

As a part of our verification process after patching or reboot, we have to check SQL ERRORLOGS for any major errors(in all the servers where changes has been applied).
I'm using the following query of checking the errors:

EXEC xp_readerrorlog 0, 1, 'failure'

Open in new window


In place of 'failure', I use keywords like 'corrupt', 'failed', etc.
I just need suggesstion in this case as to what all things should I check related to database errors, service status, etc. If you could please tell me or suggest me some new kind of query that I can use to filter major error in the SQL errorlogs.

Also one more favor. Is it possible to access these logs from powershell? Since, we have to carry out this procedure on many servers, just to save time.

Thanks in advance
0
Comment
Question by:Abhinav Singh
  • 2
  • 2
  • 2
6 Comments
 
LVL 22

Expert Comment

by:Kelvin Sparks
Comment Utility
Rather than filter the log, grab it all and remove the uninteresting stuff, and look at the rest.

The code below is part of a stored proc I created based on examples from Redgate

 CREATE Table #ErrorLog2000
 (ErrorLog varchar(4000),ContinuationRow Int)
 INSERT INTO  #ErrorLog2000  -- Stores the output of sp_readerrorlog
 EXEC sp_readerrorlog
 /* The code below deletes the rows in the error log which are mostly
 the SQL startup messages written into the error log */
 
 DELETE FROM #ErrorLog2000
 WHERE (LEFT(LTRIM(ErrorLog),4) NOT LIKE DATEPART(YYYY,GETDATE())
    AND ContinuationRow = 0)
 OR (ErrorLog LIKE '%Intel X86%')
 OR (ErrorLog LIKE '%Copyright %')
 OR (ErrorLog LIKE '%Microsoft %')
 OR (ErrorLog LIKE '%All rights reserved.%')
 OR (ErrorLog LIKE '%Server Process ID is %')
 OR (ErrorLog LIKE '%Logging SQL Server messages in file %')
 OR (ErrorLog LIKE '%Errorlog has been reinitialized%')
 OR (ErrorLog LIKE '%Starting up database %')
 OR (ErrorLog LIKE '%SQL Server Listening %')
 OR (ErrorLog LIKE '%SQL Server is ready %')
 OR (ErrorLog LIKE '%Clearing tempdb %')
 OR (ErrorLog LIKE '%Recovery %')
 OR (ErrorLog LIKE '%to execute extended stored procedure %')
 OR (ErrorLog LIKE '%Analysis of database %')
 OR (ErrorLog LIKE '%Edition%')
 OR LEN(ErrorLog) < 25


You might like to add a filter here to delete anything older than the last hour or two.

I believe you could run this from Powershell, but I'm not a good Powershell coder.

Kelvin
0
 
LVL 18

Expert Comment

by:Raheman M. Abdul
Comment Utility
$servers = @("Server1","Server2","Server3)
$lookbehindduration = 120   # 2 hours ago to now.
foreach ($server in $servers)
{
Get-SqlErrorLog -sqlserver $server  |
Where-object { (     $_.logdate -ge ((Get-Date).addminutes(-$lookbehindduration)))`
                    -and $_.Text -match '(Error|Fail|IO requests taking longer|is full)' -and $_.Text -notmatch '(without errors|found 0 errors)'}Where-object { (   $_.logdate -ge ((Get-Date).addminutes(-$lookbehindduration)))`
                     -and ($_.text  -notlike '*found 0 errors*')`
                     -and ($_.text  -notlike '*without errors*')`
                     -and ( $_.text -like '*Error*' `
                     -or $_.text -like "*Fail*"`
                     -or $_.text -like "*dump*"`
                     -or $_.text -like '*IO requests taking longer*'`
                     -or $_.text -like '*is full*') `
             } | Out-GridView
}
0
 

Author Comment

by:Abhinav Singh
Comment Utility
Hello Guys,

I'm really for replying so late.

Kelvin Sparks thanks for replying.
For some reason I'm not able to execute your query and getting the following error:

Msg 213, Level 16, State 7, Procedure xp_readerrorlog, Line 1
Column name or number of supplied values does not match table definition.

Will it be possible for you to arrange the query properly.

Raheman Mohammed Abdul, thank you for providing such a great powershell script.
I'm getting the following error while trying to execute the script:

term 'Get-SqlErrorLog' is not recognized as the name of a cmdlet, function, script file, or operable program

Please look into this.
Again guys, thank you very much.
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 18

Expert Comment

by:Raheman M. Abdul
Comment Utility
The cmdlet "get-sqlErrorLog" is available from : http://sqlpsx.codeplex.com/   (SQL Server Powershell Extentions).
0
 
LVL 22

Accepted Solution

by:
Kelvin Sparks earned 500 total points
Comment Utility
Sorry, I'd given you the SQL Server 2000 version. Here is version for SQL Server 2005 or later

CREATE TABLE #ErrorLog2005
 (LogDate DATETIME, ProcessInfo VARCHAR(50) ,[Text] VARCHAR(4000))
 INSERT INTO #ErrorLog2005
 EXEC sp_readerrorlog
 DELETE FROM #ErrorLog2005
 WHERE ([Text] LIKE '%Intel X86%')
 OR ([Text] LIKE '%Copyright%')
 OR ([Text] LIKE '%All rights reserved.%')
 OR ([Text] LIKE '%Server Process ID is %')
 OR ([Text] LIKE '%Logging SQL Server messages in file %')
 OR ([Text] LIKE '%Errorlog has been reinitialized%')
 OR ([Text] LIKE '%This instance of SQL Server has been using a process ID %')
 OR ([Text] LIKE '%Starting up database %')
 OR ([Text] LIKE '%SQL Server Listening %')
 OR ([Text] LIKE '%SQL Server is ready %')
 OR ([Text] LIKE '%Clearing tempdb %')
 OR ([Text] LIKE '%to execute extended stored procedure %')
 OR ([Text] LIKE '%Analysis of database %')
 OR ProcessInfo = 'Backup' -- Deletes backup information
0
 

Author Comment

by:Abhinav Singh
Comment Utility
Hey Raheman,

Thanks for your reply.

Will it be possible for you to tell me how to configure the above ps1 file after downloading it?
I don't what to do, after downloading the files.
Kindly guide me in this matter.

Thank You.
0

Featured Post

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Join & Write a Comment

Suggested Solutions

Create and license users in Office 365 in bulk based on a CSV file. A step-by-step guide with PowerShell script examples.
For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
Via a live example, show how to setup several different housekeeping processes for a SQL Server.
Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now