This document explains how to review and optimize a Cloud SQL for SQL Server instance if that instance is identified
by the underprovisioned instance recommender as having high memory consumption.
SQL Server memory
SQL Server memory can be divided into the following:
These are objects on a disk that can be reloaded, such as database pages and stored procedures. As a result,
the SQL Server can grow and shrink these objects based on memory utilization. Caches include buffer pools and plan caches.
Fixed memory
Fixed memory can grow and shrink. It only shrinks when not in use; for example, when the number of connections drops or the number of queries executing decreases.
It's different from caches. If there is not enough fixed memory, SQL Server can run out of memory.
Fixed memory includes connection memory and memory grants.
SQL Server overhead
SQL Server overhead includes threads and stacks.
In-Memory OLTP
In-Memory OLTP includes In-Memory tables and In-Memory filegroups.
The memory consumption by SQL Server is controlled by setting maximum server memory and memory.memory.limitmb. The memory.memory.limitmb parameter is set by Cloud SQL automatically.
We recommend you let Cloud SQL manage the value of this flag.
If you must manually manage this value, use the max_server_memory (mb)
usage formula outlined on Best practices
to help prevent SQL Server from consuming all memory.
Page life expectancy indicates the amount of time, in seconds, that the oldest page stays in the buffer pool.
This value should be more than 300 as recommended by Microsoft. If it consistently falls under
300, it could be an indication that the instance is facing high memory utilization.
Run the following query to monitor Page life expectancy.
SELECT
[object_name],
[counter_name],
[cntr_value]FROM
sys.dm_os_performance_counters
WHERE
[object_name]LIKE
'%Manager%'AND
[counter_name]='Page life expectancy'
Check the Memory Grants Pending flag.
Memory Grants Pending specifies the total number of processes waiting for a workspace memory grant.
Run the following query to check Memory Grants Pending. If this query consistently shows grants pending,
then it indicates high memory utilization. You can reduce it by querying the database
waits and tuning any statement that's waiting on memory.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Hard to understand","hardToUnderstand","thumb-down"],["Incorrect information or sample code","incorrectInformationOrSampleCode","thumb-down"],["Missing the information/samples I need","missingTheInformationSamplesINeed","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-08-25 UTC."],[],[],null,["# Optimize high memory usage in instances\n\n\u003cbr /\u003e\n\n[MySQL](/sql/docs/mysql/optimize-high-memory-usage \"View this page for the MySQL database engine\") \\| [PostgreSQL](/sql/docs/postgres/optimize-high-memory-usage \"View this page for the PostgreSQL database engine\") \\| SQL Server\n\n\u003cbr /\u003e\n\nThis document explains how to review and optimize a Cloud SQL for SQL Server instance if that instance is identified\nby the underprovisioned instance recommender as having high memory consumption.\n\nSQL Server memory\n-----------------\n\nSQL Server memory can be divided into the following:\n\n- [Caches](/sql/docs/sqlserver/optimize-high-memory-usage#cache)\n- [Fixed memory](/sql/docs/sqlserver/optimize-high-memory-usage#fixed-memory)\n- [SQL Server overhead](/sql/docs/sqlserver/optimize-high-memory-usage#sql-server-overhead)\n- [In-Memory online transactional processing (OLTP)](/sql/docs/sqlserver/optimize-high-memory-usage#oltp)\n\n### Caches\n\nThese are objects on a disk that can be reloaded, such as database pages and stored procedures. As a result,\nthe SQL Server can grow and shrink these objects based on memory utilization. Caches include buffer pools and plan caches.\n\n### Fixed memory\n\nFixed memory can grow and shrink. It only shrinks when not in use; for example, when the number of connections drops or the number of queries executing decreases.\nIt's different from caches. If there is not enough fixed memory, SQL Server can run out of memory.\nFixed memory includes connection memory and memory grants.\n\n### SQL Server overhead\n\nSQL Server overhead includes threads and stacks.\n\n### In-Memory OLTP\n\nIn-Memory OLTP includes In-Memory tables and In-Memory filegroups.\n\nThe memory consumption by SQL Server is controlled by setting `maximum server memory` and `memory.memory.limitmb`. The `memory.memory.limitmb` parameter is set by Cloud SQL automatically.\n\nTo learn more about `memory.memory.limitmb`, see the [Microsoft documentation](https://learn.microsoft.com/en-us/sql/linux/sql-server-linux-configure-mssql-conf?view=sql-server-ver16#memorylimit).\n\nMemory optimization options\n---------------------------\n\nTo determine if an instance needs more memory tuning, do the following:\n\n- [Check the value of the `max server memory (mb)`](/sql/docs/sqlserver/flags#special-flags) flag.\n\n We recommend you let Cloud SQL manage the value of this flag.\n If you must manually manage this value, use the `max_server_memory (mb)`\n usage formula outlined on [Best practices](/sql/docs/sqlserver/best-practices#sqlserver_settings)\n to help prevent SQL Server from consuming all memory.\n\n For more information, see [Special flags](/sql/docs/sqlserver/flags#special-flags).\n- Monitor the `Page life expectancy` flag.\n\n `Page life expectancy` indicates the amount of time, in seconds, that the oldest page stays in the buffer pool.\n This value should be more than 300 as recommended by Microsoft. If it consistently falls under\n 300, it could be an indication that the instance is facing high memory utilization.\n Run the following query to monitor `Page life expectancy`. \n\n ```bash\n SELECT\n [object_name],\n [counter_name],\n [cntr_value]\n FROM\n sys.dm_os_performance_counters\n WHERE\n [object_name]\n LIKE\n '%Manager%'\n AND\n [counter_name] = 'Page life expectancy'\n \n ```\n- Check the `Memory Grants Pending` flag.\n\n `Memory Grants Pending` specifies the total number of processes waiting for a workspace memory grant.\n Run the following query to check `Memory Grants Pending`. If this query consistently shows grants pending,\n then it indicates high memory utilization. You can reduce it by querying the database\n waits and tuning any statement that's waiting on memory. \n\n ```bash\n SELECT\n @@SERVERNAME AS [Server Name],\n RTRIM([object_name]) AS [Object Name],\n cntr_value AS [Memory Grants Pending]\n FROM\n sys.dm_os_performance_counters WITH(NOLOCK)\n WHERE\n [object_name]\n LIKE\n N'%Memory Manager%' -- Handles named instances\n AND\n counter_name = N'Memory Grants Pending'\n \n ```\n\nWhat's next\n-----------\n\n- [Google Cloud recommenders](/recommender/docs/recommenders)"]]