Use query insights to improve query performance

MySQL  |  PostgreSQL  |  SQL Server

This page describes how to use the Query insights dashboard todetect and analyze performance problems with your queries.

Introduction

Query insights helps you detect, diagnose, and prevent query performance problemsfor Cloud SQL databases. It supports intuitive monitoring and providesdiagnostic information that helps you go beyond detection to identify theroot cause of performance problems.

Query insights helps you improve Cloud SQL query performance by guiding youthrough the following steps:

Note: By default, query insights displays data only from completedqueries, unless you're monitoring active queries. Tomonitor all queries that are running in real time, useactive queries. For more information about active queries,seeMonitor active queries.

Query insights for Cloud SQL Enterprise Plus edition

If you're using Cloud SQL Enterprise Plus edition, then you can access additional capabilities inquery insights to perform advanced query performance diagnostics. In addition tothe standard capabilities of the Query insights dashboard,query insights for Cloud SQL Enterprise Plus edition lets you do the following:

  • Capture longer query text up to 20 KB.
  • Capture query plans for all executed queries.
  • Sample up to 200 query plans per minute.
  • Maintain a longer 30-day retention of metrics.
  • Obtain index recommendations from index advisor.
  • Terminate a session or long-running transaction in active queries.
  • Access AI-assisted troubleshooting (Preview).

The following table compares functional requirements and capabilities ofquery insights for Cloud SQL Enterprise edition with query insights for Cloud SQL Enterprise Plus edition.

Comparison areaQuery insights for Cloud SQL Enterprise editionQuery insights for Cloud SQL Enterprise Plus edition
Supported database versions

All versions of the following instances:

  • SQL Server Web
  • SQL Server Standard
  • SQL Server Enterprise

Query insights isn't supported on SQL Server Express edition instances

SQL Server Enterprise version 2019 or 2022
Supported machine typesSupported on all machine typesNot supported on instances that use ashared core machine type
Supported regionsCloud SQL regional locationsCloud SQL Enterprise Plus edition regional locations
Metrics retention period7 days30 days
Query length limit maximum4500 bytes20 KB
Query plan sample maximum Not available200
Index advisor recommendationsNot availableAvailable
Terminate sessions or long-running transactions in active queriesNot availableAvailable
AI-assisted troubleshooting (Preview)Not availableAvailable

Enable query insights for Cloud SQL Enterprise Plus edition

To enable query insights for Cloud SQL Enterprise Plus edition, selectEnable Enterprise Plus features when youEnable query insights on your Cloud SQL Enterprise Plus edition instance.

Pricing

You can create an account to evaluate how Cloud SQL performs in real-world scenarios. New customers also get $300 in free credits to spend on Cloud SQL to run, test, and deploy workloads. You won't be charged until you upgrade.

Sign up to try Cloud SQL at no charge.

There's no additional cost for query insights on Cloud SQL Enterprise edition orCloud SQL Enterprise Plus edition instances.

Storage requirements

Query insights stores metrics data on the instance and requires that youkeep the automatic storage increases setting enabled.Applicable storage fees apply.

Metrics storage limitations

The following limitations apply to query insights for Cloud SQL Enterprise Plus edition instances:

  • If your instance is undergoing heavy system load, then when you querymetrics data in theQuery insights dashboard, your queries might be slow toload or time out.
  • If you recreate a read replica, then the recreated read replicadoesn't maintain its previous metrics history.
  • If you restore an instance with an old backup, then you can lose themetrics between the time of your backup and the time that you restore theinstance for query insights for Cloud SQL Enterprise Plus edition.For example, if you restoreyour instance on April 30 with a backup taken on April 25, then you mightlose all the metrics between April 25 and April 30.

Before you begin

Before you use query insights, do the following.

  1. Add required roles and permissions.
  2. Enable the Cloud Trace API.
  3. If you're using query insights for Cloud SQL Enterprise edition or query insights for Cloud SQL Enterprise Plus edition, then make sure thatEnable automatic storage increases isenabled for the instance.

Required roles and permissions

