Filtering errors in sql error logs

Posted on 2014-11-05
Medium Priority
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
Question by:Abhinav Singh
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
  • 2
LVL 22

Expert Comment

by:Kelvin Sparks
ID: 40425598
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
    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.

LVL 19

Expert Comment

by:Raheman M. Abdul
ID: 40426020
$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

Author Comment

by:Abhinav Singh
ID: 40438323
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.
10 Questions to Ask when Buying Backup Software

Choosing the right backup solution for your organization can be a daunting task. To make the selection process easier, ask solution providers these 10 key questions.

LVL 19

Expert Comment

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

Accepted Solution

Kelvin Sparks earned 1500 total points
ID: 40438485
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

Author Comment

by:Abhinav Singh
ID: 40441927
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.

Featured Post

Will your db performance match your db growth?

In Percona’s white paper “Performance at Scale: Keeping Your Database on Its Toes,” we take a high-level approach to what you need to think about when planning for database scalability.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A project that enables an administrator to perform actions within a user session context not just at the time of login but any time later on day(s) or week(s) later.
Auditing domain password hashes is a commonly overlooked but critical requirement to ensuring secure passwords practices are followed. Methods exist to extract hashes directly for a live domain however this article describes a process to extract u…
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.
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.
Suggested Courses

770 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