forked from docs/doc-exports
Reviewed-by: Pruthi, Vineet <vineet.pruthi@t-systems.com> Co-authored-by: luhuayi <luhuayi@huawei.com> Co-committed-by: luhuayi <luhuayi@huawei.com>
142 lines
38 KiB
HTML
142 lines
38 KiB
HTML
<a name="EN-US_TOPIC_0000001811490361"></a><a name="EN-US_TOPIC_0000001811490361"></a>
|
|
|
|
<h1 class="topictitle1">Historical Top SQL</h1>
|
|
<div id="body1500282066544"><p id="EN-US_TOPIC_0000001811490361__p7863164612376">You can query historical Top SQL in historical resource monitoring views. The historical resource monitoring view records the resource usage (including memory, data spilled to disks, and CPU time), running status (including errors, termination, and exceptions), and performance alarm information when a job is complete. For queries that abnormally terminate due to FATAL or PANIC errors, their status is displayed as <strong id="EN-US_TOPIC_0000001811490361__b842352706163537">aborted</strong> and no detailed information is recorded. Status information about query parsing in the optimization phase cannot be monitored.</p>
|
|
<p id="EN-US_TOPIC_0000001811490361__p1926013415223">The following table describes the external interfaces of the historical views.</p>
|
|
|
|
<div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" id="EN-US_TOPIC_0000001811490361__table16116143418462" frame="border" border="1" rules="all"><thead align="left"><tr id="EN-US_TOPIC_0000001811490361__row2269163474610"><th align="left" class="cellrowborder" valign="top" id="mcps1.3.3.1.5.1.1"><p id="EN-US_TOPIC_0000001811490361__p8269434174616">Level</p>
|
|
</th>
|
|
<th align="left" class="cellrowborder" valign="top" id="mcps1.3.3.1.5.1.2"><p id="EN-US_TOPIC_0000001811490361__p1926911343463">Monitored Node</p>
|
|
</th>
|
|
<th align="left" class="cellrowborder" colspan="2" valign="top" id="mcps1.3.3.1.5.1.3"><p id="EN-US_TOPIC_0000001811490361__p122696344466">View</p>
|
|
</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody><tr id="EN-US_TOPIC_0000001811490361__row15269134174618"><td class="cellrowborder" rowspan="4" valign="top" width="14.430000000000001%" headers="mcps1.3.3.1.5.1.1 "><p id="EN-US_TOPIC_0000001811490361__p102691034154612">Query level/perf level</p>
|
|
<p id="EN-US_TOPIC_0000001811490361__p922025511487">(recommended)</p>
|
|
</td>
|
|
<td class="cellrowborder" rowspan="2" valign="top" width="14.430000000000001%" headers="mcps1.3.3.1.5.1.2 "><p id="EN-US_TOPIC_0000001811490361__p385934402014">Current CN</p>
|
|
</td>
|
|
<td class="cellrowborder" valign="top" width="35.57%" headers="mcps1.3.3.1.5.1.3 "><p id="EN-US_TOPIC_0000001811490361__p192721541204314">History (Internal dump interface. Only statements that have ended in the last three minutes are displayed.)</p>
|
|
</td>
|
|
<td class="cellrowborder" valign="top" width="35.57%" headers="mcps1.3.3.1.5.1.3 "><p id="EN-US_TOPIC_0000001811490361__p8270163474615"><a href="dws_04_0705.html">GS_WLM_SESSION_HISTORY</a></p>
|
|
</td>
|
|
</tr>
|
|
<tr id="EN-US_TOPIC_0000001811490361__row15270123412464"><td class="cellrowborder" valign="top" headers="mcps1.3.3.1.5.1.1 "><p id="EN-US_TOPIC_0000001811490361__p427212411434">History (all statements)</p>
|
|
</td>
|
|
<td class="cellrowborder" valign="top" headers="mcps1.3.3.1.5.1.2 "><p id="EN-US_TOPIC_0000001811490361__p427019342464"><a href="dws_04_0704.html">GS_WLM_SESSION_INFO</a></p>
|
|
</td>
|
|
</tr>
|
|
<tr id="EN-US_TOPIC_0000001811490361__row2270113412467"><td class="cellrowborder" rowspan="2" valign="top" headers="mcps1.3.3.1.5.1.1 "><p id="EN-US_TOPIC_0000001811490361__p3794195252011">All CNs</p>
|
|
</td>
|
|
<td class="cellrowborder" valign="top" headers="mcps1.3.3.1.5.1.2 "><p id="EN-US_TOPIC_0000001811490361__p1127218411439">History (Internal dump interface. Only statements that have ended in the last three minutes are displayed.)</p>
|
|
</td>
|
|
<td class="cellrowborder" valign="top" headers="mcps1.3.3.1.5.1.3 "><p id="EN-US_TOPIC_0000001811490361__p1427113346469"><a href="dws_04_0840.html">PGXC_WLM_SESSION_HISTORY</a></p>
|
|
</td>
|
|
</tr>
|
|
<tr id="EN-US_TOPIC_0000001811490361__row11271534194614"><td class="cellrowborder" valign="top" headers="mcps1.3.3.1.5.1.1 "><p id="EN-US_TOPIC_0000001811490361__p14272174110438">History (all statements)</p>
|
|
</td>
|
|
<td class="cellrowborder" valign="top" headers="mcps1.3.3.1.5.1.2 "><p id="EN-US_TOPIC_0000001811490361__p4271133444611"><a href="dws_04_0839.html">PGXC_WLM_SESSION_INFO</a></p>
|
|
</td>
|
|
</tr>
|
|
<tr id="EN-US_TOPIC_0000001811490361__row142711834144613"><td class="cellrowborder" rowspan="4" valign="top" width="14.430000000000001%" headers="mcps1.3.3.1.5.1.1 "><p id="EN-US_TOPIC_0000001811490361__p5641135816206">Operator level</p>
|
|
</td>
|
|
<td class="cellrowborder" rowspan="2" valign="top" width="14.430000000000001%" headers="mcps1.3.3.1.5.1.2 "><p id="EN-US_TOPIC_0000001811490361__p1064185814207">Current CN</p>
|
|
</td>
|
|
<td class="cellrowborder" valign="top" width="35.57%" headers="mcps1.3.3.1.5.1.3 "><p id="EN-US_TOPIC_0000001811490361__p027204110437">History (Only statements that have ended in the last three minutes are displayed.)</p>
|
|
</td>
|
|
<td class="cellrowborder" valign="top" width="35.57%" headers="mcps1.3.3.1.5.1.3 "><p id="EN-US_TOPIC_0000001811490361__p12271203415461"><a href="dws_04_0702.html">GS_WLM_OPERATOR_HISTORY</a></p>
|
|
</td>
|
|
</tr>
|
|
<tr id="EN-US_TOPIC_0000001811490361__row6271234184616"><td class="cellrowborder" valign="top" headers="mcps1.3.3.1.5.1.1 "><p id="EN-US_TOPIC_0000001811490361__p1727214174314">History (internal dump interface, all statements)</p>
|
|
</td>
|
|
<td class="cellrowborder" valign="top" headers="mcps1.3.3.1.5.1.2 "><p id="EN-US_TOPIC_0000001811490361__p6271334144617"><a href="dws_04_0701.html">GS_WLM_OPERATOR_INFO</a></p>
|
|
</td>
|
|
</tr>
|
|
<tr id="EN-US_TOPIC_0000001811490361__row1227193424614"><td class="cellrowborder" rowspan="2" valign="top" headers="mcps1.3.3.1.5.1.1 "><p id="EN-US_TOPIC_0000001811490361__p1644106102115">All CNs</p>
|
|
</td>
|
|
<td class="cellrowborder" valign="top" headers="mcps1.3.3.1.5.1.2 "><p id="EN-US_TOPIC_0000001811490361__p122731941104311">History (Only statements that have ended in the last three minutes are displayed.)</p>
|
|
</td>
|
|
<td class="cellrowborder" valign="top" headers="mcps1.3.3.1.5.1.3 "><p id="EN-US_TOPIC_0000001811490361__p16271123411461"><a href="dws_04_0836.html">PGXC_WLM_OPERATOR_HISTORY</a></p>
|
|
</td>
|
|
</tr>
|
|
<tr id="EN-US_TOPIC_0000001811490361__row62710347467"><td class="cellrowborder" valign="top" headers="mcps1.3.3.1.5.1.1 "><p id="EN-US_TOPIC_0000001811490361__p202731141104314">History (internal dump interface, all statements)</p>
|
|
</td>
|
|
<td class="cellrowborder" valign="top" headers="mcps1.3.3.1.5.1.2 "><p id="EN-US_TOPIC_0000001811490361__p727113346465"><a href="dws_04_0837.html">PGXC_WLM_OPERATOR_INFO</a></p>
|
|
</td>
|
|
</tr>
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
<div class="note" id="EN-US_TOPIC_0000001811490361__n7a9652a1f8594abf8cd88b657df7f214"><img src="public_sys-resources/note_3.0-en-us.png"><span class="notetitle"> </span><div class="notebody"><ul id="EN-US_TOPIC_0000001811490361__ul12931465406"><li id="EN-US_TOPIC_0000001811490361__li18350825114219">The view level is determined by the resource monitoring level, that is, the <a href="dws_04_0922.html#EN-US_TOPIC_0000001811490709__section153571329142612">resource_track_level</a> configuration.</li><li id="EN-US_TOPIC_0000001811490361__li541810241581">The perf and operator levels affect the values of the <strong id="EN-US_TOPIC_0000001811490361__b514213313282">query_plan</strong> and <strong id="EN-US_TOPIC_0000001811490361__b914217313284">warning</strong> columns in <a href="dws_04_0706.html">GS_WLM_SESSION_STATISTICS</a> or <a href="dws_04_0839.html">PGXC_WLM_SESSION_INFO</a>. For details, see <a href="dws_04_0446.html">SQL Self-Diagnosis</a>.</li><li id="EN-US_TOPIC_0000001811490361__li1094246194016">Prefixes <strong id="EN-US_TOPIC_0000001811490361__b147861146156">gs</strong> and <strong id="EN-US_TOPIC_0000001811490361__b1278624141520">pgxc</strong> indicate views showing single CN information and those showing cluster information, respectively. Common users can log in to a CN in the cluster to query only views with the <strong id="EN-US_TOPIC_0000001811490361__b09977810154">gs</strong> prefix.</li><li id="EN-US_TOPIC_0000001811490361__li59415465406">If instance fault occurs, some SQL statement information may fail to be recorded in historical resource monitoring views.</li><li id="EN-US_TOPIC_0000001811490361__li1714310361278">In some abnormal cases, the status information column in the historical Top SQL may be displayed as <strong id="EN-US_TOPIC_0000001811490361__b1182527152713">unknown</strong>. The recorded monitoring information may be inaccurate.</li><li id="EN-US_TOPIC_0000001811490361__li63372482446">The SQL statements that can be recorded in historical resource monitoring views are the same as those recorded in real-time resource monitoring views. For details, see <a href="dws_04_0397.html#EN-US_TOPIC_0000001764491512__li12942257154712">SQL statements recorded in real-time resource monitoring views</a>.</li><li id="EN-US_TOPIC_0000001811490361__li11949249165517">Historical top SQL statements are recorded only when the GUC parameter <a href="dws_04_0922.html#EN-US_TOPIC_0000001811490709__s5f116e109a2944e3854abcc56772eaa1">enable_resource_record</a> is enabled.</li><li id="EN-US_TOPIC_0000001811490361__li076442713561">You can query historical Top SQL queries and operator-level data only through the PostgreSQL database.</li><li id="EN-US_TOPIC_0000001811490361__li4960193712610">Historical Top SQL focuses on locating and demarcating query performance problems. It is not used for auditing or recording syntax analysis error statements.</li><li id="EN-US_TOPIC_0000001811490361__li178071323722">In 8.2.1 and later cluster versions, the <strong id="EN-US_TOPIC_0000001811490361__b3306199201118">resource_track_subsql_duration</strong> parameter (default value: 180s) is added to filter out substatements in the stored procedure whose execution time is less than the value of this parameter and archive only substatements whose execution time is greater than the value of this parameter. In 8.2.1 and later versions, the default value of <strong id="EN-US_TOPIC_0000001811490361__b65451258131114">enable_track_record_subsql</strong> is changed from <strong id="EN-US_TOPIC_0000001811490361__b20179025123">off</strong> to <strong id="EN-US_TOPIC_0000001811490361__b4956464121">on</strong>, which means substatements in stored procedures are recorded by default. If a substatement is recorded, it must meet the following conditions:<ul id="EN-US_TOPIC_0000001811490361__ul204921655135019"><li id="EN-US_TOPIC_0000001811490361__li138921125514">In the session where the statement is, the <strong id="EN-US_TOPIC_0000001811490361__b17682211134">enable_track_record_subsql</strong> parameter is enabled.</li><li id="EN-US_TOPIC_0000001811490361__li1788415418504">The substatement must be pushed down to DNs for execution. (To prevent TopSQL from recording too many substatements, substatements that are not pushed down to DNs will be filtered out.)</li><li id="EN-US_TOPIC_0000001811490361__li12433146175110">The execution time of the substatement exceeds the value of <strong id="EN-US_TOPIC_0000001811490361__b482532081420">resource_track_subsql_duration</strong> in the session.</li></ul>
|
|
</li><li id="EN-US_TOPIC_0000001811490361__li1645589153618">By default, the History view queries statements that end in the last 3 minutes. It does this by querying tables. It is actually a temporary view for performance considerations. Since the 8.1.3 cluster version, the real-time monitoring and archiving functions of the TopSQL monitoring have been greatly improved are no performance considerations are needed. Therefore, you are not advised to use the History view.</li><li id="EN-US_TOPIC_0000001811490361__li1192182220409">In 8.1.3 and later versions, the TopSQL real-time monitoring has no impact on statement performance. You can set the GUC <strong id="EN-US_TOPIC_0000001811490361__b11362181162814">parameter resource_track_cost</strong> to <strong id="EN-US_TOPIC_0000001811490361__b184153492820">0</strong> to monitor the running information of all statements. The statement archiving in the TopSQL history monitoring also has no impact on statement performance. However, when the TPS is high, the following factors need to be considered:<ul id="EN-US_TOPIC_0000001811490361__ul10538155385619"><li id="EN-US_TOPIC_0000001811490361__li174313533566">Record the disk overhead of all statements. You can estimate the disk space required for archiving a statement as 8 KB, calculate the space usage based on the peak TPS, and adjust the values of <strong id="EN-US_TOPIC_0000001811490361__b2058117493305">resource_track_duration</strong> and <strong id="EN-US_TOPIC_0000001811490361__b1183655213303">resource_track_subsql_duration</strong>.</li><li id="EN-US_TOPIC_0000001811490361__li1862451835720">For memory overhead for caching all statements, you can estimate the memory size required for archiving a statement as 16 KB, and the interval for archiving statements in batches as 5 seconds, then calculate the required peak memory size based on the peak service TPS. The calculation method is as follows: 5 seconds x TPS x 16 KB. The value of <strong id="EN-US_TOPIC_0000001811490361__b878365133316">session_history_memory GUC</strong> (default value: 100 MB) must be greater than the calculation result to ensure that all statements can be recorded.</li></ul>
|
|
</li></ul>
|
|
</div></div>
|
|
<div class="section" id="EN-US_TOPIC_0000001811490361__s3c059b5b05dd4bebba57605ec8476f1b"><h4 class="sectiontitle">Prerequisites</h4><ul id="EN-US_TOPIC_0000001811490361__u6076a0db22fd45cf953493a79d391e59"><li id="EN-US_TOPIC_0000001811490361__laa8cf480ef7849e8aa2f1857ab8696dd">The GUC parameter <a href="dws_04_0922.html#EN-US_TOPIC_0000001811490709__s9530ecdd2b0d4a98b67b66e32bf8e5d0">enable_resource_track</a> is set to <strong id="EN-US_TOPIC_0000001811490361__b2684528112110">on</strong>. The default value is <strong id="EN-US_TOPIC_0000001811490361__b46841728192114">on</strong>.</li><li id="EN-US_TOPIC_0000001811490361__li16371944105314">The GUC parameter <a href="dws_04_0922.html#EN-US_TOPIC_0000001811490709__section153571329142612">resource_track_level</a> is set to <strong id="EN-US_TOPIC_0000001811490361__b16542058203615">query</strong>, <strong id="EN-US_TOPIC_0000001811490361__b1254275813367">perf</strong>, or <strong id="EN-US_TOPIC_0000001811490361__b8542158103615">operator</strong>. The default value is <strong id="EN-US_TOPIC_0000001811490361__b354215813617">query</strong>. For details, see <a href="dws_04_0397.html#EN-US_TOPIC_0000001764491512__table0310615145919">Table 2</a>.</li><li id="EN-US_TOPIC_0000001811490361__l4975437a8a7c4b15b26bf01bc384631f">The GUC parameter <a href="dws_04_0922.html#EN-US_TOPIC_0000001811490709__s5f116e109a2944e3854abcc56772eaa1">enable_resource_record</a> is set to <span class="parmvalue" id="EN-US_TOPIC_0000001811490361__parmvalue2648203132116"><b>on</b></span>. The default value is <strong id="EN-US_TOPIC_0000001811490361__b14648143192113">on</strong>.</li><li id="EN-US_TOPIC_0000001811490361__li1235581018551">The GUC parameter <a href="dws_04_0922.html#EN-US_TOPIC_0000001811490709__section347574425112">resource_track_duration</a> is less than the sum of the job execution time and queuing time (<strong id="EN-US_TOPIC_0000001811490361__b829110353282">60s</strong> by default).</li><li id="EN-US_TOPIC_0000001811490361__li1745162845818">The GUC parameter <a href="dws_04_0922.html#EN-US_TOPIC_0000001811490709__section7181949101319">enable_track_record_subsql</a> specifies whether to record internal statements of a stored procedure or anonymous block. The default value is <strong id="EN-US_TOPIC_0000001811490361__b8199442162110">on</strong>.</li><li id="EN-US_TOPIC_0000001811490361__li292182512584">The value of <a href="dws_04_0922.html#EN-US_TOPIC_0000001811490709__section177585466812">resource_track_subsql_duration</a> is less than the execution time of the internal statement in the stored procedure (180s by default).</li><li id="EN-US_TOPIC_0000001811490361__li774512409428">Jobs whose sum of the job execution time and queuing time recorded in the real-time resource monitoring view (see <a href="dws_04_0397.html#EN-US_TOPIC_0000001764491512__table16116143418462">Table 1</a>) is no less than the value of <a href="dws_04_0922.html#EN-US_TOPIC_0000001811490709__section347574425112">resource_track_duration</a> are monitored.</li><li id="EN-US_TOPIC_0000001811490361__l7a3a85df0fb34cde8108e3f5c8ca6c48">If the Cgroups function is properly loaded, you can run the <strong id="EN-US_TOPIC_0000001811490361__b1268014288479">gs_cgroup -P</strong> command to view information about Cgroups.</li></ul>
|
|
</div>
|
|
<div class="section" id="EN-US_TOPIC_0000001811490361__sf74c4e3849684455b8bdb513fe44153d"><h4 class="sectiontitle">Procedure</h4><ol id="EN-US_TOPIC_0000001811490361__o484ff66141cc45339e715330151ca368"><li id="EN-US_TOPIC_0000001811490361__li41091322194215"><span>Query the load records of the current CN after its latest job is complete in the <strong id="EN-US_TOPIC_0000001811490361__b1996442636165442">gs_wlm_session_history</strong> view.</span><p><div class="codecoloring" codetype="Sql" id="EN-US_TOPIC_0000001811490361__screen171108227421"><div class="highlight"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><span class="normal">1</span></pre></div></td><td class="code"><div><pre><span></span><span class="k">SELECT</span><span class="w"> </span><span class="o">*</span><span class="w"> </span><span class="k">FROM</span><span class="w"> </span><span class="n">gs_wlm_session_history</span><span class="p">;</span>
|
|
</pre></div></td></tr></table></div>
|
|
</div>
|
|
</p></li><li id="EN-US_TOPIC_0000001811490361__li17295131115432"><span>Query the load records of all the CNs after their latest job are complete in the <strong id="EN-US_TOPIC_0000001811490361__b505864124">pgxc_wlm_session_history</strong> view.</span><p><div class="codecoloring" codetype="Sql" id="EN-US_TOPIC_0000001811490361__screen10295211144313"><div class="highlight"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><span class="normal">1</span></pre></div></td><td class="code"><div><pre><span></span><span class="w"> </span><span class="k">SELECT</span><span class="w"> </span><span class="o">*</span><span class="w"> </span><span class="k">FROM</span><span class="w"> </span><span class="n">pgxc_wlm_session_history</span><span class="p">;</span>
|
|
</pre></div></td></tr></table></div>
|
|
</div>
|
|
</p></li><li id="EN-US_TOPIC_0000001811490361__lc2f30b2e9de54f8d8049fe3a294cbdc4"><span>Query the load records of the current CN through the <strong id="EN-US_TOPIC_0000001811490361__b205481838123219">gs_wlm_session_info</strong> table after the task is complete. To query the historical records successfully, set <a href="dws_04_0922.html#EN-US_TOPIC_0000001811490709__s5f116e109a2944e3854abcc56772eaa1">enable_resource_record</a> to <strong id="EN-US_TOPIC_0000001811490361__b17653161442218">on</strong>.</span><p><div class="codecoloring" codetype="Sql" id="EN-US_TOPIC_0000001811490361__s099f65ceee3945659e035643d840f8a2"><div class="highlight"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><span class="normal">1</span></pre></div></td><td class="code"><div><pre><span></span><span class="k">SELECT</span><span class="w"> </span><span class="o">*</span><span class="w"> </span><span class="k">FROM</span><span class="w"> </span><span class="n">gs_wlm_session_info</span><span class="p">;</span>
|
|
</pre></div></td></tr></table></div>
|
|
</div>
|
|
<ul id="EN-US_TOPIC_0000001811490361__ul3132173154611"><li id="EN-US_TOPIC_0000001811490361__li1013215324611">Show the 10 queries that consume the most memory (You can specify a query period.):</li></ul>
|
|
<div class="codecoloring" codetype="Sql" id="EN-US_TOPIC_0000001811490361__screen121321335463"><div class="highlight"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><span class="normal">1</span></pre></div></td><td class="code"><div><pre><span></span><span class="k">SELECT</span><span class="w"> </span><span class="o">*</span><span class="w"> </span><span class="k">FROM</span><span class="w"> </span><span class="n">gs_wlm_session_info</span><span class="w"> </span><span class="k">order</span><span class="w"> </span><span class="k">by</span><span class="w"> </span><span class="n">max_peak_memory</span><span class="w"> </span><span class="k">desc</span><span class="w"> </span><span class="k">limit</span><span class="w"> </span><span class="mi">10</span><span class="p">;</span><span class="w"> </span>
|
|
</pre></div></td></tr></table></div>
|
|
</div>
|
|
<div class="codecoloring" codetype="Sql" id="EN-US_TOPIC_0000001811490361__screen1135505104213"><div class="highlight"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><span class="normal">1</span></pre></div></td><td class="code"><div><pre><span></span><span class="k">SELECT</span><span class="w"> </span><span class="o">*</span><span class="w"> </span><span class="k">FROM</span><span class="w"> </span><span class="n">gs_wlm_session_info</span><span class="w"> </span><span class="k">WHERE</span><span class="w"> </span><span class="n">start_time</span><span class="w"> </span><span class="o">>=</span><span class="w"> </span><span class="s1">'2022-05-15 21:00:00'</span><span class="w"> </span><span class="k">and</span><span class="w"> </span><span class="n">finish_time</span><span class="w"> </span><span class="o"><=</span><span class="s1">'2022-05-15 23:30:00'</span><span class="w"> </span><span class="k">order</span><span class="w"> </span><span class="k">by</span><span class="w"> </span><span class="n">max_peak_memory</span><span class="w"> </span><span class="k">desc</span><span class="w"> </span><span class="k">limit</span><span class="w"> </span><span class="mi">10</span><span class="p">;</span><span class="w"> </span>
|
|
</pre></div></td></tr></table></div>
|
|
</div>
|
|
<ul id="EN-US_TOPIC_0000001811490361__ul1113316311467"><li id="EN-US_TOPIC_0000001811490361__li191336313460">Show the 10 queries consuming the most CPU resources:</li></ul>
|
|
<div class="codecoloring" codetype="Sql" id="EN-US_TOPIC_0000001811490361__screen12133123104618"><div class="highlight"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><span class="normal">1</span></pre></div></td><td class="code"><div><pre><span></span><span class="k">SELECT</span><span class="w"> </span><span class="o">*</span><span class="w"> </span><span class="k">FROM</span><span class="w"> </span><span class="n">gs_wlm_session_info</span><span class="w"> </span><span class="k">order</span><span class="w"> </span><span class="k">by</span><span class="w"> </span><span class="n">total_cpu_time</span><span class="w"> </span><span class="k">desc</span><span class="w"> </span><span class="k">limit</span><span class="w"> </span><span class="mi">10</span><span class="p">;</span>
|
|
</pre></div></td></tr></table></div>
|
|
</div>
|
|
<div class="codecoloring" codetype="Sql" id="EN-US_TOPIC_0000001811490361__screen19705163132211"><div class="highlight"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><span class="normal">1</span></pre></div></td><td class="code"><div><pre><span></span><span class="k">SELECT</span><span class="w"> </span><span class="o">*</span><span class="w"> </span><span class="k">FROM</span><span class="w"> </span><span class="n">gs_wlm_session_info</span><span class="w"> </span><span class="k">WHERE</span><span class="w"> </span><span class="n">start_time</span><span class="w"> </span><span class="o">>=</span><span class="w"> </span><span class="s1">'2022-05-15 21:00:00'</span><span class="w"> </span><span class="k">and</span><span class="w"> </span><span class="n">finish_time</span><span class="w"> </span><span class="o"><=</span><span class="s1">'2022-05-15 23:30:00'</span><span class="w"> </span><span class="k">order</span><span class="w"> </span><span class="k">by</span><span class="w"> </span><span class="n">total_cpu_time</span><span class="w"> </span><span class="k">desc</span><span class="w"> </span><span class="k">limit</span><span class="w"> </span><span class="mi">10</span><span class="p">;</span>
|
|
</pre></div></td></tr></table></div>
|
|
</div>
|
|
</p></li><li id="EN-US_TOPIC_0000001811490361__en-us_topic_0066854643_li47671568376"><span>Query for the load records of all the CNs after their jobs are complete in the <strong id="EN-US_TOPIC_0000001811490361__b1938262665217">pgxc_wlm_session_info</strong> view. To query the historical records successfully, set <a href="dws_04_0922.html#EN-US_TOPIC_0000001811490709__s5f116e109a2944e3854abcc56772eaa1">enable_resource_record</a> to <strong id="EN-US_TOPIC_0000001811490361__b20948323153817">on</strong>.</span><p><div class="codecoloring" codetype="Sql" id="EN-US_TOPIC_0000001811490361__s83865760d3d5475bb9ff451092863e84"><div class="highlight"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><span class="normal">1</span></pre></div></td><td class="code"><div><pre><span></span><span class="k">SELECT</span><span class="w"> </span><span class="o">*</span><span class="w"> </span><span class="k">FROM</span><span class="w"> </span><span class="n">pgxc_wlm_session_info</span><span class="p">;</span>
|
|
</pre></div></td></tr></table></div>
|
|
</div>
|
|
<ul id="EN-US_TOPIC_0000001811490361__ul153931208413"><li id="EN-US_TOPIC_0000001811490361__li1939312204415">Showing the 10 queries on which the CN spends the most time:</li></ul>
|
|
<div class="codecoloring" codetype="Sql" id="EN-US_TOPIC_0000001811490361__screen1489165916415"><div class="highlight"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><span class="normal">1</span></pre></div></td><td class="code"><div><pre><span></span><span class="k">SELECT</span><span class="w"> </span><span class="o">*</span><span class="w"> </span><span class="k">FROM</span><span class="w"> </span><span class="n">pgxc_wlm_session_info</span><span class="w"> </span><span class="k">order</span><span class="w"> </span><span class="k">by</span><span class="w"> </span><span class="n">duration</span><span class="w"> </span><span class="k">desc</span><span class="w"> </span><span class="k">limit</span><span class="w"> </span><span class="mi">10</span><span class="p">;</span>
|
|
</pre></div></td></tr></table></div>
|
|
</div>
|
|
<ul id="EN-US_TOPIC_0000001811490361__ul56258225129"><li id="EN-US_TOPIC_0000001811490361__li146251222141219">Query the execution information about a query statement that has been executed. For example, query the execution information about the statement whose <strong id="EN-US_TOPIC_0000001811490361__b1860082776101954">queryid</strong> is <strong id="EN-US_TOPIC_0000001811490361__b1486537923101954">76561193695026478</strong>.</li></ul>
|
|
<pre class="screen" id="EN-US_TOPIC_0000001811490361__screen143621558131318"><strong id="EN-US_TOPIC_0000001811490361__b1753015020218">SELECT * FROM</strong> <em id="EN-US_TOPIC_0000001811490361__i13323340182219">pgxc_wlm_session_info</em> where queryid = '<em id="EN-US_TOPIC_0000001811490361__i14933156122611">76561193695026478</em>';</pre>
|
|
</p></li><li id="EN-US_TOPIC_0000001811490361__li294548102314"><span>Use the <strong id="EN-US_TOPIC_0000001811490361__b5346151102215">pgxc_get_wlm_session_info_bytime</strong> function to filter and query the <strong id="EN-US_TOPIC_0000001811490361__b203471551172217">pgxc_wlm_session_info</strong> view. To query the historical records successfully, set <a href="dws_04_0922.html#EN-US_TOPIC_0000001811490709__s5f116e109a2944e3854abcc56772eaa1">enable_resource_record</a> to <strong id="EN-US_TOPIC_0000001811490361__b15349175119224">on</strong>. You are advised to use this function if the view contains a large number of records.</span><p><div class="note" id="EN-US_TOPIC_0000001811490361__note23535177453"><img src="public_sys-resources/note_3.0-en-us.png"><span class="notetitle"> </span><div class="notebody"><p id="EN-US_TOPIC_0000001811490361__p18647195773116">A GaussDB(DWS) cluster uses the UTC time by default, which has an 8-hour time difference with the system time. Before queries, ensure that the database time is the same as the system time.</p>
|
|
</div></div>
|
|
<ul id="EN-US_TOPIC_0000001811490361__ul1750342133120"><li id="EN-US_TOPIC_0000001811490361__li950322112316">Return the queries started between <strong id="EN-US_TOPIC_0000001811490361__b10197307539">2019-09-10 15:30:00</strong> and <strong id="EN-US_TOPIC_0000001811490361__b04091951205315">2019-09-10 15:35:00</strong> on all CNs. For each CN, a maximum of 10 queries will be returned.</li></ul>
|
|
<div class="codecoloring" codetype="Sql" id="EN-US_TOPIC_0000001811490361__screen55034215311"><div class="highlight"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><span class="normal">1</span></pre></div></td><td class="code"><div><pre><span></span><span class="k">SELECT</span><span class="w"> </span><span class="o">*</span><span class="w"> </span><span class="k">FROM</span><span class="w"> </span><span class="n">pgxc_get_wlm_session_info_bytime</span><span class="p">(</span><span class="s1">'start_time'</span><span class="p">,</span><span class="w"> </span><span class="s1">'2019-09-10 15:30:00'</span><span class="p">,</span><span class="w"> </span><span class="s1">'2019-09-10 15:35:00'</span><span class="p">,</span><span class="w"> </span><span class="mi">10</span><span class="p">);</span>
|
|
</pre></div></td></tr></table></div>
|
|
</div>
|
|
<ul id="EN-US_TOPIC_0000001811490361__ul6535142964510"><li id="EN-US_TOPIC_0000001811490361__li1535529194515">Return the queries ended between <strong id="EN-US_TOPIC_0000001811490361__b4772132314586">2019-09-10 15:30:00</strong> and <strong id="EN-US_TOPIC_0000001811490361__b8774132316588">2019-09-10 15:35:00</strong> on all CNs. For each CN, a maximum of 10 queries will be returned.</li></ul>
|
|
<div class="codecoloring" codetype="Sql" id="EN-US_TOPIC_0000001811490361__screen165800904518"><div class="highlight"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><span class="normal">1</span></pre></div></td><td class="code"><div><pre><span></span><span class="k">SELECT</span><span class="w"> </span><span class="o">*</span><span class="w"> </span><span class="k">FROM</span><span class="w"> </span><span class="n">pgxc_get_wlm_session_info_bytime</span><span class="p">(</span><span class="s1">'finish_time'</span><span class="p">,</span><span class="w"> </span><span class="s1">'2019-09-10 15:30:00'</span><span class="p">,</span><span class="w"> </span><span class="s1">'2019-09-10 15:35:00'</span><span class="p">,</span><span class="w"> </span><span class="mi">10</span><span class="p">);</span>
|
|
</pre></div></td></tr></table></div>
|
|
</div>
|
|
</p></li><li id="EN-US_TOPIC_0000001811490361__li1011051711292"><span>Query the recent resource information of the job operators on the current CN in the <strong id="EN-US_TOPIC_0000001811490361__b177612960162722">gs_wlm_operator_history</strong> view. Ensure that <a href="dws_04_0922.html#EN-US_TOPIC_0000001811490709__section153571329142612">resource_track_level</a> is set to <strong id="EN-US_TOPIC_0000001811490361__en-us_topic_0058967547_b8423527061695">operator</strong>.</span><p><div class="codecoloring" codetype="Sql" id="EN-US_TOPIC_0000001811490361__screen41101617172918"><div class="highlight"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><span class="normal">1</span></pre></div></td><td class="code"><div><pre><span></span><span class="k">SELECT</span><span class="w"> </span><span class="o">*</span><span class="w"> </span><span class="k">FROM</span><span class="w"> </span><span class="n">gs_wlm_operator_history</span><span class="p">;</span>
|
|
</pre></div></td></tr></table></div>
|
|
</div>
|
|
</p></li><li id="EN-US_TOPIC_0000001811490361__li175856393329"><span>Query the recent resource information of the job operators on all the CNs in the <strong id="EN-US_TOPIC_0000001811490361__b62263438">pgxc_wlm_operator_history</strong> view. Ensure that <a href="dws_04_0922.html#EN-US_TOPIC_0000001811490709__section153571329142612">resource_track_level</a> is set to <strong id="EN-US_TOPIC_0000001811490361__b1479887662">operator</strong>.</span><p><div class="codecoloring" codetype="Sql" id="EN-US_TOPIC_0000001811490361__screen11586143918322"><div class="highlight"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><span class="normal">1</span></pre></div></td><td class="code"><div><pre><span></span><span class="k">SELECT</span><span class="w"> </span><span class="o">*</span><span class="w"> </span><span class="k">FROM</span><span class="w"> </span><span class="n">pgxc_wlm_operator_history</span><span class="p">;</span>
|
|
</pre></div></td></tr></table></div>
|
|
</div>
|
|
</p></li><li id="EN-US_TOPIC_0000001811490361__li10817527102115"><span>Query the recent resource information of the job operators on the current CN in the <strong id="EN-US_TOPIC_0000001811490361__b842352706165733">gs_wlm_operator_info</strong> view. Ensure that <a href="dws_04_0922.html#EN-US_TOPIC_0000001811490709__section153571329142612">resource_track_level</a> is set to <strong id="EN-US_TOPIC_0000001811490361__b154521184235">operator</strong> and <a href="dws_04_0922.html#EN-US_TOPIC_0000001811490709__s5f116e109a2944e3854abcc56772eaa1">enable_resource_record</a> to <strong id="EN-US_TOPIC_0000001811490361__b145418872317">on</strong>.</span><p><div class="codecoloring" codetype="Sql" id="EN-US_TOPIC_0000001811490361__screen681815271213"><div class="highlight"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><span class="normal">1</span></pre></div></td><td class="code"><div><pre><span></span><span class="k">SELECT</span><span class="w"> </span><span class="o">*</span><span class="w"> </span><span class="k">FROM</span><span class="w"> </span><span class="n">gs_wlm_operator_info</span><span class="p">;</span>
|
|
</pre></div></td></tr></table></div>
|
|
</div>
|
|
</p></li><li id="EN-US_TOPIC_0000001811490361__li48211027102110"><span>Query for the historical resource information of job operators on all the CNs in the <strong id="EN-US_TOPIC_0000001811490361__b11344144135219">pgxc_wlm_operator_info</strong> view. Ensure that <a href="dws_04_0922.html#EN-US_TOPIC_0000001811490709__section153571329142612">resource_track_level</a> is set to <strong id="EN-US_TOPIC_0000001811490361__b175911464232">operator</strong> and <a href="dws_04_0922.html#EN-US_TOPIC_0000001811490709__s5f116e109a2944e3854abcc56772eaa1">enable_resource_record</a> to <strong id="EN-US_TOPIC_0000001811490361__b5597467234">on</strong>.</span><p><div class="codecoloring" codetype="Sql" id="EN-US_TOPIC_0000001811490361__screen10821327162116"><div class="highlight"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><span class="normal">1</span></pre></div></td><td class="code"><div><pre><span></span><span class="k">SELECT</span><span class="w"> </span><span class="o">*</span><span class="w"> </span><span class="k">FROM</span><span class="w"> </span><span class="n">pgxc_wlm_operator_info</span><span class="p">;</span>
|
|
</pre></div></td></tr></table></div>
|
|
</div>
|
|
</p></li></ol>
|
|
<div class="note" id="EN-US_TOPIC_0000001811490361__note1514925216314"><img src="public_sys-resources/note_3.0-en-us.png"><span class="notetitle"> </span><div class="notebody"><ul id="EN-US_TOPIC_0000001811490361__ul2515175332318"><li id="EN-US_TOPIC_0000001811490361__li1515653202314">The number of data records that can be retained in the memory is limited due to the preset memory limit. After the real-time query is complete, the data records are imported to historical views. For a query-level view, when the number of queries to be recorded exceeds the upper limit allowed by the memory, the current query cannot be recorded and the next query is performed based on a new rule. On each CN, the memory usage of the query-level historical view is recorded (100 MB by default). You can query the data in the <a href="dws_04_0788.html">PG_TOTAL_MEMORY_DETAIL</a> view.</li><li id="EN-US_TOPIC_0000001811490361__li114068515249">For operator-level views, whether a record can be stored depends on the upper limit allowed by the memory at that time point. If the number of plan nodes plus the number of records in the memory exceeds the upper limit, the record cannot be stored. On each CN, the maximum numbers of real-time and historical operator-level records that can be stored in the memory are <strong id="EN-US_TOPIC_0000001811490361__b14991046113020">max_oper_realt_num</strong> (set to <strong id="EN-US_TOPIC_0000001811490361__b7995469306">56987</strong> by default) and <strong id="EN-US_TOPIC_0000001811490361__b49918462307">max_oper_hist_num</strong> (set to <strong id="EN-US_TOPIC_0000001811490361__b09915467307">113975</strong> by default), respectively. The average number of plan nodes of a query is <strong id="EN-US_TOPIC_0000001811490361__b8994462305">num_plan_node</strong>. Maximum number of concurrent tasks allowed by real-time views on each CN is: <strong id="EN-US_TOPIC_0000001811490361__b29954653016">num_realt_active</strong> = <strong id="EN-US_TOPIC_0000001811490361__b199204611306">max_oper_realt_num</strong>/<strong id="EN-US_TOPIC_0000001811490361__b810015469301">num_plan_node</strong>. Maximum number of concurrent tasks allowed by historical views on each CN is: <strong id="EN-US_TOPIC_0000001811490361__b7100164610302">num_hist_active</strong> = <strong id="EN-US_TOPIC_0000001811490361__b310034615301">max_oper_hist_num</strong>/(<strong id="EN-US_TOPIC_0000001811490361__b51001346203011">180</strong>/<strong id="EN-US_TOPIC_0000001811490361__b7100174615306">run_time</strong>)/<strong id="EN-US_TOPIC_0000001811490361__b31007469304">num_plan_node</strong>.</li><li id="EN-US_TOPIC_0000001811490361__li4607911142919">In high concurrency, ensure that the number of queries to be recorded does not exceed the maximum values set for query- and operator-level views. You can modify the memory of the historical query view by configuring the <a href="dws_04_0922.html#EN-US_TOPIC_0000001811490709__section27306369458">session_history_memory</a> parameter. The memory size increases in direct proportion to the maximum number of queries that can be recorded.</li></ul>
|
|
</div></div>
|
|
</div>
|
|
</div>
|
|
<div>
|
|
<div class="familylinks">
|
|
<div class="parentlink"><strong>Parent topic:</strong> <a href="dws_04_0393.html">GaussDB(DWS) Resource Monitoring</a></div>
|
|
</div>
|
|
</div>
|
|
|