Questo documento spiega come esaminare e ottimizzare un'istanza Cloud SQL per SQL Server se questa istanza viene identificata
dal motore per suggerimenti istanze con provisioning insufficiente come istanza con un elevato consumo di memoria.
Si tratta di oggetti su un disco che possono essere ricaricati, ad esempio pagine di database e stored procedure. Di conseguenza,
SQL Server può aumentare e ridurre le dimensioni di questi oggetti in base all'utilizzo della memoria. Le cache includono buffer pool e cache dei piani.
Memoria fissa
La memoria fissa può aumentare e diminuire. Si riduce solo quando non è in uso, ad esempio quando il numero di connessioni diminuisce o il numero di query in esecuzione diminuisce.
È diverso dalle cache. Se la memoria fissa non è sufficiente, SQL Server può esaurire la memoria.
La memoria fissa include la memoria di connessione e le concessioni di memoria.
Overhead di SQL Server
L'overhead di SQL Server include thread e stack.
OLTP in memoria
OLTP in-memory include tabelle in-memory e filegroup in-memory.
Il consumo di memoria da parte di SQL Server è controllato impostando maximum server memory e memory.memory.limitmb. Il parametro memory.memory.limitmb viene impostato automaticamente da Cloud SQL.
Ti consigliamo di lasciare che Cloud SQL gestisca il valore di questo flag.
Se devi gestire manualmente questo valore, utilizza la formula di utilizzo max_server_memory (mb)
descritta nelle best practice
per evitare che SQL Server consumi tutta la memoria.
Page life expectancy indica il tempo, in secondi, in cui la pagina meno recente rimane nel pool di buffer.
Questo valore deve essere superiore a 300, come consigliato da Microsoft. Se scende costantemente sotto
300, potrebbe indicare che l'istanza sta riscontrando un utilizzo elevato della memoria.
Esegui la seguente query per monitorare 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'
Controlla il flag Memory Grants Pending.
Memory Grants Pending specifica il numero totale di processi in attesa di una concessione di memoria del workspace.
Esegui la seguente query per controllare Memory Grants Pending. Se questa query mostra costantemente concessioni in attesa,
significa che l'utilizzo della memoria è elevato. Puoi ridurlo eseguendo query sui tempi di attesa del database e ottimizzando qualsiasi istruzione in attesa di memoria.
[[["Facile da capire","easyToUnderstand","thumb-up"],["Il problema è stato risolto","solvedMyProblem","thumb-up"],["Altra","otherUp","thumb-up"]],[["Difficile da capire","hardToUnderstand","thumb-down"],["Informazioni o codice di esempio errati","incorrectInformationOrSampleCode","thumb-down"],["Mancano le informazioni o gli esempi di cui ho bisogno","missingTheInformationSamplesINeed","thumb-down"],["Problema di traduzione","translationIssue","thumb-down"],["Altra","otherDown","thumb-down"]],["Ultimo aggiornamento 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)"]]