Jun 25, 2010
How much memory is each SQL Server database using?
Whilst perusing the forums over at SQL Server Central today I stumbled across an interesting question regarding how to identify how much memory is being used by SQL Server on a per database level.
As you know SQL Server stores database data and index pages in memory in an area know as the Buffer Pool. Using my trusty friend Google, I researched an answer to this question on ServerFault provided by Paul Randal. The solution made use of the SQL Server Dynamic Management View (DMV) sys.dm_os_buffer_descriptors
As you know I’m a big fan of using SQL Server DMV’s and so I wanted to take note of this handy SQL code snippet here in order to share it with you.
SELECT (CASE WHEN ([is_modified] = 1) THEN 'Dirty' ELSE 'Clean' END) AS 'Page State', (CASE WHEN ([database_id] = 32767) THEN 'Resource Database' ELSE DB_NAME (database_id) END) AS 'Database Name', COUNT (*) AS 'Page Count' FROM sys.dm_os_buffer_descriptors GROUP BY [database_id], [is_modified] ORDER BY [database_id], [is_modified]; GO






Aug 02, 2010 @ 12:31:23
I never knew that we could calculate the memory utilization of each DB!!! It was very helpful. Thanks.
Sep 14, 2010 @ 06:26:26
it was good.
it help me lot………..
Feb 09, 2011 @ 04:14:31
Quick and nice way of getting memory usage, this query certainly works on both SQL 2005 and 2008…
Jun 13, 2012 @ 13:42:00
hii can u please tell me the query to find the db size.. :)
Jun 13, 2012 @ 14:06:00
There are quite a few different ways you can achieve this. If you just want to look at the overall database size you can use the system stored procedure sp_helpdb. If you want to look at the size of each database data/log file individually then you can run the following query from Pinal Dave’s blog I hope this helps.
Jun 25, 2012 @ 15:56:47
Hey Great article, is this page count in MB or kilobytes? thanks
Jun 25, 2012 @ 17:24:15
Hi Daniel,
Page count is the number of 8KB pages. So the following should give you what you want:
(COUNT (*) * 8) / 1024