Skip to content

Commit

Permalink
#884 add auto stats async check
Browse files Browse the repository at this point in the history
  • Loading branch information
jpomfret committed Jun 5, 2022
1 parent 79f39f7 commit 4f4759a
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 17 deletions.
10 changes: 10 additions & 0 deletions checks/Databasev5.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
}
6 changes: 4 additions & 2 deletions internal/configurations/configuration.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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"



Expand Down Expand Up @@ -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"
Expand Down
36 changes: 21 additions & 15 deletions internal/functions/Get-AllDatabaseInfo.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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 { }
}

Expand All @@ -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 }
}
}
}
Expand Down

0 comments on commit 4f4759a

Please sign in to comment.