This page describes how to monitor and troubleshoot the queries that are active in your database. Monitoring these queries can help identify causes of system latency and high CPU usage.
On the Query Insights dashboard, you can view a summary of active transactions and a list of transactions with associated query and statistics. The transactions are displayed by the transaction start time. If there is a large number of queries running, the results may be limited to a subset of total queries.
You can use Gemini in Databases assistance to help you observe and troubleshoot your Cloud SQL for MySQL resources. For more information, see Observe and troubleshoot with Gemini assistance.Before you begin
To view your active queries, you must do the following:
- Set up Gemini in Databases.
- Create a custom role and add the following permissions:
Tasks Roles Permissions View recommendations databaseinsights.viewer
databaseinsights.activeQueries.fetch
databaseinsights.activitySummary.fetch
Terminate recommendations databaseinsights.operationsAdmin
N/A
Enable active queries
To enable active queries, complete the following steps:
-
In the Google Cloud console, go to the Cloud SQL Instances page.
- To open the Overview page of an instance, click the instance name.
- In the Configuration tile, click Edit configuration.
- Expand the Query insights pane.
- If the Enable query insights checkbox is cleared, then select it. The Active query analysis checkbox appears.
- If this checkbox is cleared, then select it.
- Click Save.
View active queries
To view your active queries, complete the following steps:
Add this role for each user that is viewing active queries.
In the Google Cloud console, go to the Cloud SQL Instances page.
To open the Overview page of an instance, click the instance name.
Do one of the following to display the Query insights dashboard:
- Select the Query insights tab.
- Click Go to Query insights for more in-depth info on queries and performance. The Query insights dashboard opens. It shows details about the instance at the top.
Click the Active query view tab.
From here, you can modify the query information that appears in the Longest 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 all the active queries by displaying the total connections based on the following 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 50 running queries (in the active 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 active queries on the Query insights dashboard. A normalized active query removes sensitive data and returns a digest. The digest is the same for different values used 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 the dashboard.
View top longest running transactions
The Longest running transactions table on the Query insights dashboard contains the following columns:
Column name | Description |
---|---|
Process ID | Unique identifier of the connection. |
Query | SQL query text. |
Transaction status | The current execution state of the transaction. Permitted values include: RUNNING , LOCK WAIT , ROLLING BACK , and COMMITTING . |
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.
Terminate a connection
To terminate a query or a transaction, you must have the databaseinsights.operationsAdmin
role. For more information, see IAM basic and predefined roles reference.
To terminate a query or transaction, complete the following steps:
- In the Longest running transaction table, select a query.
- In the Action column, click Terminate connection.
- In the Terminate connection window, click Confirm.
A database request returns immediately while the termination happens in the background.