WAIT_ON_SYNC_STATISTICS_REFRESH Wait Type in SQL Server

⏳Part of the SQL Server Wait Types Library, every wait type explained.Related deep dive: RESOURCE_SEMAPHORE Wait TypeRelated pillar: Performance & Troubleshooting
⚡WAIT_ON_SYNC_STATISTICS_REFRESH is a query stopped before it can compile, waiting for an automatic statistics update to finish. It explains the query that is normally instant but sometimes hangs for a while. Run the check to see how often it happens and how long each wait takes, then decide whether to switch that database to asynchronous updates.

Microsoft describes it as waiting for a synchronous statistics update to complete before query compilation and execution can resume, and it exists from SQL Server 2019. With automatic statistics updates in their default synchronous mode, a query that finds its statistics out of date updates them first and only then compiles. This wait is that pause. It is recorded in preemptive mode, so the thread keeps working on the CPU while the update runs.


Is It a Problem?

It is when it shows real duration, because a user query is paying for statistics maintenance at a random moment. How long depends on the number of statistics that need refreshing, the size of the tables and the sampling options, such as FULLSCAN; on large tables that change a lot, a synchronous update in the middle of the working day can hold a query for a long time.

Occasional short waits on modest tables are the feature working as designed. Judge it over an interval rather than the cumulative totals: the baseline to monitor is the average wait per occurrence next to your data load schedule. A rising average, or spikes right after loads, is the signal.


Common Causes

  • Automatic statistics updates running synchronously, which is the default, on large tables that pass the modification threshold during busy hours.
  • ETL loads that change enough rows to make statistics stale, so the next user query pays for the refresh.
  • FULLSCAN or high persisted sample rates on big tables, which make each refresh slower.

The Check To Run

Rank it against everything else with Get Wait Statistics, and read the count and the average for this wait:

SELECT
    wait_type,
    waiting_tasks_count,
    wait_time_ms,
    CAST(wait_time_ms * 1.0 / NULLIF(waiting_tasks_count, 0) AS DECIMAL(12, 2)) AS avg_wait_ms,
    max_wait_time_ms
FROM sys.dm_os_wait_stats
WHERE wait_type IN (
    N'WAIT_ON_SYNC_STATISTICS_REFRESH')
ORDER BY wait_time_ms DESC;

Then see which databases update statistics synchronously; is_auto_update_stats_async_on = 0 with is_auto_update_stats_on = 1 is the default, synchronous mode:

SELECT
    name,
    is_auto_update_stats_on,
    is_auto_update_stats_async_on
FROM sys.databases
ORDER BY name;

Get Statistics Health shows which statistics are stale and how many modifications they have taken since their last update. The wait stats query needs VIEW SERVER STATE.


What To Do

  1. Turn on asynchronous statistics updates for the database: ALTER DATABASE [YourDb] SET AUTO_UPDATE_STATISTICS_ASYNC ON;. Queries then compile with the existing statistics while the update runs in the background, so they never wait for it. The trade is that a query may run once more on stale statistics.
  2. On SQL Server 2022 and later, also consider the ASYNC_STATS_UPDATE_WAIT_AT_LOW_PRIORITY database scoped configuration, for the case where the background update’s schema modification lock gets in the way of other queries.
  3. Update statistics yourself on the tables that churn, straight after their load windows, so automatic updates rarely need to fire during the day.
  4. Avoid FULLSCAN on very large tables unless a plan needs it.

Frequently Asked Questions

Does asynchronous statistics update apply to temporary tables?

Not to local temporary tables. Their statistics are always updated synchronously, whatever the database setting.

Why do I not see this wait on SQL Server 2017?

It was added in SQL Server 2019. On older versions the same pause happens, it just is not named.


Where To Go Next

If WAIT_ON_SYNC_STATISTICS_REFRESH is in your top waits, these are the next places to look.

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *