Skip to content

Commit ad910af

Browse files
Merge pull request #35780 from thesqlsith/main
Query Store for readable secondaries update
2 parents 0405401 + abe1b73 commit ad910af

1 file changed

Lines changed: 4 additions & 35 deletions

File tree

docs/relational-databases/performance/query-store-for-secondary-replicas.md

Lines changed: 4 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ description: Query Store can be configured to monitor and tuning workloads on se
44
author: MikeRayMSFT
55
ms.author: mikeray
66
ms.reviewer: randolphwest
7-
ms.date: 10/23/2025
7+
ms.date: 11/07/2025
88
ms.service: sql
99
ms.subservice: performance
1010
ms.topic: concept-article
@@ -16,13 +16,13 @@ monikerRange: ">=sql-server-ver16"
1616
---
1717
# Query Store for readable secondaries
1818

19-
[!INCLUDE [sqlserver2025-asdb-asmi](../../includes/applies-to-version/sqlserver2025-asdb-asmi.md)]
19+
[!INCLUDE [sqlserver2022-and-later](../../includes/applies-to-version/sqlserver2022-and-later.md)]
2020

2121
Query Store for readable secondaries enables Query Store insights for workloads that run on secondary replicas. When enabled, secondary replicas stream query execution information (such as runtime and wait statistics) to the primary replica, where the data is persisted in Query Store and made visible across all replicas.
2222

2323
The feature was originally introduced in [!INCLUDE [sssql22-md](../../includes/sssql22-md.md)], however it was off by default and required a trace flag to enable. This was due in part because the feature was and remains to be in a preview state for [!INCLUDE [sssql22-md](../../includes/sssql22-md.md)].
2424

25-
Beginning with [!INCLUDE [sssql25-md](../../includes/sssql25-md.md)] and [!INCLUDE [ssazure-sqldb](../../includes/ssazure-sqldb.md)], Query Store for readable secondaries is enabled by default.
25+
Beginning with [!INCLUDE [sssql25-md](../../includes/sssql25-md.md)], Query Store for readable secondaries is enabled by default.
2626

