Is my stats updated on my Azure SQL DB Failover Group?
Claus Munch
Mar 23, 2026 ยท 1 min read
When managing Azure SQL Failover Groups, a common question from development teams is: "How do I know the statistics are updated on the DR replica?"
Since the secondary replica is read-only, statistics updates primarily flow from the Primary via replication. However, the secondary can also generate its own "temporary" statistics in tempdb to optimize read-heavy workloads.
The following script provides a comprehensive overview of your statistics' health, identifying whether they were replicated from the Primary or generated locally on the DR site:
SELECT
SCHEMA_NAME(obj.schema_id) AS [SchemaName],
obj.name AS [TableName],
stat.name AS [StatName],
sp.last_updated AS [LastUpdated],
stat.auto_created AS [IsAutoCreatedBySQL],
stat.user_created AS [IsUserCreated],
sp.modification_counter AS [RowsChangedSinceLastUpdate],
sp.rows AS [TotalRowsInTable],
sp.rows_sampled AS [RowsSampled],
CAST(100.0 * sp.rows_sampled / NULLIF(sp.rows, 0) AS DECIMAL(5,2)) AS [SamplePercent],
stat.is_temporary AS [IsTemporary],
CASE
WHEN stat.user_created = 1 AND sp.modification_counter = 0 THEN 'Likely Manual Update'
WHEN stat.auto_created = 1 AND sp.modification_counter = 0 THEN 'Likely Auto-Update'
WHEN sp.modification_counter > 0 THEN 'Awaiting Refresh (Stale)'
ELSE 'Unknown/Initial State'
END AS [UpdateMethodGuess],
CASE
WHEN stat.name LIKE '_readonly_database_statistic%' THEN 'DR Specific (Auto-Created)'
WHEN stat.is_temporary = 1 THEN 'DR Specific (Updated on Secondary)'
ELSE 'Replicated from Primary'
END AS [Origin]
FROM sys.stats AS stat
INNER JOIN sys.objects AS obj ON stat.object_id = obj.object_id
CROSS APPLY sys.dm_db_stats_properties(stat.object_id, stat.stats_id) AS sp
WHERE obj.type = 'U'
AND SCHEMA_NAME(obj.schema_id) = 'Customers' -- Filter for the specific schema
AND obj.name IN ('TransactionStatus') -- Filter for specific tables
ORDER BY sp.last_updated DESC;
This gives, in my humble oppinion, a great overview of the statistics on the database.