/* Skip the Wait sample: what is your SQL Server waiting for? ----------------------------------------------------------- Every query either works or waits. This script lists the waits your server has spent the most time on since it was last started. Waits of background tasks that are idle by design are left out first, so the list shows what your workload actually waits for. (Filtering idle waits before ranking is a common practice, described among others by Paul Randal of SQLskills. The exclusion table below is my own selection, grouped by why each wait is harmless.) - Read-only: it only queries sys.dm_os_wait_stats. It changes nothing and reads no table data. - Works on SQL Server 2012 and later and on Azure SQL Managed Instance. - Needs the VIEW SERVER STATE permission. - The numbers add up from the last restart, so run it after a normal busy period. How to read the result: the first few rows usually account for most of the waiting. PAGEIOLATCH_* reading data from disk (memory or scans) WRITELOG writing the transaction log LCK_M_* waiting for locks held by other sessions (blocking) CXPACKET/CXCONSUMER parallel queries SOS_SCHEDULER_YIELD CPU pressure ASYNC_NETWORK_IO the application reads results slowly A wait type is a symptom, not a diagnosis. It tells you where to look next. This is one script from the read-only diagnostic pack I use in the Skip the Wait Health Check. Michal Kovac, MICO Software, https://skipthewait.services MIT License. Copyright (c) 2026 Michal Kovac MICO s.r.o. Permission is hereby granted, free of charge, to any person obtaining a copy of this software, to deal in the software without restriction, including the rights to use, copy, modify, merge, publish, distribute, sublicense and/or sell copies, subject to including this notice. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND. */ WITH idle AS ( SELECT v.pattern FROM (VALUES -- background tasks that wait for work by design (N'CHECKPOINT_QUEUE'), (N'CHKPT'), (N'DIRTY_PAGE_POLL'), (N'DISPATCHER_QUEUE_SEMAPHORE'), (N'EXECSYNC'), (N'FSAGENT'), (N'KSOURCE_WAKEUP'), (N'LAZYWRITER_SLEEP'), (N'LOGMGR_QUEUE'), (N'MEMORY_ALLOCATION_EXT'), (N'ONDEMAND_TASK_QUEUE'), (N'PVS_PREALLOCATE'), (N'REQUEST_FOR_DEADLOCK_SEARCH'), (N'RESOURCE_QUEUE'), (N'SERVER_IDLE_CHECK'), (N'SLEEP[_]%'), (N'SOS_WORK_DISPATCHER'), (N'SP_SERVER_DIAGNOSTICS_SLEEP'), (N'UCS_SESSION_REGISTRATION'), -- sessions explicitly waiting (WAITFOR, Service Broker queues) (N'BROKER[_]%'), (N'WAIT_FOR_RESULTS'), (N'WAITFOR'), (N'WAITFOR_TASKSHUTDOWN'), -- monitoring and tracing infrastructure (N'PREEMPTIVE[_]XE[_]%'), (N'PWAIT[_]%'), (N'QDS[_]%'), (N'SQLTRACE[_]%'), (N'XE[_]%'), -- high availability background threads (N'DBMIRROR%'), (N'HADR_CLUSAPI_CALL'), (N'HADR_FABRIC_CALLBACK'), (N'HADR_FILESTREAM_IOMGR_IOCOMPLETION'), (N'HADR_LOGCAPTURE_WAIT'), (N'HADR_NOTIFICATION_DEQUEUE'), (N'HADR_TIMER_TASK'), (N'HADR_WORK_QUEUE'), (N'PARALLEL[_]REDO[_]%'), (N'REDO_THREAD_PENDING_WORK'), -- idle waits of optional features (CLR, full-text, In-Memory OLTP, backup devices, HTTP) (N'CLR_AUTO_EVENT'), (N'CLR_MANUAL_EVENT'), (N'CLR_SEMAPHORE'), (N'FT_IFTS%'), (N'PREEMPTIVE_OS_FLUSHFILEBUFFERS'), (N'SNI_HTTP_ACCEPT'), (N'VDI_CLIENT_OTHER'), (N'WAIT[_]XTP[_]%') ) AS v (pattern) ), waits AS ( SELECT ws.wait_type, ws.waiting_tasks_count, ws.wait_time_ms, ws.signal_wait_time_ms FROM sys.dm_os_wait_stats AS ws WHERE ws.waiting_tasks_count > 0 AND NOT EXISTS (SELECT 1 FROM idle WHERE ws.wait_type LIKE idle.pattern) ) SELECT TOP (15) wait_type, CAST(100.0 * wait_time_ms / SUM(wait_time_ms) OVER () AS decimal(5, 1)) AS pct_of_waiting, CAST(wait_time_ms / 1000.0 / 60 AS decimal(18, 1)) AS total_wait_minutes, waiting_tasks_count AS times_waited, CAST(1.0 * wait_time_ms / NULLIF(waiting_tasks_count, 0) AS decimal(18, 1)) AS avg_wait_ms, CAST(100.0 * signal_wait_time_ms / NULLIF(wait_time_ms, 0) AS decimal(5, 1)) AS pct_waiting_for_cpu, (SELECT sqlserver_start_time FROM sys.dm_os_sys_info) AS counted_since FROM waits ORDER BY wait_time_ms DESC;