2727
> [!IMPORTANT]
2828
> In [!INCLUDE [sssql22-md](../../includes/sssql22-md.md)], Query Store for readable secondaries is a preview feature and requires trace flag 12606 to be applied to the primary and all readable secondary replicas. It **isn't** intended for production deployments that are based on [!INCLUDE [sssql22-md](../../includes/sssql22-md.md)]. For more information, see [SQL Server 2022 release notes](../../sql-server/sql-server-2022-release-notes.md).
@@ -33,20 +33,6 @@ Beginning with [!INCLUDE [sssql25-md](../../includes/sssql25-md.md)] and [!INCLU
3333

3434
Before you use Query Store for readable secondaries on a [!INCLUDE [sssql25-md](../../includes/sssql25-md.md)] instance, an [Always On availability group](../../database-engine/availability-groups/windows/overview-of-always-on-availability-groups-sql-server.md) must be configured.
3535

36-
For Azure SQL Database, Query Store for readable secondaries supports the following service tiers:
37-
38-
- General purpose with [active geo-replication](/azure/azure-sql/database/active-geo-replication-overview) (no built-in high availability replicas; requires geo-replication configuration for secondary support)
39-
- Premium (includes built-in high availability replicas; active geo-replication also supported)
40-
- Business critical (includes built-in high availability replicas; active geo-replication also supported)
41-
- [Azure SQL Managed Instance with the Always-up-to-date policy](/azure/azure-sql/managed-instance/update-policy#always-up-to-date-update-policy)
42-
- General purpose with a [failover group](/azure/azure-sql/managed-instance/failover-group-sql-mi)
43-
- Business critical (includes built-in high availability replicas)
44-
45-
> [!NOTE]
46-
> [!INCLUDE [ssazure-sqldb](../../includes/ssazure-sqldb.md)] existing and newly created databases are automatically enrolled and enabled to support the Query Store for readable secondaries feature on supported service tiers.
47-
48-
**Applies to**: [!INCLUDE [ssSQL22](../../includes/sssql22-md.md)] and later versions.
49-
5036
If Query Store isn't already enabled and in `READ_WRITE` mode on the primary replica, you must enable it before proceeding. Execute the following script for each desired database on the primary replica:
5137

5238
```sql
@@ -65,8 +51,6 @@ ALTER DATABASE [Database_Name]
6551

6652
### Enable automatic plan correction for secondary replicas
6753

68-
**Applies to**: [!INCLUDE [ssSQL22](../../includes/sssql22-md.md)] and later versions, [!INCLUDE [ssazure-sqldb](../../includes/ssazure-sqldb.md)].
69-
7054
After enabling Query Store for secondary replicas, you can optionally enable automatic tuning to allow the automatic plan correction feature to force plans on secondary replicas. This enables the query optimizer to automatically identify and fix query performance issues caused by execution plan regressions on secondary replicas.
7155

7256
To enable automatic plan correction for secondary replicas, connect to the primary replica and execute the following script for each desired database:
@@ -131,7 +115,7 @@ The data stored about queries can be analyzed as workloads on a role basis. Quer
131115

132116
If AG1 and AG2 are configured to allow read-only connections when a read-only workload executes against either of AG1's secondary replicas, the Query Store execution statistics are sent to AG1's primary replica and aggregated and persisted as data that was generated from the `secondary` role before that data is sent back to all of the secondary replicas including the global forwarder in AG2. When a separate workload is executed against AG2's primary, the global fowarder, its data is sent back to the primary replica of AG1 and persisted as data that was generated from `Geo secondary` role.
133117

134-
From an observability perspective, the [sys.query_store_runtime_stats](../system-catalog-views/sys-query-store-runtime-stats-transact-sql.md) system catalog view is extended to help identify the role where the execution statistics originated from. There's a relationship between this view and the [sys.query_store_replicas](../system-catalog-views/sys-query-store-replicas.md) system catalog view, which can provide a more friendly name of the role. In SQL Server, Azure SQL Database, and Azure SQL Managed Instance, the replica_name column is `NULL`. However, the replica_name column is populated for the Hyperscale service tier if there's a named replica present and is being used for read-only workloads.
118+
From an observability perspective, the [sys.query_store_runtime_stats](../system-catalog-views/sys-query-store-runtime-stats-transact-sql.md) system catalog view is extended to help identify the role where the execution statistics originated from. There's a relationship between this view and the [sys.query_store_replicas](../system-catalog-views/sys-query-store-replicas.md) system catalog view, which can provide a more friendly name of the role. In SQL Server the replica_name column is `NULL`. However, the replica_name column is populated for the Hyperscale service tier if there's a named replica present and is being used for read-only workloads.
135119

136120
An example of a t-sql query that could be used to provide an overall analysis of the top 50 queries over the last 8 hours, which consumed CPU resources from all replicas would be:
137121

@@ -168,17 +152,6 @@ ORDER BY SUM(qrs.count_executions * qrs.avg_cpu_time / 1000.0) DESC, AVG(qrs.avg
168152

169153
The Query Store reports in [SQL Server Management Studio (SSMS) 21](/ssms/release-notes-21#whats-new-in-2100) and later versions provide a **Replica** dropdown list, which provides a way to view Query Store data across various replica sets/roles. Also, inside of the Object explorer view, the Query Store node reflects the current state of Query Store (that is, READ_CAPTURE) if connected to a readable secondary replica.
170154

171-
### Query Store for readable secondaries telemetry in Azure diagnostic settings
172-
173-
**Applies to**: [!INCLUDE [ssazure-sqldb](../../includes/ssazure-sqldb.md)]
174-
175-
When streaming Query Store [runtime statistics](/azure/azure-sql/database/metrics-diagnostic-telemetry-logging-streaming-export-configure#query-store-runtime-statistics) through Azure diagnostic settings, two columns are included to help identify the replica source of the telemetry data:
176-
177-
- `is_primary_b`: A Boolean value indicating whether the data originated from the primary replica (true) or a secondary replica (false)
178-
- `replica_group_id`: An integer that corresponds to the replica role
179-
180-
These columns are essential for disambiguating metrics and performance data when analyzing workloads across replica sets. When configuring diagnostic settings to stream Query Store runtime statistics to Log Analytics, Event Hubs, or Azure Storage, ensure your queries and dashboards account for these columns to properly segment data by replica role. For more information on configuring diagnostic settings and available metrics, see [Diagnostic settings in Azure Monitor](/azure/azure-monitor/platform/diagnostic-settings).
181-
182155
### Performance considerations for Query Store for readable secondaries
183156

184157
The channel used by secondary replicas to send query information back to the primary replica is the same channel used to keep secondary replicas up to date. What does `channel` mean here?
@@ -187,10 +160,6 @@ In an availability group (HADR) configuration, replicas synchronize with each ot
187160

188161
When Query Store for readable secondaries is enabled, it doesn't create a separate network endpoint. Instead, it establishes a new logical communication path over the existing transport layer:
189162

190-
- For Azure SQL Database (non-Hyperscale), Azure SQL Managed Instance, and SQL Server, this uses the high availability and disaster recovery (HADR) Always On transport layer.
191-
192-
- For Azure SQL Database Hyperscale, the RbIo (Remote Blob I/O) transport layer is used, which is the communications channel between the compute nodes and the Log Service/Page Servers. RbIo provides a reliable, encrypted channel for moving log records and data pages.
193-
194163
This path multiplexes Query Store execution data (query text, plans, runtime/wait stats) alongside the normal log record traffic, using the same encrypted session. The feature has its own capture and receive queues, which can be viewed by querying the `sys.database_query_store_internal_state` view from any replica's perspective:
195164

196165
```sql

0 commit comments

Comments
 (0)