Optimize queries with high memory usage

MySQL  |  PostgreSQL  |  SQL Server

This page describes the Cloud SQL optimize high memory queriesrecommender which reports queries with high memory utilization.

This 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 suchinstances and improve performance. Recommendations are generated daily.

Pricing

The Cloud SQL optimize high memory queries recommender is in theStandardRecommender pricing tier.

Before you begin

Before you can view recommendations and insights, do the following:

List recommendations for optimizing queries with high memory usage

You can list recommendations for optimizing queries with high memory usageusing the Google Cloud console,gcloud CLI, or the Recommender API.

Console

To list recommendations about instance performance by using the

Google Cloud console, follow these steps:

  1. Go to theCloud SQL Instances page.

Go to Cloud SQL Instances

  1. ClickExpand Details on theImprove instance health by investigating issues and acting on recommendations banner.

Alternatively, follow these steps:

  1. Go to theRecommendation Hub. See alsoFind and apply recommendations with the Recommendations.

    Go to the Recommendation Hub

  2. ClickPerformance in theAll recommendations card.

gcloud CLI

To list optimization recommendations for queries with high memory usage using gcloud CLI, run thegcloud recommender recommendations listcommand as follows:

gcloud recommender recommendations list \--project=PROJECT_ID \--location=LOCATION \--recommender=google.cloudsql.instance.PerformanceRecommender \--filter=recommenderSubtype=POSTGRES_OPTIMIZE_HIGH_MEMORY_QUERIES

Replace the following:

  • PROJECT_ID: Your project ID.
  • LOCATION: A region where your instances are located, such asus-central1.

API

To list optimization recommendations for queries with high memory usage using theRecommendations API, call therecommendations.listmethod as follows:

GET https://recommender.googleapis.com/v1/projects/PROJECT-ID/locations/LOCATION/recommenders/google.cloudsql.instance.PerformanceRecommender/recommendations

Replace the following:

  • PROJECT_ID: Your project ID.
  • LOCATION: A region where your instances are located, such asus-central1.

If 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.

View insights and detailed recommendations

You can view insights and detailed recommendations for optimizing queries with high memory usage using the Google Cloud console,gcloud, or the Recommender API.

Console

Do one of the following:

  • On thePerformance Recommendations page, clickPerformance recommendations card, clickOptimize High Memory Queries. The recommendation panel appears, which contains insights and detailed recommendations for the instance.

  • On theInstances page, clickOptimize High Memory Queries. The list of instances displays only those instances for which the recommendation applies.

gcloud CLI

To view insights and detailed recommendations for optimizing queries with high memory usage usinggcloud, run thegcloud recommender insights listcommand as follows:

gcloud recommender insights list \--project=PROJECT_ID \--location=LOCATION \--insight-type=google.cloudsql.instance.PerformanceInsight \--filter=insightSubtype=POSTGRES_HIGH_MEMORY_QUERIES_TERMINATED_TO_PREVENT_OOM

Replace the following:

  • PROJECT_ID: Your project ID.
  • LOCATION: A region, such asus-central1.

API

To view insights and detailed recommendations for optimizing queries with high memory usage using theRecommendations API,call theinsights.listmethod as follows:

GET https://recommender.googleapis.com/v1/projects/PROJECT-ID/locations/LOCATION/insightTypes/google.cloudsql.instance.PerformanceInsight/insights

Replace the following:

  • PROJECT_ID: Your project ID.
  • LOCATION: A region, such asus-central1.

Apply recommendations

Evaluate the recommendation carefully and do any of the following:

  • For more information, seeOptimize instance high memory usage.
  • To dismiss the recommendation so that it's de-emphasized and appears dimmed,clickDismiss.
  • To close the panel without applying or dismissing the recommendation, clickCancel.

What's next

Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.

Last updated 2025-07-14 UTC.