sqlskills-logo-2015-white.png

SQL Server Diagnostic Information Queries for November 2014

I revised a number of the queries this month in all five versions of the script.  It was very nice to have so many people thank me for these queries during the PASS 2014 Conference!

Here are the current query counts for each version:

SQL Server 2014         72 Queries

SQL Server 2012         69 Queries

SQL Server 2008 R2    65 Queries

SQL Server 2008         59 Queries

SQL Server 2005         51 Queries

Rather than having a separate blog post for each version, I have just put the links for all five major versions in this single post. There are two separate links for each version. The first one on the top left is the actual query script, and the one below on the right is the matching blank results spreadsheet.  

SQL Server 2005 Diagnostic Information Queries

SQL Server 2005 Blank Results

SQL Server 2008 Diagnostic Information Queries

SQL Server 2008 Blank Results

SQL Server 2008 R2 Diagnostic Information Queries

SQL Server 2008 R2 Blank Results

SQL Server 2012 Diagnostic Information Queries

SQL Server 2012 Blank Results

SQL Server 2014 Diagnostic Information Queries

SQL Server 2014 Blank Results

The basic idea is that you should run each query in the set, one at a time (after reading the directions). It is not really a good idea to simply run the entire batch in one shot, especially the first time you run these queries on a particular server, since some of these queries can take some time to run, depending on your workload and hardware. I also think it is very helpful to run each query, look at the results and think about the emerging picture of what is happening on your server as you go through the complete set.

You need to click on the top left square of the results grid in SSMS to select all of the results, and then right-click and select “Copy with Headers” to copy all of the results, including the column headers to the Windows clipboard. Then you paste the results into the matching tab in the blank results spreadsheet. There are also some comments on how to interpret the results after each query.

About half of the queries are instance specific and about half are database specific, so you will want to make sure you are connected to a database that you are concerned about instead of the master system database. Running the database-specific queries while being connected to the master database is a very common mistake that I see people making when they run these queries.

Note: These queries are stored on Dropbox. I occasionally get reports that the links to the queries and blank results spreadsheets do not work, which is most likely because Dropbox is blocked wherever people are trying to connect.

I also occasionally get reports that some of the queries simply don’t work. This usually turns out to be an issue where people have some of their user databases in 80 compatibility mode, which breaks many DMV queries.

It is also very important that you are running the correct version of the script that matches the major version of SQL Server that you are running. There is an initial query in each script that tries to confirm that you are using the correct version of the script for your version of SQL Server.

If you want to understand how to better run and interpret these queries, you should consider listening to my latest Pluralsight course, which is SQL Server 2014 DMV Diagnostic Queries – Part 1. This course is short and to the point (only 67 minutes), and I think you will enjoy it!  Part 2 of this series is recorded, and will be showing up on Pluralsight relatively soon!

Please let me know what you think of these queries, and whether you have any suggestions for improvements. Thanks!

6 thoughts on “SQL Server Diagnostic Information Queries for November 2014

  1. I came across a situation where all the databases were not listed for Query #21 (Database Properties). The SQL instance had several databases with Auto Close = ON. If a database is closed, then it does not get returned by the query. I modified the query to fix this:

    SELECT db.[name] AS [Database Name], db.recovery_model_desc AS [Recovery Model],
    db.log_reuse_wait_desc AS [Log Reuse Wait Description],
    ls.cntr_value AS [Log Size (KB)], lu.cntr_value AS [Log Used (KB)],
    CAST(CAST(lu.cntr_value AS FLOAT) / CAST(ls.cntr_value AS FLOAT)AS DECIMAL(18,2)) * 100 AS [Log Used %],
    db.[compatibility_level] AS [DB Compatibility Level],
    db.page_verify_option_desc AS [Page Verify Option], db.is_auto_create_stats_on, db.is_auto_update_stats_on,
    db.is_auto_update_stats_async_on, db.is_parameterization_forced,
    db.snapshot_isolation_state_desc, db.is_read_committed_snapshot_on,
    db.is_auto_close_on, db.is_auto_shrink_on, db.is_cdc_enabled
    FROM sys.databases AS db WITH (NOLOCK)
    LEFT JOIN sys.dm_os_performance_counters AS lu WITH (NOLOCK)
    ON db.name = lu.instance_name
    AND lu.counter_name LIKE N’Log File(s) Used Size (KB)%’
    LEFT JOIN sys.dm_os_performance_counters AS ls WITH (NOLOCK)
    ON db.name = ls.instance_name
    AND ls.counter_name LIKE N’Log File(s) Size (KB)%’
    AND ls.cntr_value > 0
    ORDER BY db.[name] OPTION (RECOMPILE);

  2. — Get socket, physical core and logical core count from (Query 12) (Core Counts)
    — SQL Server Error log. This query might take a few seconds
    — if you have not recycled your error log recently
    EXEC sys.xp_readerrorlog 0, 1, N’detected’, N’socket’;

    This is not returning any results on any of the servers. We have SQL Server 2012 Standard edition where we cycle the logs every day.

    Glenn, Any reason/fix in your mind. Thanks

    1. I would be curious whether the words “detected” or “socket” show up in any of your error logs. Probably what is happening is that your servers have been running long enough that the actual startup information from the original error log when SQL Server started has been overwritten as you recycle the log every day.

      1. Thanks Glenn,

        As per policy we have 12 log file which is sufficient for us to identify/debug any issue.
        As mentioned earlier, daily recycle overwrites older logs and server is up and running much more than 12 days.
        Do you see any issue with this strategy? or any other related tip please.

        Again thanks for reply.

        Kind Regards.

  3. Glenn
    In SQL Server 2012 there are a few of the scripts that now return results that when I copy and paste them into Excel they data from query_text for example is pasting down across multiple Excel rows.
    The (Query Execution Counts) for example.

    I added the REPLACE(..statement…., CHAR(13) + CHAR(10), ‘ ‘) as query_text to band aid this issue. I was curious if you were doing something different to not have this issue.

    Thanks.

Leave a Reply

Your email address will not be published. Required fields are marked *

Other articles

Imagine feeling confident enough to handle whatever your database throws at you.

With training and consulting from SQLskills, you’ll be able to solve big problems, elevate your team’s capacity, and take control of your data career.