dbatools is a free PowerShell module with over 200 SQL Server administration, best practice and migration commands included.

Please note that documentation and command names may be out of date while we work furiously towards 1.0


Set-DbaDbQueryStoreOptions

Configure Query Store settings for a specific or multiple databases.

Screenshots

dbatools - Set-DbaDbQueryStoreOptions

Examples

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

Set-DbaDbQueryStoreOptions -SqlInstance ServerA\SQL -State ReadWrite -FlushInterval 600 -CollectionInterval 10 -MaxSize 100 -CaptureMode All -CleanupMode Auto -StaleQueryThreshold 100 -AllDatabases

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

Set-DbaDbQueryStoreOptions -SqlInstance ServerA\SQL -FlushInterval 600

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

Set-DbaDbQueryStoreOptions -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 all user databases except the AdventureWorks database in the ServerA\SQL Instance.

Set-DbaDbQueryStoreOptions -SqlInstance ServerA\SQL -Exclude AdventureWorks -State ReadWrite -FlushInterval 600 -CollectionInterval 10 -MaxSize 100 -CaptureMode all -CleanupMode Auto -StaleQueryThreshold 100

Author

This command was created by Enrico van de Laar. You can find Enrico on Twitter.

Get-Help

From PowerShell, execute Get-Help Set-DbaDbQueryStoreOptions -Detailed for more information on this function.

Source Code

Want to see the source code? View Set-DbaDbQueryStoreOptions.ps1 on GitHub
 

Related commands