Thursday , March 28 2024

How To Filter SQL Server Error Log(Like or Not Like)

 

The SQL Server Error Log file is one of the first places each DBA looks at in order to understand and solve the problem.

In this article, we will examine the below scenarios.

  • How to read the entire Error Log file without a filter
  • How to read Error Log file by filtering.

 

As you can see in the picture below, you can read the Error Log file without a filter.

 

When the Error Log File opens, you can create a filter by clicking on the Filter as you see below.

 

In the “Message contains text” section, type the word you want to search for in the error log file, click “Apply filter”, and then click ok.

When we did this, the result was returned as follows.

 

When the “Error Log” file is too complicated, we can filter what we want to see.

Sometimes we need to filter what we don’t want to see. In this way, you can read the error log file, which is free of unnecessary information.

You can perform this operation with the help of the following script.

 

As you can see in the script, the script part of “EXEC master.dbo.Xp_readerrorlog” is used to read the entire Error Log file.

We have run the above script with many parameters.

Below are the descriptions of these parameters.

 
First Parameter 0This means we’re reading the current active log file. I recommend that you read the article “How to Increase SQL Server Error Log File Count” about the SQL Server Error Log file count.
Second Parameter 1This means that we have read SQL Server Error Log. If there were 2, we would be reading the SQL Server Agent Error Log.
Third Parameter N”This is the word we want to filter in the Message part in the Error Log. We did not select this option by typing N ”.
Fourth Parameter N”Same as the third parameter. If you want to search with more than one word, you set your second filter in this parameter. We did not select this option by typing N ”.
Fifth Parameter ‘20160922 00:00’Starting date.
Sixth Parameter ‘20160924’Finish date.

 

In the rest of the script, you see “where errorlogtext not like” statements. We’re writing the expressions that we don’t want to see in the log file with these not like expressions.

At the end of the query, you can increase the number of queries that you do not want to see by adding AND NOT LIKE. In this way, we only get an Error Log file that will contain the information we need.

Loading

About dbtut

We are a team with over 10 years of database management and BI experience. Our Expertises: Oracle, SQL Server, PostgreSQL, MySQL, MongoDB, Elasticsearch, Kibana, Grafana.

Leave a Reply

Your email address will not be published. Required fields are marked *

Categories