次の方法で共有


Q&A: Top 10 DMVs Admins must know in SQL Server

In the recent Virtual TechDays that got concluded we had a number of sessions and there were questions that couldnt be answered. You can download the PPT for the "Top 10 DMVs Admin must know in SQL Server" at: https://download.microsoft.com/download/6/1/A/61A76FEB-8035-47BC-9573-A438F7513E6A/DAY2/TRACK4/Top_10_DMVs.ppt

Question Asked: What is ITW in SQL 2000 and What are DMVs?

ITW is Index Tuning Wizard and was available in SQL 2000 days. We rewamped it as DTA (Database Tuning Wizard) in SQL Server 2005 which was far more powerful than the SQL 2000 ITW counterpart. Now to get into the second part, Dynamic Management Views (DMV) provide greater transparency and insight into the database and a powerful infrastructure for proactive monitoring of database health and performance to make managing data more flexible and secure.

Question Asked: do we need to run DMV on prod server or we can run on the restored DB also

We need to understand one fundamental thing here, DMV's are like pseudo views / tables that are exposing the in-memory structures of SQL Server. These are useful to diagnoze any potential problems that might occur in that system. Some of these views are transient and some are cummulative and some get fulshed from time-to-time. Typical examples in these categories would incude Locks data is transient and changes every micro-second while data like the Index usage (seeks, scans etc) are cummulative and data like the query cache can get flushed if there is memory pressure from any other side. Having said all this, these data are NOT like metadata (e.g. sys.tables) which can be restored on another DB and analyzed. There is a way in SQL Server 2008 using Data Collector that we can do this and check the architecture here: https://msdn.microsoft.com/en-us/library/bb677355.aspx

Question Asked: all these DMV are part of SQL 2005

DMV's were very much intrduced as concepts inside SQL Server 2005 itself. AFAIK, there were close to 80+ DMV's with SQL Server 2005 RTM build. We increased this set to ~136 with this new version of SQL Server 2008.

Question Asked: How to get a list of all DMVs available for us to query upon....?

Here is a simple query that will help you answer this part:
SELECT * FROM sys.all_objects
   WHERE [name] LIKE '%dm_%'
                AND [type] IN ('V', 'TF', 'IF')
ORDER BY [name]

With SQL 2008 we introduced a number of DMV's around auditing, Extended Events, CDC, Filestreams etc.

Question Asked: what will calculeted by awe_allocated_kb

This value shows the overall amount of memory that is allocated through the AWE mechanism on the 32-bit version of SQL Server. Or, this value shows the overall amount of memory that locked pages consume on the 64-bit version of the product. This value comes from the sys.dm_os_memory_clerks DMV and the documentation for the same is at: https://msdn.microsoft.com/en-us/library/ms175019.aspx.

Question Asked: What permission does a user need to access the DMV's

There are two types of dynamic management views and functions:
Server-scoped dynamic management views and functions (e.g OS, IO, Threads, tasks etc). These require VIEW SERVER STATE permission on the server.
Database-scoped dynamic management views and functions (e.g Index, Tables, partition, file etc). These require VIEW DATABASE STATE permission on the database.

Question Asked: Which DMV give me query plan or I will use old method to find query plan?

Here is a query that you can run to get the Total Elapsed time of queries and the number of times those queries were hit. It also give's you the query and the plan used for each of those.

select qs.execution_count
     , qs.total_elapsed_time, qs.last_elapsed_time
     , qs.min_elapsed_time, qs.max_elapsed_time
     , substring(st.text, (qs.statement_start_offset/2)+1
                        , ((case qs.statement_end_offset
                              when -1 then datalength(st.text)
                              else qs.statement_end_offset
                           end - qs.statement_start_offset)/2) + 1) as statement_text
      , qp.query_plan
from sys.dm_exec_query_stats as qs
cross apply sys.dm_exec_sql_text(qs.sql_handle) as st
cross apply sys.dm_exec_query_plan (qs.plan_handle) as qp

Question Asked: How are DMV's and DMF's changing the memory consumptions of SQL Server? consider the dm_exec_* which store the results of the current workload.

I think this has come a number of times from various people I have interacted. As described before, DMV's are in-memory structures and are anyway's used by SQL Server internally. It is with SQL Server 2005 that we started exposing them in an official manner rather than doing bit-manipulations with some DBCC commands. Hence there is nothing to be worried about the load or memory consumptions. It is not as alarming as you think.

Question Asked: does there is support for DMVs in SQL 2000?

DMV's were introduced with SQL Server 2005 onwards. Though these numbers are increasing from version to version these cannot be got with SQL 2000 version. If you are still using SQL Server 2000 version I would strongly recommend you to move to SQL Server 2008 version :).

Question Asked: it seems to be very hard to remember DMV names, is there any way to get list of DMV's and its usage?

Fair enough and I dont think you are the only person finding it difficult :). With SQL Server 2005 I gone to BOL a number of times, but with SQL 2008 the intellisense takes away half the problem. But if you want to learn more on DMV's and start using them then I would recommend you to book mark this page on MSDN: https://msdn.microsoft.com/en-us/library/ms188754.aspx

Due to time constraints we were not able to answer them during the session itself but I am sure these have got clarified now. Keep those questions coming and we will try our best to answer them during the session else dont forget to visit this blog post the event :). Hope this was of help, btw dont forget to login to the VTD site to register your views on Nov VTD Topics.

PS: These are the exact questions that were asked during the session. I have taken the relevant ones and compiled the same here for you. BTW, there are couple more blogs around other sessions that will get posted.

Vinod Kumar
Technology Evangelist
www.ExtremeExperts.com

Comments

  • Anonymous
    January 01, 2003
    I am sure you folks are enjoying all the Q&A posted by my fellow Evangelists on this blog. The intentions

  • Anonymous
    January 01, 2003
    thank you

  • Anonymous
    January 01, 2003
    In the recently concluded Virtual TechDays in Sep we had a track for SQL Server and we did 4 sessions