SQL settings should be verified on a regular basis, and I’m occasionally asked to produce a list of memory configuration settings on all servers for management. It’s a simple process to check this information using Management Studio, but scripting is a much better solution, especially if you need to verify the settings on a large number of servers.
You can verify memory settings quickly for a single system by right-clicking on the server in Object Explorer then selecting Memory on the left hand side.
SQL defaults to have access to all the memory on your server (2,147,483,647MB). Best practices suggest a variety of configurations, from 10-20% reserved for the OS, to a minimum of 4GB reserved, to 1GB reserved for every 4-8GB of RAM available. The most important thing to do is leave some space reserved for the OS. Leaving the default memory setting will allow SQL to eat all the available RAM, potentially leaving the server unresponsive as windows may eventually be completely memory starved.
I prefer to verify memory settings against all my servers at once. Not only is it faster, it’s easier to provide a report this way. Open a New Query from your Central Management Server targeting all of your servers for fastest results. Querying
sys.dm_os_sys_memory will provide the information you need, but the results leave a lot to be desired. By pivoting the data and performing a bit of formatting, you can create a report that is much cleaner and appealing.
SET NOCOUNT ON GO SELECT [TotalRamGB] = Ram/1024 ,[MinRamGB] = [Minimum size of server memory (MB)]/1024 ,[MaxRamGB] = [Maximum size of server memory (MB)]/1024 ,[RamLeftForWindowsGB] = CASE WHEN [Maximum size of server memory (MB)]/1024 = 2097151 THEN 0 ELSE Ram/1024 - [Maximum size of server memory (MB)]/1024 END FROM ( SELECT [Descr] = [Description] ,[Val] = CONVERT(BIGINT,value) ,[Ram] = total_physical_memory_kb/1024 FROM sys.configurations c ,sys.dm_os_sys_memory m WHERE c.name IN ('min server memory (MB)','max server memory (MB)') ) a PIVOT ( MIN(Val) FOR Descr IN ([Minimum size of server memory (MB)],[Maximum size of server memory (MB)]) ) b
This script converts all the memory settings to GB, but if you need to work in MB, just remove the GB conversions. The last column indicates how much memory is reserved for the OS. A value of 0 here indicates that SQL’s max memory setting has been left at default, and thus has free reign to steal all the memory. These servers should be addressed as soon as possible. Again, the amount of space you leave available will vary, but I suggest at least 4GB. If your server has such a small amount of RAM that this is a substantial portion of your total RAM, it’s probably time to ask for more RAM too. It’s one of the cheapest and best upgrades possible.