Analyzing Memory Pressure Using SQL Server

Memory (or simply RAM) is the memory or information storage in a computer that is used to store running programs and data for the programs. The default setting for min server memory is 0, and the default setting for max server memory(sp_configure max server memory) is 2,147,483,647 megabytes (2TB).

SQL Server Best Memory Practices:


Min server memory: 

Min server memory controls the minimum amount of Physical memory that sql server will try to keep committed.


Max server memory: 

To prevent Microsoft SQL Server from consuming too much memory, set Max server memory.
Usually it is 70% of total Memory.

Query to find assigned memory to SQL:

Query 1:


SELECT physical_memory_kb,physical_memory_kb/1024 as mb FROM sys.dm_os_sys_info;

EXEC sp_configure 'max server memory';


Query 2:



SELECT object_name, cntr_value,cntr_value/1024 as mb
  FROM sys.dm_os_performance_counters
-- WHERE counter_name IN ('Total Server Memory (KB)', 'Target Server Memory (KB)');
  WHERE 
   counter_name ='Target Server Memory (KB)' or 
   counter_name = 'Total Server Memory (KB)' 


When the Total Server Memory and Target Server Memory values are close to each other, there’s no memory pressure on the server.





Analyze Memory Using DMO:(sys.dm_os_ring_buffers)


The sys.dm_os_ring_buffers DMV is used to diagnose system wide problem in SQL Server. It is also used to troubleshoot connectivity error, track deadlock, monitor system health, CPU, RAM and Disk Utilization etc by using this dmo.

According to Microsoft link, taking advantage of the dynamic management object (DMO) sys.dm_os_ring_buffers might be a great way to get you that quick and accurate determination if you have memory problems and if they’re coming from the Windows operating system or within SQL Server. To get information about SQL Server memory usage you need to query sys.dm_os_ring_buffers and filter out for "RING_BUFFER_RESOURCE_MONITOR" as used in below query:



/******************************************/

SELECT 
    EventTime,
    record.value('(/Record/ResourceMonitor/Notification)[1]', 'varchar(max)') as [Type],
    record.value('(/Record/ResourceMonitor/IndicatorsProcess)[1]', 'int') as [IndicatorsProcess],
    record.value('(/Record/ResourceMonitor/IndicatorsSystem)[1]', 'int') as [IndicatorsSystem],
    record.value('(/Record/MemoryRecord/AvailablePhysicalMemory)[1]', 'bigint') AS [Avail Phys Mem, Kb],
    record.value('(/Record/MemoryRecord/AvailableVirtualAddressSpace)[1]', 'bigint') AS [Avail VAS, Kb]
FROM (
    SELECT
        --select 6610904/1024 =6455
        --select 137423795704/1024=134202925.492187
        DATEADD (ss, (-1 * ((cpu_ticks / CONVERT (float, ( cpu_ticks / ms_ticks ))) - [timestamp])/1000), GETDATE()) AS EventTime,
        CONVERT (xml, record) AS record
    FROM sys.dm_os_ring_buffers
    CROSS JOIN sys.dm_os_sys_info
    WHERE ring_buffer_type = 'RING_BUFFER_RESOURCE_MONITOR') AS tab
ORDER BY EventTime DESC;

Output:-




Meaning of output:
The Type column is to be read as follows:

  • RESOURCE_MEM_STEADY
    • No memory issues (the order above is inconsistent due to the timestamps, but these usually follow a memory low condition to say that Windows is happy with the new memory level achieved)

  • RESOURCE_MEMPHYSICAL_LOW
    • Windows is running low on memory and SQL Server must return some

  • RESOURCE_MEMPHYSICAL_HIGH
    • Windows has spare memory and SQL Server can take some more if required

If the IndicatorsSystem value is greater than zero then this means that the memory situation was server-wide.

The IndicatorsProcess value means that it was a specific process which ran into the memory condition and can be one of 3 values:

  • 1 = High Physical Memory
  • 2 = Low Physical Memory
  • 3 = Low Virtual Memory

Note: 
If available memory is constantly low and server load cannot be reduced, it’s necessary to add more RAM. 
Name

Azure Backup Database Clustering Crash Dumps DBCC Deadlock Link Server Log Shipping Maintenance Migration Mirroring Monitoring Performance Tuning Permissions Post Installations Prerequisites Replication Restore Database SQL Installations SQL on Linux SQL Uninstallations SSIS T-SQL Windows Server
false
ltr
item
hybriddba.blogspot.com: Analyzing Memory Pressure Using SQL Server
Analyzing Memory Pressure Using SQL Server
https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgC7gFVO2jhcNQL1n0LwQgKiG1QKD0nuwoU-Zifg5wvpax1SvwImqcEVLQk0bhkV6YAbEnkVMKE16h7Nv58Psld_mZWidsY_XVoSFU_Nxgx13vZyd_WeX4YxEPEGeGzYL_16FxPWB-hz1OW/s1600/1580849346029929-0.png
https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgC7gFVO2jhcNQL1n0LwQgKiG1QKD0nuwoU-Zifg5wvpax1SvwImqcEVLQk0bhkV6YAbEnkVMKE16h7Nv58Psld_mZWidsY_XVoSFU_Nxgx13vZyd_WeX4YxEPEGeGzYL_16FxPWB-hz1OW/s72-c/1580849346029929-0.png
hybriddba.blogspot.com
https://hybriddba.blogspot.com/2019/03/analyzing-memory-pressure-using-sql.html
https://hybriddba.blogspot.com/
https://hybriddba.blogspot.com/
https://hybriddba.blogspot.com/2019/03/analyzing-memory-pressure-using-sql.html
true
7679493960263860249
UTF-8
Not found any posts Not found any related posts VIEW ALL Readmore Reply Cancel reply Delete By Home PAGES POSTS View All RECOMMENDED FOR YOU Tag ARCHIVE SEARCH ALL POSTS Not found any post match with your request Back Home Contents See also related Sunday Monday Tuesday Wednesday Thursday Friday Saturday Sun Mon Tue Wed Thu Fri Sat January February March April May June July August September October November December Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec just now 1 minute ago $$1$$ minutes ago 1 hour ago $$1$$ hours ago Yesterday $$1$$ days ago $$1$$ weeks ago more than 5 weeks ago Followers Follow THIS CONTENT IS PREMIUM Please share to unlock Copy All Code Select All Code All codes were copied to your clipboard Can not copy the codes / texts, please press [CTRL]+[C] (or CMD+C with Mac) to copy