To use query insights, you need to grant a predefined role,create a custom role, or provide a user accountwith the required Identity and Access Management permissions.

For more information about granting roles, seeManage access.

To get the permissions that you need to access historical query execution data in the Query insights dashboard, ask your administrator to grant you the following IAM roles on the project that hosts the Cloud SQL instance:

For more information about granting roles, seeManage access to projects, folders, and organizations.

These predefined roles contain the permissions required to access historical query execution data in the Query insights dashboard. To see the exact permissions that are required, expand theRequired permissions section:

Required permissions

The following permissions are required to access historical query execution data in the Query insights dashboard:

  • databaseinsights.aggregatedStats.query
  • databaseinsights.timeSeries.query

You might also be able to get these permissions withcustom roles or otherpredefined roles.

For example, in Database Insights, you can ask your administrator to grant you theDatabase Insights Viewer (roles/databaseinsights.viewer) predefined role. Then, in Cloud SQL, you can ask your administrator to grant you one of the following predefined roles:

Enable the Cloud Trace API

To view query plans and their end-to-end views, your Google Cloud projectmust have the Cloud Trace API enabled. This setting lets yourGoogle Cloud project receive trace data from authenticated sources at noadditional cost. This data can help you detect and diagnose performance issuesin your instance.

To confirm that the Cloud Trace API is enabled, follow these steps:

  1. From the Google Cloud console, go toAPIs and Services:

    Go to APIs and Services

  2. ClickEnable APIs and Services.
  3. In the search bar, enterCloud Trace API.
  4. IfAPI enabled is displayed, then this API is enabled and there's nothing for you to do. Otherwise, clickEnable.

Enable automatic storage increases

If you're using query insights for Cloud SQL Enterprise Plus edition, then make sure that the instance settingtoenable automatic storage increasesremains enabled. By default, this option is enabled for Cloud SQLinstances.

If you previously disabled this instance setting and want toenable query insights for Cloud SQL Enterprise Plus edition, then re-enable automatic storage increases first.You can't turn off automatic storage increases and enable query insights for Cloud SQL Enterprise Plus edition.

Enable query insights

Note: Query insights metrics are encrypted at rest.

When you enable query insights, all other operations aretemporarily suspended. These operations include health checks, logging,monitoring, and other instance operations.

Console

Note: If you don't have query insights enabled on anyof your instances, then you can enable query insights by clickingEnableorEnable for multiple instances ontheQuery insights dashboard.

Enable query insights for an instance

  1. In the Google Cloud console, go to theCloud SQL Instances page.

    Go to Cloud SQL Instances

  2. To open theOverview page of an instance, click the instance name.
  3. On theConfiguration tile, clickEdit configuration.
  4. In theCustomize your instance section, expandQuery insights.
  5. Select theEnable Query insights checkbox.
  6. Optional: Select additional features for your instance. Some features are available only for Cloud SQL Enterprise Plus edition.
  7. FeatureDescriptionCloud SQL Enterprise editionCloud SQL Enterprise Plus edition
    Enable Enterprise Plus features Select this checkbox to enable query insights for Cloud SQL Enterprise Plus edition. Query insights for Cloud SQL Enterprise Plus edition lets you terminate sessions and long-running transactions in active queries, enables index advisor recommendations to help you speed up query processing, and increases metric data retention to 30 days. Index advisor recommendations are enabled automatically when you enable query insights for Cloud SQL Enterprise Plus edition. To disable index advisor recommendations, clear this checkbox. You must select this checkbox to enable index advisor recommendations and AI-assisted troubleshooting (Preview).Not availableAvailable

    Default: Disabled
    AI-assisted troubleshootingSelect this checkbox to enable performance anomaly detection, root cause and situation analysis, and to obtain recommendations for fixing problems with your queries and database. This feature is is inPreview, and you can enable and access this feature only using the Google Cloud console. For more information, seeObserve and troubleshoot with AI assistance.Not availableAvailable

    Default: Disabled
    Customize query lengths Select this checkbox to customize the limit for the length of a query string. Higher query lengths are more useful for analytical queries, but they also require more memory. Any query string that goes above the specified limit becomes truncated in the display.

    Changing the query length limit requires you to restart the instance.
    You can set the limit in bytes from256 bytes to4500 bytes.

    Default:1024.
    You can specify a limit in bytes from256 to20480.

    Default:10240 bytes (10 KB).
    Set the maximum sampling rate Select this checkbox to set the maximum sampling rate. The sampling rate is the number of executed query plan samples that are captured per minute across all databases on the instance. Increasing the sampling rate is likely to give you more data points but might increase performance overhead.You change this value to a number from0 to20.

    Default:5.
    You can increase the maximum to200 to provide more data points.

    Default:5.
  8. ClickSave.

