Solved

Filtering errors in sql error logs

Posted on 2014-11-05
6
184 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
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
 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 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
}
0
 

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.
0
Zoho SalesIQ

Hassle-free live chat software re-imagined for business growth. 2 users, always free.

 
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).
0
 
LVL 22

Accepted Solution

by:
Kelvin Sparks earned 500 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
0
 

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.
0

Featured Post

Are your AD admin tools letting you down?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Solution for warm standby SQL server 20 37
Powershell script 13 60
sql Total query 2 16
C# guarantee sql connection close 6 13
Utilizing an array to gracefully append to a list of EmailAddresses
This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
Using examples as well as descriptions, and references to Books Online, show the different Recovery Models available in SQL Server and explain, as well as show how full, differential and transaction log backups are performed
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.

911 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

22 Experts available now in Live!

Get 1:1 Help Now