Tuesday, May 28, 2019

SQL Server memory node memory footprints

Day-in, day-out i use perfmon to monitor SQL Server resource utilization and behavior, because its observer overhead is so low.

But its useful to have a few TSQL queries in the stable, too, for adhoc use or if a given memory state needs to result in some action taken within SQL Server.

i'm sure there's a clever wayt to use 'pivot', 'unpivot' and/or 'cross apply' to make this query more elegant. But i just wanted to get this here somewhere. if i figure out a more elegant way to get the resultset i'll update this blog post.
~~~~~

;WITH dbc AS (SELECT node=instance_name, dbc = cntr_value
     FROM sys.dm_os_performance_counters 
     WHERE counter_name = 'Database Node Memory (KB)'),
stl AS (SELECT [node]=instance_name, stl = cntr_value
     FROM sys.dm_os_performance_counters
     WHERE counter_name = 'Stolen Node Memory (KB)'),
fre AS (SELECT [node]=instance_name, fre = cntr_value
     FROM sys.dm_os_performance_counters
     WHERE counter_name = 'Free Node Memory (KB)'),
tot AS (SELECT [node]=instance_name, tot = cntr_value
     FROM sys.dm_os_performance_counters
     WHERE counter_name = 'Total Node Memory (KB)'),
tgt AS (SELECT [node]=instance_name, tgt = cntr_value
     FROM sys.dm_os_performance_counters
     WHERE counter_name = 'Target Node Memory (KB)'),
fgn AS (SELECT [node]=instance_name, fgn = cntr_value
     FROM sys.dm_os_performance_counters
     WHERE counter_name = 'Foreign Node Memory (KB)')
SELECT [memNode] = dbc.[node], 
       [dbCache] = dbc.dbc, 
       [stolen]  = stl.stl, 
       [free]    = fre.fre,
       [total]   = tot.tot, 
       [target]  = tgt.tgt, 
       [foreign] = fgn.fgn
FROM dbc
JOIN stl ON dbc.[node] = stl.[node]
JOIN fre ON dbc.[node] = fre.[node]
JOIN tot ON dbc.[node] = tot.[node]
JOIN tgt ON dbc.[node] = tgt.[node]
JOIN fgn ON dbc.[node] = fgn.[node];


These results - in the order of their capture - are much more interesting.





Let's look at the results below a bit.
The target for the instance is 4 * 180, 991, 992 kb =  723, 967, 968 kb = 707, 000 mb.
Total for the instance is 883, 498, 216 = 862, 791 mb. 155, 791 mb is a pretty big overage.



Total foreign memory is 207, 386, 832 kb = 202, 506 mb. That's a lot of foreign memory.







Q.


No comments:

Post a Comment