Enable query insights for multiple instances

  1. In the Google Cloud console, go to theCloud SQL Instances page.

    Go to Cloud SQL Instances

  2. Click theMore Actions menu on any row.
  3. SelectEnable Query insights.
  4. In the dialog, select theEnable Query insights for multiple instances checkbox.
  5. ClickEnable.
  6. In the subsequent dialog, select the instances for which you want to enable query insights.
  7. ClickEnable Query insights.Note: If you enable query insights for multiple instances, then the configuration of the instances is based on thedefault configurations.

gcloud

To enable query insights for a Cloud SQL instance by usinggcloud, rungcloud sql instances patch with the--insights-config-query-insights-enabled flag as follows after replacingINSTANCE_ID with the ID of the instance.

If you enable query insights for a Cloud SQL Enterprise Plus edition instance, then you enable index advisor recommendations automatically.

gcloudsqlinstancespatchINSTANCE_ID\--insights-config-query-insights-enabled

Also, use one or more of the following optional flags:

  • --insights-config-query-string-length

    Sets the default query length limit. Higher query lengths are more useful for analytical queries, but they also require more memory. Changing the query length requires you to restart the instance. For Cloud SQL Enterprise edition, you can specify a value in bytes from256 to4500. The default query length is1024 bytes. For Cloud SQL Enterprise Plus edition, you can specify a limit in bytes from256 to20480. The default value is10240 bytes (10 KB).

  • --insights-config-query-plans-per-minute

    By default, a maximum of 5 executed query plan samples are captured per minute across all databases on the instance. Increasing the sampling rate is likely to give you more data points but might add a performance overhead. To disable sampling, set this value to0. For Cloud SQL Enterprise edition, you can change the value from 0 to 20. For Cloud SQL Enterprise Plus edition, you can increase the maximum up to 200 to provide more data points.

Replace the following:

  • INSIGHTS_CONFIG_QUERY_STRING_LENGTH: The query string length to be stored, in bytes.
  • API_TIER_STRING: Thecustom instance configuration to use for the instance.
  • REGION: Theregion for the instance.
gcloudsqlinstancespatchINSTANCE_ID\--insights-config-query-insights-enabled\--insights-config-query-string-length=INSIGHTS_CONFIG_QUERY_STRING_LENGTH\--insights-config-query-plans-per-minute=QUERY_PLANS_PER_MINUTE\--tier=API_TIER_STRING\--region=REGION

REST v1

To enable query insights for a Cloud SQL instance by using the REST API, call theinstances.patch method withinsightsConfig settings.

If you enable query insights for a Cloud SQL Enterprise Plus edition instance, then you enable index advisor recommendations automatically.

Before using any of the request data, make the following replacements:

  • PROJECT_ID: the project ID
  • INSTANCE_ID: the instance ID

HTTP method and URL:

PATCH https://sqladmin.googleapis.com/v1/projects/PROJECT_ID/instances/INSTANCE_ID

Request JSON body:

{  "settings" : {     "insightsConfig" : {       "queryInsightsEnabled" : true,       "recordClientAddress" : true,       "queryStringLength" : 1024,       "queryPlansPerMinute" : 20,   }  }}

To send your request, expand one of these options:

curl (Linux, macOS, or Cloud Shell)

Note: The following command assumes that you have logged in to thegcloud CLI with your user account by runninggcloud init orgcloud auth login , or by usingCloud Shell, which automatically logs you into thegcloud CLI . You can check the currently active account by runninggcloud auth list.

