< Back

Invoke-DbaDbccFreeCache

Mon Jan 13, 2020 12:12 pm

NAME Invoke-DbaDbccFreeCache



SYNOPSIS

Execution of Database Console Commands that clear Server level Memory caches





SYNTAX

Invoke-DbaDbccFreeCache [-SqlInstance] <Sqlcollaborative.Dbatools.Parameter.DbaInstanceParameter[]>

[[-SqlCredential] <Pscredential>] [[-Operation] <String>] [[-InputValue] <String>] [-NoInformationalMessages

<Switch>] [-MarkInUseForRemoval <Switch>] [-EnableException <Switch>] [<CommonParameters>]





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- ... ansact-sql



- https://docs.microsoft.com/en-us/sql/t- ... ansact-sql



- https://docs.microsoft.com/en-us/sql/t- ... ansact-sql





PARAMETERS

-EnableException [<Switch>]

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.



Required? false

Position? named

Default value

Accept pipeline input? False

Accept wildcard characters? false



-InputValue [<String>]

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



Required? false

Position? named

Default value

Accept pipeline input? False

Accept wildcard characters? false



-MarkInUseForRemoval [<Switch>]

Used when Operation = DBCC FREESYSTEMCACHE

Asynchronously frees currently used entries from their respective caches after they become unused



Required? false

Position? named

Default value

Accept pipeline input? False

Accept wildcard characters? false



-NoInformationalMessages [<Switch>]

Suppresses all informational messages.



Required? false

Position? named

Default value

Accept pipeline input? False

Accept wildcard characters? false



-Operation [<String>]

DBCC Operation to Perform - Supports specific set of operations



Required? false

Position? named

Default value

Accept pipeline input? False

Accept wildcard characters? false



-SqlCredential [<Pscredential>]

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.



Required? false

Position? named

Default value

Accept pipeline input? False

Accept wildcard characters? false



-SqlInstance [<Sqlcollaborative.Dbatools.Parameter.DbaInstanceParameter[]>]

The target SQL Server instance or instances.



Required? false

Position? named

Default value

Accept pipeline input? False

Accept wildcard characters? false



<CommonParameters>

This cmdlet supports the common parameters: Verbose, Debug,

ErrorAction, ErrorVariable, WarningAction, WarningVariable,

OutBuffer, PipelineVariable, and OutVariable. For more information, see

about_CommonParameters (https:/go.microsoft.com/fwlink/?LinkID=113216).



INPUTS



OUTPUTS



NOTES





Tags: DBCC

Author: Patrick Flynn (@sqllensman)



Website: https://dbatools.io

Copyright: (c) 2018 by dbatools, licensed under MIT

License: MIT https://opensource.org/licenses/MIT



-------------------------- 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".



RELATED LINKS

https://dbatools.io/Invoke-DbaDbccFreeCache