Active queries

更新时间:
复制 MD 格式

AnalyticDB for PostgreSQL provides the Active Queries feature, which automatically collects and displays a list of active queries every 5 seconds. You can use it to cancel blocking queries or terminate their corresponding sessions.

Procedure

  1. Log on to the AnalyticDB for PostgreSQL console.
  2. In the upper-left corner of the console, select a region.
  3. Find the instance that you want to manage and click the instance ID.
  4. In the left-side navigation pane, choose Diagnostics and Optimization > Query Analysis.

  5. On the Active Queries page, view the current active queries for the instance.

    Note

    You can also filter queries by criteria such as Username, Execution Duration, Database, or SQL keywords.

  6. Cancel or terminate queries as needed.

    • Cancel Task (Recommended): If a query runs for too long or consumes excessive resources, you can cancel it. This action runs the pg_cancel_backend() function to gracefully cancel the query. If successful, the query stops, but the client connection remains active and can submit new queries.

    • Terminate: If a client connection is in a bad state or you want to end the entire session and release all its resources, you can use this option. This action runs the pg_terminate_backend() function to immediately terminate the specified backend process. The client connection associated with the process is forcibly disconnected.

    Note
    • You can apply the Cancel Task or Terminate operation to multiple queries at once.

    • The Cancel Task and Terminate operations are asynchronous. A query might temporarily remain in the list after you perform one of these actions. The query usually disappears after the next automatic refresh.

      If a query remains in the list for a long time (for example, 3 minutes) after you perform the Cancel Task or Terminate operation, the action may have failed. In this case, you can Submit a ticket for further investigation.