diff --git a/source/checks/Instancev5.Tests.ps1 b/source/checks/Instancev5.Tests.ps1 index 7ed8eb58..59bcfd2b 100644 --- a/source/checks/Instancev5.Tests.ps1 +++ b/source/checks/Instancev5.Tests.ps1 @@ -382,6 +382,15 @@ Describe "Linked Servers" -Tags LinkedServerConnection, Connectivity, Medium, In } } +Describe "Max Memory" -Tag MaxMemory, High, Instance -ForEach $InstancesToTest { + $skip = ($__dbcconfig | Where-Object { $_.Name -eq 'skip.instance.maxmemory' }).Value + Context "Testing Max Memory on <_.Name>" { + It "Max Memory setting should be correct on <_.Name>" -Skip:$skip { + $Psitem.MaxMemory.MaxValue | Should -BeLessThan $Psitem.MaxMemory.RecommendedValue -Because 'You do not want to exhaust server memory' + } + } +} + <# Describe "TempDB Configuration" -Tags TempDbConfiguration, Medium, Instance -ForEach $InstancesToTest { Context "Testing TempDB Configuration on $psitem" -Skip:(($__dbcconfig | Where-Object { $_.Name diff --git a/source/internal/configurations/configuration.ps1 b/source/internal/configurations/configuration.ps1 index feca161d..fc80ec0f 100644 --- a/source/internal/configurations/configuration.ps1 +++ b/source/internal/configurations/configuration.ps1 @@ -282,6 +282,7 @@ Set-PSFConfig -Module dbachecks -Name skip.instance.tempdb -Validation bool -Val Set-PSFConfig -Module dbachecks -Name skip.instance.BackupPathAccess -Validation bool -Value $false -Initialize -Description "Skip the check for the backup path access check" Set-PSFConfig -Module dbachecks -Name skip.instance.networklatency -Validation bool -Value $false -Initialize -Description "Skip the check for network latency" Set-PSFConfig -Module dbachecks -Name skip.instance.linkedserverconnection -Validation bool -Value $false -Initialize -Description "Skip the check for linked server connection" +Set-PSFConfig -Module dbachecks -Name skip.instance.maxmemory -Validation bool -Value $false -Initialize -Description "Skip the check for max memory" diff --git a/source/internal/functions/NewGet-AllInstanceInfo.ps1 b/source/internal/functions/NewGet-AllInstanceInfo.ps1 index 103bf946..42a092a9 100644 --- a/source/internal/functions/NewGet-AllInstanceInfo.ps1 +++ b/source/internal/functions/NewGet-AllInstanceInfo.ps1 @@ -333,6 +333,27 @@ function NewGet-AllInstanceInfo { $LinkedServerResults = Test-DbaLinkedServerConnection -SqlInstance $Instance } + 'MaxMemory' { + if ($isLinux -or $isMacOS) { + $totalMemory = $Instance.PhysicalMemory + # Some servers under-report by 1. + if (($totalMemory % 1024) -ne 0) { + $totalMemory = $totalMemory + 1 + } + $MaxMemory = [PSCustomObject]@{ + MaxValue = $totalMemory + RecommendedValue = $Instance.Configuration.MaxServerMemory.ConfigValue + 379 + # because we added 379 before and I have zero idea why + } + } else { + $MemoryValues = Test-DbaMaxMemory -SqlInstance $Instance + $MaxMemory = [PSCustomObject]@{ + MaxValue = $MemoryValues.MaxValue + RecommendedValue = $MemoryValues.RecommendedValue + } + } + } + Default { } } @@ -422,6 +443,7 @@ function NewGet-AllInstanceInfo { Result = 'None' } } + MaxMemory = $MaxMemory # TempDbConfig = [PSCustomObject]@{ # TF118EnabledCurrent = $tempDBTest[0].CurrentSetting # TF118EnabledRecommended = $tempDBTest[0].Recommended