Skip to content

Commit 010fc70

Browse files
Merge pull request #36475 from WilliamDAssafMSFT/20260126-query-store-readable-secondaries
20260126 query store readable secondaries
2 parents b5fb93e + e9bcefd commit 010fc70

6 files changed

Lines changed: 77 additions & 53 deletions

File tree

azure-sql/database/features-comparison.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22
title: Compare SQL Database Engine Features
33
titleSuffix: Azure SQL Database & Azure SQL Managed Instance
44
description: This article compares the database engine features of Azure SQL Database and Azure SQL Managed Instance
5-
author: danimir
6-
ms.author: danil
7-
ms.reviewer: wiassaf, bonova, mathoma, danil, randolphwest
8-
ms.date: 06/16/2025
5+
author: WilliamDAssafMSFT
6+
ms.author: wiassaf
7+
ms.reviewer: danil, bonova, mathoma, danil, randolphwest
8+
ms.date: 01/27/2026
99
ms.service: azure-sql
1010
ms.subservice: service-overview
1111
ms.topic: product-comparison
@@ -97,7 +97,7 @@ The following table lists the major features of SQL Server and provides informat
9797
| [Operators](/sql/t-sql/language-elements/operators-transact-sql) | Most, see individual operators |Yes, see [T-SQL differences](../managed-instance/transact-sql-tsql-differences-sql-server.md) |
9898
| [Query Notifications](/sql/relational-databases/native-client/features/working-with-query-notifications) | No | Yes |
9999
| [Query Store](/sql/relational-databases/performance/monitoring-performance-by-using-the-query-store) | Yes | Yes |
100-
| [Query Store for secondary replicas](/sql/relational-databases/performance/query-store-for-secondary-replicas) | No, the Query Store for secondary replicas feature isn't available for Azure SQL Database. Currently, the Query Store on the secondary replica contains information about workloads from the primary replica. | No, the Query Store for secondary replicas feature isn't available for Azure SQL Managed Instance. Currently, the Query Store on the secondary replica contains information about workloads from the primary replica.|
100+
| [Query Store for secondary replicas](/sql/relational-databases/performance/query-store-for-secondary-replicas) | [Yes](/sql/relational-databases/performance/query-store-for-secondary-replicas) | [Yes](/sql/relational-databases/performance/query-store-for-secondary-replicas) |
101101
| [Machine Learning Services](/sql/advanced-analytics/what-is-sql-server-machine-learning) (_Formerly R Services_)| No | Yes, see [Machine Learning Services in Azure SQL Managed Instance](../managed-instance/machine-learning-services-overview.md) |
102102
| [Recovery models](/sql/relational-databases/backup-restore/recovery-models-sql-server) | Only Full Recovery that guarantees high availability is supported. Simple and Bulk Logged recovery models aren't available. | Only Full Recovery that guarantees high availability is supported. Simple and Bulk Logged recovery models aren't available. |
103103
| [Resource governor](/sql/relational-databases/resource-governor/resource-governor) | No | Yes |

