How-to find out the SQL MI total amount of RAM

Published Aug 02 2021 03:23 AM 2,083 Views
Microsoft

Continuing with the series of blog posts on how to find out the information about Azure SQL Managed Instance (SQL MI) for your automation scripts and tools, started with How-to find out the SQL MI Service Tier basic details with T-SQL, this article will focus on extracting information on the available memory & reserved disk space from Azure SQL Managed Instance.


You can find and reference the whole series with the following link http://aka.ms/sqlmi-howto.


In the previous blog post of this How-to series we have focused on the initial hardware properties of the SQL Managed Instance - CPU vCores and in this post we shall continue with hardware properties, focusing on the Memory.

Precise information on the memory is essential for performance optimization reasons and is one of the key properties for any relational database engine.
For the 5th Generation of SQL MI hardware, we are currently providing you with 5.1 GB of RAM per each CPU vCore, meaning that a total amount of RAM for a 4 CPU vCore SQL MI is 20.4 GB and for a 16 CPU vCore SQL MI would be 81.6 GB, and so forth.

 

If your application needs more RAM to function properly, at the moment of this article writing, on Azure SQL Managed Instance, the only solution is to increase the number of CPU vCores.

 

For Azure SQL Managed Instance, none of the habitual old DMVs such as sys.dm_os_process_memory or sys.dm_os_sys_info will provide correct answer, because they were not updated to adjust to the reality of the complex Azure SQL implementations.

In order to get the correct information the Job Object, the DMV sys.dm_os_job_object will need to be used.
Job Object is a grouping of processes that need to be managed as a single unit with an explicit resource governance for CPU, memory and IO for the processes.
This is the way how SQL MI is being run in our cloud and extracting information from the corresponding view is the way to have a precise information on the processes within Job Object. Job objects are namable, securable, sharable objects that control attributes of the processes associated with them.

For more information please consult the official documentation for Job Objects.

To observe the total amount of memory attributed to your Azure SQL MI, use the following query by consulting the column [process_memory_limit_mb], meaning that for example, for my 4 CPU vCores Azure SQL Managed Instance I expect to get 20.4 GB of RAM:

 

 

 

SELECT cpu_rate / 100 as CPU_vCores,
	CAST( (process_memory_limit_mb) /1024. as DECIMAL(9,1)) as TotalMemoryGB
FROM sys.dm_os_job_object;

 

 

 

total ram amount for SQLMI.png

There is an important detail that needs to be added to the information extraction, because as in the case of any SQL Server installation, there is a certain amount of memory that will be spent on running the SQL Server itself. This is not the amount of memory that is being spent on the Operating System, this is the amount of memory that is spent on making non-SOS memory allocations of the Azure SQL Managed Instance to function properly.


On Azure SQL MI, currently, there is no possibility of controlling the maximum server memory setting, and, we do reserve some amount of memory in order to run the process as a part of service correctly & successfully. This amount of memory is set aside for thread stacks, DLLs, and other non-SOS memory allocations.

 

In the DMV sys.dm_os_job_object, this information is exposed through the column [non_sos_mem_gap_mb] containing the reserved amount of memory in MB.
SQL OS (SOS) target memory is the difference between the values in columns [process_memory_limit_mb] and [non_sos_mem_gap_mb].

 

 

 

SELECT cpu_rate / 100 as CPU_vCores,
CAST( (process_memory_limit_mb) /1024. as DECIMAL(9,1)) as TotalMemoryGB,
CAST( non_sos_mem_gap_mb /1024. as DECIMAL(9,1)) as NonSOSMemGapGB,
CAST( (process_memory_limit_mb - non_sos_mem_gap_mb) /1024. as DECIMAL(9,1)) as TotalAvailableMemoryGB
FROM sys.dm_os_job_object;

 

 

 

total available RAM amount for SQLMI.pngNotice that the amount of the memory allocated for those processes is not a static percentage and will depend on the size of the SQL Managed Instance, going lower on SQL Managed Instances with more CPU vCores.

 

Rests to add that consulting the sys.dm_os_job_object DMV on SQL Managed Instance, requires VIEW SERVER STATE permission. 

 

In this blog post we have provided you with a script to consult the total and the total available memory for your SQL MI environment. In the next post of this series, we shall focus on the disk.

