The longest wait name most DBAs will ever paste into a search engine is also one of the least interesting: QDS_CLEANUP_STALE_QUERIES_TASK_MAIN_LOOP_SLEEP is recorded by the Query Store cleanup task while it sleeps between runs that remove old query information from the store. Size-based and time-based cleanup both ride this schedule.
A timer between housekeeping sweeps, wherever Query Store is enabled.
Is It a Problem?
No; it has not been a contention point and belongs on the benign filter list with the rest of the QDS_* background waits. Its total tracks uptime and QS-enabled database count.
If Query Store cleanup itself is the concern, the base evidence is whether stores stay under their size caps: sys.database_query_store_options shows current size against max_storage_size_mb and whether the state flipped to READ_ONLY because cleanup lost the race. Those symptoms warrant retention tuning; this sleep timer never does.
Common Causes
- Query Store enabled with its cleanup task on schedule.
- Long uptime and many QS databases stacking up sleep intervals.
What To Do
- Filter it out; our
Get-WaitStatisticsscript excludes it by default. - For stores hitting their caps, tune
CLEANUP_POLICY(stale query threshold) andMAX_STORAGE_SIZE_MBper database rather than anything wait-related. - Nothing else attaches to this wait.
How To See It
Rank waits with Get-WaitStatistics, where it is filtered as background noise.
Part of the SQL Server Wait Types Library.
Related deep dive: IO_COMPLETION Wait Type.
Leave a Reply