Filtering errors in sql error logs

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
Abhinav SinghSoftware EngineerAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Kelvin SparksCommented:
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
Raheman M. AbdulSenior Infrastructure Support Analyst & Systems DeveloperCommented:
$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
Abhinav SinghSoftware EngineerAuthor Commented:
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
Has Powershell sent you back into the Stone Age?

If managing Active Directory using Windows Powershell® is making you feel like you stepped back in time, you are not alone.  For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why.

Raheman M. AbdulSenior Infrastructure Support Analyst & Systems DeveloperCommented:
The cmdlet "get-sqlErrorLog" is available from : http://sqlpsx.codeplex.com/   (SQL Server Powershell Extentions).
0
Kelvin SparksCommented:
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Abhinav SinghSoftware EngineerAuthor Commented:
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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft SQL Server

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.