dataplat / dbatools

🚀 SQL Server automation and instance migrations have never been safer, faster or freer
https://dbatools.io
MIT License
2.39k stars 788 forks source link

Update Set-DbaDbQueryStoreOption.ps1 #9205

Closed tominyorks closed 6 months ago

tominyorks commented 6 months ago

Ignore snapshots when setting Query Store options

Set-DbaDbQueryStoreOptions uses ALTER DATABASE statements under the hood, and these fail when run against a read only database snapshot. Update the call to Get-DbaDatabase to exclude snapshots upfront.

Please read -- recent changes to our repo

On November 10, 2022, we removed some bloat from our repository (for the second and final time). This change requires that all contributors reclone or refork their repo.

PRs from repos that have not been recently reforked or recloned will be closed and @potatoqualitee will cherry-pick your commits and open a new PR with your changes.

Type of Change

Purpose

Stop Set-DbaDbQueryStoreOption from failing when a database snapshot exists but isn't explicitly added to an exclusion list

Approach

Excludes database snapshots when retrieving the available databases from an instance

Commands to test

Set-DbaDbQueryStoreOption is the only command affected.

Running the below, targeting a SQL instance that hosts at least one database snapshot will no longer error in the fixed version. Note, this will enable Query Store on all databases unless the -Database parameter is also provided.

Set-DbaDbQueryStoreOption -SqlInstance localhost `
    -State ReadWrite `
    -StaleQueryThreshold 90 `
    -FlushInterval 900 `
    -CollectionInterval 30 `
    -MaxSize 500 `
    -MaxPlansPerQuery 200 `
    -WaitStatsCaptureMode On
potatoqualitee commented 6 months ago

hey nice, thank you both 💯 !