Read SQL Server Error Log on Linux System

Since I started blogging on SQL Server on Linux, I was asked a couple of questions on it. One of the most common questions was on SQL Server Error log. Therefore, I decided to write this blog. It may help you to explore all possible way to read the SQL Server Error Log file on a Linux System.

Before I demonstrate, I would like to emphasis – “It is really just SQL Server”; it does not matter whether it is running on Linux or Windows. The functionality of SQL Server remains same. Hat off to SQL Server product team who made it happen.

Let’s explore the methods to read SQL Server Error Log on a Linux system.

Method-1

  • Go to the default location of SQL Server Error Log file on a Linux machine

Syntax: cd /var/opt/mssql/log

Syntax: ls -l

01sqlservererrorloglocation

  •  Read the error log file using Linux command “cat”

Syntax: cat <errorfilename>

02readsqlservererrorlogviacat

Method-2

Syntax: xp_readerrorlog

02readsqlservererrorlogviassms

Method-3

a) Connect and read the error log data in one shot from SQL Server on Linux Instance using SQLCMD tool

Syntax: sqlcmd -S localhost -U <username> -P’password’ -Q “xp_readerrorlog”

05readsqlservererrorlogviasqlcmd

b) First connect to SQL Server on Linux Instance using SQLCMD tool and then read the error log file

Syntax: sqlcmd -S localhost -U <username> -P’password’

04readsqlservererrorlogviasqlcmd

Summary:

The above demonstrations confirm that the functionality of SQL Server remains same on the Linux system. When you read the SQL Server error log file from SQLCMD tool, you may face some difficulties because of text formatting issue. 

4 thoughts on “Read SQL Server Error Log on Linux System

  • Maruti Nandan

    Hi

    Reply
    • Dharmendra

      Hi Maruti, Let’s me know, if you have any question…

      Reply
  • Pavithra Kakarla

    Thank you for all your valuable posts regarding “SQL server on Linux”. These all are very useful Dharmendra.

    Reply
  • Dharmendra

    Thank you so much for your valuable input Pavithra!

    Reply

Leave a comment

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