azure-sql/database/read-scale-out.md

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22
title: Read Queries on Replicas
33
titleSuffix: Azure SQL Database & Azure SQL Managed Instance
44
description: Azure SQL provides the ability to use the capacity of read-only replicas for read workloads, called Read Scale-Out.
5-
author: rajeshsetlem
6-
ms.author: rsetlem
7-
ms.reviewer: wiassaf, mathoma, randolphwest
8-
ms.date: 06/13/2025
5+
author: WilliamDAssafMSFT
6+
ms.author: wiassaf
7+
ms.reviewer: rsetlem, mathoma, randolphwest, mikeray
8+
ms.date: 01/27/2026
99
ms.service: azure-sql
1010
ms.subservice: scale-out
1111
ms.topic: concept-article
@@ -39,7 +39,7 @@ If your SQL connection string is configured with `ApplicationIntent=ReadOnly`, t
3939
For Azure SQL Database only, if you wish to ensure that the application connects to the primary replica regardless of the `ApplicationIntent` setting in the SQL connection string, you must explicitly disable read scale-out when creating the database or when altering its configuration. For example, if you upgrade your database from Standard or General Purpose tier to Premium or Business Critical and want to make sure all your connections continue to go to the primary replica, disable read scale-out. For details on how to disable it, see [Enable and disable read scale-out](#enable-and-disable-read-scale-out-for-sql-database).
4040

4141
> [!NOTE]
42-
> Query Store and SQL Profiler features are not supported on read-only replicas.
42+
> SQL Profiler feature is not supported on read-only replicas.
4343
4444
## Data consistency
4545

@@ -229,12 +229,18 @@ In this fashion, creating a geo-replica can provide multiple additional read-onl
229229
230230
## Feature support on read-only replicas
231231

232-
A list of the behavior of some features on read-only replicas follows:
232+
Query Store on secondary replicas is supported in Azure SQL Database and Azure SQL Managed Instance. For more information, see [Query Store for readable secondary replicas](/sql/relational-databases/performance/query-store-for-secondary-replicas).
233233

234234
- Auditing on read-only replicas is automatically enabled. For more information about the hierarchy of the storage folders, naming conventions, and log format, see [SQL Database audit log format](audit-log-format.md).
235-
- [Query Performance Insight for Azure SQL Database](query-performance-insight-use.md) relies on data from the [Query Store](/sql/relational-databases/performance/monitoring-performance-by-using-the-query-store), which currently doesn't track activity on the read-only replica. Query Performance Insight doesn't show queries that execute on the read-only replica.
236-
- Automatic tuning relies on the Query Store, as detailed in the [Automatic tuning paper](https://www.microsoft.com/research/uploads/prod/2019/02/autoindexing_azuredb.pdf). Automatic tuning only works for workloads running on the primary replica.
237-
235+
- [Query Performance Insight for Azure SQL Database](query-performance-insight-use.md) relies on data from the [Query Store](/sql/relational-databases/performance/monitoring-performance-by-using-the-query-store?view=azuresqldb-current&preserve-view=true). Query Performance Insights `does not` currently support the `replica_group_id` concept which is associated with the [Query Store for readable secondaries](/sql/relational-databases/performance/query-store-for-secondary-replicas?view=azuresqldb-current&preserve-view=true) feature. Data displayed within the Query Performance Insights dashboard will aggregate all runtime and wait statistics data from all replicas.
236+
- The [Automatic plan correction](/sql/relational-databases/automatic-tuning/automatic-tuning?view=azuresqldb-current&preserve-view=true#automatic-plan-correction) component of the [automatic tuning](/sql/relational-databases/automatic-tuning/automatic-tuning?view=azuresqldb-current&preserve-view=true) feature is supported on read-only replicas. Each database would need to be enabled to support automatic plan correction. See [automatic plan correction for secondary replicas](/sql/relational-databases/performance/query-store-for-secondary-replicas?view=azuresqldb-current&preserve-view=true#enable-automatic-plan-correction-for-secondary-replicas) for more information.
237+
- [Diagnostic settings in Azure Monitor](/azure/azure-monitor/platform/diagnostic-settings) supports the streaming of Query Store [runtime statistics](metrics-diagnostic-telemetry-logging-streaming-export-configure.md#query-store-runtime-statistics) through Azure diagnostic settings. Two columns are included to help identify the replica source of the telemetry data:
238+
239+
- `is_primary_b`: A Boolean value indicating whether the data originated from the primary replica (true) or a secondary replica (false)
240+
- `replica_group_id`: An integer that corresponds to the replica role
241+
242+
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.
243+
238244
## Related content
239245

240246
- [Configure a license-free standby replica for Azure SQL Database](standby-replica-how-to-configure.md)

docs/relational-databases/performance/parameter-sensitive-plan-optimization.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ title: Parameter Sensitive Plan Optimization
33
description: Learn about Parameter Sensitive Plan Optimization in the Query Store.
44
author: MikeRayMSFT
55
ms.author: mikeray
6-
ms.reviewer: derekw, maghan, randolphwest
6+
ms.reviewer: derekw, maghan, randolphwest, wiassaf
77
ms.date: 10/23/2025
88
ms.service: sql
99
ms.subservice: performance
@@ -333,19 +333,19 @@ PSP optimization provides audit data for the dispatcher plan statement, and any
333333
| Issue | Date discovered | Status | Date resolved |
334334
| --- | --- | --- | --- |
335335
| Access Violation exception occurs in Query Store in [!INCLUDE [sssql22-md](../../includes/sssql22-md.md)] under certain conditions. You might encounter Access violation exceptions when PSP optimization Query Store integration is enabled. For more information, see the update in [Parameter Sensitive Plan Optimization, Why?](https://techcommunity.microsoft.com/blog/sqlserver/parameter-sensitive-plan-optimization-why/3836281) | March 2023 | Resolved | August 2023 (CU 7) |
336-
| Access violation exception can occur on readable secondary replicas under certain conditions in [!INCLUDE [sssql25-md](../../includes/sssql25-md.md)]. You might encounter access violation excpetions when PSP optimization is enabled on a readable secondary database that has been configured to use the [Query Store for readable secondaries](query-store-for-secondary-replicas.md) feature. | September 2025 | Has workaround | |
336+
| Access violation exception can occur on readable secondary replicas under certain conditions in [!INCLUDE [sssql25-md](../../includes/sssql25-md.md)]. You might encounter access violation exceptions when PSP optimization is enabled on a readable secondary database that has been configured to use the [Query Store for readable secondary replicas](query-store-for-secondary-replicas.md) feature. | September 2025 | Has workaround | |
337337

338338
### Has workaround
339339

340340
#### Access violation exception can occur on readable secondary replicas under certain conditions
341341

342-
Queries that meet the following conditions could experience an access violation when a PSP [query variant](#query-variant) can't determine the persisted state of its parent dispatcher statement:
342+
Queries that meet the following conditions could experience an access violation when a parameter sensitive plan (PSP) [query variant](#query-variant) can't determine the persisted state of its parent dispatcher statement:
343343

344344
- Executed on a secondary replica
345345
- Sensitive to parameter sniffing
346346
- Eligible for parameter sensitive plan (PSP) optimization
347347

348-
**Workaround**: Disable PSP on secondaries for each database that was onboarded to use the Query Store for readable secondaries feature. From within the context of a specific database, issue the following Transact-SQL statement:
348+
**Workaround**: Disable parameter sensitive plan (PSP) optimization on secondary replicas for each database that was onboarded to use the Query Store for readable secondary replicas feature. From within the context of a specific database, issue the following Transact-SQL statement:
349349

350350
```sql
351351
ALTER DATABASE SCOPED CONFIGURATION FOR SECONDARY

docs/relational-databases/performance/persisted-stats-secondary-replicas.md

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,36 @@
11
---
22
title: Persisted Statistics for Readable Secondary Replicas
3-
description: Describes functions of auto created statistics on readable secondaries. Introduces in SQL Server 2025.
3+
description: Describes functions of auto created statistics on readable secondary replicas. Introduces in SQL Server 2025.
44
author: MikeRayMSFT
55
ms.author: mikeray
6-
ms.reviewer: randolphwest
7-
ms.date: 12/08/2025
6+
ms.reviewer: randolphwest, wiassaf
7+
ms.date: 01/26/2026
88
ms.service: sql
99
ms.topic: concept-article
1010
ms.custom:
1111
- ignite-2025
12-
# customer intent: As a data engineer, I want statistics that are created on readable secondaries to be persisted so that my workloads that are running against secondary replicas are optimized.
12+
# customer intent: As a data engineer, I want statistics that are created on readable secondary replicas to be persisted so that my workloads that are running against secondary replicas are optimized.
1313
monikerRange: "=azuresqldb-current || >=sql-server-ver17 || >=sql-server-linux-ver17"
1414
---
1515

16-
# Persisted statistics for readable secondaries
16+
# Persisted statistics for readable secondary replicas
1717

1818
[!INCLUDE [sqlserver2025-asdb](../../includes/applies-to-version/sqlserver2025-asdb.md)]
1919

20-
[Query Store for readable secondaries](query-store-for-secondary-replicas.md) is available in [!INCLUDE [sssql25-md](../../includes/sssql25-md.md)] and Azure SQL Database, and the persisted statistics for readable secondaries feature uses the infrastructure that Query Store has in place for readable secondaries.
20+
With persisted statistics, primary replica retains statistics information as permanent statistics, which can be sent to all secondary replicas. This process occurs automatically without requiring manual intervention. The statistics persistence mechanism uses the Query Store for readable secondary replicas infrastructure.
2121

22-
Query Store for readable secondaries is **on** by default in [!INCLUDE [sssql25-md](../../includes/sssql25-md.md)] and Azure SQL Database.
22+
[Query Store for readable secondary replicas](query-store-for-secondary-replicas.md) is available in [!INCLUDE [sssql25-md](../../includes/sssql25-md.md)] and Azure SQL Database.
23+
24+
Query Store for readable secondary replicas is **on** by default in [!INCLUDE [sssql25-md](../../includes/sssql25-md.md)] and Azure SQL Database.
2325

2426
## Background
2527

26-
On readable secondary replicas, statistics can also be automatically created when the [auto create statistics](../../t-sql/statements/alter-database-transact-sql-set-options.md) option is enabled but those statistics are temporary and disappear when an instance is restarted. When statistics on a read-only database or read-only snapshot are missing or stale, the Database Engine creates and maintains temporary statistics in `tempdb`.
28+
On readable secondary replicas, statistics can also be automatically created when the [auto create statistics](../../t-sql/statements/alter-database-transact-sql-set-options.md) option is enabled, but those statistics are temporary and disappear when an instance is restarted. When statistics on a read-only database or read-only snapshot are missing or stale, the Database Engine creates and maintains temporary statistics in `tempdb`.
2729

2830
When the Database Engine creates temporary statistics, the statistics name is appended with the suffix `_readonly_database_statistic` to differentiate the temporary statistics from the permanent statistics. The suffix `_readonly_database_statistic` is reserved for statistics generated by SQL Server. The reason that this approach was taken was to address workloads that execute against readable secondary replicas that might require distinct statistics that don't exist on the primary replica.
2931

3032
Temporary statistics created on secondary replicas remain visible only to the replica that generated them. The primary replica never directly accesses these temporary statistics objects and is only aware of the permanent statistics object after persistence. When temporary statistics are persisted to the primary replica, they become available to all replicas in the availability group through the synchronization mechanism.
3133

32-
The persistence mechanism uses the Query Store for readable secondaries infrastructure introduced in [!INCLUDE [sssql22-md](../../includes/sssql22-md.md)]. Statistics information is sent to the primary replica where it's persisted as permanent statistics, then synchronized back to all secondary replicas. This process occurs automatically without requiring manual intervention.
33-
3434
## Support catalog views
3535

3636
To support comparing stats creation or update between secondary and primary, and to assist with understanding where statistics were created, three new columns have been added to the `sys.stats` catalog view:
@@ -98,10 +98,10 @@ ORDER BY sch.[name], obj.[name], s.stats_id;
9898

9999
## Considerations
100100

101-
The persisted statistics for readable secondaries feature is enabled by default as long as the [auto create statistics](../../t-sql/statements/alter-database-transact-sql-set-options.md) option is enabled and the `READABLE_SECONDARY_TEMPORARY_STATS_AUTO_CREATE` and `READABLE_SECONDARY_TEMPORARY_STATS_AUTO_UPDATE` database scoped configuration options are enabled, which is the default configuration. There's no database-scoped configuration to toggle the feature on and off.
101+
The persisted statistics for readable secondary replicas feature is enabled by default as long as the [auto create statistics](../../t-sql/statements/alter-database-transact-sql-set-options.md) option is enabled and the `READABLE_SECONDARY_TEMPORARY_STATS_AUTO_CREATE` and `READABLE_SECONDARY_TEMPORARY_STATS_AUTO_UPDATE` database scoped configuration options are enabled, which is the default configuration. There's no database-scoped configuration to toggle the feature on and off.
102102

103103
## Related content
104104

105-
- [Query Store for readable secondaries](query-store-for-secondary-replicas.md)
105+
- [Query Store for readable secondary replicas](query-store-for-secondary-replicas.md)
106106
- [AlwaysOn: Making latest statistics available on Readable Secondary, Read-Only database and Database Snapshot](/archive/blogs/sqlserverstorageengine/alwayson-making-latest-statistics-available-on-readable-secondary-read-only-database-and-database-snapshot)
107107
- [Statistics for Read-Only Access Databases](../../database-engine/availability-groups/windows/active-secondaries-readable-secondary-replicas-always-on-availability-groups.md#Read-OnlyStats)

0 commit comments

Comments
 (0)