Microsoft SQL Server
TMA-MSSQL-5.1
Ensure 'Maximum number of error log files' is set to greater than or equal to '12'
說明
SQL Server error log files must be protected from loss. The log files must be backed up before they are overwritten. Retaining more error logs helps prevent loss from frequent recycling before backups can occur. Follows the benchmark T-SQL method: NumErrorLogs >= 12, or -1 (registry value absent) is accepted as the benchmark states; note that an absent value means SQL Server keeps its default of 6 logs, so set the value explicitly. Default: 6 SQL Server error log files in addition to the current error log file are retained by default. Runs one sqlcmd query with its defaults (Windows authentication to the local default instance); set SQLCMDSERVER, SQLCMDUSER and SQLCMDPASSWORD for another instance or SQL authentication. Needs VIEW SERVER STATE / sysadmin-level read access.
檢查方式
稽核方法: SQL 查詢
sqlcmd -b -h -1 -W -Q "SET NOCOUNT ON; DECLARE @n int; EXEC master.sys.xp_instance_regread N'HKEY_LOCAL_MACHINE', N'Software\Microsoft\MSSQLServer\MSSQLServer', N'NumErrorLogs', @n OUTPUT; SELECT CASE WHEN ISNULL(@n, -1) = -1 OR @n >= 12 THEN 'compliant' ELSE 'noncompliant' END;"- 預期輸出
compliant
修補方式
修補方法: 操作指南或基礎設施修補檔
Adjust the number of logs to prevent data loss. The default value of 6 may be insufficient for a production environment. Perform either the GUI or T-SQL method shown: GUI Method 1. Open SQL Server Management Studio. 2. Open Object Explorer and connect to the target instance. 3. Navigate to the Management tab in Object Explorer and expand. Right click on the SQL Server Logs file and select Configure 4. Check the Limit the number of error log files before they are recycled 5. Set the Maximum number of error log files to greater than or equal to 12 T-SQL Method Run the following T-SQL to change the number of error log files, replace <NumberGreaterThan11> with your desired number of error log files: EXEC master.sys.xp_instance_regwrite N'HKEY_LOCAL_MACHINE', N'Software\Microsoft\MSSQLServer\MSSQLServer', N'NumErrorLogs', REG_DWORD, <NumberGreaterThan11>;
屬性
- 作業系統
- 不限
- 標籤
- mssqldatabaselogging
- 參考資料
- CIS Microsoft SQL Server 2025 Benchmark v1.0.0 - 5.1 Ensure 'Maximum number of error log files' is set to greater than or equal to '12'
檢查此主機
請在您有權稽核的機器上執行此指令。掃描為唯讀操作。
tmaegis scan --target mssql