%3CLINGO-SUB%20id%3D%22lingo-sub-2596376%22%20slang%3D%22en-US%22%3EHow-to%20find%20out%20the%20SQL%20MI%20total%20amount%20of%20RAM%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2596376%22%20slang%3D%22en-US%22%3E%3CP%3EContinuing%20with%20the%20series%20of%20blog%20posts%20on%20how%20to%20find%20out%20the%20information%20about%20Azure%20SQL%20Managed%20Instance%20(SQL%20MI)%20for%20your%20automation%20scripts%20and%20tools%2C%20started%20with%20%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fazure-sql%2Fhow-to-find-out-the-sql-mi-service-tier-basic-details-with-t-sql%2Fba-p%2F2520706%22%20target%3D%22_self%22%3EHow-to%20find%20out%20the%20SQL%20MI%20Service%20Tier%20basic%20details%3C%2FA%3E%20with%20T-SQL%2C%20this%20article%20will%20focus%20on%20extracting%20information%20on%20the%20available%20memory%20%26amp%3B%20reserved%20disk%20space%20from%20Azure%20SQL%20Managed%20Instance.%3C%2FP%3E%0A%3CP%3E%3CSPAN%3E%3CBR%20%2F%3EYou%20can%20find%20and%20reference%20the%20whole%20series%20with%20the%20following%20link%26nbsp%3B%3C%2FSPAN%3E%3CA%20href%3D%22http%3A%2F%2Faka.ms%2Fsqlmi-howto%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3Ehttp%3A%2F%2Faka.ms%2Fsqlmi-howto%3C%2FA%3E%3CSPAN%3E%26nbsp%3Bwhich%20will%20lead%20you%20precisely%20to%20this%20very%20post.%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%3CBR%20%2F%3EIn%20the%20previous%20blog%20post%20of%20this%20How-to%20series%20we%20have%20focused%20on%20the%20initial%20%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fazure-sql%2Fhow-to-find-out-the-sql-mi-number-of-cpu-vcores%2Fba-p%2F2594971%22%20target%3D%22_self%22%3Ehardware%20properties%20of%20the%20SQL%20Managed%20Instance%20-%20CPU%20vCores%3C%2FA%3E%20and%20in%20this%20post%20we%20shall%20continue%20with%20hardware%20properties%2C%20focusing%20on%20the%20Memory.%3C%2FP%3E%0A%3CP%3EPrecise%20information%20on%20the%20memory%20is%20essential%20for%20performance%20optimization%20reasons%20and%20is%20one%20of%20the%20key%20properties%20for%20any%20relational%20database%20engine.%3CBR%20%2F%3E%3CSTRONG%3EFor%20the%205th%20Generation%20of%20SQL%20MI%20hardware%3C%2FSTRONG%3E%2C%20we%20are%20currently%20providing%20you%20with%20%3CSTRONG%3E5.1%20GB%20of%20RAM%20per%20each%20CPU%20vCore%3C%2FSTRONG%3E%2C%20meaning%20that%20a%20total%20amount%20of%20RAM%20for%20a%204%20CPU%20vCore%20SQL%20MI%20is%2020.4%20GB%20and%20for%20a%2016%20CPU%20vCore%20SQL%20MI%20would%20be%2081.6%20GB%2C%20and%20so%20forth.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EIf%20your%20application%20needs%20more%20RAM%20to%20function%20properly%2C%20at%20the%20moment%20of%20this%20article%20writing%2C%20on%20Azure%20SQL%20Managed%20Instance%2C%20the%20only%20solution%20is%20to%20increase%20the%20number%20of%20CPU%20vCores.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EFor%20Azure%20SQL%20Managed%20Instance%2C%20none%20of%20the%20habitual%20old%20DMVs%20such%20as%20%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fsql%2Frelational-databases%2Fsystem-dynamic-management-views%2Fsys-dm-os-process-memory-transact-sql%22%20target%3D%22_self%22%20rel%3D%22noopener%20noreferrer%22%3Esys.dm_os_process_memory%3C%2FA%3E%20or%20%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fsql%2Frelational-databases%2Fsystem-dynamic-management-views%2Fsys-dm-os-sys-info-transact-sql%22%20target%3D%22_self%22%20rel%3D%22noopener%20noreferrer%22%3Esys.dm_os_sys_info%3C%2FA%3E%20will%20provide%20correct%20answer%2C%20because%20they%20were%20not%20updated%20to%20adjust%20to%20the%20reality%20of%20the%20complex%20Azure%20SQL%20implementations.%3C%2FP%3E%0A%3CP%3EIn%20order%20to%20get%20the%20correct%20information%20the%20Job%20Object%2C%20the%20DMV%20%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fsql%2Frelational-databases%2Fsystem-dynamic-management-views%2Fsys-dm-os-job-object-transact-sql%22%20target%3D%22_self%22%20rel%3D%22noopener%20noreferrer%22%3Esys.dm_os_job_object%3C%2FA%3E%20will%20need%20to%20be%20used.%3CBR%20%2F%3EJob%20Object%20is%20a%20grouping%20of%20processes%20that%20need%20to%20be%20managed%20as%20a%20single%20unit%20with%20an%20explicit%20resource%20governance%20for%20CPU%2C%20memory%20and%20IO%20for%20the%20processes.%3CBR%20%2F%3EThis%20is%20the%20way%20how%20SQL%20MI%20is%20being%20run%20in%20our%20cloud%20and%20extracting%20information%20from%20the%20corresponding%20view%20is%20the%20way%20to%20have%20a%20precise%20information%20on%20the%20processes%20within%20Job%20Object.%20Job%20objects%20are%20namable%2C%20securable%2C%20sharable%20objects%20that%20control%20attributes%20of%20the%20processes%20associated%20with%20them.%3C%2FP%3E%0A%3CP%3EFor%20more%20information%20please%20consult%20%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fwindows%2Fwin32%2Fprocthread%2Fjob-objects%22%20target%3D%22_self%22%20rel%3D%22noopener%20noreferrer%22%3Ethe%20official%20documentation%20for%20Job%20Objects%3C%2FA%3E.%3C%2FP%3E%0A%3CP%3ETo%20observe%20the%20total%20amount%20of%20memory%20attributed%20to%20your%20Azure%20SQL%20MI%2C%20use%20the%20following%20query%20by%20consulting%20the%20column%20%5B%3CSTRONG%3Eprocess_memory_limit_mb%3C%2FSTRONG%3E%5D%2C%20meaning%20that%20for%20example%2C%20for%20my%204%20CPU%20vCores%20Azure%20SQL%20Managed%20Instance%20I%20expect%20to%20get%2020.4%20GB%20of%20RAM%3A%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%20class%3D%22lia-code-sample%20language-sql%22%3E%3CCODE%3ESELECT%20cpu_rate%20%2F%20100%20as%20CPU_vCores%2C%0A%20CAST(%20(process_memory_limit_mb)%20%2F1024.%20as%20DECIMAL(9%2C1))%20as%20TotalMemoryGB%0AFROM%20sys.dm_os_job_object%3B%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-left%22%20image-alt%3D%22total%20ram%20amount%20for%20SQLMI.png%22%20style%3D%22width%3A%20167px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F299565i5EEA4409BD9D1AE7%2Fimage-size%2Flarge%3Fv%3Dv2%26amp%3Bpx%3D999%22%20role%3D%22button%22%20title%3D%22total%20ram%20amount%20for%20SQLMI.png%22%20alt%3D%22total%20ram%20amount%20for%20SQLMI.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3EThere%20is%20an%20important%20detail%20that%20needs%20to%20be%20added%20to%20the%20information%20extraction%2C%20because%20as%20in%20the%20case%20of%20any%20SQL%20Server%20installation%2C%20there%20is%20a%20certain%20amount%20of%20memory%20that%20will%20be%20spent%20on%20running%20the%20SQL%20Server%20itself.%20This%20is%20not%20the%20amount%20of%20memory%20that%20is%20being%20spent%20on%20the%20Operating%20System%2C%20this%20is%20the%20amount%20of%20memory%20that%20is%20spent%20on%20making%20%3CSPAN%3Enon-SOS%20memory%20allocations%3C%2FSPAN%3E%26nbsp%3Bof%20the%20Azure%20SQL%20Managed%20Instance%20to%20function%20properly.%3C%2FP%3E%0A%3CP%3E%3CBR%20%2F%3EOn%20Azure%20SQL%20MI%2C%20currently%2C%20there%20is%20no%20possibility%20of%20controlling%20the%20maximum%20server%20memory%20setting%2C%20and%2C%20we%20do%20reserve%20some%20amount%20of%20memory%20in%20order%20to%20run%20the%20process%20as%20a%20part%20of%20service%20correctly%20%26amp%3B%20successfully.%20This%20amount%20of%20memory%20is%20set%20aside%20for%20thread%20stacks%2C%20DLLs%2C%20and%20other%20non-SOS%20memory%20allocations.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EIn%20the%20DMV%20%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fsql%2Frelational-databases%2Fsystem-dynamic-management-views%2Fsys-dm-os-job-object-transact-sql%22%20target%3D%22_self%22%20rel%3D%22noopener%20noreferrer%22%3Esys.dm_os_job_object%3C%2FA%3E%2C%20this%20information%20is%20exposed%20through%20the%20column%20%5B%3CSTRONG%3Enon_sos_mem_gap_mb%3C%2FSTRONG%3E%5D%20containing%20the%20reserved%20amount%20of%20memory%20in%20MB.%3CBR%20%2F%3ESQL%20OS%20(SOS)%20target%20memory%20is%20the%20difference%20between%20the%20values%20in%20columns%20%5B%3CSTRONG%3Eprocess_memory_limit_mb%3C%2FSTRONG%3E%5D%20and%20%5B%3CSTRONG%3Enon_sos_mem_gap_mb%5D%3C%2FSTRONG%3E.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%20class%3D%22lia-code-sample%20language-sql%22%3E%3CCODE%3ESELECT%20cpu_rate%20%2F%20100%20as%20CPU_vCores%2C%0ACAST(%20(process_memory_limit_mb)%20%2F1024.%20as%20DECIMAL(9%2C1))%20as%20TotalMemoryGB%2C%0ACAST(%20non_sos_mem_gap_mb%20%2F1024.%20as%20DECIMAL(9%2C1))%20as%20NonSOSMemGapGB%2C%0ACAST(%20(process_memory_limit_mb%20-%20non_sos_mem_gap_mb)%20%2F1024.%20as%20DECIMAL(9%2C1))%20as%20TotalAvailableMemoryGB%0AFROM%20sys.dm_os_job_object%3B%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-left%22%20image-alt%3D%22total%20available%20RAM%20amount%20for%20SQLMI.png%22%20style%3D%22width%3A%20407px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F299566iB1637417B86C7A21%2Fimage-size%2Flarge%3Fv%3Dv2%26amp%3Bpx%3D999%22%20role%3D%22button%22%20title%3D%22total%20available%20RAM%20amount%20for%20SQLMI.png%22%20alt%3D%22total%20available%20RAM%20amount%20for%20SQLMI.png%22%20%2F%3E%3C%2FSPAN%3ENotice%20that%20the%20amount%20of%20the%20memory%20allocated%20for%20those%20processes%20is%20not%20a%20static%20percentage%20and%20will%20depend%20on%20the%20size%20of%20the%20SQL%20Managed%20Instance%2C%20going%20lower%20on%20SQL%20Managed%20Instances%20with%20more%20CPU%20vCores.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3ERests%20to%20add%20that%20consulting%20the%26nbsp%3B%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fsql%2Frelational-databases%2Fsystem-dynamic-management-views%2Fsys-dm-os-job-object-transact-sql%22%20target%3D%22_self%22%20rel%3D%22noopener%20noreferrer%22%3Esys.dm_os_job_object%3C%2FA%3E%20DMV%26nbsp%3B%3CSPAN%3Eon%20SQL%20Managed%20Instance%2C%20requires%20VIEW%20SERVER%20STATE%26nbsp%3B%3C%2FSPAN%3E%3CSPAN%3Epermission.%26nbsp%3B%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%3EIn%20this%20blog%20post%20we%20have%20provided%20you%20with%20a%20script%20to%20consult%20the%20total%20and%20the%20total%20available%20memory%20for%20your%20SQL%20MI%20environment.%20In%20the%20next%20post%20of%20this%20series%2C%20we%20shall%20focus%20on%20the%20disk.%3C%2FSPAN%3E%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-TEASER%20id%3D%22lingo-teaser-2596376%22%20slang%3D%22en-US%22%3E%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-left%22%20image-alt%3D%22total%20ram%20amount%20for%20SQLMI.png%22%20style%3D%22width%3A%20167px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F299565i5EEA4409BD9D1AE7%2Fimage-size%2Flarge%3Fv%3Dv2%26amp%3Bpx%3D999%22%20role%3D%22button%22%20title%3D%22total%20ram%20amount%20for%20SQLMI.png%22%20alt%3D%22total%20ram%20amount%20for%20SQLMI.png%22%20%2F%3E%3C%2FSPAN%3EDiscover%20scripts%20for%20consulting%20the%20total%20and%20total%20available%20amounts%20of%20RAM%20in%20Azure%20SQL%20Managed%20Instance%20with%20the%20help%20of%20T-SQL.%20With%20the%20help%20of%26nbsp%3B%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fsql%2Frelational-databases%2Fsystem-dynamic-management-views%2Fsys-dm-os-job-object-transact-sql%22%20target%3D%22_self%22%20rel%3D%22noopener%20noreferrer%22%3Esys.dm_os_job_object%3C%2FA%3E%26nbsp%3BDMV%20(currently%20available%20only%20on%20Azure%20SQL%20DB%20%26amp%3B%20Azure%20SQL%20MI)%2C%20consult%20the%20virtual%20memory%20properties%20of%20your%20SQL%20MI.%3C%2FP%3E%3C%2FLINGO-TEASER%3E%3CLINGO-LABS%20id%3D%22lingo-labs-2596376%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EAzure%20SQL%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EAzure%20SQL%20Managed%20Instance%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E
Co-Authors
Version history
Last update:
‎Sep 21 2021 07:10 AM
Updated by: