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.
Configure Query Store settings for a specific or multiple databases.
Configure Query Store settings for a specific or multiple databases.
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>]
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.
PS C:\> Set-DbaDbQueryStoreOption -SqlInstance ServerA\SQL -FlushInterval 600
Only configure the FlushInterval setting for all Query Store databases in the ServerA\SQL Instance.
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.
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.
The target SQL Server instance or instances.
Alias | |
Required | True |
Pipeline | true (ByValue) |
Default Value |
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 |
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 |
The database(s) to exclude - this list is auto-populated from the server
Alias | |
Required | False |
Pipeline | false |
Default Value |
Run command against all user databases
Alias | |
Required | False |
Pipeline | false |
Default Value | False |
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 |
Set the flush to disk interval of the Query Store in seconds.
Alias | |
Required | False |
Pipeline | false |
Default Value | 0 |
Set the runtime statistics collection interval of the Query Store in minutes.
Alias | |
Required | False |
Pipeline | false |
Default Value | 0 |
Set the maximum size of the Query Store in MB.
Alias | |
Required | False |
Pipeline | false |
Default Value | 0 |
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 |
Set the query cleanup mode policy. Valid options are "Auto" and "Off".
Alias | |
Required | False |
Pipeline | false |
Default Value | |
Accepted Values | Auto,Off |
Set the stale query threshold in days.
Alias | |
Required | False |
Pipeline | false |
Default Value | 0 |
Set the max plans per query captured and kept.
Alias | |
Required | False |
Pipeline | false |
Default Value | 0 |
Set wait stats capture on or off.
Alias | |
Required | False |
Pipeline | false |
Default Value | |
Accepted Values | On,Off |
Set the custom capture policy execution count. Only available in SQL Server 2019 and above.
Alias | |
Required | False |
Pipeline | false |
Default Value | 0 |
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 |
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 |
Set the custom capture policy stale threshold. Only available in SQL Server 2019 and above.
Alias | |
Required | False |
Pipeline | false |
Default Value | 0 |
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 |
Shows what would happen if the command were to run
Alias | wi |
Required | False |
Pipeline | false |
Default Value |
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 |