|
1 | 1 | --- |
2 | 2 | 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. |
4 | 4 | author: MikeRayMSFT |
5 | 5 | ms.author: mikeray |
6 | | -ms.reviewer: randolphwest |
7 | | -ms.date: 12/08/2025 |
| 6 | +ms.reviewer: randolphwest, wiassaf |
| 7 | +ms.date: 01/26/2026 |
8 | 8 | ms.service: sql |
9 | 9 | ms.topic: concept-article |
10 | 10 | ms.custom: |
11 | 11 | - 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. |
13 | 13 | monikerRange: "=azuresqldb-current || >=sql-server-ver17 || >=sql-server-linux-ver17" |
14 | 14 | --- |
15 | 15 |
|
16 | | -# Persisted statistics for readable secondaries |
| 16 | +# Persisted statistics for readable secondary replicas |
17 | 17 |
|
18 | 18 | [!INCLUDE [sqlserver2025-asdb](../../includes/applies-to-version/sqlserver2025-asdb.md)] |
19 | 19 |
|
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. |
21 | 21 |
|
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. |
23 | 25 |
|
24 | 26 | ## Background |
25 | 27 |
|
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`. |
27 | 29 |
|
28 | 30 | 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. |
29 | 31 |
|
30 | 32 | 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. |
31 | 33 |
|
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 | | - |
34 | 34 | ## Support catalog views |
35 | 35 |
|
36 | 36 | 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; |
98 | 98 |
|
99 | 99 | ## Considerations |
100 | 100 |
|
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. |
102 | 102 |
|
103 | 103 | ## Related content |
104 | 104 |
|
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) |
106 | 106 | - [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) |
107 | 107 | - [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