En este documento, se explica cómo revisar y optimizar una instancia de Cloud SQL para SQL Server si el recomendador de instancias con aprovisionamiento insuficiente identifica que esa instancia tiene un consumo elevado de memoria.
Memoria de SQL Server
La memoria de SQL Server se puede dividir de la siguiente manera:
Estos son objetos de un disco que se pueden volver a cargar, como las páginas de la base de datos y los procedimientos almacenados. Como resultado, SQL Server puede aumentar y reducir estos objetos según la utilización en la memoria. Las cachés incluyen las de grupos de búferes y de planes.
Memoria fija
La memoria fija puede aumentar o reducirse. Solo se reduce cuando no está en uso. Por ejemplo, cuando disminuye la cantidad de conexiones o disminuye la cantidad de consultas que se ejecutan.
Es diferente de las cachés. Si no hay suficiente memoria fija, SQL Server puede quedarse sin memoria.
La memoria fija incluye memoria de conexión y otorgamientos de memoria.
Sobrecarga de SQL Server
La sobrecarga de SQL Server incluye subprocesos y pilas.
OLTP en memoria
OLTP en memoria incluye tablas en la memoria y grupos de archivos en la memoria.
El consumo de memoria de SQL Server se controla mediante la configuración de maximum server memory y memory.memory.limitmb. Cloud SQL establece el parámetro memory.memory.limitmb de forma automática.
Te recomendamos que permitas que Cloud SQL administre el valor de esta marca.
Si debes administrar este valor de forma manual, usa la fórmula de uso de max_server_memory (mb) que se describe en Prácticas recomendadas para evitar que SQL Server consuma toda la memoria.
Page life expectancy indica la cantidad de tiempo, en segundos, que la página más antigua permanece en el grupo de búferes.
Este valor debe ser mayor que 300 según lo recomendado por Microsoft. Si se reduce de forma constante a menos de
300, podría ser un indicador de que la instancia experimenta una utilización alta de memoria.
Ejecuta la siguiente consulta para supervisar 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'
Verifica la marca Memory Grants Pending.
Memory Grants Pending especifica la cantidad total de procesos que esperan una concesión de memoria del lugar de trabajo.
Ejecuta la siguiente consulta para verificar Memory Grants Pending. Si esta consulta muestra de forma coherente las asignaciones pendientes,
indica una utilización de memoria alta. Para reducirla, consulta las esperas de la base de datos
y ajusta cualquier declaración que esté esperando memoria.
[[["Fácil de comprender","easyToUnderstand","thumb-up"],["Resolvió mi problema","solvedMyProblem","thumb-up"],["Otro","otherUp","thumb-up"]],[["Difícil de entender","hardToUnderstand","thumb-down"],["Información o código de muestra incorrectos","incorrectInformationOrSampleCode","thumb-down"],["Faltan la información o los ejemplos que necesito","missingTheInformationSamplesINeed","thumb-down"],["Problema de traducción","translationIssue","thumb-down"],["Otro","otherDown","thumb-down"]],["Última actualización: 2025-09-04 (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)"]]