이 페이지에서는 Spanner 인스턴스에서 실행 중인 쿼리를 모니터링하고 문제를 해결하는 방법을 설명합니다. 활성 쿼리는 인스턴스 성능에 영향을 줄 수 있는 장기 실행 쿼리입니다. 이러한 쿼리를 모니터링하면 인스턴스 지연 시간 및 높은 CPU 사용량의 원인을 파악하는 데 도움이 될 수 있습니다.
Google Cloud 콘솔을 사용하여 Spanner 쿼리 통계 페이지에서 활성 쿼리를 볼 수 있습니다. 이러한 쿼리는 쿼리 시작 시간을 기준으로 정렬됩니다. 활성 쿼리가 많으면 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-05-14(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)."]]