diff --git a/checks/Databasev5.Tests.ps1 b/checks/Databasev5.Tests.ps1 index 3760d6c1..e35567ec 100644 --- a/checks/Databasev5.Tests.ps1 +++ b/checks/Databasev5.Tests.ps1 @@ -160,3 +160,13 @@ Describe "Auto Update Statistics" -Tag AutoUpdateStatistics, Low, Database -ForE } } } + +Describe "Auto Update Statistics Asynchronously" -Tag AutoUpdateStatisticsAsynchronously, Low, Database -ForEach $InstancesToTest { + $skip = Get-DbcConfigValue skip.database.autoupdatestatisticsasynchronously + + Context "Testing Auto Update Statistics Asynchronously on <_.Name>" { + It "Database <_.Name> should have Auto Update Statistics Asynchronously set to <_.ConfigValues.autoupdatestatsasync> on <_.SqlInstance>" -Skip:$skip -ForEach $psitem.Databases.Where{ if ($Database) { $_.Name -in $Database } else { $psitem.ConfigValues.autoupdatestatsasyncexclude -notcontains $PsItem.Name } } { + $psitem.AutoUpdateStatisticsAsync | Should -Be $psitem.ConfigValues.autoupdatestatsasync -Because "This value is expected for autoupdate statistics asynchronously" + } + } +} \ No newline at end of file diff --git a/internal/configurations/configuration.ps1 b/internal/configurations/configuration.ps1 index 51f32922..f754aca7 100644 --- a/internal/configurations/configuration.ps1 +++ b/internal/configurations/configuration.ps1 @@ -234,8 +234,9 @@ 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" -Set-PSFConfig -Module dbachecks -Name policy.autoupdatestats.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 the auto create stats checks" +Set-PSFConfig -Module dbachecks -Name policy.autoupdatestats.excludedb -Value @() -Initialize -Description "Databases to exclude from the auto update stats checks" +Set-PSFConfig -Module dbachecks -Name policy.autoupdatestatisticsasynchronously.excludedb -Value @() -Initialize -Description "Databases to exclude from the auto update stats asynchronously checks" @@ -265,6 +266,7 @@ Set-PSFConfig -Module dbachecks -Name skip.database.autoclose -Validation bool - 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.autocreatestatistics -Validation bool -Value $false -Initialize -Description "Skip the auto create statistics test" Set-PSFConfig -Module dbachecks -Name skip.database.autoupdatestatistics -Validation bool -Value $false -Initialize -Description "Skip the auto update statistics test" +Set-PSFConfig -Module dbachecks -Name skip.database.autoupdatestatisticsasynchronously -Validation bool -Value $false -Initialize -Description "Skip the auto update statistics asynchronously 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 4af55ac3..71d77b0f 100644 --- a/internal/functions/Get-AllDatabaseInfo.ps1 +++ b/internal/functions/Get-AllDatabaseInfo.ps1 @@ -107,6 +107,11 @@ function Get-AllDatabaseInfo { $ConfigValues | Add-Member -MemberType NoteProperty -Name 'autoupdatestats' -Value (Get-DbcConfigValue policy.database.autoupdatestatistics) $ConfigValues | Add-Member -MemberType NoteProperty -Name 'autoupdatestatsexclude' -Value (Get-DbcConfigValue policy.autoupdatestats.excludedb) } + 'AutoUpdateStatisticsAsynchronously' { + $autoupdatestatsasync = $true + $ConfigValues | Add-Member -MemberType NoteProperty -Name 'autoupdatestatsasync' -Value (Get-DbcConfigValue policy.database.autoupdatestatisticsasynchronously) + $ConfigValues | Add-Member -MemberType NoteProperty -Name 'autoupdatestatsasyncexclude' -Value (Get-DbcConfigValue policy.autoupdatestatisticsasynchronously.excludedb) + } Default { } } @@ -118,21 +123,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 so counting ones that are too short - AutoClose = if ($autoclose) { $psitem.AutoClose} - AutoCreateStatistics = if ($autocreatestats) { $psitem.AutoCreateStatisticsEnabled } - AutoUpdateStatistics = if ($autoupdatestats) { $psitem.AutoUpdateStatisticsEnabled } - 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 } + AutoUpdateStatistics = if ($autoupdatestats) { $psitem.AutoUpdateStatisticsEnabled } + AutoUpdateStatisticsAsync = if ($autoupdatestatsasync) { $psitem.AutoUpdateStatisticsAsync } + AutoShrink = if ($autoshrink) { $psitem.AutoShrink} + VLF = if ($vlf) { ($psitem.Query("DBCC LOGINFO") | Measure-Object).Count } + LogFileCount = if ($logfilecount) { ($psitem.LogFiles | Measure-Object).Count } } } }