[[["易于理解","easyToUnderstand","thumb-up"],["解决了我的问题","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["很难理解","hardToUnderstand","thumb-down"],["信息或示例代码不正确","incorrectInformationOrSampleCode","thumb-down"],["没有我需要的信息/示例","missingTheInformationSamplesINeed","thumb-down"],["翻译问题","translationIssue","thumb-down"],["其他","otherDown","thumb-down"]],["最后更新时间 (UTC):2025-08-25。"],[[["\u003cp\u003eThis guide explains how to monitor active queries in your database, which are long-running queries that can negatively affect performance.\u003c/p\u003e\n"],["\u003cp\u003eActive queries can be viewed on the query insights dashboard after enabling advanced query insights features and active query analysis in your instance settings.\u003c/p\u003e\n"],["\u003cp\u003eThe query insights dashboard's "Active queries view" tab displays a summary of currently running queries, including the top 50 longest-running transactions, with options to filter by database, user, and node ID.\u003c/p\u003e\n"],["\u003cp\u003eThe "Longest running transactions" table provides detailed information about each transaction, including its process ID, query, status, duration, and wait events.\u003c/p\u003e\n"],["\u003cp\u003eUsers with the appropriate IAM role can terminate active queries or transactions directly from the dashboard's "Longest running transactions" table, but forceful terminations may lead to data inconsistencies.\u003c/p\u003e\n"]]],[],null,["# Monitor active queries\n\nThis page describes how to monitor and troubleshoot the queries that are active in your database. Active queries are long-running queries on your database that can affect performance. Monitoring these queries can help identify causes of system latency and high CPU usage.\n\nYou can view active queries on the query insights dashboard. These queries are displayed by the transaction start time. If there is a large number of queries running, the results may be limited to a subset of total queries due to the memory constraints the system enforces on the data collection.\n\nBefore you begin\n----------------\n\nTo start viewing active queries, you must enable [advanced query insights features](/alloydb/docs/advanced-query-insights-overview) and turn on active query analysis for your instance as follows:\n\n1. In the Google Cloud console, go to the **Clusters** page.\n\n [Go to Clusters](https://console.cloud.google.com/alloydb/clusters)\n2. From the list of clusters and instances, click either a [primary](/alloydb/docs/instance-primary-create) or a [read pool](/alloydb/docs/instance-read-pool-create) instance.\n\n3. Click **Query insights**.\n\n4. Click **Edit Settings**.\n\n5. In the **Edit query insights settings** window, select **Enable advanced query insights features for AlloyDB** \\\u003e **Active Query Analysis**.\n\n6. Click **Save changes**.\n\n7. In the **Changes require restart** window, click **Confirm and restart**.\n\nYou can use Gemini Cloud Assist assistance to help you monitor and troubleshoot\nyour AlloyDB for PostgreSQL resources. For more information, see\n[Monitor and troubleshoot with Gemini assistance](/alloydb/docs/monitor-troubleshoot-with-gemini).\n\nView active queries\n-------------------\n\nTo view your active queries, do the following:\n\n1. Create a custom role and add the [`databaseinsights.monitoringViewer`](/iam/docs/understanding-roles#databaseinsights.monitoringViewer) Identity and Access Management (IAM) permission.\n\n2. Add this role for each user that is viewing active queries.\n\n3. In the Google Cloud console, open the **AlloyDB** page.\n\n [Go to AlloyDB](https://console.cloud.google.com/alloydb)\n4. Click the name of a cluster to open its **Overview** page.\n\n5. Select the **Query insights** tab.\n The query insights dashboard shows details about the selected cluster.\n\n6. Click the **Active queries view** tab.\n The tab contains a summary of active queries running along with the top 50 longest running transactions.\n\n You can filter the information by either of the following:\n - **Database**: filters query load on a specific database or all databases.\n - **User**: filters query load from a specific database user or all of the users.\n - **Node ID** : displays only for [read pool](/alloydb/docs/instance-read-pool-create) instances; filters query load on a specific read pool instance node or all of the nodes.\n\n **Summary scorecard of all normalized active queries**: provides an overview of all the active queries by displaying the total connections based on the following parameters:\n - Distribution of active connections categorized by connection state.\n - Distribution of active connections based on different wait event types.\n - Distribution of transaction durations for queries that are not in an idle state.\n\n **Longest running transactions** : provides an overview of the top 50 running queries in the `active` and `idle in transaction` state based on descending execution time.\n\nYou can view a list of top fifty normalized active queries on the query insights dashboard.\n\nA normalized active query removes sensitive data, and returns a digest. Two queries that are identical except for WHERE-clause values have the same digest. For example, consider the following three example queries:\n\n- `select * from my_table where id = 1;`\n- `select * from my_table where id = 2;`\n- `select * from my_table where id = 100;`\n\nThe normalized version of these queries is the following digest:\n\n`select * from my_table where id = ?;`\n\nA query that runs in different sessions is displayed as different entries on the dashboard.\n\n### View top longest running transactions\n\nThe following table describes the columns of the **Longest running transactions** table on the query insights dashboard:\n\nThe display is refreshed every 60 seconds automatically.\n\nUsing the **Database** and **User** fields for filtering refreshes the data on the page.\n\nTo analyze static data, disable **Auto-refresh** and use the **Filter** field of the **Longest running transactions** table as needed.\n\nTerminate a query or transaction\n--------------------------------\n\nTo terminate a query or a transaction, you must have the [`databaseinsights.operationsAdmin`](/iam/docs/understanding-roles#databaseinsights.operationsAdmin) role. For more information, see [IAM basic and predefined roles reference](/iam/docs/understanding-roles).\n\nA transaction can contain multiple queries. To identify which of the queries are active at the moment, see the **Query** column in the **Longest running transaction** table.\n\nTo terminate a query or transaction, complete the following steps:\n\n1. Select the query in the **Longest running transaction** table.\n2. Scroll right to the **Action** column.\n3. Click **Terminate connection**.\n4. In the **Terminate connection** window, click **Confirm**.\n\n The page refreshes after initiating termination. If termination fails, it is silent and the query continues showing up in the Active Query list. If termination is successful, the query no longer displays in the list.\n\n| **Warning:** Data inconsistency issues might arise when you forcefully terminate backend processes in the middle of a transaction.\n\nWhat's next\n-----------\n\n- [Improve query performance using query insights](/alloydb/docs/using-query-insights)\n- [Monitor instances](/alloydb/docs/monitor-instance)"]]