---
title: "Get-DbaDbQueryStoreOption"
description: "Retrieves Query Store configuration settings from databases across SQL Server instances."
url: "https://dbatools.io/Get-DbaDbQueryStoreOption/"
availability: "Windows, Linux, macOS"
tags: ["QueryStore"]
author: "Enrico van de Laar (@evdlaar) | Klaas Vandenberghe (@PowerDBAKlaas) | Tracy Boggiano (@TracyBoggiano)"
source: "https://github.com/dataplat/dbatools/blob/master/public/Get-DbaDbQueryStoreOption.ps1"
last_updated: "2024-01-01"
---

# Get-DbaDbQueryStoreOption

## Synopsis

Retrieves Query Store configuration settings from databases across SQL Server instances.

## Description

Returns the complete Query Store configuration for user databases, including capture modes, storage limits, cleanup policies, and retention settings. This function helps DBAs audit Query Store configurations across their environment, identify databases with suboptimal settings, and ensure consistent Query Store policies. Query Store settings directly impact query performance monitoring, plan regression detection, and storage consumption, so regular configuration reviews are essential for maintaining optimal performance insights.

## Syntax

```powershell
Get-DbaDbQueryStoreOption
    [-SqlInstance] <DbaInstanceParameter[]>
    [[-SqlCredential] <PSCredential>]
    [[-Database] <Object[]>]
    [[-ExcludeDatabase] <Object[]>]
    [-EnableException]
    [<CommonParameters>]

```

## Examples

### Example 1: Returns Query Store configuration settings for every database on the ServerA\sql instance

```powershell
PS C:\> Get-DbaDbQueryStoreOption -SqlInstance ServerA\sql
```

### Example 2: Returns the Query Store configuration for all databases on ServerA\sql where the Query Store feature is in...

```powershell
PS C:\> Get-DbaDbQueryStoreOption -SqlInstance ServerA\sql | Where-Object {$_.ActualState -eq "ReadWrite"}
```

Returns the Query Store configuration for all databases on ServerA\sql where the Query Store feature is in Read/Write mode.  

### Example 3: Returns Query Store configuration settings for every database on the ServerA\sql instance inside a table...

```powershell
PS C:\> Get-DbaDbQueryStoreOption -SqlInstance localhost | format-table -AutoSize -Wrap
```

Returns Query Store configuration settings for every database on the ServerA\sql instance inside a table format.  

### Required Parameters

##### -SqlInstance

The target SQL Server instance or instances.

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

| Property | Value |
| --- | --- |
| Alias |  |
| Required | False |
| Pipeline | false |
| Default Value |  |

##### -Database

Specifies which user databases to retrieve Query Store configuration from. Accepts database names, wildcards, or arrays for multiple databases.  
Use this when you need to audit Query Store settings for specific databases rather than scanning your entire instance.

| Property | Value |
| --- | --- |
| Alias |  |
| Required | False |
| Pipeline | false |
| Default Value |  |

##### -ExcludeDatabase

Excludes specific databases from Query Store configuration retrieval. System databases (master, tempdb, model) are automatically excluded.  
Useful for skipping databases that you know don't need Query Store monitoring or have restricted access permissions.

| Property | Value |
| --- | --- |
| Alias |  |
| Required | False |
| Pipeline | false |
| Default Value |  |

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

| Property | Value |
| --- | --- |
| Alias |  |
| Required | False |
| Pipeline | false |
| Default Value | False |

## Outputs

**Microsoft.SqlServer.Management.Smo.QueryStoreOptions**

Returns one object per database with Query Store configuration settings. The base object is the QueryStoreOptions SMO object enhanced with additional properties and adjusted based on the SQL Server version.

**Default display properties (via Select-DefaultView):**

- ComputerName: The computer name of the SQL Server instance
- InstanceName: The SQL Server instance name
- SqlInstance: The full SQL Server instance name (computer\instance)
- Database: Name of the database
- ActualState: Current Query Store state (ReadWrite, ReadOnly, or Off)
- DataFlushIntervalInSeconds: Interval in seconds for flushing data to storage
- StatisticsCollectionIntervalInMinutes: Interval in minutes for statistics collection
- MaxStorageSizeInMB: Maximum storage size allocated for Query Store (in megabytes)
- CurrentStorageSizeInMB: Current storage size being used by Query Store (in megabytes)
- QueryCaptureMode: Query capture mode (All, Auto, None, or Custom)
- SizeBasedCleanupMode: Cleanup mode when max storage is exceeded (Off, Auto)
- StaleQueryThresholdInDays: Number of days after which a query is considered stale for cleanup

**Additional properties for SQL Server 2017 (v14) and later:**

- MaxPlansPerQuery: Maximum number of plans tracked per query
- WaitStatsCaptureMode: Wait statistics capture mode (Off, On)

**Additional properties for SQL Server 2019 (v15) and later:**

- CustomCapturePolicyExecutionCount: Custom capture policy execution count threshold
- CustomCapturePolicyTotalCompileCPUTimeMS: Custom capture policy compile CPU time threshold in milliseconds
- CustomCapturePolicyTotalExecutionCPUTimeMS: Custom capture policy execution CPU time threshold in milliseconds
- CustomCapturePolicyStaleThresholdHours: Custom capture policy stale threshold in hours
All properties from the base SMO QueryStoreOptions object are accessible via Select-Object *, even though only default properties are displayed in standard output. The number of properties returned varies based on the SQL Server version of the target instance.

---

Part of [dbatools](https://dbatools.io/), a free and open source PowerShell module for SQL Server administration. Full command index: https://dbatools.io/commands/
