
We frequently see SQL Server instances that use the default memory settings, or settings that do not optimize performance. The default settings are 0 MB for min server memory and 2,147,483,647 MB for max server memory, or more than 2 million GB (keep in mind, memory settings are designated in MB, not GB).
The caveats are: Setting max memory too high means SQL Server will compete for memory with other processes on the same host. Setting it too low impairs performance. Microsoft recommends “75% of available system memory not consumed by other processes.” We prefer to start with a formula popularized by Jonathan Kehayias in this blog post.
Reserve 1 GB for the OS, plus 1 GB for each 4 GB of RAM between 4 and 16 GB, plus 1 GB for every 8 GB of RAM above 16 GB. What’s left is your starting value for max server memory. For a server with 128 GB of RAM: OS reserve = 1 + ((16 – 4) / 4) + ((128 – 16) / 8) = 1 + 3 + 14 = 18 GB Max server memory = 128 – 18 = 110 GB (112,640 MB) More simply: reserve 4 GB for the first 16 GB of RAM, then 1 GB for every 8 GB after that.
Our guidance: For servers with 16 GB or more, start with max server memory = Total RAM – (4 GB + ((Total RAM – 16 GB) / 8)), enter the result in MB, and adjust based on workload.
Whatever formula you use, keep in mind that this is just a starting point. What is really needed is to monitor memory usage / pressure and adjust accordingly. A good place to start is the Windows counter Memory\Available MBytes. If it stays comfortably above 1 GB under normal workload, you likely have room to raise max server memory. If it drops into the low hundreds of MB, lower it.
Also keep in mind that the above is for a dedicated SQL Server with no other services. If you are running SSRS, SSIS, or SSAS on the same server, for example, you would need to include the memory those processes use.
SQL Server memory settings
Max server memory: The upper limit SQL Server places on its own memory manager. You aren’t telling Windows anything; it’s a cap SQL Server enforces on itself. Since SQL Server 2012, that cap covers much more than the buffer pool (the data cache). It also includes the plan cache, query memory grants, lock memory, and CLR. A few things fall outside it, mainly thread stacks and components loaded into the SQL Server process, so total process memory can run a little above the number you set. If you’re running 128 GB of RAM and set max to 110 GB, SQL Server’s memory manager stays at or under 110 GB. Leave it at the default and it will take nearly everything. SQL Server is really good at taking all the memory it can, and it only gives memory back when Windows signals memory pressure, which isn’t something you want to depend on.
Lock pages in memory: This is a Windows policy that determines which accounts can use a process to keep data in physical memory rather than paging to disc. You want to add the SQL Server service account to the policy so that Windows knows to keep SQL Server data in physical memory.
Min server memory: The floor SQL Server won’t shrink below when Windows asks for memory back. It doesn’t reserve memory at startup. SQL Server still has to ramp up to that level through normal use. On a dedicated SQL Server, leaving it at the default of 0 is fine. It’s worth setting when SQL Server shares a host with other instances or applications, or runs on a VM whose memory the host might reclaim. In those cases, setting it keeps SQL Server from being squeezed too far. Don’t set it equal to (or close to) max server memory; that takes away SQL Server’s ability to adjust.
Lock pages in memory (LPIM): A Windows user right that lets SQL Server keep its memory in physical RAM, so Windows can’t page it out to disk. To use it, grant the right to the SQL Server service account and restart the service. Setup doesn’t do this for you. Set max server memory first, because locked memory is harder for Windows to reclaim, and the cap is what leaves room for the OS. LPIM doesn’t lock SQL Server’s memory in place entirely. If Windows signals low memory, SQL Server will still shrink.
To confirm it’s working, run:
SELECT sql_memory_model_desc FROM sys.dm_os_sys_info;A result of LOCK_PAGES means it’s on. With LPIM enabled, Task Manager won’t show all of SQL Server’s memory. Use the SQL Server:Memory Manager\Total Server Memory counter instead.
Optimize for ad hoc workloads: An sp_configure setting that keeps single-use queries from bloating the plan cache. When it’s on, SQL Server caches only a small plan stub the first time a query runs and stores the full plan only if the query runs again. That leaves more memory for plans that actually get reused, and more room for the buffer pool.
You can also use dbatools (one of the most useful PowerShell modules you can find) to configure your instances. Set-DbaMaxMemory and Test-DbaMaxMemory are your friends here. Think of these as great starting points, and set and monitor rather than set and forget.
Need Expert Advice?
If SQL Server isn’t working right no matter how you configure memory, we can help. Schedule time with us and we’ll dig in right away.








This Post Has One Comment
Pingback: Hat mein SQL-Server genug Arbeitsspeicher? – Erhard RAINER
Comments are closed.