This topic describes how to use the global slow log analysis feature in Database Autonomy Service (DAS). You can create and manage user groups to centrally monitor and analyze multiple database instances. This feature helps you efficiently find, diagnose, and manage slow SQL statements, resolve issues such as high database payloads and performance fluctuations, and ensure the stability of your core business.
Core concept: User group
User groups are a core component of the slow log analysis feature. A user group functions as a custom instance monitoring dashboard. You can create a user group to perform the following operations:
Logical grouping: Group database instances from different lines of business for easier management. Each user group can contain up to 10 instances.
Unified view: View the slow log trends, event distribution, and SQL statistics for all instances in a group from a single page.
Efficient switching: Quickly switch between different business focus areas without having to repeatedly select instances.
DAS creates a default system group named Top Slow Log Group. Every hour, DAS automatically selects the top five instances under your account that have the most important anomalous activities and the highest number of slow query logs in the last 24 hours. These instances are added to the group to help you quickly locate and resolve critical issues.
Prerequisites
Supported database engines: Your database instance must use one of the following engine types:
Relational databases:
RDS MySQL, PolarDB for MySQL, MyBase MySQL
RDS SQL Server, MyBase SQL Server
RDS PostgreSQL, PolarDB for PostgreSQL, PolarDB for PostgreSQL (Compatible with Oracle)
PolarDB-X 2.0
NoSQL databases:
Tair (Redis-compatible), MyBase Redis
ApsaraDB for MongoDB
Instance access: The target database instance must be connected to DAS. For more information, see Connect to a database instance.
Region support:
Slow query log details: This feature is supported in all regions.
Real-time slow query log statistics: This feature is supported in the Chinese mainland, Hong Kong (China), Singapore, Malaysia (Kuala Lumpur), Indonesia (Jakarta), Japan (Tokyo), Germany (Frankfurt), UK (London), US (Silicon Valley), and US (Virginia) regions.
Self-managed databases: The slow log analysis page does not support self-managed database instances.
Slow query log threshold: The database kernel controls the recording of slow query logs. DAS is responsible for analysis and does not set the threshold. To configure the slow query log threshold, such as the
long_query_timeparameter for MySQL, you must log on to the specific database instance.
Procedure
Enter the global slow log page
Log on to the DAS console.
In the navigation pane on the left, choose .
Optional: Click the Back to Old Version button in the upper-right corner to switch to the old view. For more information, see Slow query logs (Old version).
Manage and switch user groups
Switch user groups: In the drop-down list in the upper-left corner of the page, select a user group to switch the analysis view.
Create a user group: Click the Add new user group button. In the dialog box that appears, enter a name for the user group and click Confirm.
Manage user groups:
Edit or delete a group: In the user group panel, click the action icon next to a user group name to rename or delete the group.
Add an instance: After you select the target user group, click the Add more instances button below the panel. In the dialog box that appears:
In the Available Instances list, click an instance to add it to the current user group.
In the Selected instances list, click a selected instance to remove it from the current user group.
Delete an instance: In the instance list of the current user group, click the × icon on the instance card to remove the instance.
Hide an instance: In the instance list of the current user group, click the
icon on the instance card to hide the instance from the view. The slow query log information of the instance, including trends, events, and the slow query log list, is no longer displayed. Click the icon again to show the instance and restore its information.Save user group as: Click the Save as button to create a new user group based on the instance configuration of the current group.
Instance permissions: An instance card highlighted in blue indicates that you have permissions for the instance. An instance for which you do not have permissions is highlighted in yellow. You can view only its ID, not its specific data. You can create a custom user group and exclude instances for which you do not have permissions to ensure that the group contains only accessible instances.
Analyze trends and events
Slow Query Log Trends: After you select a time range, the trend chart at the top displays the total number and trend of slow query logs for all instances in the current user group. This helps you quickly identify when performance fluctuations occurred.
Event Distribution: Below the trend chart, key database events that occurred within the specified time range are displayed. These events include the following:
Optimization Events: Events where SQL optimization analysis was performed or optimization suggestions were generated.
Security Events: Events such as SQL attacks or configuration vulnerabilities that pose medium to high security risks.
Throttling Event: Events where SQL throttling or automatic SQL throttling actions occurred.
Automatic Scaling Events: Events where automatic scale-out or scale-in actions occurred.
Locate and diagnose slow SQL statements
The Slow log list at the bottom of the page is the main analysis area. It aggregates the slow query log information for all instances in the current user group.
Global statistics: By default, the list aggregates all slow SQL statements and shows the number of executions, maximum execution duration, maximum lock wait time, maximum scanned rows, maximum returned rows, and maximum CPU time for each statement.
Single-instance drill-down: Click the
arrow next to Instance ID/Name to perform a detailed analysis of the slow query logs for a specific instance.In the slow query log information for the instance, you can view the Slow Log Trend, Event Distribution, Slow Log Statistics, and Slow Log Details.
In the Slow Log Trend chart, you can select a point in time to view the Slow Log Statistics and Slow Log Details for that time.
NoteIf a slow SQL statement is too long to be fully displayed, you can hover the mouse pointer over the statement to view the complete SQL statement in a pop-up box.
On the Slow Query Log Statistics and Slow Query Log Details tabs, you can click
to save the slow query log information to your computer.You can click
to go to the OpenAPI Explorer console. The currently selected and entered parameters are automatically carried over for API debugging.In the Event Distribution area, you can query for slow log events within a specified time range. Click an event to view its details.
In the Slow Log Statistics area:
Above the list, you can select filter conditions to filter the data. The available filter conditions vary depending on the database engine.
Click the data ID in the Query ID column of the target SQL template to view correlations and a detailed list that includes user distribution, client distribution, and metric trends.
In the Actions column of the target SQL template, click Optimize. In the SQL Diagnostic Optimization dialog box that appears, view the SQL diagnosis results.
If you accept the diagnostic suggestion, click Copy in the upper-right corner of the page and paste the optimized SQL statement into your database client or DMS to execute it. If you do not accept the suggestion, click Cancel to end the diagnosis.
NoteDAS performs SQL diagnosis based on the complexity of the SQL statement, the data volume of the corresponding table, and the database payload. The diagnostic suggestion may take more than 20 seconds to be returned. After the diagnosis is complete, the diagnostics engine provides a diagnosis result, an optimization suggestion, and the expected optimization benefits. You can decide whether to accept the suggestion based on the diagnosis result.
In the Actions column of the target SQL template, click Throttling. On the SQL Throttling page, configure the throttling parameters to apply rate limiting to the target SQL statement. For more information, see SQL throttling.
For a PolarDB for MySQL database instance, in the Actions column of the target SQL template, click IMCI to view the documentation for In-Memory Column Index (IMCI).
NoteThe IMCI button is displayed if a PolarDB for MySQL database instance does not have an In-Memory Column Index node, the Max Execution Time of a slow query log exceeds 20 seconds, and the Max Scanned Rows exceeds 200,000.
For complex queries with large data volumes, you can use In-Memory Column Index (IMCI) to improve query performance.
In the Slow Log Details area, you can also click Optimize and Throttling in the Actions column for a target SQL statement to perform SQL Diagnostic Optimization and SQL Throttling.
FAQ
Q: Why can't I see any slow query log data?
A: This may be because real-time computing and window aggregation techniques are used, which cause the latest slow query log statistics to be displayed with a delay of about 3 minutes. You can also check the following:
Confirm that the slow query log feature is enabled for the database instance and that the threshold is set to a reasonable value.
Confirm that slow query logs were generated within the selected time range.
Confirm that the current account has DAS access permissions for the target instance.
Q: What should I do if a RAM user does not have permission to view or manage user groups?
A: An administrator must grant account-level action permissions to the RAM user. This authorization affects only the permissions to operate on global slow log groups and does not change the RAM user's data permissions for other instances.
Global group administrator policy: For example, DASGlobalGroupAdmin. This policy allows the user to create, delete, modify, and query global groups.
{ "Version": "1", "Statement": [ { "Action": [ "hdm:DescribeGlobalGroups", "hdm:CreateGlobalGroup", "hdm:DeleteGlobalGroup", "hdm:ModifyGlobalGroup" ], "Resource": "*", "Effect": "Allow" } ] }Global group read-only policy: For example, DASGlobalGroupReadOnly. This policy allows the user to only view global groups.
{ "Version": "1", "Statement": [ { "Action": "hdm:DescribeGlobalGroups", "Resource": "*", "Effect": "Allow" } ] }
Q: Why are some instances highlighted in yellow, indicating that the current user does not have access permissions?
A: The yellow highlight indicates that the RAM user does not have data access permissions for the instance. You can resolve this issue in one of the following two ways:
Contact an administrator: Request the administrator to grant access permissions for the instance to the RAM user.
Grant global group permissions: Grant the DASGlobalGroupAdmin permission to the RAM user. This allows the RAM user to create user groups and view data for instances that they have permission to access in batches.
Q: Why is the number of returned rows (Rows_sent) in the slow query log 0, even though the query actually returns data?
A: This is usually because the application uses the server-side cursor mode. In cursor mode, the execution of an SQL statement is divided into two stages:
EXECUTE stage: The server executes the query and generates a result set but does not immediately send the data rows to the client. It returns only metadata, such as column definitions.
FETCH stage: The client pulls the data rows in batches using the
FETCHcommand.
The slow query log records statistics from the EXECUTE stage. In this stage, MySQL has scanned the data (so
Rows_examinedis not 0), but has not yet sent any data rows to the client (the data is sent in the subsequent FETCH stage). Therefore,Rows_sentis recorded as 0.Common scenarios:
Java/JDBC:
useCursorFetch=trueis enabled in the connection URL, andPreparedStatement.setFetchSize()is set to a value greater than 0 or toInteger.MIN_VALUE.Python:
MySQLdb.cursors.SSCursororpymysql.cursors.SSCursoris used.ORM frameworks: Some Object-Relational Mapping (ORM) frameworks use streaming queries by default when processing large dataset queries, which is based on the cursor mode.
To confirm whether this is the cause, check if `fetchSize` is configured or if a streaming cursor is used in your application code. You can also run the
SHOW GLOBAL STATUS LIKE 'Com_stmt_fetch';command in the database to check for FETCH requests.Q: Why is the completion time in the slow query log different from the actual execution time of the SQL statement?
A: This issue usually occurs because the time zone was changed when the SQL statement was executed. The time zone for the SQL execution time recorded in the slow query log can be at the session, database, or system level. The logic for determining the time in the slow query log is as follows: If a time zone is set for the database, the database time zone is used. Otherwise, the system time zone is used. If the session-level time zone is modified using an SQL statement, the time zone in the slow query log record may not be converted correctly.
References
You can enable the automatic database administration feature of DAS to automatically optimize slow SQL statements when they occur in your database instance.