Monitor active queries

MySQL  |  PostgreSQL  |  SQL Server

This page describes how to monitor and troubleshoot the queries that are activein your database. Monitoring these queries can help identify causes of systemlatency and high CPU usage.

On theQuery insights dashboard, you can view a summary of activetransactions and a list of transactions with associated query and statistics.The transactions are displayed by the transaction start time. If there is alarge number of queries running, then the results might be limited to asubset of total queries.

Before you begin

To monitor active queries, you can use either Cloud SQL Enterprise edition or Cloud SQL Enterprise Plus edition.

To terminate a session or a long-running transaction in active queries,you must use Cloud SQL Enterprise Plus edition for your Cloud SQL instance.

For more information aboutCloud SQL editions, seeIntroduction to Cloud SQL editions.

Required roles and permissions

To get the permissions that you need to view active queries, 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 view active queries. To see the exact permissions that are required, expand theRequired permissions section:

Required permissions

The following permissions are required to view active queries:

  • View database activity summary and long-running transactions:
    • databaseinsights.activeQueries.fetch
    • databaseinsights.activitySummary.fetch

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

Enable active queries

To enable active queries for a Cloud SQL Enterprise edition instance, 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. On theConfiguration tile, clickEdit configuration.
  4. In theCustomize your instance section, expandQuery insights.
  5. Make sureEnable Query insights is enabled.
  6. SelectActive query analysis.
  7. ClickSave.

To enable active queries for a Cloud SQL Enterprise Plus edition instance, 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. On theConfiguration tile, clickEdit configuration.
  4. In theCustomize your instance section, expandQuery insights.
  5. Make sureEnable Query insights is enabled.
  6. SelectEnable Enterprise Plus features.
  7. SelectActive query analysis.
  8. ClickSave.

To be able to terminate a session or long-running transaction in active queries,you must use query insights for Cloud SQL Enterprise Plus edition.

Disable active queries

To disable active queries on a Cloud SQL Enterprise edition or Cloud SQL Enterprise Plus edition instance, 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. On theConfiguration tile, clickEdit configuration.
  4. In theCustomize your instance section, expandQuery insights.
  5. Clear theActive query analysis checkbox.
  6. ClickSave.

View active queries

To view your active queries, complete the following 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. Do one of the following to display theQuery insights dashboard:

    • Select theQuery insights tab.
    • ClickGo to Query insights for more in-depth info on queries and performance.TheQuery insights dashboard opens. It shows details about the instanceat the top.
  4. Click theActive queries tab.

    From here, you can modify the query information that appears in theLongest running transactions table:

    • Database: filters query load on a specific database or all databases.
    • User: filters query load from a specific user account.
    • Summary scorecard of all active queries: provides an overview of allthe active queries by displaying the total connections based on thefollowing parameters:

      1. Distribution of active connections categorized by connection state.
      2. Distribution of active transactions based on transaction state.
      3. Distribution of query durations.
    • Longest running transactions: provides an overview of the top 50running queries (in theactive andidle in transaction state) based ondescending execution time. You can filter and sort active queries in thetable.

View normalized active queries

You can view a list of top long-running transactions with normalized activequeries on theQuery insights dashboard. A normalized active query removessensitive data and returns a digest. The digest is the same for different valuesused in the following example:

  • Regular queries

    • select * from test_table where id=1;
    • select * from test_table_where id=2;
  • Digest or normalized query

    • select * from test_table where id=?;

A query that runs in different sessions is displayed as different entries on thedashboard.

View top longest running transactions

TheLongest running transactions table on theQuery insights dashboardcontains the following columns:

Column nameDescription
Process IDUnique identifier of the connection or thread ID.
QuerySQL query text.
StatusStatus of the connection.
Session durationDuration of the last session running.
Transaction durationDuration of the active transaction running.
Query durationDuration of the last query running in that transaction.
Wait event typeWait event type of the occurring wait event.
Wait eventOccurring wait event.
DatabaseDatabase name on which this connection is running.
Application nameApplication name on which this connection is running.
User nameName of the user connected to the database.
Client addressSpecific IP address of the client that sent a query.
ActionContains a link for terminating a transaction.

The display is refreshed every 60 seconds automatically.

You can use theContent display options...vertical menu to filter the columns you want to display.

Terminate a process

To terminate a process or long-running transaction in active queries,you must use Cloud SQL Enterprise Plus edition and enable bothActive query analysisandquery insights for Cloud SQL Enterprise Plus edition.

Long running operations can take longer to terminate.

To terminate a query or transaction, complete the following steps:

  1. In theLongest running transaction table, select a query.
  2. In theAction column, clickTerminate connection.
  3. In theTerminate connection window, clickConfirm.

If the system successfully terminates the query or transaction, then a successmessage appears. The system also performs a rollback if needed.

Note: IfTerminate isn't available, then you might have insufficientIAM permissions. For more information, seeBefore you begin.

Blocked active queries

Preview —Blocked active queries

This feature is subject to the "Pre-GA Offerings Terms" in the General Service Terms section of theService Specific Terms. You can process personal data for this feature as outlined in theCloud Data Processing Addendum, subject to the obligations and restrictions described in the agreement under which you access Google Cloud. Pre-GA features are available "as is" and might have limited support. For more information, see thelaunch stage descriptions.

If a specific active query is blocked or running much longer than expected, thenthat active query can block other dependent queries.

Cloud SQL gives you the option to terminate specific long-running orblocked active queries.

Enable the analysis of blocked active queries

By default, Google Cloud console doesn't display which active queries are blocked.To be able to analyze blocked active queries, first have both Cloud SQL Enterprise Plus edition andactive queries enabled on the instance.

To enable blocked active query analysis, do the following:

Console

  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. ExpandQuery insights.
  5. Select bothEnable Enterprise Plus features andActive query analysis. Both settings are required.
  6. SelectBlocked query analysis.
  7. ClickSave.

Identify and terminate a blocked active query

The following steps show you how to identify and terminate a specific activequery that might be blocking other queries.

Console

  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. In the SQL navigation menu, clickQuery insights.
  4. Click theActive queries tab.

    If you don't already have active queries running, navigate toCloud SQL Studio and run the queries you want to investigate.

  5. Navigate to theLongest running transactions section. You can see up to 50 of the longest running active queries.

    Each entry displayed includes the following information:

    • Process ID: The process ID of the query. Clickexpand to view the entry. You can see one of two icons:
      • Hourglass icon: This icon indicates that the process is waiting for another query to finish. If a number is included beside the icon, then the number indicates how many dependent queries are waiting for this process to finish.
      • Block symbol icon: This icon indicates that the process is unable to finish and might be blocking other queries.
    • Query type: The type of query running, such asSELECT orUPDATE.
    • Status: The status of the active query, such asACTIVE.
    • Session duration (seconds): The duration of current session (in seconds).
    • Transaction duration (seconds): The duration of current active transaction (in seconds).
    • Query duration (seconds): The duration of current active query (in seconds).
    • Wait event type: The currently occurring wait event type during query execution, such asTimeout orLock.
    • Wait event: The currently occurring wait event during query execution.
    • Action: Possible actions to take, such asTerminate connection.

    Click to expand the process ID you want to investigate. You can expand underlying processes up to three levels deep in the investigation tree.

  6. Identify the specific query that's blocked, then clickTerminate connection. After you terminate the connection, you can navigate toCloud SQL Studio to run your active queries again.

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-11-24 UTC.