forked from docs/doc-exports
Reviewed-by: Wagner, Fabian <fabian.wagner@t-systems.com> Co-authored-by: Ru, Li Yi <liyiru7@huawei.com> Co-committed-by: Ru, Li Yi <liyiru7@huawei.com>
56 lines
15 KiB
HTML
56 lines
15 KiB
HTML
<a name="slow_query_log-sqlserver"></a><a name="slow_query_log-sqlserver"></a>
|
|
|
|
<h1 class="topictitle1">Viewing and Downloading Slow Query Logs</h1>
|
|
<div id="body8662426"><div class="section" id="slow_query_log-sqlserver__en-us_topic_0171818656_section12909141294214"><h4 class="sectiontitle">Scenarios</h4><p id="slow_query_log-sqlserver__en-us_topic_0171818656_p1913233735018">Slow query logs record statements that exceed <span class="parmname" id="slow_query_log-sqlserver__parmname1785613570505"><b>long_query_time</b></span> (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.</p>
|
|
</div>
|
|
<div class="section" id="slow_query_log-sqlserver__en-us_topic_0171818656_section16601112910434"><h4 class="sectiontitle">Parameter Description</h4>
|
|
<div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" id="slow_query_log-sqlserver__en-us_topic_0171818656_table1455312241604" frame="border" border="1" rules="all"><caption><b>Table 1 </b>Parameters related to Microsoft SQL Server slow queries</caption><thead align="left"><tr id="slow_query_log-sqlserver__en-us_topic_0171818656_row1755318241201"><th align="left" class="cellrowborder" valign="top" width="22.79%" id="mcps1.3.2.2.2.3.1.1"><p id="slow_query_log-sqlserver__en-us_topic_0171818656_p455311242020"><strong id="slow_query_log-sqlserver__b842352706181819">Parameter</strong></p>
|
|
</th>
|
|
<th align="left" class="cellrowborder" valign="top" width="77.21000000000001%" id="mcps1.3.2.2.2.3.1.2"><p id="slow_query_log-sqlserver__en-us_topic_0171818656_p15534249012"><strong id="slow_query_log-sqlserver__b147631718121816">Description</strong></p>
|
|
</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody><tr id="slow_query_log-sqlserver__en-us_topic_0171818656_row145532241400"><td class="cellrowborder" valign="top" width="22.79%" headers="mcps1.3.2.2.2.3.1.1 "><p id="slow_query_log-sqlserver__en-us_topic_0171818656_p26741582414">long_query_time</p>
|
|
</td>
|
|
<td class="cellrowborder" valign="top" width="77.21000000000001%" headers="mcps1.3.2.2.2.3.1.2 "><p id="slow_query_log-sqlserver__en-us_topic_0171818656_p121871817112119">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.</p>
|
|
<p id="slow_query_log-sqlserver__en-us_topic_0171818656_p0668124910584">You can modify the slow log threshold as required.</p>
|
|
<ol id="slow_query_log-sqlserver__en-us_topic_0171818656_ol2197921185015"><li id="slow_query_log-sqlserver__li17616348171">Log in to the management console.</li><li id="slow_query_log-sqlserver__li146168481712">Click <span><img id="slow_query_log-sqlserver__rds_modify_instance_name_en-us_topic_0192953815_image192529212293" src="en-us_image_0000001191211679.png"></span> in the upper left corner and select a region and a project.</li><li id="slow_query_log-sqlserver__li96167481711">Click <strong id="slow_query_log-sqlserver__rds_modify_instance_name_b171171523153019">Service List</strong>. Under <strong id="slow_query_log-sqlserver__rds_modify_instance_name_b111722319302">Database</strong>, click <strong id="slow_query_log-sqlserver__rds_modify_instance_name_b15118152363010">Relational Database Service</strong>. The RDS console is displayed.</li><li id="slow_query_log-sqlserver__en-us_topic_0171818656_li1852174118242">On the <strong id="slow_query_log-sqlserver__b14567024141815">Instances</strong> page, click the target DB instance.</li><li id="slow_query_log-sqlserver__en-us_topic_0171818656_li14198142155010">In the navigation pane on the left, choose <span class="uicontrol" id="slow_query_log-sqlserver__uicontrol19211046193919"><b>Logs</b></span>. On the <span class="uicontrol" id="slow_query_log-sqlserver__uicontrol199218461398"><b>Slow Query Logs</b></span> page, click <span><img id="slow_query_log-sqlserver__en-us_topic_0171818656_image3857343615410" src="en-us_image_0000001145051706.png"></span> in the <span class="parmname" id="slow_query_log-sqlserver__en-us_topic_0171818656_parmname867921612919"><b>Threshold of Slow Query Log (long_query_time)</b></span> field to change the threshold.<ul id="slow_query_log-sqlserver__en-us_topic_0171818656_ul1137218215315"><li id="slow_query_log-sqlserver__en-us_topic_0171818656_li1837242153112">To submit the change, click <span><img id="slow_query_log-sqlserver__en-us_topic_0171818656_image12216421202217" src="en-us_image_0000001191211533.png"></span>.</li><li id="slow_query_log-sqlserver__en-us_topic_0171818656_li16461758312">To cancel the change, click <span><img id="slow_query_log-sqlserver__image12572928514" src="en-us_image_0000001191131375.png"></span>.</li></ul>
|
|
<div class="note" id="slow_query_log-sqlserver__en-us_topic_0171818656_note199097234317"><span class="notetitle"> NOTE: </span><div class="notebody"><p id="slow_query_log-sqlserver__en-us_topic_0171818656_p2912923123111">The recommended value is <strong id="slow_query_log-sqlserver__b842352706195824">1s</strong>. The lock wait time is not calculated into the query time.</p>
|
|
</div></div>
|
|
</li></ol>
|
|
</td>
|
|
</tr>
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
</div>
|
|
<div class="section" id="slow_query_log-sqlserver__en-us_topic_0171818656_section10218113118539"><h4 class="sectiontitle">Viewing Slow Query Logs</h4><ol id="slow_query_log-sqlserver__en-us_topic_0171818656_ol1557515415534"><li id="slow_query_log-sqlserver__li03831135164316"><span>Log in to the management console.</span></li><li id="slow_query_log-sqlserver__li5383133511436"><span>Click <span><img id="slow_query_log-sqlserver__rds_modify_instance_name_en-us_topic_0192953815_image192529212293_1" src="en-us_image_0000001191211679.png"></span> in the upper left corner and select a region and a project.</span></li><li id="slow_query_log-sqlserver__li6383163512438"><span>Click <strong id="slow_query_log-sqlserver__rds_modify_instance_name_b171171523153019_1">Service List</strong>. Under <strong id="slow_query_log-sqlserver__rds_modify_instance_name_b111722319302_1">Database</strong>, click <strong id="slow_query_log-sqlserver__rds_modify_instance_name_b15118152363010_1">Relational Database Service</strong>. The RDS console is displayed.</span></li><li id="slow_query_log-sqlserver__en-us_topic_0171818656_li154727359619"><span>On the <strong id="slow_query_log-sqlserver__b1737691316234">Instances</strong> page, click the target DB instance.</span></li><li id="slow_query_log-sqlserver__li843334173017"><span>In the navigation pane on the left, choose <strong id="slow_query_log-sqlserver__b56028260405">Logs</strong>. On the <span class="uicontrol" id="slow_query_log-sqlserver__uicontrol17282202197"><b>Slow Query Logs</b></span> page, click <span><img id="slow_query_log-sqlserver__image175101530194720" src="en-us_image_0000001191211405.png"></span> to enable the slow query log function.</span></li><li id="slow_query_log-sqlserver__en-us_topic_0171818656_li654810813132"><a name="slow_query_log-sqlserver__en-us_topic_0171818656_li654810813132"></a><a name="en-us_topic_0171818656_li654810813132"></a><span>The generated slow query logs are displayed.</span><p><div class="note" id="slow_query_log-sqlserver__en-us_topic_0171818656_note647216351866"><img src="public_sys-resources/note_3.0-en-us.png"><span class="notetitle"> </span><div class="notebody"><p id="slow_query_log-sqlserver__en-us_topic_0171818656_p1947263516617">Enabling slow query log slightly affects DB instance performance.</p>
|
|
</div></div>
|
|
</p></li><li id="slow_query_log-sqlserver__en-us_topic_0171818656_li1575204110535"><span>Connect to the DB instance through the Microsoft SQL Server client.</span></li><li id="slow_query_log-sqlserver__en-us_topic_0171818656_li203542321018"><span>After the DB instance is connected, run the following command to view slow query log details:</span><p><p id="slow_query_log-sqlserver__en-us_topic_0171818656_p14129323155"><strong id="slow_query_log-sqlserver__en-us_topic_0171818656_b65882383187">select * from ::fn_trace_gettable('D:\SQLTrace\audit\</strong><em id="slow_query_log-sqlserver__en-us_topic_0171818656_i2059213851812">XXX</em><strong id="slow_query_log-sqlserver__en-us_topic_0171818656_b1358973881817">', default)</strong></p>
|
|
<div class="note" id="slow_query_log-sqlserver__en-us_topic_0171818656_note1457011307207"><img src="public_sys-resources/note_3.0-en-us.png"><span class="notetitle"> </span><div class="notebody"><p id="slow_query_log-sqlserver__en-us_topic_0171818656_p3571173052011"><strong id="slow_query_log-sqlserver__b576611063912"><em id="slow_query_log-sqlserver__en-us_topic_0171818656_i88271636172016">XXX</em></strong> indicates the name of the slow query log recorded in <a href="#slow_query_log-sqlserver__en-us_topic_0171818656_li654810813132">6</a>.</p>
|
|
</div></div>
|
|
<p id="slow_query_log-sqlserver__en-us_topic_0171818656_p19893449115">Example:</p>
|
|
<p id="slow_query_log-sqlserver__en-us_topic_0171818656_p659212325222"><strong id="slow_query_log-sqlserver__en-us_topic_0171818656_b193241842122219">select * from ::fn_trace_gettable('D:\SQLTrace\audit\SQLTrace.trc', default)</strong></p>
|
|
<p id="slow_query_log-sqlserver__en-us_topic_0171818656_p75381613152314">The result is shown in <a href="#slow_query_log-sqlserver__en-us_topic_0171818656_fig19196129142415">Figure 1</a>.</p>
|
|
<div class="fignone" id="slow_query_log-sqlserver__en-us_topic_0171818656_fig19196129142415"><a name="slow_query_log-sqlserver__en-us_topic_0171818656_fig19196129142415"></a><a name="en-us_topic_0171818656_fig19196129142415"></a><span class="figcap"><b>Figure 1 </b>Slow query log details</span><br><span><img id="slow_query_log-sqlserver__en-us_topic_0171818656_image7198193248" src="en-us_image_0000001145211498.png"></span></div>
|
|
</p></li></ol>
|
|
</div>
|
|
<div class="section" id="slow_query_log-sqlserver__en-us_topic_0171818656_section1021714251349"><h4 class="sectiontitle">Downloading a Log</h4><ol id="slow_query_log-sqlserver__en-us_topic_0171818656_ol9778114310159"><li id="slow_query_log-sqlserver__li16462111010449"><span>Log in to the management console.</span></li><li id="slow_query_log-sqlserver__li8463191014413"><span>Click <span><img id="slow_query_log-sqlserver__rds_modify_instance_name_en-us_topic_0192953815_image192529212293_2" src="en-us_image_0000001191211679.png"></span> in the upper left corner and select a region and a project.</span></li><li id="slow_query_log-sqlserver__li54641410134418"><span>Click <strong id="slow_query_log-sqlserver__rds_modify_instance_name_b171171523153019_2">Service List</strong>. Under <strong id="slow_query_log-sqlserver__rds_modify_instance_name_b111722319302_2">Database</strong>, click <strong id="slow_query_log-sqlserver__rds_modify_instance_name_b15118152363010_2">Relational Database Service</strong>. The RDS console is displayed.</span></li><li id="slow_query_log-sqlserver__en-us_topic_0171818656_li1426913204172"><span>On the <strong id="slow_query_log-sqlserver__b856472316402">Instances</strong> page, click the target DB instance.</span></li><li id="slow_query_log-sqlserver__li125291115173614"><span>In the navigation pane on the left, choose <strong id="slow_query_log-sqlserver__b759625211210">Logs</strong>. On the <span class="uicontrol" id="slow_query_log-sqlserver__uicontrol1559616528218"><b>Slow Query Logs</b></span> page, click <span><img id="slow_query_log-sqlserver__image453091523611" src="en-us_image_0000001145211504.png"></span> to enable the slow query log function.</span><p><div class="note" id="slow_query_log-sqlserver__en-us_topic_0171818656_note146839366503"><img src="public_sys-resources/note_3.0-en-us.png"><span class="notetitle"> </span><div class="notebody"><p id="slow_query_log-sqlserver__en-us_topic_0171818656_p1668419368501">Enabling slow query log slightly affects DB instance performance.</p>
|
|
</div></div>
|
|
</p></li><li id="slow_query_log-sqlserver__en-us_topic_0171818656_li121912551908"><a name="slow_query_log-sqlserver__en-us_topic_0171818656_li121912551908"></a><a name="en-us_topic_0171818656_li121912551908"></a><span>Locate a log to be downloaded and click <strong id="slow_query_log-sqlserver__b842352706201839">Download</strong> in the <strong id="slow_query_log-sqlserver__b842352706201844">Operation</strong> column.</span><p><ol type="a" id="slow_query_log-sqlserver__en-us_topic_0171818656_ol192151352494"><li id="slow_query_log-sqlserver__en-us_topic_0171818656_li48376121118">The system automatically loads the downloading preparation tasks. The loading duration is determined by the log file size and network environment.<ul id="slow_query_log-sqlserver__en-us_topic_0171818656_ul192158521915"><li id="slow_query_log-sqlserver__en-us_topic_0171818656_li32151952897">When the log is being prepared for download, the log status is <strong id="slow_query_log-sqlserver__b202091419411">Preparing</strong>.</li><li id="slow_query_log-sqlserver__en-us_topic_0171818656_li192156524910">When the log is ready for download, the log status is <strong id="slow_query_log-sqlserver__b16529312104116">Preparation completed</strong>.</li><li id="slow_query_log-sqlserver__en-us_topic_0171818656_li72158526915">If the preparation for download fails, the log status is <strong id="slow_query_log-sqlserver__b519342700152327">Abnormal</strong>.</li></ul>
|
|
</li><li id="slow_query_log-sqlserver__en-us_topic_0171818656_li17215652699">In the displayed dialog box, click <span class="uicontrol" id="slow_query_log-sqlserver__uicontrol13983498221128"><b>OK</b></span> to download the log whose status is <strong id="slow_query_log-sqlserver__b6748012221154">Preparation completed</strong>. If you click <span class="uicontrol" id="slow_query_log-sqlserver__uicontrol46308415521215"><b>Cancel</b></span>, the system does not download the log.<p id="slow_query_log-sqlserver__en-us_topic_0171818656_p1320334133219">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 <a href="#slow_query_log-sqlserver__en-us_topic_0171818656_li121912551908">6</a> to try to download a log again.</p>
|
|
<div class="note" id="slow_query_log-sqlserver__note348614374314"><img src="public_sys-resources/note_3.0-en-us.png"><span class="notetitle"> </span><div class="notebody"><p id="slow_query_log-sqlserver__p44871837163111">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:</p>
|
|
<p id="slow_query_log-sqlserver__p105149113318"><strong id="slow_query_log-sqlserver__b19301210153511">select * from ::fn_trace_gettable('<em id="slow_query_log-sqlserver__i173511724123414">XXX</em>', default)</strong></p>
|
|
<p id="slow_query_log-sqlserver__p16338145033312">In the preceding command, <em id="slow_query_log-sqlserver__i396702153411">XXX</em> indicates the local path for storing slow query logs.</p>
|
|
</div></div>
|
|
</li></ol>
|
|
</p></li></ol>
|
|
</div>
|
|
</div>
|
|
<div>
|
|
<div class="familylinks">
|
|
<div class="parentlink"><strong>Parent topic:</strong> <a href="rds_sqlserver_log.html">Log Management</a></div>
|
|
</div>
|
|
</div>
|
|
|