diff --git a/checks/Databasev5.Tests.ps1 b/checks/Databasev5.Tests.ps1 index dcb4383a..bfb2172f 100644 --- a/checks/Databasev5.Tests.ps1 +++ b/checks/Databasev5.Tests.ps1 @@ -140,3 +140,13 @@ Describe "Log File Count Checks" -Tag LogfileCount, Medium, Database -ForEach $I } } } + +Describe "Auto Create Statistics" -Tag AutoCreateStatistics, Low, Database -ForEach $InstancesToTest { + $skip = Get-DbcConfigValue skip.database.autocreatestats + + Context "Testing Auto Create Statistics for <_.Name>" { + It "Database <_.Name> should have Auto Create Statistics set to <_.ConfigValues.autocreatestats> on <_.SqlInstance>" -Skip:$skip -ForEach $psitem.Databases.Where{ if ($Database) { $_.Name -in $Database } else { $psitem.ConfigValues.autocreatestatsexclude -notcontains $PsItem.Name } } { + $psitem.AutoCreateStatistics | Should -Be $psitem.ConfigValues.autocreatestats -Because "This value is expected for autocreate statistics" + } + } +} diff --git a/internal/configurations/configuration.ps1 b/internal/configurations/configuration.ps1 index 4957dc61..354e1351 100644 --- a/internal/configurations/configuration.ps1 +++ b/internal/configurations/configuration.ps1 @@ -234,6 +234,7 @@ Set-PSFConfig -Module dbachecks -Name policy.autoclose.excludedb -Value @() -In 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" +Set-PSFConfig -Module dbachecks -Name policy.autocreatestats.excludedb -Value @() -Initialize -Description "Databases to exclude from log file count checks" @@ -261,6 +262,7 @@ Set-PSFConfig -Module dbachecks -Name skip.database.databasecollation -Validatio 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.database.autocreatestats -Validation bool -Value $false -Initialize -Description "Skip the auto create statistics 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 f12f918b..e78097eb 100644 --- a/internal/functions/Get-AllDatabaseInfo.ps1 +++ b/internal/functions/Get-AllDatabaseInfo.ps1 @@ -97,6 +97,11 @@ function Get-AllDatabaseInfo { $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) } + 'AutoCreateStatistics' { + $autocreatestats = $true + $ConfigValues | Add-Member -MemberType NoteProperty -Name 'autocreatestats' -Value (Get-DbcConfigValue policy.database.autocreatestatistics) + $ConfigValues | Add-Member -MemberType NoteProperty -Name 'autocreatestatsexclude' -Value (Get-DbcConfigValue policy.autocreatestats.excludedb) + } Default { } } @@ -108,22 +113,22 @@ function Get-AllDatabaseInfo { ConfigValues = $ConfigValues # can we move this out to here? Databases = $Instance.Databases.Foreach{ [PSCustomObject]@{ - Name = $psitem.Name - SqlInstance = $Instance.Name - Owner = if ($owner) { $psitem.owner } - ServerCollation = if ($collation) { $Instance.collation } - Collation = if ($collation) { $psitem.collation } - SuspectPage = if ($suspectPage) { (Get-DbaSuspectPage -SqlInstance $Instance -Database $psitem.Name | Measure-Object).Count } - ConfigValues = $ConfigValues # can we move this out? - AsymmetricKeySize = if ($asymmetrickey) { ($psitem.AsymmetricKeys | Where-Object { $_.KeyLength -lt 2048} | Measure-Object).Count } - #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 } - LogFileCount = if ($logfilecount) { ($psitem.LogFiles | Measure-Object).Count } + Name = $psitem.Name + SqlInstance = $Instance.Name + Owner = if ($owner) { $psitem.owner } + ServerCollation = if ($collation) { $Instance.collation } + Collation = if ($collation) { $psitem.collation } + SuspectPage = if ($suspectPage) { (Get-DbaSuspectPage -SqlInstance $Instance -Database $psitem.Name | Measure-Object).Count } + ConfigValues = $ConfigValues # can we move this out? + AsymmetricKeySize = if ($asymmetrickey) { ($psitem.AsymmetricKeys | Where-Object { $_.KeyLength -lt 2048} | Measure-Object).Count } + #AsymmetricKeySize = if ($asymmetrickey) { $psitem.AsymmetricKeys.KeyLength } # doing this I got $null if there wasn't a key so counting ones that are too short + AutoClose = if ($autoclose) { $psitem.AutoClose} + AutoCreateStatistics = if ($autocreatestats) { $psitem.AutoCreateStatisticsEnabled } + AutoShrink = if ($autoshrink) { $psitem.AutoShrink} + VLF = if ($vlf) { ($psitem.Query("DBCC LOGINFO") | Measure-Object).Count } + LogFileCount = if ($logfilecount) { ($psitem.LogFiles | Measure-Object).Count } } } } return $testInstanceObject -} - +} \ No newline at end of file