You can view slow query logs in the ApsaraDB for MongoDB console. Analyzing these logs helps you identify performance bottlenecks and optimize your database.
Prerequisites
Before you begin, make sure you have:
Limitations
Slow query logs are available for the last 7 days.
ApsaraDB for MongoDB does not support deleting slow query logs.
The slow query log feature is not available for standalone instances due to architectural limitations.
The log management feature is not yet available in all regions. Check the console to confirm its availability.
Procedure
Go to the Replica Set Instances or Sharded Cluster Instances page. In the top navigation bar, select a resource group and a region. Then, click the ID of the target instance.
In the left-side navigation pane of the instance details page, choose .
Filter the slow query logs based on the instance type.
Note Click the
icon in the upper-right corner to download the logs on the current page.
FAQ
Why are expected long-running operations missing from the slow query log?
If you do not find the expected long-running operations when you query the slow query log, check the following:
Check the slow operation threshold. An operation is considered slow if its execution time exceeds the specified threshold. Verify that the operationProfiling.slowOpThresholdMs parameter is configured correctly. The default value is 100 milliseconds. For more information about how to view and set parameters, see Set instance parameters.
Check the instance version. If your instance runs MongoDB 4.0, we recommend that you analyze the audit log or perform a major version upgrade to MongoDB 4.2. For more information, see Query audit logs and Upgrade the major version of a database.
After you enable the audit log feature, it audits the admin and slow operation types by default, which records corresponding slow query entries in the audit log. However, on MongoDB 4.0 instances, if you modify the audited operation types, slow update and delete operations may not generate corresponding entries in the slow query log. We recommend that you either analyze operation execution times directly from the audit log or upgrade to MongoDB 4.2. This behavior is optimized in MongoDB 4.2 and later versions to ensure that all slow operations are recorded in the slow query log.
Why does a RAM user lack permission to access the slow query log?
Database Autonomy Service (DAS) provides the slow query log analysis feature. To use this feature, the RAM user must have the required HDM-related permissions. For more information, see How can a RAM user use DAS?.
Related topics
To learn more about viewing and exporting slow query logs, see Slow query log.