All Products
Search
Document Center

PolarDB:Session management

Last Updated:Jul 21, 2023

PolarDB-X allows you to view information about instance sessions and session statistics. When an alert is generated due to a rapid increase in CPU utilization, the number of active sessions, or the response time of your PolarDB-X instance, you can use the 10-second SQL analysis feature to analyze the SQL statements that are executed within a 10-second time window on your instance in real time.

Manage sessions

  1. Log on to the PolarDB for Xscale console.

  2. In the top navigation bar, select the region in which your instance resides.

  3. In the left-side navigation pane, click Instance List. On the Instance List page, click the PolarDB-X 2.0 tab.

  4. Find the instance that you want to manage and click the instance ID.

  5. In the left-side navigation pane, choose Diagnosis and optimization > Instance session. On the page that appears, view details such as instance sessions and session statistics.

    • You can perform the following operations in the Instance Sessions section:

      • View information such as exceptional sessions, active sessions, the longest execution duration, CPU utilization, and connection usage.

      • In the upper-right corner of the section, click 10s SQL Analysis. In the dialog box that appears, view the information about SQL statements that are executed within a 10-second time window, such as SQL statistics, slow query logs, and SQL overview. For more information, see Perform a 10-second SQL analysis.

      • Click SQL Throttling. In the dialog box that appears, configure the parameters to enable threshold-based SQL throttling on sessions.

      • Click Optimize to optimize sessions. For more information, see .

      • Export active sessions.

      • Terminate sessions.

        Warning

        Service interruptions may occur if you terminate sessions. Exercise caution when you perform this operation.

    • In the Session Statistics section, you can perform the following operations:

      • View summary information and session statistics by user, access source, or database. The summary information includes the total number of sessions, the total number of running sessions, and the longest session runtime.

        Note

        The statistics information includes the total number of sessions, the total number of active sessions, the maximum session duration in seconds, the number of sessions that are active for more than 3 seconds, and the number of queries that do not use indexes.

      • Export summary information and session statistics by user, access source, or database.

SQL throttling

  1. Log on to the PolarDB for Xscale console.

  2. In the top navigation bar, select the region in which your instance resides.

  3. In the left-side navigation pane, click Instance List. On the Instance List page, click the PolarDB-X 2.0 tab.

  4. Find the instance that you want to manage and click the instance ID.

  5. In the left-side navigation pane, choose Diagnosis and optimization > Instance session.

  6. Click SQL Throttling in the Instance Sessions section.

  7. In the SQL Throttling dialog box, configure the parameters described in the following table.

    Parameter

    Description

    Throttling Mode

    The throttling mode. Valid values:

    • Throttled by SQL Template ID: throttles the SQL statements that use the SQL templates with the specified IDs. The SQL template IDs can be obtained from SQL logs, sessions, and results that are returned after EXPLAIN statements are executed.

      Note

      The ID of an SQL template is a hexadecimal string that contains eight characters in length.

    • Throttled by Execution Duration: throttles SQL statements by execution duration. If the execution duration of an SQL statement of the specified type exceeds the specified threshold value, the system fetches the ID of the SQL template used by the SQL statement and adds the ID to the throttling rule. Then, SQL statements that use the SQL template are executed with the specified concurrency.

      Note

      You can configure the maximum number of SQL template IDs. After the number of SQL template IDs added to the throttling rule reaches the upper limit, the system stops fetching SQL template IDs.

    SQL Type

    The type of SQL statements that you want to throttle. Valid values: SELECT, UPDATE, DELETE, and INSERT.

    Maximum Concurrency

    The maximum number of concurrent SQL statements. The minimum value of this parameter is 1.

    Throttling is triggered when the number of SQL statements that are concurrently executed and meet the throttling policy reaches the maximum value.

    Throttling Duration

    The duration during which the SQL throttling rule takes effect. The throttling feature is intended only for emergency use. We recommend that you specify the throttling duration based on your business requirements and disable throttling when it is no longer needed.

    Template ID

    The ID of an SQL template used by an SQL statement that you want to throttle. Separate multiple IDs with commas (,).

    Note

    This parameter is required only if the Throttling Mode parameter is set to Throttled by SQL Template ID.

    Executed At

    The threshold value of the execution duration. If the execution duration of an SQL statement exceeds the specified threshold value, the system fetches the ID of the SQL template used by the SQL statement and adds the ID to the throttling rule.

    Note

    This parameter is required only if the Throttling Mode parameter is set to Throttled by Execution Duration.

    Maximum Number of Throttled Queries

    The maximum number of IDs of SQL templates used by SQL statements throttled by execution duration. After the number of SQL template IDs added to the throttling rule reaches the upper limit, the system stops fetching IDs of SQL templates used by SQL statements whose execution duration exceeds the specified threshold value.

    Note

    This parameter is required only if the Throttling Mode parameter is set to Throttled by Execution Duration.

    Database Account with Throttled Queries

    The database account to which the throttled SQL statement belongs.

    Note

    This parameter is required only if the Throttling Mode parameter is set to Throttled by SQL Template ID.

  8. Click Create.

    After the SQL throttling rule is created, you can view the status of the rule in the list of throttling rules. aa

    If you want to disable or modify a throttling rule before the specified throttling duration expires, click Disable or Edit in the Actions column corresponding to the throttling rule.

Perform a 10-second SQL analysis

The 10-second SQL analysis feature helps you analyze SQL statements that are executed within a 10-second time window on your instance in real time. When you perform a 10-second SQL analysis on a PolarDB-X instance, the system executes the SHOW PROCESSLIST statement at an interval of 1 second within a 10-second time window. Then, the system analyzes the returned result sets. The analysis result shows the SQL statements that are most frequently executed and whether slow SQL queries exist within the 10-second time window.

  1. Log on to the PolarDB for Xscale console.

  2. In the top navigation bar, select the region in which your instance resides.

  3. In the left-side navigation pane, click Instance List. On the Instance List page, click the PolarDB-X 2.0 tab.

  4. Find the instance that you want to manage and click the instance ID.

  5. In the left-side navigation pane, choose Diagnosis and optimization > Instance session.

  6. On the page that appears, click 10s SQL Analysis.

  7. Wait for 10 seconds. Then, view the analysis results, including the SQL statements that are most frequently executed and whether slow SQL queries exist within this 10-second time window.