SQL Clone
SQLServerCentral is supported by Redgate
Log in  ::  Register  ::  Not logged in

March 2011 Version of SQL Server 2005 and 2008 Diagnostic Queries

Another month, and another new version of my SQL Server Diagnostic Information queries for both SQL Server 2005 and SQL Server 2008/2008 R2. I have uploaded the scripts for each version to DropBox (see the links below).

There are two new queries in this version:

-- Get total buffer usage by database for current instance
SELECT DB_NAME(database_id) AS [Database Name],
COUNT(*) * 8/1024.0 AS [Cached Size (MB)]
FROM sys.dm_os_buffer_descriptors
WHERE database_id > 4 -- system databases
AND database_id <> 32767 -- ResourceDB
GROUP BY DB_NAME(database_id)
ORDER BY [Cached Size (MB)] DESC;

-- Tells you how much memory (in the buffer pool) is being used by each database on the instance
-- Find missing index warnings for cached plans in the current database
-- Note: This query could take some time on a busy instance
SELECT TOP(25) OBJECT_NAME(objectid) AS [ObjectName],
               query_plan, cp.objtype, cp.usecounts
FROM sys.dm_exec_cached_plans AS cp
CROSS APPLY sys.dm_exec_query_plan(cp.plan_handle) AS qp
WHERE CAST(query_plan AS NVARCHAR(MAX)) LIKE N'%MissingIndex%'
AND dbid = DB_ID()
ORDER BY cp.usecounts DESC;

-- Helps you connect missing indexes to specific stored procedures
-- This can help you decide whether to add them or not


Here is the March 2011 SQL Server 2005 Diagnostic Information Query Script, and here is the March 2011 SQL Server 2008 Diagnostic Information Query Script. The second script also works on SQL Server 2008 R2.

You will need VIEW SERVER STATE permission to run many of these queries. You should read the comments and instructions for each query, and then run them one at a time (instead of running the entire batch at once). Then, you can paste the results into the matching results spreadsheet for each version of the query. These spreadsheets have labeled tabs that are in the same order as the queries.

Here is the March 2011 results spreadsheet for SQL Server 2005, and here is the March 2011 results spreadsheet for SQL Server 2008.


Posted by John Sansom on 8 March 2011

I've got to say Glenn that I really do appreciate you continuing to share this awesome query set with us all!

I've been using your Diagnostic Queries for quite some time and they have come in very handy when troubleshooting issues. It's great to have code ready to hand in order to diagnose potential issues and it also provides a certain amount of consistency to the troubleshooting methodology that is used, something that can be a challenge in large environments.

Posted by Glenn Berry on 8 March 2011

Thanks, John, I appreciate your thanks.

Posted by Ramkumar on 26 April 2011


I am the active user of all your DMV queries listed here.

and sharing this link with attendees in all my training sessions.

eagerly waiting for your ebook on SQL hardware

Leave a Comment

Please register or log in to leave a comment.