Home
%3CLINGO-SUB%20id%3D%22lingo-sub-1042647%22%20slang%3D%22en-US%22%3EHow%20to%20configure%20the%20number%20of%20error%20logs%20for%20your%20SQL%20Server%20instance%20on%20Linux%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1042647%22%20slang%3D%22en-US%22%3E%3CP%3EYou%20might%20have%20noticed%20in%20the%20past%20that%20the%20default%20behavior%20in%20SQL%20Server%20on%20Linux%20is%20to%20keep%20128%20error%20logs%20in%20the%20LOG%20folder.%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20style%3D%22width%3A%20848px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F159626i4E4268F18822EF99%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20alt%3D%22default%20behavior.PNG%22%20title%3D%22default%20behavior.PNG%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3EThis%20differs%20from%20the%20behavior%20on%20Windows%20where%20we%20keep%20only%206%20old%20error%20log%20files%20when%20you%20cycle%20them.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3ENow%20you%20have%20a%20mechanism%20to%20control%20how%20many%20error%20log%20files%20you%20want%20to%20retain%20in%20the%20LOG%20folder%20on%20Linux.%20You%20can%20install%20SQL%20Server%202019%20and%20then%20use%20the%20list%20option%20of%20%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fsql%2Flinux%2Fsql-server-linux-configure-mssql-conf%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noopener%20noreferrer%20noopener%20noreferrer%22%3Emssql-conf%3C%2FA%3E%20configuration%20utility%2C%20you%20will%20notice%20that%20we%20have%20a%20new%20option%20named%26nbsp%3B%3CSTRONG%3Eerrorlog.numerrorlogs%3C%2FSTRONG%3E.%3C%2FP%3E%0A%3CPRE%20class%3D%22lia-code-sample%20language-markup%22%3E%3CCODE%3Esudo%20%2Fopt%2Fmssql%2Fbin%2Fmssql-conf%20list%20%7C%20grep%20log%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20style%3D%22width%3A%20972px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F159627i08995431C186FD39%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20alt%3D%22mssql-conf%20list.PNG%22%20title%3D%22mssql-conf%20list.PNG%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EIf%20you%20want%20to%20retain%206%20error%20logs%20in%20the%20LOG%20folder%2C%20you%20will%20configure%20it%20as%20follows%3A%3C%2FP%3E%0A%3CPRE%20class%3D%22lia-code-sample%20language-markup%22%3E%3CCODE%3Esudo%20%2Fopt%2Fmssql%2Fbin%2Fmssql-conf%20set%20errorlog.numerrorlogs%206%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20style%3D%22width%3A%20738px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F159628i24BDFA72112EC9F4%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20alt%3D%22errorlog%20configure.PNG%22%20title%3D%22errorlog%20configure.PNG%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EYou%20can%20verify%20this%20from%20the%20configuration%20settings%20file%3A%3C%2FP%3E%0A%3CPRE%20class%3D%22lia-code-sample%20language-markup%22%3E%3CCODE%3Esudo%20cat%20%2Fvar%2Fopt%2Fmssql%2Fmssql.conf%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20style%3D%22width%3A%20560px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F159629i9D30034667873C2C%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20alt%3D%22verify%20errorlog.PNG%22%20title%3D%22verify%20errorlog.PNG%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EIf%20you%20attempt%20to%20configure%20an%20invalid%20value%2C%20you%20will%20encounter%20the%20following%20error%3A%3C%2FP%3E%0A%3CPRE%20class%3D%22lia-code-sample%20language-markup%22%3E%3CCODE%3Esudo%20%2Fopt%2Fmssql%2Fbin%2Fmssql-conf%20set%20errorlog.numerrorlogs%205%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20style%3D%22width%3A%20732px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F159630i44E99E8B9C5FEC6E%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20alt%3D%22invalid%20value.PNG%22%20title%3D%22invalid%20value.PNG%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3ENow%20you%20will%20notice%20that%20SQL%20Server%20cycles%20only%20the%20error%20logs%20up%20to%20errorlog.6%3A%3C%2FP%3E%0A%3CPRE%20class%3D%22lia-code-sample%20language-markup%22%3E%3CCODE%3Esudo%20ls%20-lt%20%2Fvar%2Fopt%2Fmssql%2Flog%2F%20%7C%20grep%20errorlog%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20style%3D%22width%3A%20639px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F159655i2DF90A97ECA0C26E%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20alt%3D%22log%20directory%20after%20config%20change.PNG%22%20title%3D%22log%20directory%20after%20config%20change.PNG%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EAfter%20you%20implement%20this%20configuration%20change%2C%20you%20have%20to%20manually%20get%20rid%20of%20the%20additional%20error%20log%20files%20that%20existed%20before%20this%20configuration%20change%20went%20into%20effect.%20In%20the%20above%20example%2C%20those%20would%20be%20errorlog.7%20onwards%20that%20needs%20to%20be%20manually%20cleaned.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EIf%20you%20need%20to%20reset%20the%20configuration%20to%20the%20defaults%2C%20you%20can%20use%20the%20following%20procedure%3A%3C%2FP%3E%0A%3CPRE%20class%3D%22lia-code-sample%20language-markup%22%3E%3CCODE%3Esudo%20%2Fopt%2Fmssql%2Fbin%2Fmssql-conf%20unset%20errorlog.numerrorlogs%0Asudo%20cat%20%2Fvar%2Fopt%2Fmssql%2Fmssql.conf%0Asudo%20systemctl%20restart%20mssql-server.service%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20style%3D%22width%3A%20720px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F159657i602142108802EF1F%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20alt%3D%22reset%20config.PNG%22%20title%3D%22reset%20config.PNG%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EIf%20you%20want%20to%20test%20all%20this%20on%20your%20dev%20or%20QA%20server%20where%20there%20is%20no%20production%20workload%20running%2C%20you%20can%20use%20a%20script%20like%20this%3A%3C%2FP%3E%0A%3CPRE%20class%3D%22lia-code-sample%20language-markup%22%3E%3CCODE%3E%23!%2Fbin%2Fbash%0A%23%20loop%20to%20restart%20sql%20server%20service%0A%0Acounter%3D1%0Awhile%20%5B%20%24counter%20-le%2010%20%5D%0Ado%0Aecho%20%24counter%0Asudo%20systemctl%20restart%20mssql-server%0Asleep%20120%0A((counter%2B%2B))%0Adone%0A%0Aecho%20End%20of%20loop%0A%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3ESave%20this%20snippet%20as%20a%20bash%20script%20file%20and%20execute%20it.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EHope%20this%20information%20is%20useful%20for%20you!%3C%2FP%3E%0A%3CP%3EThanks%3C%2FP%3E%0A%3CP%3ESuresh%20Kandoth%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-TEASER%20id%3D%22lingo-teaser-1042647%22%20slang%3D%22en-US%22%3E%3CP%3EAre%20you%20used%20to%20too%20many%20error%20logs%20for%20SQL%20Server%20on%20Linux%3F%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20style%3D%22width%3A%20848px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F159625iB2DEE778523C58B2%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20alt%3D%22default%20behavior.PNG%22%20title%3D%22default%20behavior.PNG%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3ENow%20we%20have%20a%20mechanism%20to%20control%20this%20with%20ease!%3C%2FP%3E%3C%2FLINGO-TEASER%3E%3CLINGO-LABS%20id%3D%22lingo-labs-1042647%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3ELinux%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3ESQL%202019%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E
Microsoft

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:

#!/bin/bash
# loop to restart sql server service

counter=1
while [ $counter -le 10 ]
do
echo $counter
sudo systemctl restart mssql-server
sleep 120
((counter++))
done

echo End of loop

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

 

Hope this information is useful for you!

Thanks

Suresh Kandoth