A friend of mine asked me today (trying to calm down an agitated customer of his) how you could find out in SQL Server 2005 which database uses how much memory (in the server's RAM that is) at any given time.
Is that possible at all? If so - how? Can you do this with built-in SQL Server tools, or do you need extra third-party options?
His customer was all flustered because his dedicated SQL Server machine suddenly uses all but 200KB of its 4 GB of RAM. I don't think this is a problem, really - but since this guy claims it happened more or less over night, he wants to know what caused this increase in memory usage.....
Marc
It was most likely caused by a query wanting to read more pages into the buffer pool, and the buffer pool grabbing more memory to accomodate that. This is how SQL Server is supposed to work. If the box experiences memory pressure, it will ask SQL Server to give up some memory, which it will do. The customer shouldn't be concerned.
You can use the DMV
sys.dm_os_buffer_descriptors
to see how much of the buffer pool memory is being used by which database. This snippet will tell you how many clean and dirty (modified since last checkpoint or read from disk) pages from each database are in the buffer pool. You can modify further.I explain this a little more in this blog post Inside the Storage Engine: What's in the buffer pool?
You could also checkout KB 907877 (How to use the DBCC MEMORYSTATUS command to monitor memory usage on SQL Server 2005) which will give you an idea of the breakdown of the rest of SQL Server's memory usage (but not per-database).
Hope this helps!
Your friend can also limit the amount of RAM that SQL will take because, as Paul states above, SQL will take every bit of memory it can.
Limit the amount of memory taken by SQL Server to 2000 Mb (or whatever you think is best).