The content of this page has been automatically translated by AI. If you encounter any problems while reading, you can view the corresponding content in Chinese.

Manage slow logs

Last updated: 2025-02-08 10:50:20

The TencentDB for MongoDB console supports viewing slow logs generated during database operation and analyzing slow logs to optimize database performance.

Background

In MongoDB, slow logs are often used as a basis to optimize business operations. For more information on slow logs, please refer to the official documentation.
The system provides two query methods, detailed as follows:
Abstract query: Query slow logs by time period, with query results aggregated and analyzed by command type.
Specific query: Specify specific operation commands to query slow logs, with query results listing the execution time of operation commands and log details.

Version Description

All versions of MongoDB currently support slow log management.

Must-Knows

The system logs operations with an execution time of more than 100 ms.
Slow logs are retained for 7 days, and the time span of a single query does not exceed 1 day.
The query is limited to the first 10,000 slow logs. If the query is slow, narrow the query time range.

Prerequisites

You have applied for a TencentDB for MongoDB instance.
The TencentDB for MongoDB replica set or sharding instance is in Running status.

Directions

Querying slow log

2. In the left navigation bar, select MongoDB from the drop-down list, then choose Replica Set Instance or Sharded Instance. The operations for replica set instances and sharded instances are similar.
3. Select Region at the top of the Instance List page on the right.
4. In the Instance List, find the target instance.
5. Click the Target Instance ID to enter Instance Detailspage.
6. Select the Database Management tab, then select the Slow Log Query tab.
7. On the Slow Log Query page, select the Query Method to query slow logs.
Abstract Query: Select the Query Time Range, set the Time Consumption threshold, and click Inquiry.
Specific Query: In the Query Command, select the specific execution command to be queried, then select the Query Time Range, set the Time Consumption threshold, and click Inquiry.
8. View and analyze slow logs.
Abstract query results include four fields:
Query Method: abstract query.
Example sentence: A statement output with command type as the aggregation dimension, recording operations in the slow log. Users mainly refer to command for troubleshooting.
Note:
Please pay attention to keywords such as command, COLLSCAN, IXSCAN, keysExamined, and docsExamined. For more log notes, please see MongoDB Official Website.
command indicates an operation recorded in the slow log.
COLLSCAN indicates that a full table scan is performed for the query, IXSCAN indicates an index scan.
keysExamined represents index scan entries, docsExamined represents document scan entries. Larger values of keysExamined and docsExamined indicate no index or low index selectivity. For index optimization, please see Optimizing Indexes to Break Through Read/Write Performance Bottlenecks.
Average Execution Time (MS): The average execution time of operations aggregated by command type, in milliseconds.
Total Counts: The number of operations aggregated by command type.

Specific Query results contain three fields:
Query Method: Specific query.
Time Consumption: The execution time of business commands, in milliseconds.
Log details: Business command details.


Managing Slow Queries

Viewing slow log request statements

1. On the Slow Query Management page, you can view the request statements of the slow logs.
2. In the top right search box, enter query information to search.
Parameter Name
Parameter information
Query statement
Query statement
Op type
Operation Type
Node location
Node where the operation is executed
Command space
Namespace of the database table
Executed time
Time consumption
Details
Details of the execution statement

Batch Killing

1. On the Slow Log Management page, select the slow log request statements to be cleared.
2. Click Batch Kill at the top of the list to prepare for clearing.
3. In the Note dialog box, read the prompt information carefully.
4. Click OK.

Downloading Slow Log Files

1. On the Slow Log Download List page, you can view the current slow log files.
2. Find the file you need to download, and click Download in its Operation column.

Relevant API

API Interface
API Description
DescribeSlowLogs
DescribeSlowLogPatterns