< Back

Set-DbaDbQueryStoreOption

Mon Jan 13, 2020 5:36 pm

NAME Set-DbaDbQueryStoreOption



SYNOPSIS

Configure Query Store settings for a specific or multiple databases.





SYNTAX

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

[[-SqlCredential] <Pscredential>] [[-Database] <System.Object[]>] [[-ExcludeDatabase] <System.Object[]>]

[-AllDatabases <Switch>] [[-State] <System.String[]>] [[-FlushInterval] <Long>] [[-CollectionInterval] <Long>]

[[-MaxSize] <Long>] [[-CaptureMode] <System.String[]>] [[-CleanupMode] <System.String[]>] [[-StaleQueryThreshold]

<Long>] [[-MaxPlansPerQuery] <Long>] [[-WaitStatsCaptureMode] <System.String[]>]

[[-CustomCapturePolicyExecutionCount] <Long>] [[-CustomCapturePolicyTotalCompileCPUTimeMS] <Long>]

[[-CustomCapturePolicyTotalExecutionCPUTimeMS] <Long>] [[-CustomCapturePolicyStaleThresholdHours] <Long>]

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





DESCRIPTION

Configure Query Store settings for a specific or multiple databases.





PARAMETERS

-AllDatabases [<Switch>]

Run command against all user databases



Required? false

Position? named

Default value

Accept pipeline input? False

Accept wildcard characters? false



-CaptureMode [<System.String[]>]

Set the query capture mode of the Query Store. Valid options are "Auto" and "All".



Required? false

Position? named

Default value

Accept pipeline input? False

Accept wildcard characters? false



-CleanupMode [<System.String[]>]

Set the query cleanup mode policy. Valid options are "Auto" and "Off".



Required? false

Position? named

Default value

Accept pipeline input? False

Accept wildcard characters? false



-CollectionInterval [<Long>]

Set the runtime statistics collection interval of the Query Store in minutes.



Required? false

Position? named

Default value

Accept pipeline input? False

Accept wildcard characters? false



-CustomCapturePolicyExecutionCount [<Long>]

Set the custom capture policy execution count. Only available in SQL Server 2019 and above.



Required? false

Position? named

Default value

Accept pipeline input? False

Accept wildcard characters? false



-CustomCapturePolicyStaleThresholdHours [<Long>]

Set the custom capture policy stale threshold. Only available in SQL Server 2019 and above.



Required? false

Position? named

Default value

Accept pipeline input? False

Accept wildcard characters? false



-CustomCapturePolicyTotalCompileCPUTimeMS [<Long>]

Set the custom capture policy total compile CPU time. Only available in SQL Server 2019 and above.



Required? false

Position? named

Default value

Accept pipeline input? False

Accept wildcard characters? false



-CustomCapturePolicyTotalExecutionCPUTimeMS [<Long>]

Set the custom capture policy total execution CPU time. Only available in SQL Server 2019 and above.



Required? false

Position? named

Default value

Accept pipeline input? False

Accept wildcard characters? false



-Database [<System.Object[]>]

The database(s) to process - this list is auto-populated from the server. If unspecified, all databases will

be processed.



Required? false

Position? named

Default value

Accept pipeline input? False

Accept wildcard characters? false



-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



-ExcludeDatabase [<System.Object[]>]

The database(s) to exclude - this list is auto-populated from the server



Required? false

Position? named

Default value

Accept pipeline input? False

Accept wildcard characters? false



-FlushInterval [<Long>]

Set the flush to disk interval of the Query Store in seconds.



Required? false

Position? named

Default value

Accept pipeline input? False

Accept wildcard characters? false



-MaxPlansPerQuery [<Long>]

Set the max plans per query captured and kept.



Required? false

Position? named

Default value

Accept pipeline input? False

Accept wildcard characters? false



-MaxSize [<Long>]

Set the maximum size of the Query Store in MB.



Required? false

Position? named

Default value

Accept pipeline input? False

Accept wildcard characters? false



-SqlCredential [<Pscredential>]

SqlLogin 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



-StaleQueryThreshold [<Long>]

Set the stale query threshold in days.



Required? false

Position? named

Default value

Accept pipeline input? False

Accept wildcard characters? false



-State [<System.String[]>]

Set the state of the Query Store. Valid options are "ReadWrite", "ReadOnly" and "Off".



Required? false

Position? named

Default value

Accept pipeline input? False

Accept wildcard characters? false



-WaitStatsCaptureMode [<System.String[]>]

Set wait stats capture on or off.



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: QueryStore

Author: Enrico van de Laar (@evdlaar) | Tracy Boggiano ( @TracyBoggiano )



Website: https://dbatools.io

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

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



-------------------------- EXAMPLE 1 --------------------------



PS C:\\>Set-DbaDbQueryStoreOption -SqlInstance ServerA\\SQL -State ReadWrite -FlushInterval 600 -CollectionInterval

10 -MaxSize 100 -CaptureMode All -CleanupMode Auto -StaleQueryThreshold 100 -AllDatabases



Configure the Query Store settings for all user databases in the ServerA\\SQL Instance.

-------------------------- EXAMPLE 2 --------------------------



PS C:\\>Set-DbaDbQueryStoreOption -SqlInstance ServerA\\SQL -FlushInterval 600



Only configure the FlushInterval setting for all Query Store databases in the ServerA\\SQL Instance.

-------------------------- EXAMPLE 3 --------------------------



PS C:\\>Set-DbaDbQueryStoreOption -SqlInstance ServerA\\SQL -Database AdventureWorks -State ReadWrite -FlushInterval

600 -CollectionInterval 10 -MaxSize 100 -CaptureMode all -CleanupMode Auto -StaleQueryThreshold 100



Configure the Query Store settings for the AdventureWorks database in the ServerA\\SQL Instance.

-------------------------- EXAMPLE 4 --------------------------



PS C:\\>Set-DbaDbQueryStoreOption -SqlInstance ServerA\\SQL -Exclude AdventureWorks -State ReadWrite -FlushInterval

600 -CollectionInterval 10 -MaxSize 100 -CaptureMode all -CleanupMode Auto -StaleQueryThreshold 100



Configure the Query Store settings for all user databases except the AdventureWorks database in the ServerA\\SQL

Instance.



RELATED LINKS

https://dbatools.io/Set-DbaQueryStoreOptions