Viewing and Downloading Slow Query Logs
Scenarios
Slow query logs record statements that exceed the log_min_duration_statement value. You can view log details and statistics to identify statements that are executing slowly and optimize the statements. You can also download slow query logs for analysis.
Parameter Description
| Parameter | Description |
|---|---|
| log_min_duration_statement | Specifies how many milliseconds a query has to run before it has to be logged. If this parameter is set to a smaller value, the number of log records increases, which increases the disk I/O and deteriorates the SQL performance. |
| log_statement | Specifies the statement type. The value can be none, ddl, or mod. |
Viewing and Downloading Slow Query Logs
- Original logs will be automatically deleted 30 days later. If the instance is deleted, its logs are also deleted.
- This function takes effect only for slow query logs generated after it is enabled. Historical slow query logs generated before the function is enabled are not displayed in plaintext.
- Log in to the RDS console.
- Click
in the upper left corner and select a region. - On the Instances page, click the target instance name to go to the Summary page.
- In the navigation pane, choose Logs and click the Slow Query Logs tab.
- On the Log Details tab page, turn on the toggle switch
next to Show Original Logs. Figure 1 Enabling Show Original Logs
- In the displayed dialog box, click OK. Figure 2 Confirming to enable this function
- Log in to the RDS console.
- Click
in the upper left corner and select a region. - On the Instances page, click the target instance name to go to the Summary page.
- In the navigation pane, choose Logs and click the Slow Query Logs tab.
- On the Log Details tab page, view slow query log details. Figure 3 Viewing slow query log details
- You can view the slow query log records of a specified execution statement type or a specific time period.
- The log_min_duration_statement parameter determines when a slow query log is recorded. However, changes to this parameter do not affect already recorded logs. For example, if you change the value of this parameter from 100 to 1000 (unit: ms), RDS starts recording statements that meet the new threshold and continues to display the logs that were previously recorded under the old threshold.
- A maximum of 2,000 slow query log entries can be queried and exported.
Table 2 Slow query log details Parameter
Description
Execute Statement
The slow query log records only statements that have been executed and whose execution time exceeds the threshold. Statements still in progress are not logged.
Statement Type
- You can choose a statement type from the drop-down list in the upper right corner. Options include: All statement types, SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, ALTER, DO, CALL, COPY, WITH, and OTHER.
- You can also click
in the upper right corner to select a time range and view slow query logs for different periods. You can view slow query logs from up to the last 30 days.
Occurred
UTC time when the slow SQL statement starts to be executed.
Execution Time (s)
Duration of the slow SQL query.
Database
Database where the SQL statement is executed.
Username
Account that executed the SQL statement.
IP Address
Address of the host that connects to the database.
- Log in to the RDS console.
- Click
in the upper left corner and select a region. - On the Instances page, click the target instance name to go to the Summary page.
- In the navigation pane, choose Logs and click the Slow Query Logs tab.
- Click the Statistics tab to view details. Figure 4 Viewing statistics
Table 3 Slow query log statistics Parameter
Description
Query ID
A hash-based digital signature used to uniquely identify and group SQL queries that share the same structure but differ in parameters.
Execute Statement
On the Statistics page, only one of the SQL statements of the same type is displayed as an example. For example, if two select sleep(N) statements, select sleep(1) and select sleep(2), are executed in sequence, only select sleep(1) will be displayed.
Statement Type
You can choose a statement type from the drop-down list in the upper right corner. Options include: All statement types, SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, ALTER, DO, CALL, COPY, WITH, and OTHER.
No. and Ratio of SQL Executions
Number of times that this type of SQL statement was executed slowly in the selected time range, along with the percentage it represents out of all slow SQL statements during the same period.
Avg. Execution Time (s)
Average duration of slow SQL queries within the selected time range.
Database
Database where the SQL statement is executed on.
Client IP Address
Address of the host that connects to the database.
Execution User
Account that executed the SQL statement.
Operation
Click One-Click Throttling to set a throttling rule for the statement. For more throttling operations, see Creating a SQL Throttling Rule.
- Max. Concurrent Requests: the maximum number of concurrent statements allowed under the same rule. Requests exceeding this limit are rejected. The upper limit is 50000. A value of 0 indicates that no concurrency limit is enforced.
- Max. Wait Time (s): the wait time for SQL statements subject to throttling. The valid range is 0–1000000000.
Figure 5 One-click throttling
- Log in to the RDS console.
- Click
in the upper left corner and select a region. - On the Instances page, click the target instance name to go to the Summary page.
- In the navigation pane, choose Logs and click the Slow Query Logs tab.
- On the Downloads tab page, find the log which is in the Preparation completed state and click Download in the Operation column.
- It is recommended that a single log file to be downloaded contain a maximum of 10,000 lines and the file size be no more than 10 MB. Otherwise, the log information will be truncated.
- The system automatically loads the downloading preparation tasks. The loading duration is determined by the log file size and network environment.
- When the log is being prepared for download, the log status is Preparing.
- When the log is ready for download, the log status is Preparation completed.
- If the preparation for download fails, the log status is Abnormal.
Logs in the Preparing or Abnormal status cannot be downloaded.
- Only the latest log file of 40 MB to 100 MB can be downloaded.
- The download link is valid for 5 minutes. After the download link expires, a message is displayed indicating that the download link has expired. If you need to redownload the log, click OK.
Configuring Slow Query Log Ingestion to LTS and Showing the Analysis View
In certain regions, to use this function, you need to submit a service ticket to obtain required permissions.
- Log in to the RDS console.
- Click
in the upper left corner and select a region. - On the Instances page, click the target instance name to go to the Summary page.
- In the navigation pane, choose Logs and click the Slow Query Logs tab.
- Click Ingest Logs to LTS in the upper right corner of the page.
- In the displayed dialog box, select Ingest Logs to LTS, select Slow logs under Log Types, select a log group and log stream, and click OK. Figure 6 Configuring slow log ingestion to LTS
- If slow query log ingestion to LTS is enabled, you can switch to the analysis view in the upper right corner of the page to see more details. Figure 7 List view
Figure 8 Analysis view
- On the Log Search tab page, you can view structured fields and index configuration fields under Quick Analysis as well as view and download log contents. For more information, see Searching and Analyzing Logs.
For explanations of the fields on the Raw Logs page in the analysis view, see Table 4.
Table 4 LTS slow query log fields Parameter
Description
log_type
Log type. Fixed value: slow_log.
instance_id
Instance ID.
node_id
Node ID within an instance.
_resource_id
Resource ID. Fixed value: DBS_LOG. Ignore this parameter.
_resource_name
Resource name. Fixed value: DBS_LOG. Ignore this parameter.
_service_type
Service type. Fixed value: DBS.
service_name
Service name. Fixed value: POSTGRESQL.
operate_type
Type of the executed SQL statement, for example, SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, ALTER, DO, CALL, COPY, WITH, or OTHER.
query_id
A hash-based digital signature used to uniquely identify and group SQL queries that share the same structure but differ in parameters.
count
Number of current SQL statements. Fixed value: 1.
log_time
UTC time when the slow SQL statement starts to be executed.
log_timestamp
Timestamp (in seconds) when the slow SQL statement started execution.
database
Database where the SQL statement is executed.
statement
SQL statements whose execution time exceeds the current slow query threshold.
host
Host that connects to the database.
user
Account that executed the SQL statement.
execute_time
Duration of a slow SQL statement (in milliseconds).
project_id
Project ID. You can view it by hovering over the username in the upper right corner and choosing My Credentials from the drop-down list.
- On the Charts tab page, you can view scenario-specific data in multiple chart types, including tables, bar charts, and line charts. For more information, see Statistical Charts.
- On the Log Analysis tab page, you can search for and analyze collected log data. For more information, see Log Search and Analysis.
- On the Real-Time Logs tab page, you can view logs reported in real time to quickly search for and analyze log data. For more information, see Viewing Real-Time Logs.
- On the Log Search tab page, you can view structured fields and index configuration fields under Quick Analysis as well as view and download log contents. For more information, see Searching and Analyzing Logs.
What is your overall rating for this page?
Thank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbot