Skip to content

Commit

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



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

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

}

0 comments on commit ae1344b

Please sign in to comment.