Monitor active queries Stay organized with collections Save and categorize content based on your preferences.
This page describes how to monitor and troubleshoot queries that arerunning in your Spanner instance. Active queries are long-runningqueries that might affect the performance of your instance. Monitoring thesequeries can help you identify causes of instance latency and high CPU usage.
Using the Google Cloud console, you can view active queries on theSpannerQuery insights page. These queriesare sorted by the start time of the query. If there are manyactive queries, the results might be limited to a subset of total queriesbecause of the memory constraints that Spanner enforces ondata collection.
Before you begin
To get the permissions that you need to view active queries, ask your administrator to grant you the following IAM roles on the instance:
- Cloud Spanner Viewer (
roles/spanner.viewer) - Cloud Spanner Database Reader (
roles/spanner.databaseReader)
For more information about granting roles, seeManage access to projects, folders, and organizations.
You might also be able to get the required permissions throughcustom roles or otherpredefined roles.
View active queries
To view active queries for each database, do the following:
In the Google Cloud console, go to the SpannerInstances page.
Click the instance that contains the queries that you want to monitor.
In the navigation menu, clickQuery insights.
Use theDatabase menu to specify the database that you want to monitor.
Click theActive queries tab. The tab contains a summary of activequeries, along with a table of the top 50 longest-running activequeries.
View longest-running queries
The following table describes the default columns in theLongest running queries table on theActive queries tab:
| Column name | Description |
|---|---|
| Query ID | The unique identifier for the query. |
| Query | The SQL query text. |
| Fingerprint | Hash of the request tag, or if a tag isn't present, a hash of the SQL query text. |
| Start time | The timestamp for when the query started. |
| Query duration | The duration the active query has been running. |
| Action | Contains a link to terminate the query. |
When theAuto refresh toggle is on, the display refreshes every60 seconds.
You can use theColumn display options button to select any of the followingoptional columns to show up in the Longest running queries table:
| Column name | Description |
|---|---|
| Client IP address | The IP address of the client that requested the query. Sometimes, the client IP address might be redacted. The IP address shown here is consistent with audit logs and follows the same redaction guidelines. For more information, seeIP address of the caller in audit logs. Spanner recommends requesting the client IP address only when the client IP is required, as requests for client IP addresses might incur additional latency. |
| Server region | The region where the Spanner root server processes the query. For more information, seeLife of a query. |
| Transaction type | The query's transaction type. Possible values areREAD_ONLY,READ_WRITE, andNONE. |
| API client header | Theapi_client header from the client. |
| Priority | The priority of the query. To view available priorities, seeRequestOptions. |
| User agent header | Theuser_agent header that Spanner receives from the client. |
Terminate a query
You can terminate a query that is running in your instance. Terminating a querymight help free up resources and reduce the load on your instance. Terminatinga query is a best-effort operation.
The Google Cloud console page refreshes after you initiate the termination.If the termination is successful, the query is removed from the table.If the termination fails, it does so in the background, and the query continuesto appear in theLongest running queries table.
Spanner might not cancel a query when servers are busy.You can try to terminate a query again to cancel it.
To get the permission that you need to terminate a query, ask your administrator to grant you the Cloud Spanner Database Reader (spanner.databaseReader) IAM role on the instance.
This predefined role contains the spanner.sessions.delete permission, which is required to terminate a query.
To terminate a query, do the following:
- Select the query that you want to terminate from theLongest runningqueries table.
- In theActions column, clickTerminate.
- In theTerminate query window, clickConfirm.
To terminate multiple queries, do the following:
- Select the queries you want to terminate from theLongest running queriestable.
- ClickTerminate selected queries.
- In theTerminate the following queries window, clickConfirm.
What's next
- Learn more aboutAnalyze query performance.
- Learn more aboutOldest active queries statistics.
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.