-
Notifications
You must be signed in to change notification settings - Fork 225
SqlMemory
Parameter | Attribute | DataType | Description | Allowed Values |
---|---|---|---|---|
InstanceName | Key | String | The name of the SQL Server instance to be configured. | |
ServerName | Write | String | The host name of the SQL Server to be configured. Default value is the current computer name. | |
Ensure | Write | String | When set to 'Present' then min and max memory will be set to either the value in parameter MinMemory and MaxMemory, or dynamically configured when parameter DynamicAlloc is set to $true . When set to 'Absent' min and max memory will be set to its default values. Default value is 'Present' . |
Present , Absent
|
DynamicAlloc | Write | Boolean | If set to $true then max memory will be dynamically configured. When this parameter is set to $true , the parameter MaxMemory must be set to $null or not be configured. Default value is $false . |
|
MinMemory | Write | SInt32 | Minimum amount of memory, in MB, in the buffer pool used by the instance of SQL Server. | |
MaxMemory | Write | SInt32 | Maximum amount of memory, in MB, in the buffer pool used by the instance of SQL Server. | |
ProcessOnlyOnActiveNode | Write | Boolean | Specifies that the resource will only determine if a change is needed if the target node is the active host of the SQL Server instance. | |
IsActiveNode | Read | Boolean | Returns if the current node is actively hosting the SQL Server instance. |
The SqlMemory
DSC resource sets the minimum server memory and
maximum server memory configuration option. That means it sets the minimum
and the maximum amount of memory, in MB, in the buffer pool used by the
instance of SQL Server The default setting for minimum server memory is 0,
and the default setting for maximum server memory is 2147483647 MB. Read
more about minimum server memory and maximum server memory in this article
Server Memory Server Configuration Options.
NOTE These configuration options can also be configured using the DSC resource SqlConfiguration but will not allow the dynamic configuration as this resource provides. Make sure this value is not configured by both the resources SqLMemory and SqlConfiguration!
The formula is based on the SQL Max Memory Calculator website. This was inspired from the repository sql-max maintained by @mirontoli.
The dynamic maximum memory (in MB) is calculate with this formula:
TotalPhysicalMemory - (NumOfSQLThreads * ThreadStackSize) - (1024 * CEILING(NumOfCores / 4)) - OSReservedMemory
- If the number of cores is less than or equal to 4, the number of SQL threads is set to: 256 + (NumberOfCores - 4) * 8.
- If the number of cores is greater than 4, the number of SQL threads is set to: 0 (zero).
- If the architecture of windows server is x86, the size of thread stack is 1MB.
- If the architecture of windows server is x64, the size of thread stack is 2MB.
- If the architecture of windows server is IA64, the size of thread stack is 4MB.
- If the total physical memory is less than or equal to 20GB, the percentage of reserved memory for OS is 20% of total physical memory.
- If the total physical memory is greater than 20GB, the percentage of reserved memory for OS is 12.5% of total physical memory.
- Target machine must be running Windows Server 2012 or later.
- Target machine must be running SQL Server Database Engine 2012 or later.
All issues are not listed here, see here for all open issues.
This example shows how to set the minimum and maximum memory configuration option with the value equal to 1024 and 12288.
Configuration Example
{
param
(
[Parameter(Mandatory = $true)]
[System.Management.Automation.PSCredential]
$SqlAdministratorCredential
)
Import-DscResource -ModuleName 'SqlServerDsc'
node localhost
{
SqlMemory 'Set_SQLServerMaxMemory_To12GB'
{
Ensure = 'Present'
DynamicAlloc = $false
MinMemory = 1024
MaxMemory = 12288
ServerName = 'sqltest.company.local'
InstanceName = 'DSC'
PsDscRunAsCredential = $SqlAdministratorCredential
}
}
}
This example shows how to set the maximum memory configuration option with the automatic configuration.
In the event this is applied to a Failover Cluster Instance (FCI), the ProcessOnlyOnActiveNode property will tell the Test-TargetResource function to evaluate if any changes are needed if the node is actively hosting the SQL Server instance.
Configuration Example
{
param
(
[Parameter(Mandatory = $true)]
[System.Management.Automation.PSCredential]
$SqlAdministratorCredential
)
Import-DscResource -ModuleName 'SqlServerDsc'
node localhost
{
SqlMemory 'Set_SQLServerMaxMemory_ToAuto'
{
Ensure = 'Present'
DynamicAlloc = $true
ServerName = 'sqltest.company.local'
InstanceName = 'DSC'
ProcessOnlyOnActiveNode = $true
PsDscRunAsCredential = $SqlAdministratorCredential
}
}
}
This example shows how to set the minimum memory to 2GB and the maximum memory configuration option with the automatic configuration.
Configuration Example
{
param
(
[Parameter(Mandatory = $true)]
[System.Management.Automation.PSCredential]
$SqlAdministratorCredential
)
Import-DscResource -ModuleName 'SqlServerDsc'
node localhost
{
SqlMemory 'Set_SQLServerMinAndMaxMemory_ToAuto'
{
Ensure = 'Present'
DynamicAlloc = $true
ServerName = 'sqltest.company.local'
InstanceName = 'DSC'
MinMemory = 2048
PsDscRunAsCredential = $SqlAdministratorCredential
}
}
}
This example shows how to set the minimum and maximum memory configuration option with the default configuration.
Configuration Example
{
param
(
[Parameter(Mandatory = $true)]
[System.Management.Automation.PSCredential]
$SqlAdministratorCredential
)
Import-DscResource -ModuleName 'SqlServerDsc'
node localhost
{
SqlMemory 'Set_SQLServerMaxMemory_ToDefault'
{
Ensure = 'Absent'
ServerName = 'sqltest.company.local'
InstanceName = 'DSC'
PsDscRunAsCredential = $SqlAdministratorCredential
}
}
}
- Add-SqlDscNode
- Add-SqlDscTraceFlag
- Complete-SqlDscFailoverCluster
- Complete-SqlDscImage
- Connect-SqlDscDatabaseEngine
- ConvertFrom-SqlDscDatabasePermission
- ConvertFrom-SqlDscServerPermission
- ConvertTo-SqlDscDatabasePermission
- ConvertTo-SqlDscServerPermission
- Disable-SqlDscAudit
- Disconnect-SqlDscDatabaseEngine
- Enable-SqlDscAudit
- Get-SqlDscAudit
- Get-SqlDscConfigurationOption
- Get-SqlDscDatabasePermission
- Get-SqlDscManagedComputer
- Get-SqlDscManagedComputerService
- Get-SqlDscPreferredModule
- Get-SqlDscServerPermission
- Get-SqlDscStartupParameter
- Get-SqlDscTraceFlag
- Import-SqlDscPreferredModule
- Initialize-SqlDscRebuildDatabase
- Install-SqlDscServer
- Invoke-SqlDscQuery
- New-SqlDscAudit
- Remove-SqlDscAudit
- Remove-SqlDscNode
- Remove-SqlDscTraceFlag
- Repair-SqlDscServer
- Save-SqlDscSqlServerMediaFile
- Set-SqlDscAudit
- Set-SqlDscDatabasePermission
- Set-SqlDscServerPermission
- Set-SqlDscStartupParameter
- Set-SqlDscTraceFlag
- Test-SqlDscIsDatabasePrincipal
- Test-SqlDscIsLogin
- Test-SqlDscIsSupportedFeature
- Uninstall-SqlDscServer
- SqlAG
- SqlAGDatabase
- SqlAgentAlert
- SqlAgentFailsafe
- SqlAgentOperator
- SqlAGListener
- SqlAGReplica
- SqlAlias
- SqlAlwaysOnService
- SqlAudit
- SqlConfiguration
- SqlDatabase
- SqlDatabaseDefaultLocation
- SqlDatabaseMail
- SqlDatabaseObjectPermission
- SqlDatabasePermission
- SqlDatabaseRole
- SqlDatabaseUser
- SqlEndpoint
- SqlEndpointPermission
- SqlLogin
- SqlMaxDop
- SqlMemory
- SqlPermission
- SqlProtocol
- SqlProtocolTcpIp
- SqlReplication
- SqlRole
- SqlRS
- SqlRSSetup
- SqlScript
- SqlScriptQuery
- SqlSecureConnection
- SqlServiceAccount
- SqlSetup
- SqlTraceFlag
- SqlWaitForAG
- SqlWindowsFirewall