Skip to content

Commit

Permalink
#884 add log file count check
Browse files Browse the repository at this point in the history
  • Loading branch information
jpomfret committed Jun 1, 2022
1 parent 027e4cc commit dbfd172
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
12 changes: 11 additions & 1 deletion checks/Databasev5.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -129,4 +129,14 @@ Describe "Virtual Log Files" -Tag VirtualLogFile, Medium, Database -ForEach $Ins
$psitem.VLF | Should -BeLessThan $psitem.ConfigValues.maxvlf -Because "Too many VLFs can impact performance and slow down backup/restore"
}
}
}
}

Describe "Log File Count Checks" -Tag LogfileCount, Medium, Database -ForEach $InstancesToTest {
$skip = Get-DbcConfigValue skip.database.logfilecounttest

Context "Testing Log File count for <_.Name>" {
It "Database <_.Name> should have <_.ConfigValues.logfilecount> or less log files on <_.SqlInstance>" -Skip:$skip -ForEach $psitem.Databases.Where{ if ($Database) { $_.Name -in $Database } else { $psitem.ConfigValues.logfilecountexclude -notcontains $PsItem.Name } } {
$psitem.LogFileCount | Should -BeLessOrEqual $psitem.ConfigValues.logfilecount -Because "You want the correct number of log files"
}
}
}
1 change: 1 addition & 0 deletions internal/configurations/configuration.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,7 @@ Set-PSFConfig -Module dbachecks -Name policy.asymmetrickeysize.excludedb -Value
Set-PSFConfig -Module dbachecks -Name policy.autoclose.excludedb -Value @() -Initialize -Description "Databases to exclude from autoclose key size checks"
Set-PSFConfig -Module dbachecks -Name policy.autoshrink.excludedb -Value @() -Initialize -Description "Databases to exclude from autoclose key size checks"
Set-PSFConfig -Module dbachecks -Name policy.vlf.excludedb -Value @('master', 'msdb', 'tempdb', 'model') -Initialize -Description "Databases to exclude from asymmetric key size checks"
Set-PSFConfig -Module dbachecks -Name policy.logfilecount.excludedb -Value @() -Initialize -Description "Databases to exclude from log file count checks"



Expand Down
7 changes: 6 additions & 1 deletion internal/functions/Get-AllDatabaseInfo.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,11 @@ function Get-AllDatabaseInfo {
$ConfigValues | Add-Member -MemberType NoteProperty -Name 'maxvlf' -Value (Get-DbcConfigValue policy.database.maxvlf)
$ConfigValues | Add-Member -MemberType NoteProperty -Name 'vlfexclude' -Value (Get-DbcConfigValue policy.vlf.excludedb)
}

'LogFileCount' {
$logfilecount = $true
$ConfigValues | Add-Member -MemberType NoteProperty -Name 'logfilecount' -Value (Get-DbcConfigValue policy.database.logfilecount)
$ConfigValues | Add-Member -MemberType NoteProperty -Name 'logfilecountexclude' -Value (Get-DbcConfigValue policy.logfilecount.excludedb)
}
Default { }
}

Expand All @@ -116,6 +120,7 @@ function Get-AllDatabaseInfo {
AutoClose = if ($autoclose) { $psitem.AutoClose}
AutoShrink = if ($autoshrink) { $psitem.AutoShrink}
VLF = if ($vlf) { ($psitem.Query("DBCC LOGINFO") | Measure-Object).Count }
LogFileCount = if ($logfilecount) { ($psitem.LogFiles | Measure-Object).Count }
}
}
}
Expand Down

0 comments on commit dbfd172

Please sign in to comment.