From bc2b135336bdcec85d658e160cf7319f82ce2a74 Mon Sep 17 00:00:00 2001 From: jpomfret Date: Wed, 1 Jun 2022 12:45:50 +0100 Subject: [PATCH] #884 - adding VLF. --- checks/Databasev5.Tests.ps1 | 10 ++++++++++ internal/configurations/configuration.ps1 | 2 ++ internal/functions/Get-AllDatabaseInfo.ps1 | 6 ++++++ 3 files changed, 18 insertions(+) diff --git a/checks/Databasev5.Tests.ps1 b/checks/Databasev5.Tests.ps1 index b6de8527..a680688e 100644 --- a/checks/Databasev5.Tests.ps1 +++ b/checks/Databasev5.Tests.ps1 @@ -119,4 +119,14 @@ Describe "Auto Shrink" -Tag AutoShrink, High, Database -ForEach $InstancesToTest $psitem.AutoShrink | Should -Be $psitem.ConfigValues.autoshrink -Because "Shrinking databases causes fragmentation and performance issues" } } +} + +Describe "Virtual Log Files" -Tag VirtualLogFile, Medium, Database -ForEach $InstancesToTest { + $skip = Get-DbcConfigValue skip.database.vlf + + Context "Testing Database VLFs on <_.Name>" { + It "Database <_.Name> VLF count should be less than <_.ConfigValues.maxvlf> on <_.SqlInstance>" -Skip:$skip -ForEach $psitem.Databases.Where{ if ($Database) { $_.Name -in $Database } else { $psitem.ConfigValues.vlfexclude -notcontains $PsItem.Name } } { + $psitem.VLF | Should -BeLessThan $psitem.ConfigValues.maxvlf -Because "Too many VLFs can impact performance and slow down backup/restore" + } + } } \ No newline at end of file diff --git a/internal/configurations/configuration.ps1 b/internal/configurations/configuration.ps1 index 9c646ac5..c237f3d0 100644 --- a/internal/configurations/configuration.ps1 +++ b/internal/configurations/configuration.ps1 @@ -232,6 +232,7 @@ Set-PSFConfig -Module dbachecks -Name policy.build.behind -Value $null -Initiali Set-PSFConfig -Module dbachecks -Name policy.asymmetrickeysize.excludedb -Value @('master', 'msdb', 'tempdb') -Initialize -Description "Databases to exclude from asymmetric key size checks" 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" @@ -258,6 +259,7 @@ Set-PSFConfig -Module dbachecks -Name skip.database.invaliddatabaseowner -Valida Set-PSFConfig -Module dbachecks -Name skip.database.databasecollation -Validation bool -Value $false -Initialize -Description "Skip the database collation test" Set-PSFConfig -Module dbachecks -Name skip.database.suspectpage -Validation bool -Value $false -Initialize -Description "Skip the suspect pages test" Set-PSFConfig -Module dbachecks -Name skip.database.autoclose -Validation bool -Value $false -Initialize -Description "Skip the autoclose test" +Set-PSFConfig -Module dbachecks -Name skip.database.vlf -Validation bool -Value $false -Initialize -Description "Skip the virtual log file test" Set-PSFConfig -Module dbachecks -Name skip.logshiptesting -Validation bool -Value $false -Initialize -Description "Skip the logshipping test" diff --git a/internal/functions/Get-AllDatabaseInfo.ps1 b/internal/functions/Get-AllDatabaseInfo.ps1 index 8f5e9e0b..39e6d6d3 100644 --- a/internal/functions/Get-AllDatabaseInfo.ps1 +++ b/internal/functions/Get-AllDatabaseInfo.ps1 @@ -87,6 +87,11 @@ function Get-AllDatabaseInfo { $suspectPage = $true $ConfigValues | Add-Member -MemberType NoteProperty -Name 'suspectpageexclude' -Value (Get-DbcConfigValue policy.suspectpage.excludedb) } + 'VirtualLogFile' { + $vlf = $true + $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) + } Default { } } @@ -110,6 +115,7 @@ function Get-AllDatabaseInfo { #AsymmetricKeySize = if ($asymmetrickey) { $psitem.AsymmetricKeys.KeyLength } # doing this I got $null if there wasn't a key AutoClose = if ($autoclose) { $psitem.AutoClose} AutoShrink = if ($autoshrink) { $psitem.AutoShrink} + VLF = if ($vlf) { ($psitem.Query("DBCC LOGINFO") | Measure-Object).Count } } } }