Slow query log

更新时间:
复制 MD 格式

Slow queries can significantly impact database stability. When a database experiences high load or performance fluctuations, identifying slow queries is often the first step in troubleshooting. Database Autonomy Service (DAS) provides a slow query log analysis feature that collects and analyzes requests exceeding a specified execution time threshold. This feature helps you quickly pinpoint and resolve performance issues, improving database stability and reliability.

Video introduction

Prerequisites

The target database must be an ApsaraDB for MongoDB replica set instance or sharded cluster instance.

Background

Slow query logs are generated by the database engine. The configuration parameters and thresholds that define a slow query vary by database engine. For more information, see the official documentation for your database engine.

Procedure

  1. Log on to the DAS console.

  2. In the navigation pane on the left, click Intelligent O&M Center > Instance Monitoring .

  3. Find the target instance and click the instance ID to open the instance details page.

  4. In the left-side navigation pane, click Request Analysis > Slow Logs.

  5. Select a time range to view the Slow Log Trend, Event Distribution, Slow Log Statistics, and Slow Log Details.

    Note

    The end time must be later than the start time, and the time range cannot exceed seven days. You can query slow query logs from the last month.

    • In the Slow Log Trend chart, you can select a specific point in time to view the corresponding Slow Log Statistics and Slow Log Details.

      Note

      If a slow SQL statement is too long to be fully displayed, hover the pointer over the statement to view the complete text in a pop-up window.

    • For sharded cluster instances, use the Node ID drop-down list to view the number of slow queries for each node.

    • On the Slow Query Log Statistics and Slow Query Log Details tabs, click image to save the slow query log information to a local file.

    • Click image to go to OpenAPI Explorer and debug the API. The currently selected and entered parameters are passed automatically.

    • In the Event Distribution section, you can find slow log events within the specified time range. Click an event to view its details.

    • In the Slow Log Statistics section, click Details in the Actions column of a log template to view its Slow Log Sample .

    • In the Slow Log Statistics section, click Optimize in the Actions column of a log template to view the diagnostic results in the Optimize dialog box.

      Note

      The optimization feature is available only for slow queries where the Operation Type is query. It primarily provides index optimization suggestions.

      Supported scenarios

      • Single-field query: For example, if DAS flags a db.col.find({ a: 1 }) query as slow, it recommends creating the corresponding index: db.col.createIndex({ a: 1 }).

      • Multi-field query: For example, if DAS flags a db.col.find({ a: 1, b: 1 }) query as slow, it recommends creating a compound index: db.col.createIndex({ a: 1, b: 1 }).

      Unsupported scenarios

      • DAS does not recommend indexes that already exist.

      • Special index types, such as text, unique, and hash, are not supported.

      • Queries that contain complex logical operators, such as $or and $and, are not supported.

      • DAS cannot generate index suggestions for operations other than find, such as sorting ($sort) and collation ($collation).

      If you accept the suggestion, click Copy in the upper-right corner, then paste and run the statement in a database client or DMS. To reject the suggestion, click Cancel.

      Important

      Adding an index might degrade the execution plans of other queries and consume instance resources such as storage. Before you apply a suggestion, you must assess the potential risks, including the impact on related queries and resource consumption.

FAQ

Q: Why can I access the legacy slow query log page but receive a permission error (such as NoPermission or Forbidden.RAM) when trying to access the new page?

A: The new slow query log page has been redesigned with more powerful data filtering and screening features, which require different permission policies than the legacy page. If you do not have the required permissions, you cannot access the new page. For instructions, see RAM user authorization to grant the following permission policies to your RAM user:

  • Required permissions: slow query log trend chart data (DescribeSlowLogHistogramAsync), slow query log template statistics (DescribeSlowLogStatistic), slow query log details (DescribeSlowLogRecords), Event Center data (GetInstanceEventWithGroupType), and performance trend data (GetPerformanceMetrics).

  • Recommended permissions: tag SQL statements (CreateSqlTag) and retrieve SQL tags (DescribeDasQueryTagNames).