View slow query logs

更新时间:
复制 MD 格式

You can use the ApsaraDB for MongoDB console to view slow query logs. This analysis helps you identify and optimize database performance.

Prerequisites

The instance is a replica set instance or a sharded cluster instance.

Limitations

  • Slow query logs are retained for 7 days.

  • ApsaraDB for MongoDB does not support deleting slow query logs.

  • Standalone instances do not support viewing slow query logs due to their architecture.

  • The Logs feature is not available in all regions. Check the console to confirm its availability.

Procedure

  1. Go to the Replica Set Instances or Sharded Cluster Instances page. At the top of the page, select a resource group and a region, and then click the ID of the desired instance.

  2. In the left-side navigation pane, click Logs > Slow Query Logs.

  3. Filter the logs based on your instance type.

    • For a replica set instance

      You can filter the query results by database name and time range.

    • For a sharded cluster instance

      You can filter the query results by database name, shard node, and time range.

    Note

    To download the currently displayed slow query logs, click the image icon in the upper-right corner.

FAQ

Why are expected slow operations missing from the slow query log?

If you do not find the expected slow operations in the slow query log, check the following:

  1. Check the slow operation threshold. An operation is recorded as slow if its execution time exceeds the specified threshold. Verify that the operationProfiling.slowOpThresholdMs parameter (default: 100 ms) is set correctly. For more information, see Set instance parameters.

  2. Check the instance version. If your instance runs MongoDB 4.0, analyze the audit log or upgrade the instance to MongoDB 4.2. For more information, see Query audit logs and Upgrade the major database version.

    After you enable the audit log feature, the admin and slow operation types are audited by default, and the corresponding slow operations are recorded in the audit log. However, on MongoDB 4.0, if you change the audited operation types, slow update and delete operations do not generate a separate slow query log entry. Either analyze the execution time directly in the audit log or upgrade to MongoDB 4.2. In version 4.2, this behavior is optimized to ensure that all slow operations are recorded in the slow query log.

Why does a RAM user have no permission to access slow query logs?

The slow query log analysis feature is provided by Database Autonomy Service (DAS). To access this feature, a RAM user must have the required permissions for DAS. For more information, see How can a RAM user use DAS?.

Related topics

For details on viewing and exporting slow query logs, see Slow query logs.