Problem
I need to determine what objects/structures are consuming the largest amount of space at a given time (or over time) within the SQL Server buffer pool. How can I achieve this in SQL Server 2005?
Solution
In SQL Server 2000, this was a bit complicated to determine to say the least, however with SQL Server 2005’s new dynamic management functions/views, it’s become exponentially easier to gain this type of insight; additionally, it’s also become easy to aggregate this information for use/display/reporting purposes.
Procedure 1
In this scenario, the use of the sys.dm_os_buffer_descriptors DMV optionally correlated against other catalog views within a given database will provide you all the information you need to get this type of information.
Below are a couple of possible solutions to retrieving this type of data. The first and simpler of two procedures provide you with aggregated information from the DMV rolled-up on a per database, file, and page type combination (page type being things like data pages vs. index pages vs. PFS pages vs. etc., etc.). It’s a simple procedure with no parameters and a single select statement with some grouping, rollup, and sorting.
Click here to get the code
Here is sample output from the first 10 rows of the result set.

Procedure 2
The second and more complex of the procedures provides more detailed information for each given database on the system – instead of providing only server-level information (like what database, file, etc. is consuming the buffer pool), it will dig into specific database(s) to provide more targeted information within the given database(s) in regards to specific indexes/tables/views/etc. that are utilizing the most space. Optional parameters are included to target to a specific database, all databases on the system, system level only information, and return only a certain number of results.
Here is sample output from the first 10 rows of the result set.

Next Steps
- Add these procedures to your toolbox to help get further insight into how your SQL Server 2005 Buffer Pool is being used.
- Take a look at these other tips that relate to DMVs
- As always, be sure to understand the performance impact associated with some possible incarnations of executing these procedures – if you have a large 64-bit system with a large buffer pool, these could get somewhat intensive.
- Special thanks to Chad Boyd of the MSSQLTips.com community for this tip.

Chad is an Architect, Administrator, and Developer with technologies such as Sql Server (and related technologies), .NET, Windows Server, and the Microsoft Clustering stack (MSCS, NLB, HPC). After nearly 5 years at Microsoft in a variety of roles related to pushing the limits of the Microsoft stack in many of the largest, most complex Sql Server installations in the world, he now provides consulting to many different customers and clients ranging from startup to Fortune 50. Most recently he has been spending much of his time as an architect at SpruceMedia, Inc., a startup firm in the Facebook/Social Advertising space (http://sprucemedia.com) and resides in the Redmond, WA area where he also spends a significant amount of time writing, talking, presenting and blogging about the data-related technologies on the Microsoft stack. Chad regularly posts Sql Server related content, tools, and advice with the MSSQLTips team and on stackoverflow.com at http://stackoverflow.com/users/169012/chadhoc. Chad can be contacted via email at chad dot boyd dot tips at gmail dot com.