TempDB monitoring and Troubleshooting for IO bottleneck

Hi Friends,

DBA’s spend good amount of time monitoring and troubleshooting TempDB. This may include IO Bottleneck, Allocation Contention, DDL contention, Space issues, etc. IO bottleneck is a common issue. Workload demands increased over time and many DBA’s jump to conclusion that IO sub system needs to be upgraded. Yes, IO sub system upgrade may be a final solution but not the first option.

In my opinion, Memory pressure can be checked first. If you do not have enough physical memory on the box, extra IO can occur. You can check the following performance counters like Buffer Cache Hit Ratio, Page Life Expectancy, Chekpoint pages/sec, etc to see if there is memory pressure.

Second, you need to know which queries cause maximum IO. There may be throwaway queries causing IO contention or even well written queries but not utilizing the right indexes, etc. Following code snippet gives you top 10 queries that are generating maximum IO across all executions. If you find a culprit after investigating the execution plan, you can probably re-write the queries.

    (total_logical_reads/execution_count) AS
    (total_logical_writes/execution_count) AS
                                 AS avg_phys_reads,
    statement_start_offset as stmt_start_offset, 
    (SELECT SUBSTRING(text, statement_start_offset/2 + 1,
        (CASE WHEN statement_end_offset = -1 
            THEN LEN(CONVERT(nvarchar(MAX),text)) * 2 
                ELSE statement_end_offset 
            END - statement_start_offset)/2)
     FROM sys.dm_exec_sql_text(sql_handle)) AS query_text, 
FROM sys.dm_exec_query_stats  
  (total_logical_reads + total_logical_writes) DESC

Hope this helps




About Amit Bansal

Amit Bansal is always brainstorming around SQL Server. Despite working with SQL since 1997, he is amazed that he keeps learning new things every single day. SQL Server is AB's first love, and his wife does not mind that. He tries to share as much and spreads the SQL goodness. Internals and Performance Tuning excites him, and also gives him sleepless nights at times, simply because he is not a genius, but quite a hard worker and does not give up. It has been a long and exciting journey since 1997, you can read here: http://sqlmaestros.com/amit-bansal/ He is on Twitter: https://www.twitter.com/A_Bansal

View all posts by Amit Bansal →

One Comment on “TempDB monitoring and Troubleshooting for IO bottleneck”

  1. I use this version of the query for the same analysis

    1 select (total_logical_reads/execution_count) AS avg_logical_reads,

    2 (total_logical_writes/execution_count) AS avg_logical_writes,

    3 (total_physical_reads/execution_count) AS avg_phys_reads,

    4 execution_count,

    5 text

    6 from sys.dm_exec_query_stats s

    7 cross apply sys.dm_exec_sql_text(plan_handle)order by total_logical_reads desc,total_logical_writes desc

    The difference in o/p for my query and Amit’s query is that with my query it gives a hint on the SP name rather than the query text inside a SP which can quiet be cumbersome to identify.

Leave a Reply

Your email address will not be published.