# Query Store Configuration and Usage > [!Note] > Enabling and tuning the **Query Store** transforms transient plan data into a **persistent performance history**, empowering you to monitor regressions, force stable plans, and analyze workload behavior with minimal impact on live workloads. The Query Store, introduced in SQL Server 2016, captures query texts, execution plans, and runtime statistics automatically once enabled. You configure it at the database level—either via SSMS under the **Query Store** settings in the database properties or through T-SQL. Key configuration elements include the **operation mode** (Read Write or Read Only), **capture policy** (all queries versus high-cost only), **data retention** period, and **maximum storage size**. After activation, the engine begins collecting and persisting plan history, enabling you to diagnose performance trends and enforce plan stability without pausing the application. > [!tip] > Use Read Only mode on secondary replicas to analyze plan behavior without generating new data, and adjust **max_storage_size_mb** to prevent uncontrolled growth under heavy ad hoc workloads. Below is a concise table summarizing the main configuration steps: |**Step**|**Description**|**Example T-SQL**| |---|---|---| |**Enable Query Store**|Turn on the Query Store feature for the target database.|`ALTER DATABASE [MyDB] SET QUERY_STORE = ON;`| |**Set Operation Mode**|Choose **READ_WRITE** to allow captures or **READ_ONLY** for analysis on replicas.|`ALTER DATABASE [MyDB] SET QUERY_STORE (OPERATION_MODE = READ_WRITE);`| |**Configure Capture**|Adjust **QUERY_CAPTURE_MODE** and **QUERY_CAPTURE_POLICY** to control which queries are stored (e.g. all, high cost only).|`ALTER DATABASE [MyDB] SET QUERY_STORE (QUERY_CAPTURE_MODE = AUTO, QUERY_CAPTURE_POLICY = (MAX_PLANS_PER_QUERY = 10));`| |**Retention & Size**|Define **STALE_QUERY_THRESHOLD_DAYS** and **MAX_STORAGE_SIZE_MB** to govern how long data persists and storage limits.|`ALTER DATABASE [MyDB] SET QUERY_STORE (STALE_QUERY_THRESHOLD_DAYS = 30, MAX_STORAGE_SIZE_MB = 100);`| > [!caution] > After changing configuration, monitor **sys.database_query_store_options** and the Query Store Dashboard in SSMS to ensure the settings take effect as expected. --- ## ## References - Korotkevitch, D. (2022). _SQL Server advanced troubleshooting and performance tuning: Best practices and techniques_. O’Reilly Media. - Nevarez, B. (2022). _SQL Server query tuning and optimization: Optimize Microsoft SQL Server 2022 queries and applications_. Packt Publishing.