Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQL memory - viewing actual memory used and Memory available

I've done some research and came across a few different ways to see how much memory SQL Server is actually using (since Task manager isn't accurate, as SQL will reserve as much memory as it can for itself)

I found these two resources to be the most useful:

How much RAM is SQL Server actually using?

How to analyze 'dbcc memorystatus' result in SQL Server 2008

However, the struggle I'm having is that when I try both methods on the same server, I'm having trouble correlating the numbers.

I get very different results from the performance counters (SQL memory manager -- total server memory and target server memory) compared to query "dbcc memorystatus" VM Reserved and VM Committed.

They both appear to be listed in "KB" yet the numbers are not anywhere close. Maybe I'm not looking at the right results (maybe VM reserved / committed isn't a physical memory reading and the counter is? But then in this case, where in the SQL query does it show the amount of memory SQL is using / reserving , as none of the results seem like numbers that correspond with the performance counters)

If anyone can give me some guidance, bearing in mind I'm not very experienced in SQL performance monitoring, I'd really appreciate it.

Thank you in advance.

like image 267
vnat Avatar asked May 31 '11 15:05

vnat


People also ask

Is SQL view in memory?

A view is a virtual table in SQL that functions similarly to a standard table, but does not need to be physically stored, i.e. it is only stored in memory and does not take up actual storage space.

How can I monitor memory usage?

Check Computer Memory Usage EasilyTo open up Resource Monitor, press Windows Key + R and type resmon into the search box. Resource Monitor will tell you exactly how much RAM is being used, what is using it, and allow you to sort the list of apps using it by several different categories.

Does SQL Server use all available memory?

SQL Server will consume as much memory as you will allow it. By default, that number would encompass 100% of your numerical memory on your machine. SQL Server will dynamically use memory, so even if you set max memory to 12 GB if SQL requires, it will use memory to 12 GB.


1 Answers

Looking at the Perfmon counters for Total Server Memory and Target Server Memory will give you the size of the buffer pool cache, which is a subset of the total memory being used by SQL Server. It's usually the largest single pool of memory though. For example, on my dev server, I have Total Server Memory of 2759 MB. You can use the following query to pull this number out:

SELECT object_name, counter_name, cntr_value AS 'Total Server Memory (KB)'
FROM sys.dm_os_performance_counters 
WHERE counter_name = 'Total Server Memory (KB)'

DBCC MEMORYSTATUS, on the otherhand, displays a lot of information. If you scroll about 3/4 of the way down, you'll see a resultset with columns named "Buffer Pool" and "Value", with the first buffer pools being named "Committed" and "Target". These two values are listed as 8 KB Pages, so multiply the value by 8192 to get a result in bytes, and then divide by 1048576 to get a result in MB. On my dev server, I have 353,230 pages, or 2759 MB.

The first resultset of DBCC MEMORYSTATUS gives you the amount of Virtual Memory (VM) reserved and committed by SQL Server. I would ignore Reserved, as it's not a good indicator of how much memory is actually in use (that's what the Committed value is). Also, Reserved is quite a bit higher than the total physical memory in all of my servers. If you have a value for "Locked Pages Allocated", then your "VM Committed" value is likely to be about 400 MB - AWE and Locked Pages don't count in the commit charge, which is why Task Manager shows an incorrect value.

You shouldn't need to dig too deep into DBCC MEMORYSTATUS unless you have a specific problem with memory management. My rules of thumb is to size your buffer pool appropriately, have your available physical memory is low to avoid wasted memory (~1-2 GB, but Windows will always try to keep 128-256 MB physical memory available), and your "Peak Commit Charge" (from Task Manager) is never higher than the physical amount of memory in the server.

like image 90
Jim McLeod Avatar answered Nov 15 '22 06:11

Jim McLeod