このページでは、Spanner インスタンスで実行されているクエリをモニタリングしてトラブルシューティングする方法について説明します。アクティブ クエリとは、インスタンスのパフォーマンスに影響する可能性がある長時間実行クエリのことです。これらのクエリをモニタリングすると、インスタンスのレイテンシと CPU 使用率が高い原因を特定できます。
Google Cloud コンソールを使用して、Spanner の [Query Insights] ページでアクティブ クエリを表示できます。これらのクエリは、クエリの開始時間で並べ替えられます。アクティブ クエリが多い場合、Spanner がデータ収集に適用するメモリの制約により、結果が合計クエリのサブセットに限定される可能性があります。
始める前に
アクティブ クエリを表示するために必要な権限を取得するには、インスタンスに対する次の IAM ロールを付与するよう管理者に依頼してください。
[[["わかりやすい","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-08-17 UTC。"],[],[],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)."]]