SQL Server 2008 R2 – Memory Caching and Release Issues

sql-server-2008-r2

i am working on SQL server 2008 R2. It has been allowed to take a maximum memory which is around 45 GB. In couple of days it caches everything and the limit is reached. We have other processing as well on the server. Why doesn't it release all the memory after it has finished the processing?

How can i know the reason of the issue which process is doing this caching? I could find out some of the query plans cached but 40 GB of caching after that other processes from the SQL server it takes too much around 47/48 GB which has been an headache.

Best Answer

For any RDBMS, the bottleneck for performance is (usually) disk performance. Compared to all other parts of the computer, disk I/O is the most expensive in terms of time required. To this end, RDBMS engines focus on operating on as much data as possible in memory, as RAM is much faster to read and write to than physical disk. It also provides a safety mechanism for ACID compliance, so that only work that is completed successfully will be persisted to disk. If anything is rolled back, either due to failure or manual intervention, it can easily be discarded from memory without affecting the physical storage.

This means that relational engines will try and keep as much data in memory for as long as possible. To continuously push and pull objects from disk to memory is expensive and will hurt application performance. There are times items need to be cycled out of memory, but this will happen based on a LRU algorithm that is designed to keep active data in memory.

It is possible to view information about what is in your cache. Note that the memory pool for SQL Server will contain different objects. Primarily it will be the buffer pool, which stores data objects, and the plan cache, which are the query execution plans. You can utilize specific dynamic management views for this observation, which are used in Glenn Berry's DMV script. Look at queries 39 and 55.

If you wish to restrict the amount of memory SQL Server can use, the only option you really have is to reduce your Max Memory configuration for your instance. Be careful with adjusting this, though, as a reduced memory pool can hamper your performance based on the factors described above.