Save the request body in a file namedrequest.json, and execute the following command:

curl -X PATCH \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H "Content-Type: application/json; charset=utf-8" \
-d @request.json \
"https://sqladmin.googleapis.com/v1/projects/PROJECT_ID/instances/INSTANCE_ID"

PowerShell (Windows)

Note: The following command assumes that you have logged in to thegcloud CLI with your user account by runninggcloud init orgcloud auth login . You can check the currently active account by runninggcloud auth list.

Save the request body in a file namedrequest.json, and execute the following command:

$cred = gcloud auth print-access-token
$headers = @{ "Authorization" = "Bearer $cred" }

Invoke-WebRequest `
-Method PATCH `
-Headers $headers `
-ContentType: "application/json; charset=utf-8" `
-InFile request.json `
-Uri "https://sqladmin.googleapis.com/v1/projects/PROJECT_ID/instances/INSTANCE_ID" | Select-Object -Expand Content

You should receive a JSON response similar to the following:

{  "kind": "sql#operation",  "targetLink": "https://sqladmin.googleapis.com/v1/projects/PROJECT_ID/instances/INSTANCE_ID",  "status": "PENDING",  "user": "user@example.com",  "insertTime": "2025-03-28T22:43:40.009Z",  "operationType": "UPDATE",  "name": "OPERATION_ID",  "targetId": "INSTANCE_ID",  "selfLink": "https://sqladmin.googleapis.com/v1/projects/PROJECT_ID/operations/OPERATION_ID",  "targetProject": "PROJECT_ID"}

Terraform

To use Terraform to enable query insights for a Cloud SQL instance, set thequery_insights_enabled flag totrue.

If you enable query insights for a Cloud SQL Enterprise Plus edition instance, then you enable index advisor recommendations automatically.

Also, you can use one or more of the following optional flags:

  • query_string_length: for Cloud SQL Enterprise edition, you can specify a value in bytes from256 to4500. The default query length is1024 bytes. For Cloud SQL Enterprise Plus edition, you can specify a limit in bytes from256 to20480. The default value is10240 bytes (10 KB).
  • record_client_address: set the value totrue if you want to record the client IP address. The default isfalse.
  • query_plans_per_minute: for Cloud SQL Enterprise edition, you can set the value from0 to20. The default is5. For Cloud SQL Enterprise Plus edition, you can increase the maximum up to200 to provide more data points.

Here's an example:

To apply your Terraform configuration in a Google Cloud project, complete the steps in the following sections.

Prepare Cloud Shell

  1. LaunchCloud Shell.
  2. Set the default Google Cloud project where you want to apply your Terraform configurations.

    You only need to run this command once per project, and you can run it in any directory.

    export GOOGLE_CLOUD_PROJECT=PROJECT_ID

    Environment variables are overridden if you set explicit values in the Terraform configuration file.

Prepare the directory

Each Terraform configuration file must have its own directory (alsocalled aroot module).

  1. InCloud Shell, create a directory and a new file within that directory. The filename must have the.tf extension—for examplemain.tf. In this tutorial, the file is referred to asmain.tf.
    mkdirDIRECTORY && cdDIRECTORY && touch main.tf
  2. If you are following a tutorial, you can copy the sample code in each section or step.

    Copy the sample code into the newly createdmain.tf.

    Optionally, copy the code from GitHub. This is recommended when the Terraform snippet is part of an end-to-end solution.

  3. Review and modify the sample parameters to apply to your environment.
  4. Save your changes.
  5. Initialize Terraform. You only need to do this once per directory.
    terraform init

    Optionally, to use the latest Google provider version, include the-upgrade option:

    terraform init -upgrade

Apply the changes

  1. Review the configuration and verify that the resources that Terraform is going to create or update match your expectations:
    terraform plan

    Make corrections to the configuration as necessary.

  2. Apply the Terraform configuration by running the following command and enteringyes at the prompt:
    terraform apply

    Wait until Terraform displays the "Apply complete!" message.

  3. Open your Google Cloud project to view the results. In the Google Cloud console, navigate to your resources in the UI to make sure that Terraform has created or updated them.
Note: Terraform samples typically assume that the required APIs are enabled in your Google Cloud project.

Metrics are expected to be available in query insights within minutes of querycompletion.

View the Query insights dashboard

The Query insights dashboard shows thequery load based on factorsthat you select. Query load is a measurement of the total work for all thequeries in the instance in the selected time range. The dashboard provides aseries of filters that help you view query load.

To open theQuery insights dashboard, follow these steps:

  1. To open theOverview page of an instance, click the instance name.
  2. In the Cloud SQL navigation menu, clickQuery insights, or clickGo to Query insights for more in-depth info on queries and performance on theInstance overview page.
  3. TheQuery insights dashboard opens. Depending on whether you're usingquery insights for Cloud SQL Enterprise edition or query insights for Cloud SQL Enterprise Plus edition, the Query insights dashboardshows the following information aboutyour instance:

Shows the Query Insights dashboard, with drop-down menus         for databases. To the right of the drop-down         menus, there's a filter for setting a time range.

Note: The data retention policy for query metrics is7 days for query insights for Cloud SQL Enterprise editionand 30 days for query insights for Cloud SQL Enterprise Plus edition.

View the database load for all queries

Database query load is a measure of the work (in CPU seconds) that the executedqueries in your selected database perform over time. Each runningquery is either using or waiting for CPU resources, IO resources, or lockresources. Database query load is the ratio of the amount of time taken by allthe queries that are completed in a given time window to the wall-clock time.

The top-level query insights dashboard shows theDatabase load by execution timegraph. Drop-down menus on the dashboard let you filter the graph for all databasesor a specific database.

Shows all executed queries for a chosen database.

Colored lines in the graph show per database load by execution time.Review the graph and use the filtering options to explore these questions:

  • Is the query load high? Is the graph spiking or elevated over time? If you don't see a high load, then the problem isn't with your query.
  • How long has the load been high? Is it high only now or has it been high for a long time? Use the range selector to select various time periods to find out how long the problem has lasted. Zoom in to view a time window where query load spikes are observed. Zoom out to view up to one week of the timeline.
  • Which database is experiencing the load? Select different databases from the Databases drop-down menu to find the databases with the highest loads.

Filter the database load

You can filter the database load by queries.If you're using query insights for Cloud SQL Enterprise Plus edition, then you can customize the database load chartto break down the displayed data usingany of the following dimensions:

  • All queries

  • Databases

To customize the database load chart, select a dimensionfrom theDatabase Load by execution time drop-down.

View the top contributors to database load

To view the top contributors to the database load,you can use theTop dimensions by database load table.TheTop dimensions by database load table displays the top contributors forthe time period and dimension that you select in theDatabase Load by execution time chart drop-down. You can modify thetime period or dimension to view the top contributors for a different dimensionor time period.

In theTop dimensions by data load table, you can select the following tabs.

TabDescription
QueriesThe table displays the top normalized queries by total execution time. For each query, the data shown in columns are listed as follows:
  • Avg execution time (ms): average time for the query to execute.
  • Total execution time (ms): the total execution time taken by the specific query.
  • Avg rows returned: the average number of rows fetched for the query.
  • Times called: the number of times the query was called by the application.
DatabasesThe table shows the list of top databases that contributed to the load during the chosen time period across all executed queries.
  • Avg time spent in database (ms): average time the queries spent in the specific database.
  • Total time spent in database (ms): the total execution time the queries spent in the specific database.

Filter by queries

TheTop queries table provides an overview of the queries that cause themost query load. The table shows all the normalized queries for the time rangeand options selected on the Query insights dashboard. It sorts queries by thetotal execution time during the time range that you selected.

To sort the table, select a column heading.

The table shows the following properties:

  • Query: the normalized query string. By default, query insights shows only 1024 characters in the query string.
  • Database: the database against which the query was run.
  • Recommendations: the suggested recommendations, such asCreate indexes, to improve query performance.
  • Avg execution time (ms): the average time for the query to execute.
  • Total execution time (ms): the total time for the query to execute.
  • Times called: the number of times the application called the query.
  • Avg rows returned: the average number of rows returned for the query.

Query insights stores and displays only normalized queries.

Examine operations in a sampled query plan

Aquery plan takes asample of your query and breaks it down into individual operations. It explainsand analyzes each operation in the query.

TheQuery plan samples graph shows all the query plans running atparticular times and the amount of time each plan took to run. You can changethe rate at which query plan samples are captured per minute. SeeEnable Query Insights.

Shows a query plan and a visualization of end-to-end tracing.

By default, the panel on the right shows the details for the sample query planthat takes the longest time, as visible on theQuery plan samples graph.To see the details for another sample query plan, click the relevant circle onthe graph. Expanded details show a model of all the operations in the query plan.

Each operation shows the rows returned and, if available, the cost of theoperation. Use the full screen view or theEnd-to-end tab to seeestimated execution statistics for each node (operation), as well as runtimeexecution statistics associated with the root node.

Shows a query plan using a visualization tree.

Try to narrow down the problem by looking into the following questions:

  1. What's the resource consumption?
  2. How does it relate to other queries?
  3. Does consumption change over time?

Query details feature

Query details can provide further details about a specific query, including averageexecution time, the number of times called, and the average number of rowsreturned. It can also offer recommendations, such as indexes, to help improvequery performance.

Query details also provide the following metrics:

  • Query plan samples: These samples help explain and analyze your query by providing a breakdown of the different operations in a sample of the query.

    Shows a query plan and a visualization of end-to-end tracing.

  • Query execution count over time: Shows the number of times the query has completed over a specified period. The chart helps you better understand when a query is usually executed and can help you estimate the impact of the query on instance performance.

    Shows the number of times the query has been executed over a        specified period.

  • Average rows returned over time: Shows the average number of rows returned by the query over time. This data can help you correlate slower than usual queries with an increased amount of data returned by those queries.

    Shows the average number of rows returned by the query over time.

  • I/O statistics: Shows the input and output statistics for the query, including the following filters:
    • Average logical reads
    • Average physical reads
    • Average logical writes

    You can use I/O metrics to help you correlate slower than usual queries with more intensive I/O usage or changes in I/O patterns.

    For example, if the number of logical reads increased, then that could be an indication that the query started reading more data than usual. If the number of physical reads increased, then that could indicate that Cloud SQL started reading more data from disk rather than from the buffer cache. For example, perhaps there wasn't enough memory to cache all data or the instance started reading too much data. If the number of logical writes increased, then that could indicate that the query started writing more data to the data disk.

    This is one example of how this metric could help measure the impact of the query on instance I/O.

    Shows a representation of the input and output statistics for the        query.

  • Memory statistics: Shows the memory usage statistics for the query, including the following filters:
    • Average ideal memory
    • Average reserved memory
    • Average used memory

    This metric can help you detect changes in memory consumption related to the query, including the following examples:

    • Use this metric to detect when Cloud SQL mispredicted the amount of memory required for executing the query and might have reserved more memory than used by the query.
    • Use this metric to detect when Cloud SQL couldn't allocate enough memory and reserved a smaller memory grant. When this happens, Cloud SQL uses thetempdb database, which is slower than using memory.
    • Use the metric together with the number of query executions to measure impact of the query on memory consumption of the instance.
    • Use the metric when you see high memory usage or memory pressure.

    Shows the memory usage statistics for the query.

  • CPU and execution time statistics: Shows a combined view of CPU time and execution time statistics for the query. You can use the CPU time metric to investigate high CPU usage on the instance, including the following examples:
    • You can use a combination of CPU time and execution count metrics to measure the impact of the query on total CPU consumption in the instance.
    • You can use a combination of CPU time, execution time, and parallelism metrics to measure the percentage of time the query was waiting for resources.
    • You can use the execution time metric to detect when a query took more time to execute than usual.

    Shows a combined view of CPU time and execution time statistics for        the query.

  • Additional query statistics: Shows additional statistics related to the query, including the following filters:
    • Common language runtime (CLR) statistics
    • Columnstore statistics
    • Memory spills
    • Parallelism statistics

    Shows additional statistics related to the query, including common        language runtime (CLR) statistics, columnstore statistics, memory spills,        and parallelism statistics.

Disable query insights

Note: When you disable query insights, Cloud SQL doesn't delete any data from disk.

Console

To disable query insights for a Cloud SQL instance by using the Google Cloud console, follow these steps:

  1. In the Google Cloud console, go to theCloud SQL Instances page.

    Go to Cloud SQL Instances

  2. To open theOverview page of an instance, click the instance name.
  3. On theConfiguration tile, clickEdit configuration.
  4. In theConfiguration options section, expandQuery insights.
  5. Clear theEnable Query insights checkbox.
  6. ClickSave.

gcloud

To disable query insights for a Cloud SQL instance by usinggcloud, rungcloud sql instances patch with the--no-insights-config-query-insights-enabled flag as follows, after replacingINSTANCE_ID with the ID of the instance.

gcloudsqlinstancespatchINSTANCE_ID\--no-insights-config-query-insights-enabled

REST

To disable query insights for a Cloud SQL instance by using the REST API, call theinstances.patch method withqueryInsightsEnabled set tofalse as follows.

Before using any of the request data, make the following replacements:

  • project-id: The project ID.
  • instance-id: The instance ID.

HTTP method and URL:

PATCH https://sqladmin.googleapis.com/sql/v1beta4/projects/project-id/instances/instance-id

Request JSON body:

{  "settings" : { "insightsConfig" : { "queryInsightsEnabled" : false } }}

To send your request, expand one of these options:

curl (Linux, macOS, or Cloud Shell)

Note: The following command assumes that you have logged in to thegcloud CLI with your user account by runninggcloud init orgcloud auth login , or by usingCloud Shell, which automatically logs you into thegcloud CLI . You can check the currently active account by runninggcloud auth list.

Save the request body in a file namedrequest.json, and execute the following command:

curl -X PATCH \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H "Content-Type: application/json; charset=utf-8" \
-d @request.json \
"https://sqladmin.googleapis.com/sql/v1beta4/projects/project-id/instances/instance-id"

PowerShell (Windows)

Note: The following command assumes that you have logged in to thegcloud CLI with your user account by runninggcloud init orgcloud auth login . You can check the currently active account by runninggcloud auth list.

Save the request body in a file namedrequest.json, and execute the following command:

$cred = gcloud auth print-access-token
$headers = @{ "Authorization" = "Bearer $cred" }

Invoke-WebRequest `
-Method PATCH `
-Headers $headers `
-ContentType: "application/json; charset=utf-8" `
-InFile request.json `
-Uri "https://sqladmin.googleapis.com/sql/v1beta4/projects/project-id/instances/instance-id" | Select-Object -Expand Content

You should receive a JSON response similar to the following:

{  "kind": "sql#operation",  "targetLink": "https://sqladmin.googleapis.com/sql/v1beta4/projects/project-id/instances/instance-id",  "status": "PENDING",  "user": "user@example.com",  "insertTime": "2021-01-28T22:43:40.009Z",  "operationType": "UPDATE",  "name": "operation-id",  "targetId": "instance-id",  "selfLink": "https://sqladmin.googleapis.com/sql/v1beta4/projects/project-id/operations/operation-id",  "targetProject": "project-id"}

Disable query insights for Cloud SQL Enterprise Plus edition

To disable query insights for Cloud SQL Enterprise Plus edition, do the following:

  1. In the Google Cloud console, go to theCloud SQL Instances page.

    Go to Cloud SQL Instances

  2. To open theOverview page of an instance, click the instance name.
  3. ClickEdit.
  4. In theCustomize your instance section, expandQuery insights.
  5. Clear theEnable Enterprise Plus features checkbox.
  6. ClickSave.
Note: If you clear theEnable Query insights checkbox, then you also turn off query insights for Cloud SQL Enterprise Plus edition.

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-18 UTC.