How to configure the number of error logs for your SQL Server instance on Linux
Published Dec 02 2019 02:23 PM 2,983 Views

You might have noticed in the past that the default behavior in SQL Server on Linux is to keep 128 error logs in the LOG folder.

default behavior.PNG

This differs from the behavior on Windows where we keep only 6 old error log files when you cycle them.


Now you have a mechanism to control how many error log files you want to retain in the LOG folder on Linux. You can install SQL Server 2019 and then use the list option of mssql-conf configuration utility, you will notice that we have a new option named errorlog.numerrorlogs.

sudo /opt/mssql/bin/mssql-conf list | grep log

mssql-conf list.PNG


If you want to retain 6 error logs in the LOG folder, you will configure it as follows:

sudo /opt/mssql/bin/mssql-conf set errorlog.numerrorlogs 6

errorlog configure.PNG


You can verify this from the configuration settings file:

sudo cat /var/opt/mssql/mssql.conf

verify errorlog.PNG


If you attempt to configure an invalid value, you will encounter the following error:

sudo /opt/mssql/bin/mssql-conf set errorlog.numerrorlogs 5

invalid value.PNG


Now you will notice that SQL Server cycles only the error logs up to errorlog.6:

sudo ls -lt /var/opt/mssql/log/ | grep errorlog

log directory after config change.PNG


After you implement this configuration change, you have to manually get rid of the additional error log files that existed before this configuration change went into effect. In the above example, those would be errorlog.7 onwards that needs to be manually cleaned.


If you need to reset the configuration to the defaults, you can use the following procedure:

sudo /opt/mssql/bin/mssql-conf unset errorlog.numerrorlogs
sudo cat /var/opt/mssql/mssql.conf
sudo systemctl restart mssql-server.service

reset config.PNG


If you want to test all this on your dev or QA server where there is no production workload running, you can use a script like this:

# loop to restart sql server service

while [ $counter -le 10 ]
echo $counter
sudo systemctl restart mssql-server
sleep 120

echo End of loop

Save this snippet as a bash script file and execute it.


Hope this information is useful for you!


Suresh Kandoth

Version history
Last update:
‎Dec 02 2019 03:57 PM
Updated by: