Monitor active queries Stay organized with collections Save and categorize content based on your preferences.
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:
- View instance activity summary:Cloud SQL Viewer (
roles/cloudsql.viewer) - View database activity summary and long-running transactions:Database Insights Viewer (
roles/databaseinsights.viewer) - Terminate a session or long running transaction:
- Cloud SQL Editor (
roles/cloudsql.editor) - Database Insights Operations Admin (
roles/databaseinsights.operationsAdmin)
- Cloud SQL Editor (
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.fetchdatabaseinsights.activitySummary.fetch
You might also be able to get these permissions withcustom roles or otherpredefined roles.
Enable active queries
When youenable query insights,you enable active queries automatically. To be able to terminate a session orlong-running transaction in active queries, you must usequery insights for Cloud SQL Enterprise Plus edition.
Disable active queries
You can't disable active queries without disabling query insights. To disable active queries and query insights, seeDisable query insights.
View active queries
To view your active queries, complete the following steps:
In the Google Cloud console, go to theCloud SQL Instances page.
To open theOverview page of an instance, click the instance name.
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.
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:
- Distribution of active connections categorized by connection state.
- Distribution of active transactions based on transaction state.
- Distribution of query durations.
- Longest running transactions: provides an overview of the top 50running queries (in theactive state) based on descending execution time.You can filter and sort active queries in the table.
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 name | Description |
|---|---|
| Process ID | Unique identifier of the connection. |
| Query | SQL query text. |
| Transaction state | The current execution state of the transaction. Permitted values include:RUNNING,LOCK WAIT,ROLLING BACK, andCOMMITTING. |
| Thread state | Thread state (or query state) indicates the current state of the active thread. |
| Transaction start time | The timestamp when the transaction started its execution. |
| Transaction duration | The duration of current active transaction in seconds. |
| Transaction wait duration | The duration of wait in seconds on current active transaction. |
| Thread state duration | Time elapsed in the query. |
| Transaction rows locked | Number of rows locked by the current active transaction. |
| Transaction rows modified | Number of rows modified by the current active transaction. |
| Database | Database name on which this connection is running. |
| User name | Name of the user connected to the database. |
| Client address | The IP address of client from where a user connects to the database. |
| Action | Contains 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.
Note: Data comes from theinnodb_trx andprocesslist tables. Because bothtables collect data separately, the transaction state and thread state might becaptured at different point in time.Terminate a connection
To terminate a connection or long-running transaction in active queries,you must use Cloud SQL Enterprise Plus edition and enablequery 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:
- In theLongest running transaction table, select a query.
- In theAction column, clickTerminate connection.
- In theTerminate connection window, clickConfirm.
A database request returns immediately while the termination happens in thebackground.
The page refreshes after initiating termination. If termination fails,then an error message or notification isn't returned. The query continues showing up inthe Active Query list. If termination is successful, then the query no longer displaysin the list. If the termination requires a rollback, then theTxn state columnshows theROLLING BACK state, which means that termination is still in progress.
Note: IfTerminate isn't available, then you might have insufficientIAM permissions. For more information, seeBefore you begin.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-12-15 UTC.