Monitor active queries

This page describes how to monitor and troubleshoot queries that are running in your Spanner instance. Active queries are long-running queries that might affect the performance of your instance. Monitoring these queries can help you identify causes of instance latency and high CPU usage.

Using the Google Cloud console, you can view active queries on the Spanner Query insights page. These queries are sorted by the start time of the query. If there are many active queries, the results might be limited to a subset of total queries because of the memory constraints that Spanner enforces on data 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:

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

You might also be able to get the required permissions through custom roles or other predefined roles.

View active queries

To view active queries for each database, do the following:

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

    Go to the Spanner Instances page

  2. Click the instance that contains the queries that you want to monitor.

  3. In the navigation menu, click Query insights.

  4. Use the Database menu to specify the database that you want to monitor.

  5. Click the Active queries tab. The tab contains a summary of active queries, along with a table of the top 50 longest-running active queries.

View longest-running queries

The following table describes the columns in the Longest running queries table on the Active queries tab:

Column name Description
Query ID The unique identifier for the query.
Query The SQL query text.
Fingerprint The hash of the REQUEST_TAG or 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 the Auto refresh toggle is on, the display refreshes every 60 seconds.

Terminate a query

You can terminate a query that is running in your instance. Terminating a query might help free up resources and reduce the load on your instance. Terminating a 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 continues to appear in the Longest 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 permissions 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.

To terminate a query, do the following:

  1. Select the query that you want to terminate from the Longest running queries table.
  2. In the Actions column, click Terminate.
  3. In the Terminate connection window, click Confirm.

What's next