Rank Index Contention with sys.dm_db_index_operational_stats
Oct 22, 2026 / · 7 min read · sql server sys.dm_db_index_operational_stats sys.indexes sys.dm_os_wait_stats sys.dm_db_index_usage_stats lock contention row locks blocking indexes performance tuning dmv tsql ·Once sys.dm_os_wait_stats points to locking, the next question is which index the waits belong to. The script below reads sys.dm_db_index_operational_stats for the current database and ranks each user-table index by its number of row-lock waits. Next to each count it returns the share of row-lock requests that had to …
Read MoreMeasure Internal Latch Contention with sys.dm_os_latch_stats
Oct 21, 2026 / · 8 min read · sql server sys.dm_os_latch_stats sys.dm_os_wait_stats sys.dm_os_sys_info sys.dm_pdw_nodes_os_latch_stats latch contention latches wait statistics performance tuning dmv ·When LATCH_* waits show up near the top of sys.dm_os_wait_stats, you know threads are waiting on non-buffer latches. You don't know which engine structure they're waiting for. sys.dm_os_latch_stats splits those waits by latch class. The script below ranks the non-buffer classes that make up the first 95% of latch wait …
Read MoreCatch Memory Grant Waits via sys.dm_exec_query_memory_grants
Oct 17, 2026 / · 10 min read · sql server sys.dm_exec_query_memory_grants sys.dm_exec_query_resource_semaphores sys.dm_exec_requests sys.dm_exec_sql_text sys.dm_os_memory_clerks sys.dm_exec_query_plan sys.dm_os_wait_stats sys.messages sys.dm_os_sys_info memory grants resource semaphore performance tuning scripts ·Finding the one query stuck behind a RESOURCE_SEMAPHORE wait starts with a plain fact most dashboards gloss over: a query waiting on a memory grant isn't failing yet — it's queued, holding a worker thread while SQL Server decides who gets the next slice of execution memory. If that wait outlasts the query's own timeout …
Read MoreA DMV query that grinds to five or ten minutes against a large plan cache is a real failure mode, not a hypothetical one — joining sys.dm_exec_query_stats to sys.dm_exec_sql_text row by row scales badly once the cache holds enough plans. sys.dm_exec_procedure_stats exists to sidestep exactly that cost: one row per …
Read MoreA stored procedure that returned in 20 milliseconds yesterday is timing out today, and nothing in the code changed. Indexes are intact and statistics look current, yet the query now takes a different, slower path. One cause worth checking is a cached plan that was compiled for an unrepresentative set of parameter …
Read MoreDBCC DBREINDEX vs ALTER INDEX REBUILD in SQL Server
Open the SQL Agent job history on an instance that has been running for a decade and you will still find DBCC DBREINDEX in a nightly maintenance step, quietly doing its job. It works — which is exactly why nobody has touched it. But it has been deprecated for the better part of twenty years, it locks tables it does not …
Read MoreSQL Server Wait Statistics Report: dm_os_wait_stats
This T-SQL script reads sys.dm_os_wait_stats, removes the wait types that only record idle background threads, and ranks what is left by its share of the remaining wait time. The top rows show which resource the instance has spent the most time waiting for since the engine started or the counters were last reset. …
Read MoreSQL Server: Find Tables with Clustered Indexes for Rebuild
SQL Server Query to Identify Tables with Clustered Indexes for Rebuilding Database administrators frequently need to perform maintenance operations on clustered indexes to optimize database performance. This SQL Server query provides a quick and efficient way to identify all user tables that contain clustered indexes, …
Read MoreSQL Server UPDATE STATISTICS and SELECT Dynamic Scripts
Aug 6, 2025 / · 4 min read · sql server database administration t-sql performance tuning dynamic sql database maintenance statistics automation sysobjects update statistics sys.tables ·SQL Server Dynamic Update Statistics and Select Scripts for Database Maintenance Purpose These SQL Server scripts are designed to automatically generate database maintenance commands by dynamically creating UPDATE STATISTICS statements and SELECT queries for all user tables in a database. This approach is particularly …
Read MoreSQL Server DBCC DBREINDEX with Timing: Index Maintenance
Aug 5, 2025 / · 4 min read · sql server database maintenance performance tuning dbcc commands index optimization dba scripts database administration sql scripts DBCC DBREINDEX sysobjects ·SQL Server DBCC DBREINDEX Script with Timing - Database Maintenance Guide Database maintenance is a critical aspect of SQL Server administration, and index rebuilding plays a vital role in maintaining optimal database performance. This comprehensive guide explores powerful DBCC DBREINDEX scripts that include timing …
Read More