Author | Shawn Melton (@wsmelton), wsmelton.github.com |
Availability | Windows, Linux, macOS |
Want to see the source code for this command? Check out Set-DbaErrorLogConfig on GitHub.
Want to see the Bill Of Health for this command? Check out Set-DbaErrorLogConfig.
Configures SQL Server error log retention and size rollover settings
Configures how SQL Server manages its error log files by setting retention count and automatic rollover size. You can specify how many error log files to keep (6-99) across all SQL Server versions, and set the file size limit in KB for automatic rollover on SQL Server 2012 and later.
This helps DBAs manage disk space and ensure adequate error log history for troubleshooting without manual intervention. When a log file reaches the specified size limit, SQL Server automatically creates a new error log and archives the previous one.
To set the Path to the ErrorLog, use Set-DbaStartupParameter -ErrorLog. Note that this command requires
remote, administrative access to the Windows/WMI server, similar to SQL Configuration Manager.
Set-DbaErrorLogConfig
[-SqlInstance] <DbaInstanceParameter[]>
[[-SqlCredential] <PSCredential>]
[[-LogCount] <Int32>]
[[-LogSize] <Int32>]
[-EnableException]
[-WhatIf]
[-Confirm]
[<CommonParameters>]
PS C:\> Set-DbaErrorLogConfig -SqlInstance sql2017,sql2014 -LogCount 25
Sets the number of error log files to 25 on sql2017 and sql2014
PS C:\> Set-DbaErrorLogConfig -SqlInstance sql2014 -LogSize 102400
Sets the size of the error log file, before it rolls over, to 102400 KB (100 MB) on sql2014
PS C:\> Set-DbaErrorLogConfig -SqlInstance sql2012 -LogCount 25 -LogSize 500
Sets the number of error log files to 25 and size before it will roll over to 500 KB on sql2012
The target SQL Server instance or instances
Alias | |
Required | True |
Pipeline | true (ByPropertyName) |
Default Value |
Login to the target instance using alternative credentials. Accepts PowerShell credentials (Get-Credential).
Windows Authentication, SQL Server Authentication, Active Directory - Password, and Active Directory - Integrated are all supported.
For MFA support, please use Connect-DbaInstance.
Alias | |
Required | False |
Pipeline | false |
Default Value |
Sets the number of error log files SQL Server retains before deleting the oldest ones. Must be between 6 and 99.
Use this to balance disk space with troubleshooting history - more files provide longer history but consume more disk space.
Alias | |
Required | False |
Pipeline | false |
Default Value | 0 |
Sets the maximum size in KB for each error log file before SQL Server automatically creates a new log file. Only available on SQL Server 2012 and later.
Use this to prevent error logs from growing too large and to ensure regular log rotation without manual intervention.
Alias | |
Required | False |
Pipeline | false |
Default Value | 0 |
By default, when something goes wrong we try to catch it, interpret it and give you a friendly warning message.
This avoids overwhelming you with "sea of red" exceptions, but is inconvenient because it basically disables advanced scripting.
Using this switch turns this "nice by default" feature off and enables you to catch exceptions with your own try/catch.
Alias | |
Required | False |
Pipeline | false |
Default Value | False |
If this switch is enabled, no actions are performed but informational messages will be displayed that explain what would happen if the command were to run.
Alias | wi |
Required | False |
Pipeline | false |
Default Value |
If this switch is enabled, you will be prompted for confirmation before executing any operations that change state.
Alias | cf |
Required | False |
Pipeline | false |
Default Value |