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 |
---|---|
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.
|
Enabling slow query log slightly affects DB instance performance.
select * from ::fn_trace_gettable('D:\SQLTrace\audit\XXX', default)
Example:
select * from ::fn_trace_gettable('D:\SQLTrace\audit\SQLTrace.trc', default)
The result is shown in Figure 1.
Enabling slow query log slightly affects DB instance performance.
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.