Relational Database ServiceRelational Database Service

Compute
Elastic Cloud Server
Bare Metal Server
Auto Scaling
Image Management Service
Dedicated Host
FunctionGraph
Networking
Virtual Private Cloud
Elastic IP
Elastic Load Balance
NAT Gateway
Direct Connect
Virtual Private Network
Domain Name Service
VPC Endpoint
Cloud Connect
Enterprise Switch
Security & Compliance
Anti-DDoS
Web Application Firewall
Host Security Service
Data Encryption Workshop
Database Security Service
Advanced Anti-DDoS
Data Security Center
Container Guard Service
Situation Awareness
Managed Threat Detection
Compass
Cloud Certificate Manager
Anti-DDoS Service
Databases
Relational Database Service
Document Database Service
Data Admin Service
Data Replication Service
GaussDB NoSQL
GaussDB(for MySQL)
Distributed Database Middleware
GaussDB(for openGauss)
Developer Services
ServiceStage
Distributed Cache Service
Simple Message Notification
Application Performance Management
Application Operations Management
Blockchain Service
API Gateway
Cloud Performance Test Service
Distributed Message Service for Kafka
Distributed Message Service for RabbitMQ
Distributed Message Service for RocketMQ
Cloud Service Engine
DevCloud
ProjectMan
CodeHub
CloudRelease
CloudPipeline
CloudBuild
CloudDeploy
Cloud Communications
Message & SMS
Cloud Ecosystem
Marketplace
Partner Center
User Support
My Account
Billing Center
Cost Center
Resource Center
Enterprise Management
Service Tickets
HUAWEI CLOUD (International) FAQs
ICP License Service
Support Plans
Customer Operation Capabilities
Partner Support Plans
Professional Services
enterprise-collaboration
Meeting
IoT
IoT
Intelligent EdgeFabric
DeveloperTools
SDK Developer Guide
API Request Signing Guide
Terraform
Koo Command Line Interface
Updated at: Apr 02, 2022 GMT+08:00

Viewing and Downloading Slow Query Logs

Scenarios

Slow query logs record statements that exceed long_query_time (1 second by default). You can view log details to identify statements that are executing slowly and optimize the statements. You can also download slow query logs for service analysis.

Parameter Description

Table 1 Parameters related to Microsoft SQL Server slow queries

Parameter

Description

long_query_time

Specifies how many microseconds a SQL query has to take to be defined as a slow query log. The default value is 1s. When the execution time of an SQL statement exceeds the value of this parameter, the SQL statement is recorded in slow query logs.

You can modify the slow log threshold as required.

  1. Log in to the management console.
  2. Click in the upper left corner and select a region and a project.
  3. Click in the upper left corner of the page and choose Database > Relational Database Service. The RDS console is displayed.
  4. On the Instance Management page, click the target DB instance.
  5. In the navigation pane on the left, choose Logs. On the Slow Query Logs page, click in the Threshold of Slow Query Log (long_query_time) field to change the threshold.
    • To submit the change, click .
    • To cancel the change, click .
    NOTE:

    The recommended value is 1s. The lock wait time is not calculated into the query time.

Viewing Slow Query Logs

  1. Log in to the management console.
  2. Click in the upper left corner and select a region and a project.
  3. Click in the upper left corner of the page and choose Database > Relational Database Service. The RDS console is displayed.
  4. On the Instance Management page, click the target DB instance.
  5. In the navigation pane on the left, choose Logs. On the Slow Query Logs page, click to enable the slow query log function.
  6. The generated slow query logs are displayed.

    Figure 1 SQL Server slow query log

    Enabling slow query log slightly affects DB instance performance.

  7. Connect to the DB instance through the Microsoft SQL Server client. For details, see Connecting to a DB Instance Through a Public Network.
  8. After the DB instance is connected, run the following command to view slow query log details:

    select * from ::fn_trace_gettable('D:\SQLTrace\audit\XXX', default)

    XXX indicates the name of the slow query log recorded in 6.

    Example:

    select * from ::fn_trace_gettable('D:\SQLTrace\audit\SQLTrace.trc', default)

    The result is shown in Figure 2.

    Figure 2 Slow query log details

Downloading a Log

  1. Log in to the management console.
  2. Click in the upper left corner and select a region and a project.
  3. Click in the upper left corner of the page and choose Database > Relational Database Service. The RDS console is displayed.
  4. On the Instance Management page, click the target DB instance.
  5. In the navigation pane on the left, choose Logs. On the Slow Query Logs page, click to enable the slow query log function.

    Enabling slow query log slightly affects DB instance performance.

  6. Locate a log to be downloaded and click Download in the Operation column.

    1. 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.
    2. If the size of a log to be downloaded is greater than 40 MB, you need to use OBS Browser+ to download it. For details, see Method 1: Using OBS Browser+.
    3. In the displayed dialog box, click OK to download the log whose status is Preparation completed. If you click Cancel, the system does not download the log.

      The download link is valid for 5 minutes. After the download link expires, a message is displayed indicating that the download link has expired. You can close the window and repeat the procedure 6 to try to download a log again.

      After downloading slow query logs to a local PC, you can use SSMS to connect to the local database and run the following SQL statement to view the slow query log details:

      select * from ::fn_trace_gettable('XXX', default)

      In the preceding command, XXX indicates the local path for storing slow query logs.

Did you find this page helpful?

Failed to submit the feedback. Please try again later.

Which of the following issues have you encountered?







Please complete at least one feedback item.

Content most length 200 character

Content is empty.

OK Cancel