commands

^

Set-DbaMaxMemory

Author Chrissy LeMaire (@cl), netnerds.net
Availability Windows, Linux, macOS

 

Want to see the source code for this command? Check out Set-DbaMaxMemory on GitHub.
Want to see the Bill Of Health for this command? Check out Set-DbaMaxMemory.

Synopsis

Sets SQL Server 'Max Server Memory' configuration setting to a new value then displays information this setting.

Description

Sets SQL Server max memory then displays information relating to SQL Server Max Memory configuration settings.

Inspired by Jonathan Kehayias's post about SQL Server Max memory (http://bit.ly/sqlmemcalc), this uses a formula to
determine the default optimum RAM to use, then sets the SQL max value to that number.

Jonathan notes that the formula used provides a general recommendation that doesn't account for everything that may
be going on in your specific environment.

Syntax

Set-DbaMaxMemory
    [[-SqlInstance] <DbaInstanceParameter[]>]
    [[-SqlCredential] <PSCredential>]
    [[-Max] <Int32>]
    [[-InputObject] <PSObject[]>]
    [-EnableException]
    [-WhatIf]
    [-Confirm]
    [<CommonParameters>]

 

Examples

 

Example: 1
PS C:\> Set-DbaMaxMemory sqlserver1

Set max memory to the recommended on just one server named "sqlserver1"

Example: 2
PS C:\> Set-DbaMaxMemory -SqlInstance sqlserver1 -Max 2048

Explicitly set max memory to 2048 on just one server, "sqlserver1"

Example: 3
PS C:\> Get-DbaRegServer -SqlInstance sqlserver | Test-DbaMaxMemory | Where-Object { $_.MaxValue -gt $_.Total } | Set-DbaMaxMemory

Find all servers in SQL Server Central Management Server that have Max SQL memory set to higher than the total memory
of the server (think 2147483647), then pipe those to Set-DbaMaxMemory and use the default recommendation.

Optional Parameters

-SqlInstance

The target SQL Server instance or instances.

Alias
Required False
Pipeline false
Default Value
-SqlCredential

Login to the target instance using alternative credentials. Accepts PowerShell credentials (Get-Credential).
Windows Authentication, SQL Server Authentication, Active Directory - Password, and Active Directory - Integrated are all supported.
For MFA support, please use Connect-DbaInstance.

Alias
Required False
Pipeline false
Default Value
-Max

Specifies the max megabytes (MB)

Alias
Required False
Pipeline false
Default Value 0
-InputObject

A InputObject returned by Test-DbaMaxMemory

Alias
Required False
Pipeline true (ByValue)
Default Value
-EnableException

By default, when something goes wrong we try to catch it, interpret it and give you a friendly warning message.
This avoids overwhelming you with "sea of red" exceptions, but is inconvenient because it basically disables advanced scripting.
Using this switch turns this "nice by default" feature off and enables you to catch exceptions with your own try/catch.

Alias
Required False
Pipeline false
Default Value False
-WhatIf

Shows what would happen if the cmdlet runs. The cmdlet is not run.

Alias wi
Required False
Pipeline false
Default Value
-Confirm

Prompts you for confirmation before running the cmdlet.

Alias cf
Required False
Pipeline false
Default Value