commands

^

Invoke-DbaDbccFreeCache

Author Patrick Flynn (@sqllensman)
Availability Windows, Linux, macOS

 

Synopsis

Execution of Database Console Commands that clear Server level Memory caches

Description

Allows execution of Database Console Commands that act at Server Level to clear Memory caches

Allows execution of the following commands DBCC FREEPROCCACHE DBCC FREESESSIONCACHE DBCC FREESYSTEMCACHE

Read more: - https://docs.microsoft.com/en-us/sql/t-sql/database-console-commands/dbcc-freeproccache-transact-sql - https://docs.microsoft.com/en-us/sql/t-sql/database-console-commands/dbcc-freesessioncache-transact-sql - https://docs.microsoft.com/en-us/sql/t-sql/database-console-commands/dbcc-freesystemcache-transact-sql

Syntax

Invoke-DbaDbccFreeCache
    [-SqlInstance] <DbaInstanceParameter[]>
    [[-SqlCredential] <PSCredential>]
    [[-Operation] <String>]
    [[-InputValue] <String>]
    [-NoInformationalMessages]
    [-MarkInUseForRemoval]
    [-EnableException]
    [-WhatIf]
    [-Confirm]
    [<CommonParameters>]

 

Examples

 

Example: 1
PS C:\> Invoke-DbaDbccFreeCache -SqlInstance SqlServer2017 -Operation FREEPROCCACHE

Runs the command DBCC FREEPROCCACHE against the instance SqlServer2017 using Windows Authentication

Example: 2
PS C:\> Invoke-DbaDbccFreeCache -SqlInstance SqlServer2017 -Operation FREESESSIONCACHE -NoInformationalMessages

Runs the command DBCC FREESESSIONCACHE WITH NO_INFOMSGS against the instance SqlServer2017 using Windows Authentication

Example: 3
PS C:\> Invoke-DbaDbccFreeCache -SqlInstance SqlServer2017 -Operation FREESYSTEMCACHE -NoInformationalMessages

Runs the command DBCC FREESYSTEMCACHE WITH NO_INFOMSGS against the instance SqlServer2017 using Windows Authentication

Example: 4
PS C:\> Invoke-DbaDbccFreeCache -SqlInstance SqlServer2017 -Operation FREEPROCCACHE -InputValue 0x060006001ECA270EC0215D05000000000000000000000000

Remove a specific plan with plan_handle 0x060006001ECA270EC0215D05000000000000000000000000 from the cache via the command DBCC FREEPROCCACHE(0x060006001ECA270EC0215D05000000000000000000000000)
against the instance SqlServer2017 using Windows Authentication

Example: 5
PS C:\> Invoke-DbaDbccFreeCache -SqlInstance SqlServer2017 -Operation FREEPROCCACHE -InputValue default

Runs the command DBCC FREEPROCCACHE('default') against the instance SqlServer2017 using Windows Authentication. This clears all cache entries associated with a resource pool 'default'.

Example: 6
PS C:\> Invoke-DbaDbccFreeCache -SqlInstance SqlServer2017 -Operation FREESYSTEMCACHE -InputValue default

Runs the command DBCC FREESYSTEMCACHE ('ALL', default) against the instance SqlServer2017 using Windows Authentication. This will clean all the caches with entries specific to the resource pool named
"default".

Example: 7
PS C:\> Invoke-DbaDbccFreeCache -SqlInstance SqlServer2017 -Operation FREESYSTEMCACHE -InputValue default -MarkInUseForRemoval

Runs the command DBCC FREESYSTEMCACHE ('ALL', default) WITH MARK_IN_USE_FOR_REMOVAL against the instance SqlServer2017 using Windows Authentication. This will to release entries once the entries
become unused for all the caches with entries specific to the resource pool named "default".

Required Parameters

-SqlInstance

The target SQL Server instance or instances.

Alias
Required True
Pipeline true (ByValue)
Default Value

Optional Parameters

-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
-Operation

DBCC Operation to Perform - Supports specific set of operations

Alias
Required False
Pipeline false
Default Value FreeProcCache
Accepted Values FreeProcCache,FreeSessionCache,FreeSystemCache
-InputValue

Value used for Operation - meaning depends on Operation DBCC FREEPROCCACHE accepts a plan_handle of type varbinary(64) a sql_handle of type varbinary(64) or the name of a Resource Governor resource pool of type sysname If blank then clears all elements from the plan cache DBCC FREESYSTEMCACHE accepts 'ALL' for ALL specifies all supported caches or name of a Resource Governor pool cache Not required for other values

Alias
Required False
Pipeline false
Default Value
-NoInformationalMessages

Suppresses all informational messages.

Alias
Required False
Pipeline false
Default Value False
-MarkInUseForRemoval

Used when Operation = DBCC FREESYSTEMCACHE Asynchronously frees currently used entries from their respective caches after they become unused

Alias
Required False
Pipeline false
Default Value False
-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

 

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