commands

^

Set-DbaDbQueryStoreOption

Author Enrico van de Laar (@evdlaar) , Tracy Boggiano (@TracyBoggiano)
Availability Windows, Linux, macOS

 

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

Synopsis

Configure Query Store settings for a specific or multiple databases.

Description

Configure Query Store settings for a specific or multiple databases.

Syntax

Set-DbaDbQueryStoreOption
    [-SqlInstance] <DbaInstanceParameter[]>
    [[-SqlCredential] <PSCredential>]
    [[-Database] <Object[]>]
    [[-ExcludeDatabase] <Object[]>]
    [-AllDatabases]
    [[-State] <String[]>]
    [[-FlushInterval] <Int64>]
    [[-CollectionInterval] <Int64>]
    [[-MaxSize] <Int64>]
    [[-CaptureMode] <String[]>]
    [[-CleanupMode] <String[]>]
    [[-StaleQueryThreshold] <Int64>]
    [[-MaxPlansPerQuery] <Int64>]
    [[-WaitStatsCaptureMode] <String[]>]
    [[-CustomCapturePolicyExecutionCount] <Int64>]
    [[-CustomCapturePolicyTotalCompileCPUTimeMS] <Int64>]
    [[-CustomCapturePolicyTotalExecutionCPUTimeMS] <Int64>]
    [[-CustomCapturePolicyStaleThresholdHours] <Int64>]
    [-EnableException]
    [-WhatIf]
    [-Confirm]
    [<CommonParameters>]

 

Examples

 

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.

Required Parameters

-SqlInstance

The target SQL Server instance or instances.

Alias
Required True
Pipeline true (ByValue)
Default Value

Optional Parameters

-SqlCredential

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

Alias
Required False
Pipeline false
Default Value
-Database

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

Alias
Required False
Pipeline false
Default Value
-ExcludeDatabase

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

Alias
Required False
Pipeline false
Default Value
-AllDatabases

Run command against all user databases

Alias
Required False
Pipeline false
Default Value False
-State

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

Alias
Required False
Pipeline false
Default Value
Accepted Values ReadWrite,ReadOnly,Off
-FlushInterval

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

Alias
Required False
Pipeline false
Default Value 0
-CollectionInterval

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

Alias
Required False
Pipeline false
Default Value 0
-MaxSize

Set the maximum size of the Query Store in MB.

Alias
Required False
Pipeline false
Default Value 0
-CaptureMode

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

Alias
Required False
Pipeline false
Default Value
Accepted Values Auto,All,None,Custom
-CleanupMode

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

Alias
Required False
Pipeline false
Default Value
Accepted Values Auto,Off
-StaleQueryThreshold

Set the stale query threshold in days.

Alias
Required False
Pipeline false
Default Value 0
-MaxPlansPerQuery

Set the max plans per query captured and kept.

Alias
Required False
Pipeline false
Default Value 0
-WaitStatsCaptureMode

Set wait stats capture on or off.

Alias
Required False
Pipeline false
Default Value
Accepted Values On,Off
-CustomCapturePolicyExecutionCount

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

Alias
Required False
Pipeline false
Default Value 0
-CustomCapturePolicyTotalCompileCPUTimeMS

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

Alias
Required False
Pipeline false
Default Value 0
-CustomCapturePolicyTotalExecutionCPUTimeMS

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

Alias
Required False
Pipeline false
Default Value 0
-CustomCapturePolicyStaleThresholdHours

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

Alias
Required False
Pipeline false
Default Value 0
-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 command were to run

Alias wi
Required False
Pipeline false
Default Value
-Confirm

Prompts for confirmation of every step. For example:
Are you sure you want to perform this action?
Performing the operation "Changing Desired State" on target "pubs on SQL2016\VNEXT".
[Y] Yes [A] Yes to All [N] No [L] No to All [S] Suspend [?] Help (default is "Y"):

Alias cf
Required False
Pipeline false
Default Value