I'm planning to create a job that automatically gets the status of my server's RAM/memory at the time of the job's activation.
My job has the command:
use master
insert into Rec.dbo.MemoryRec
SELECT
(physical_memory_in_use_kb/1024) AS Memory_usedby_Sqlserver_MB,
(locked_page_allocations_kb/1024) AS Locked_pages_used_Sqlserver_MB,
(total_virtual_address_space_kb/1024) AS Total_VAS_in_MB,
process_physical_memory_low,
process_virtual_memory_low ,
getdate()
FROM sys.dm_os_process_memory;
Is this enough to monitor a server's RAM? Are there better queries that can be used?
Ps Please, as much as possible, do not suggest 3rd party programs because I currently cannot afford things like those
Best Answer
If your requirement is just to check SQL Server memory usage then the query used is fine with slight modification.
Do not forget to add new columns to table
rec.dbo.MemoryRec
or the query will start failing.The column alias
Total_Mem_used_RAMAndPagefile
tracks Total memory used by SQL Server RAM+Page file. And if you subtract this value fromphysical_memory_in_use_kb
it will give you amount of memory used by SQL Server process in page file. Or simply how much SQL Server is getting paged. Please note on normal system there would always be some amount of paging so do not worry.If your requirement is to see if SQL Server instance is facing memory pressure then you need to take help of perfmon counters. Let me know what you need