Ottimizzare le query con un utilizzo elevato della memoria
Mantieni tutto organizzato con le raccolte
Salva e classifica i contenuti in base alle tue preferenze.
MySQL | PostgreSQL | SQL Server
Questa pagina descrive il suggerimento di Cloud SQL per ottimizzare le query con utilizzo elevato della memoria, che segnala le query con utilizzo elevato della memoria.
Questo strumento di raccomandazione segnala il testo normalizzato delle query terminate per evitare errori di memoria insufficiente nelle ultime 24 ore. Fornisce poi consigli su come ottimizzare queste istanze e migliorare le prestazioni. I consigli vengono generati ogni giorno.
Prezzi
Il motore per suggerimenti per l'ottimizzazione delle query con utilizzo elevato di memoria di Cloud SQL si trova nel livello di prezzo Standarddi Recommender.
Prima di iniziare
Prima di poter visualizzare consigli e approfondimenti, procedi nel seguente modo:
Per ottenere le autorizzazioni per visualizzare e utilizzare approfondimenti e consigli,
assicurati di disporre dei ruoli Identity and Access Management (IAM) necessari.
Tasks
Ruoli
Visualizza i suggerimenti
Uno di questi ruoli: recommender.cloudsqlViewer o
cloudsql.viewer.
Applica consigli
Uno di questi ruoli: recommender.cloudsqlAdmin, cloudsql.editor
o cloudsql.admin.
Elenco di consigli per ottimizzare le query con un utilizzo elevato di memoria
Puoi elencare i suggerimenti per ottimizzare le query con un utilizzo elevato della memoria
utilizzando la console Google Cloud , gcloud CLI o l'API Recommender.
Console
Per elencare i suggerimenti sul rendimento dell'istanza utilizzando
Fai clic su Rendimento nella scheda Tutti i suggerimenti.
Interfaccia a riga di comando gcloud
Per elencare i suggerimenti per l'ottimizzazione delle query con utilizzo elevato della memoria utilizzando gcloud CLI, esegui il comando
gcloud recommender recommendations list
come segue:
LOCATION: una regione in cui si trovano le istanze, ad esempio us-central1.
API
Per elencare i suggerimenti per l'ottimizzazione delle query con utilizzo elevato della memoria utilizzando l'API Recommendations, chiama il metodo recommendations.list come segue:
GET https://recommender.googleapis.com/v1/projects/PROJECT-ID/locations/LOCATION/recommenders/google.cloudsql.instance.PerformanceRecommender/recommendations
Sostituisci quanto segue:
PROJECT_ID: il tuo ID progetto.
LOCATION: una regione in cui si trovano le istanze, ad esempio us-central1.
Se il sistema di suggerimenti segnala istanze con query terminate, le elenca in una tabella. Ogni riga mostra il nome dell'istanza, un breve suggerimento, il tipo di macchina attuale, il tipo di macchina consigliato, la località e la data dell'ultimo aggiornamento.
Visualizzare approfondimenti e consigli dettagliati
Puoi visualizzare approfondimenti e consigli dettagliati per ottimizzare le query con un elevato utilizzo di memoria utilizzando la console Google Cloud ,
gcloud o l'API Recommender.
Console
Esegui una di queste operazioni:
Nella pagina Consigli sul rendimento, fai clic sulla scheda Consigli sul rendimento, quindi su Ottimizza query con utilizzo elevato di memoria. Viene visualizzato il riquadro dei suggerimenti, che contiene approfondimenti e suggerimenti dettagliati per l'istanza.
Nella pagina Istanze, fai clic su Ottimizza query con utilizzo elevato di memoria. L'elenco delle istanze mostra solo quelle a cui si applica il consiglio.
Interfaccia a riga di comando gcloud
Per visualizzare approfondimenti e suggerimenti dettagliati per ottimizzare le query con un utilizzo elevato della memoria utilizzando gcloud, esegui il comando
gcloud recommender insights list come segue:
Per visualizzare approfondimenti e suggerimenti dettagliati per ottimizzare le query con un utilizzo elevato della memoria utilizzando l'API Recommendations,
chiama il metodo insights.list come segue:
GET https://recommender.googleapis.com/v1/projects/PROJECT-ID/locations/LOCATION/insightTypes/google.cloudsql.instance.PerformanceInsight/insights
Sostituisci quanto segue:
PROJECT_ID: il tuo ID progetto.
LOCATION: una regione, ad esempio us-central1.
Applica consigli
Valuta attentamente il consiglio e procedi in uno dei seguenti modi:
[[["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 queries with high memory usage\n\n\u003cbr /\u003e\n\nMySQL \\| PostgreSQL \\| SQL Server\n\n\u003cbr /\u003e\n\nThis page describes the Cloud SQL optimize high memory queries [recommender](/recommender/docs/overview) which reports queries with high memory utilization.\n\nThis recommender reports normalized query text of the queries terminated to prevent out-of-memory errors in the past 24 hours. It then provides recommendations on how to optimize such\ninstances and improve performance. Recommendations are generated daily.\n\nPricing\n-------\n\nThe Cloud SQL optimize high memory queries recommender is in the *Standard*\n[Recommender pricing tier](/recommender/pricing).\n\nBefore you begin\n----------------\n\nBefore you can view recommendations and insights, do the following:\n\n- To get the permissions to view and work with insights and recommendations, ensure that you have the required [Identity and Access Management (IAM) roles](/sql/docs/postgres/project-access-control#roles).\n\n For more information about IAM roles, see [IAM basic and predefined roles reference](/iam/docs/understanding-roles) and [Manage access to projects, folders, and organizations](/iam/docs/granting-changing-revoking-access).\n-\n\n\n Enable the Recommender API.\n\n\n [Enable the API](https://console.cloud.google.com/flows/enableapi?apiid=recommender.googleapis.com)\n\nList recommendations for optimizing queries with high memory usage\n------------------------------------------------------------------\n\nYou can list recommendations for optimizing queries with high memory usage\nusing the Google Cloud console, [gcloud CLI](/sdk/gcloud), or the Recommender API. \n\n### Console\n\nTo list recommendations about instance performance by using the\n\nGoogle Cloud console, follow these steps:\n\n1. Go to the **Cloud SQL Instances** page.\n\n[Go to Cloud SQL Instances](https://console.cloud.google.com/sql/instances)\n\n1. Click **Expand Details** on the **Improve instance health by investigating issues and acting on recommendations** banner.\n\nAlternatively, follow these steps:\n\n1. Go to the **Recommendation Hub** . See also [Find and apply recommendations with the Recommendations](/recommender/docs/recommendation-hub/identify-configuration-problems).\n\n [Go to the Recommendation Hub](https://console.cloud.google.com/home/recommendations/)\n2. Click **Performance** in the **All recommendations** card.\n\n### gcloud CLI\n\nTo list optimization recommendations for queries with high memory usage using gcloud CLI, run the\n[`gcloud recommender recommendations list`](/sdk/gcloud/reference/recommender/recommendations/list)\ncommand as follows: \n\n```\ngcloud recommender recommendations list \\\n--project=PROJECT_ID \\\n--location=LOCATION \\\n--recommender=google.cloudsql.instance.PerformanceRecommender \\\n--filter=recommenderSubtype=POSTGRES_OPTIMIZE_HIGH_MEMORY_QUERIES\n```\n\nReplace the following:\n\n- \u003cvar translate=\"no\"\u003ePROJECT_ID\u003c/var\u003e: Your project ID.\n- \u003cvar translate=\"no\"\u003eLOCATION\u003c/var\u003e: A region where your instances are located, such as `us-central1`.\n\n### API\n\nTo list optimization recommendations for queries with high memory usage using the\n[Recommendations API](/recommender/docs/using-api), call the\n[`recommendations.list`](/recommender/docs/reference/rest/v1/projects.locations.recommenders.recommendations/list)\nmethod as follows: \n\n```\nGET https://recommender.googleapis.com/v1/projects/PROJECT-ID/locations/LOCATION/recommenders/google.cloudsql.instance.PerformanceRecommender/recommendations\n```\n\nReplace the following:\n\n- \u003cvar translate=\"no\"\u003ePROJECT_ID\u003c/var\u003e: Your project ID.\n- \u003cvar translate=\"no\"\u003eLOCATION\u003c/var\u003e: A region where your instances are located, such as `us-central1`.\n\nIf the recommender reports instances with terminated queries, it lists them in a table. Each row shows the instance name, a brief recommendation, the current machine type, the recommended machine type, the location, and the last refresh date.\n\nView insights and detailed recommendations\n------------------------------------------\n\nYou can view insights and detailed recommendations for optimizing queries with high memory usage using the Google Cloud console,\n`gcloud`, or the Recommender API. \n\n### Console\n\nDo one of the following:\n\n- On the **Performance Recommendations** page, click **Performance recommendations** card, click **Optimize High Memory Queries**. The recommendation panel appears, which contains insights and detailed recommendations for the instance.\n\n- On the **Instances** page, click **Optimize High Memory Queries**. The list of instances displays only those instances for which the recommendation applies.\n\n### gcloud CLI\n\nTo view insights and detailed recommendations for optimizing queries with high memory usage using `gcloud`, run the\n[`gcloud recommender insights list`](/sdk/gcloud/reference/recommender/insights/list)\ncommand as follows: \n\n```\ngcloud recommender insights list \\\n--project=PROJECT_ID \\\n--location=LOCATION \\\n--insight-type=google.cloudsql.instance.PerformanceInsight \\\n--filter=insightSubtype=POSTGRES_HIGH_MEMORY_QUERIES_TERMINATED_TO_PREVENT_OOM\n```\n\nReplace the following:\n\n- \u003cvar translate=\"no\"\u003ePROJECT_ID\u003c/var\u003e: Your project ID.\n- \u003cvar translate=\"no\"\u003eLOCATION\u003c/var\u003e: A region, such as `us-central1`.\n\n### API\n\nTo view insights and detailed recommendations for optimizing queries with high memory usage using the [Recommendations API](/recommender/docs/using-api),\ncall the [`insights.list`](/recommender/docs/reference/rest/v1/projects.locations.insightTypes.insights/list)\nmethod as follows: \n\n```\nGET https://recommender.googleapis.com/v1/projects/PROJECT-ID/locations/LOCATION/insightTypes/google.cloudsql.instance.PerformanceInsight/insights\n```\n\nReplace the following:\n\n- \u003cvar translate=\"no\"\u003ePROJECT_ID\u003c/var\u003e: Your project ID.\n- \u003cvar translate=\"no\"\u003eLOCATION\u003c/var\u003e: A region, such as `us-central1`.\n\nApply recommendations\n---------------------\n\nEvaluate the recommendation carefully and do any of the following:\n\n- For more information, see [Optimize instance high memory usage](/sql/docs/postgres/optimize-high-memory-usage).\n- To dismiss the recommendation so that it's de-emphasized and appears dimmed, click **Dismiss**.\n- To close the panel without applying or dismissing the recommendation, click **Cancel**.\n\nWhat's next\n-----------\n\n- [Google Cloud recommenders](/recommender/docs/recommenders)\n- [About database observability](/sql/docs/postgres/observability)"]]