[[["容易理解","easyToUnderstand","thumb-up"],["確實解決了我的問題","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["難以理解","hardToUnderstand","thumb-down"],["資訊或程式碼範例有誤","incorrectInformationOrSampleCode","thumb-down"],["缺少我需要的資訊/範例","missingTheInformationSamplesINeed","thumb-down"],["翻譯問題","translationIssue","thumb-down"],["其他","otherDown","thumb-down"]],["上次更新時間:2025-09-05 (世界標準時間)。"],[],[],null,["# Monitor active queries\n\nThis page describes how to monitor and troubleshoot queries that are\nrunning in your Spanner instance. Active queries are long-running\nqueries that might affect the performance of your instance. Monitoring these\nqueries can help you identify causes of instance latency and high CPU usage.\n\nUsing the Google Cloud console, you can view active queries on the\nSpanner **Query insights** page. These queries\nare sorted by the start time of the query. If there are many\nactive queries, the results might be limited to a subset of total queries\nbecause of the memory constraints that Spanner enforces on\ndata collection.\n\nBefore you begin\n----------------\n\n\nTo get the permissions that\nyou need to view active queries,\n\nask your administrator to grant you the\nfollowing IAM roles on the instance:\n\n- [Cloud Spanner Viewer](/iam/docs/roles-permissions/spanner#spanner.viewer) (`roles/spanner.viewer`)\n- [Cloud Spanner Database Reader](/iam/docs/roles-permissions/spanner#spanner.databaseReader) (`roles/spanner.databaseReader`)\n\n\nFor more information about granting roles, see [Manage access to projects, folders, and organizations](/iam/docs/granting-changing-revoking-access).\n\n\nYou might also be able to get\nthe required permissions through [custom\nroles](/iam/docs/creating-custom-roles) or other [predefined\nroles](/iam/docs/roles-overview#predefined).\n\nView active queries\n-------------------\n\nTo view active queries for each database, do the following:\n\n1. In the Google Cloud console, go to the Spanner **Instances** page.\n\n [Go to the Spanner Instances page](https://console.cloud.google.com/spanner/instances)\n2. Click the instance that contains the queries that you want to monitor.\n\n3. In the navigation menu, click **Query insights**.\n\n4. Use the **Database** menu to specify the database that you want to monitor.\n\n5. Click the **Active queries** tab. The tab contains a summary of active\n queries, along with a table of the top 50 longest-running active\n queries.\n\nView longest-running queries\n----------------------------\n\nThe following table describes the columns in the **Longest running queries**\ntable on the **Active queries** tab:\n\nWhen the **Auto refresh** toggle is on, the display refreshes every\n60 seconds.\n\nTerminate a query\n-----------------\n\nYou can terminate a query that is running in your instance. Terminating a query\nmight help free up resources and reduce the load on your instance. Terminating\na query is a best-effort operation.\n\nThe Google Cloud console page refreshes after you initiate the termination.\nIf the termination is successful, the query is removed from the table.\nIf the termination fails, it does so in the background, and the query continues\nto appear in the **Longest running queries** table.\n\nSpanner might not cancel a query when servers are busy.\nYou can try to terminate a query again to cancel it.\n\n\nTo get the permission that\nyou need to terminate a query,\n\nask your administrator to grant you the\n\n\nCloud Spanner Database Reader (`spanner.databaseReader`)\nIAM role on the instance.\n\n\nThis predefined role contains the\n` spanner.sessions.delete`\npermission,\nwhich is required to\nterminate a query.\n\n\nTo terminate a query, do the following:\n\n1. Select the query that you want to terminate from the **Longest running\n queries** table.\n2. In the **Actions** column, click **Terminate**.\n3. In the **Terminate query** window, click **Confirm**.\n\nTo terminate multiple queries, do the following:\n\n1. Select the queries you want to terminate from the **Longest running queries** table.\n2. Click **Terminate selected queries**.\n3. In the **Terminate the following queries** window, click **Confirm**.\n\nWhat's next\n-----------\n\n- Learn more about [Analyze query performance](/spanner/docs/using-query-insights).\n- Learn more about [Oldest active queries statistics](/spanner/docs/introspection/oldest-active-queries)."]]