Skip to content

Commit

Permalink
autoclose - #884
Browse files Browse the repository at this point in the history
  • Loading branch information
jpomfret committed May 27, 2022
1 parent 57cd8dd commit c9ced52
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 0 deletions.
9 changes: 9 additions & 0 deletions checks/Databasev5.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -110,4 +110,13 @@ Describe "Auto Close" -Tag AutoClose, High, Database -ForEach $InstancesToTest {
$psitem.AutoClose | Should -Be $psitem.ConfigValues.autoclose -Because "Because!"
}
}
}

Describe "Auto Shrink" -Tag AutoShrink, High, Database -ForEach $InstancesToTest {
$skip = Get-DbcConfigValue skip.database.autoshrink
Context "Testing Auto Shrink on <_.Name>" {
It "Database <_.Name> should have Auto Shrink set to <_.ConfigValues.autoshrink> on <_.SqlInstance>" -Skip:$skip -ForEach $psitem.Databases.Where{ if ($Database) { $_.Name -in $Database } else { $psitem.ConfigValues.autoshrinkexclude -notcontains $PsItem.Name } } {
$psitem.AutoShrink | Should -Be $psitem.ConfigValues.autoshrink -Because "Shrinking databases causes fragmentation and performance issues"
}
}
}
1 change: 1 addition & 0 deletions internal/configurations/configuration.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,7 @@ Set-PSFConfig -Module dbachecks -Name policy.build.behind -Value $null -Initiali
# exclude databases
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"



Expand Down
7 changes: 7 additions & 0 deletions internal/functions/Get-AllDatabaseInfo.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,12 @@ function Get-AllDatabaseInfo {
$ConfigValues | Add-Member -MemberType NoteProperty -Name 'autocloseexclude' -Value (Get-DbcConfigValue policy.autoclose.excludedb)
}

'AutoShrink' {
$autoshrink = $true
$ConfigValues | Add-Member -MemberType NoteProperty -Name 'autoshrink' -Value (Get-DbcConfigValue policy.database.autoshrink)
$ConfigValues | Add-Member -MemberType NoteProperty -Name 'autoshrinkexclude' -Value (Get-DbcConfigValue policy.autoshrinke.excludedb)
}

'ValidDatabaseOwner' {
$owner = $true
$ConfigValues | Add-Member -MemberType NoteProperty -Name 'validdbownername' -Value (Get-DbcConfigValue policy.validdbowner.name)
Expand Down Expand Up @@ -103,6 +109,7 @@ function Get-AllDatabaseInfo {
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}
}
}
}
Expand Down

0 comments on commit c9ced52

Please sign in to comment.