You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
22
22
23
23
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)].
24
24
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.
26
26
27
27
> [!IMPORTANT]
28
28
> 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
33
33
34
34
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.
35
35
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
-
50
36
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:
51
37
52
38
```sql
@@ -65,8 +51,6 @@ ALTER DATABASE [Database_Name]
65
51
66
52
### Enable automatic plan correction for secondary replicas
67
53
68
-
**Applies to**: [!INCLUDE [ssSQL22](../../includes/sssql22-md.md)] and later versions, [!INCLUDE [ssazure-sqldb](../../includes/ssazure-sqldb.md)].
69
-
70
54
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.
71
55
72
56
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
131
115
132
116
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.
133
117
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.
135
119
136
120
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:
137
121
@@ -168,17 +152,6 @@ ORDER BY SUM(qrs.count_executions * qrs.avg_cpu_time / 1000.0) DESC, AVG(qrs.avg
168
152
169
153
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.
170
154
171
-
### Query Store for readable secondaries telemetry in Azure diagnostic settings
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
-
182
155
### Performance considerations for Query Store for readable secondaries
183
156
184
157
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
187
160
188
161
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:
189
162
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
-
194
163
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:
0 commit comments