No matter how much memory you put in a system, SQL Server will use all it can get until it’s caching the whole database in memory. Why does it do this? SQL Server is a database: SQL writes data to hard drives and fetches it when needed (e.g. SELECT statements are issued). To improve performance, SQL Server caches data in memory. With SQL only one server’s SQLserver.exe can touch the data files at any given time. SQL Server knows that once it reads a piece of data from the drives that data isn’t going to change unless SQL Server itself does the changing (an UPDATE, INSERT, or DELETE query). Data can be read into memory once and safely kept around forever. If you have a server with enough memory to cache the entire database, then that is what SQL Server will do.
The buffer pool is by far the largest consumer of memory in SQL Server, it holds and manages SQL server’s data cache. Monitoring the buffer pool is a good way to sport memory pressure. Performance monitor provides counters like:
Memory\Available MByte: This shows how much physical RAM windows has that isn’t being currently used. There are various ideas as to how much is a good minimum with some recommending 150MB and other recommending up to 1GB. Try to keep at east 500MB as a minimum so there will be enough RAM to enable support tool to be run on the server. If the available MB drops below 64MB then most windows servers will signal a low memory notification that SQL Server monitors for, and the SQLOS inside of SQL Server will reduce memory usage as a result of this notification occurring.
Buffer Manager \ Page Life Expectancy: This shows how many seconds SQL server expects to keep a page in the data cache and is a good measure of memory pressure. If the PLE is below 300 you should check ‘available Mbytes’ to see how much RAM is available, if ‘available Mbytes’ is less than 5MB then windows will begin trimming working sets aggressively.
- If PLE is low (below 300) and available Mbytes is high (above 600MB) you should increase ‘Max Server Memory’.
- If PLE is low and Mbytes is low you need to buy more RAM.
- If PLE is high and Mbytes is low then you should lower ‘Max Server Memory’.
Another thing to look for if the PLE is low is the lazy writes/sec. If this is showing non-zero values and the Page reads/sec and Page writes/sec is high then there may be buffer pool contention.
Also if the PLE is low, looking at the ‘Memory manager\Total server memory’ and the ‘Memory manager\Target server memory’ will tell you if SQL has reduced the size of the buffer pool. (The Total server memory is the current size of the buffer pool. The Target server memory is the ideal size for the buffer pool). In a stable SQL server the total and target server memory size will be very close. If the Total server memory is much less than the Target server memory size then either the workload on the server is not big enough to grow the buffer pool or the buffer pool cannot grow due to memory pressure and further troubleshooting is required.