forked from docs/doc-exports
Reviewed-by: Pruthi, Vineet <vineet.pruthi@t-systems.com> Reviewed-by: Rechenburg, Matthias <matthias.rechenburg@t-systems.com> Co-authored-by: Lu, Huayi <luhuayi@huawei.com> Co-committed-by: Lu, Huayi <luhuayi@huawei.com>
86 lines
12 KiB
HTML
86 lines
12 KiB
HTML
<a name="EN-US_TOPIC_0000001330488844"></a><a name="EN-US_TOPIC_0000001330488844"></a>
|
|
|
|
<h1 class="topictitle1">Do I Need to Run VACUUM FULL and ANALYZE on Common Tables Periodically?</h1>
|
|
<div id="body0000001330488844"><p id="EN-US_TOPIC_0000001330488844__p148521618105418">Yes.</p>
|
|
<p id="EN-US_TOPIC_0000001330488844__en-us_topic_0000001145816511_p99751926195117">For tables that are frequently added, deleted, or modified, you need to periodically perform <strong id="EN-US_TOPIC_0000001330488844__b1161010341426">VACUUM FULL</strong> and <strong id="EN-US_TOPIC_0000001330488844__b14671163611424">ANALYZE </strong>to reclaim the disk space occupied by updated or deleted data, preventing performance deterioration caused by data bloat and inaccurate statistics.</p>
|
|
<ul id="EN-US_TOPIC_0000001330488844__ul1173012427454"><li id="EN-US_TOPIC_0000001330488844__li9731242204510">Generally, you are advised to perform <strong id="EN-US_TOPIC_0000001330488844__b12824319439">ANALYZE</strong> after a large number of <strong id="EN-US_TOPIC_0000001330488844__b1571011450431">adding or modification</strong> operations are performed on a table.</li><li id="EN-US_TOPIC_0000001330488844__li673104214456">After a table is deleted, you are advised to run <strong id="EN-US_TOPIC_0000001330488844__b10551121134412">VACUUM</strong> rather than <strong id="EN-US_TOPIC_0000001330488844__b5429140114512">VACUUM FULL</strong>. However, you can run <strong id="EN-US_TOPIC_0000001330488844__b156541622124518">VACUUM FULL</strong> in some particular cases, such as when you want to physically narrow a table to decrease the occupied disk space after deleting most rows of the table. For details about the differences between <strong id="EN-US_TOPIC_0000001330488844__b14637165154612">VACUUM</strong> and <strong id="EN-US_TOPIC_0000001330488844__b16191093468">VACUUM FULL</strong>, see <a href="#EN-US_TOPIC_0000001330488844__section6930204215810">VACUUM and VACUUM FULL</a>.</li></ul>
|
|
<div class="section" id="EN-US_TOPIC_0000001330488844__en-us_topic_0000001145816511_section1865663735214"><h4 class="sectiontitle">Syntax</h4><p id="EN-US_TOPIC_0000001330488844__p6518133615412">Perform <strong id="EN-US_TOPIC_0000001330488844__b559021654618">ANALYZE</strong> on a table.</p>
|
|
<pre class="screen" id="EN-US_TOPIC_0000001330488844__screen081620115612">ANALYZE <em id="EN-US_TOPIC_0000001330488844__i6222183445718">table_name</em>;</pre>
|
|
<p id="EN-US_TOPIC_0000001330488844__p381122265510">Perform <strong id="EN-US_TOPIC_0000001330488844__b118648259467">ANALYZE</strong> on all tables (non-foreign tables) in the database.</p>
|
|
<pre class="screen" id="EN-US_TOPIC_0000001330488844__screen12901426105615">ANALYZE;</pre>
|
|
<p id="EN-US_TOPIC_0000001330488844__p113654717553">Perform <strong id="EN-US_TOPIC_0000001330488844__b7836031154615">VACUUM</strong> on a table.</p>
|
|
<pre class="screen" id="EN-US_TOPIC_0000001330488844__screen1644573618569">VACUUM <em id="EN-US_TOPIC_0000001330488844__i1121525175718">table_name</em>;</pre>
|
|
<p id="EN-US_TOPIC_0000001330488844__p79046102575">Perform <strong id="EN-US_TOPIC_0000001330488844__b15673193584614">VACUUM FULL</strong> on a table.</p>
|
|
<pre class="screen" id="EN-US_TOPIC_0000001330488844__screen1750125618556">VACUUM FULL <em id="EN-US_TOPIC_0000001330488844__i726144945717">table_name</em>;</pre>
|
|
<p id="EN-US_TOPIC_0000001330488844__en-us_topic_0000001145816511_p98619201484">For details, see sections "VACUUM" and "ANALYZE | ANALYSE" in the <em id="EN-US_TOPIC_0000001330488844__i61294906394111">Developer Guide</em>.</p>
|
|
<div class="note" id="EN-US_TOPIC_0000001330488844__en-us_topic_0000001145816511_note548518259111"><img src="public_sys-resources/note_3.0-en-us.png"><span class="notetitle"> </span><div class="notebody"><ul id="EN-US_TOPIC_0000001330488844__ul8406258114710"><li id="EN-US_TOPIC_0000001330488844__li1340614581472">If the physical space usage does not decrease after you run the <strong id="EN-US_TOPIC_0000001330488844__b44032246994111">VACUUM FULL</strong> command, check whether there were other active transactions (started before you delete data transactions and not ended before you run <strong id="EN-US_TOPIC_0000001330488844__b147560510494111">VACUUM FULL</strong>). If yes, run this command again when the transactions have finished.</li><li id="EN-US_TOPIC_0000001330488844__li154061958124716">In version 8.1.3 or later, <strong id="EN-US_TOPIC_0000001330488844__b134751747142213">VACUUM</strong>/<strong id="EN-US_TOPIC_0000001330488844__b144345016220">VACUUM FULL</strong> can be invoked on the management plane. For details, see "Intelligent O&M" in the <em id="EN-US_TOPIC_0000001330488844__i17191104814290">Data Warehouse Service (DWS) User Guide</em>.</li></ul>
|
|
</div></div>
|
|
</div>
|
|
<div class="section" id="EN-US_TOPIC_0000001330488844__section6930204215810"><a name="EN-US_TOPIC_0000001330488844__section6930204215810"></a><a name="section6930204215810"></a><h4 class="sectiontitle">VACUUM and VACUUM FULL</h4><p id="EN-US_TOPIC_0000001330488844__p1531563518183">In GaussDB(DWS), the <strong id="EN-US_TOPIC_0000001330488844__b9736183304810">VACUUM</strong> operation is like a vacuum cleaner used to absorb dust. Here, "dust" means old data. If the data is not cleared in a timely manner, more database space will be used to store such data, causing performance downgrade or even a system breakdown.</p>
|
|
<p id="EN-US_TOPIC_0000001330488844__p5542855201119">Purposes of VACUUM:</p>
|
|
<ul id="EN-US_TOPIC_0000001330488844__ul1778815423190"><li id="EN-US_TOPIC_0000001330488844__li117881242161914">Solve space bloat: Clear obsolete tuples and corresponding indexes, which include the tuple (and index) of a committed <strong id="EN-US_TOPIC_0000001330488844__b13126747718">DELETE</strong> transaction, the old version (and index) of an <strong id="EN-US_TOPIC_0000001330488844__b149584381110">UPDATE</strong> transaction, the inserted tuple (and index) of a rolled back <strong id="EN-US_TOPIC_0000001330488844__b86571394612">INSERT</strong> transaction, the new version (and index) of an <strong id="EN-US_TOPIC_0000001330488844__b1837218111376">UPDATE</strong> transaction, and the tuple (and index) of a <strong id="EN-US_TOPIC_0000001330488844__b125071639777">COPY</strong> transaction.</li><li id="EN-US_TOPIC_0000001330488844__li127883428191">VACUUM FREEZE: Prevents system breakdown caused by transaction ID wraparound. It converts transaction IDs smaller than OldestXmin to freeze xids, update relfrozenxids in a table, and update relfrozenxids and truncate clogs in a database.</li><li id="EN-US_TOPIC_0000001330488844__li1378813423193">Update statistics: <strong id="EN-US_TOPIC_0000001330488844__b1244619221153">VACUUM ANALYZE</strong> updates statistics, enabling the optimizer to select a better way to execute SQL statements.</li></ul>
|
|
<p id="EN-US_TOPIC_0000001330488844__p2083994815519">The VACUUM statement includes <strong id="EN-US_TOPIC_0000001330488844__b1197195192316">VACUUM</strong> and <strong id="EN-US_TOPIC_0000001330488844__b457920882313">VACUUM FULL</strong>. Currently, <strong id="EN-US_TOPIC_0000001330488844__b5810714132518">VACUUM</strong> can only work on row-store tables. <strong id="EN-US_TOPIC_0000001330488844__b816411062614">VACUUM FULL</strong> can be used to release space of column-store tables. For details, see the following table.</p>
|
|
|
|
<div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" id="EN-US_TOPIC_0000001330488844__table1933020321620" frame="border" border="1" rules="all"><caption><b>Table 1 </b>VACUUM and VACUUM FULL</caption><thead align="left"><tr id="EN-US_TOPIC_0000001330488844__row1633112321126"><th align="left" class="cellrowborder" valign="top" width="15%" id="mcps1.3.5.6.2.4.1.1"><p id="EN-US_TOPIC_0000001330488844__p6331032026">Item</p>
|
|
</th>
|
|
<th align="left" class="cellrowborder" valign="top" width="40%" id="mcps1.3.5.6.2.4.1.2"><p id="EN-US_TOPIC_0000001330488844__p133314324212">VACUUM</p>
|
|
</th>
|
|
<th align="left" class="cellrowborder" valign="top" width="45%" id="mcps1.3.5.6.2.4.1.3"><p id="EN-US_TOPIC_0000001330488844__p8727105615411">VACUUM FULL</p>
|
|
</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody><tr id="EN-US_TOPIC_0000001330488844__row15331432125"><td class="cellrowborder" valign="top" width="15%" headers="mcps1.3.5.6.2.4.1.1 "><p id="EN-US_TOPIC_0000001330488844__p149736526210">Clearing space</p>
|
|
</td>
|
|
<td class="cellrowborder" valign="top" width="40%" headers="mcps1.3.5.6.2.4.1.2 "><p id="EN-US_TOPIC_0000001330488844__p18380417410">If the deleted record is at the end of a table, the space occupied by the deleted record is physically released and returned to the operating system. If the data is not at the end of a table, the space occupied by dead tuples in the table or index is set to be available for reuse.</p>
|
|
</td>
|
|
<td class="cellrowborder" valign="top" width="45%" headers="mcps1.3.5.6.2.4.1.3 "><p id="EN-US_TOPIC_0000001330488844__p1333219326210">Despite the position of the deleted data, the space occupied by the data is physically released and returned to the operating system. When data is inserted, a new disk page is allocated.</p>
|
|
</td>
|
|
</tr>
|
|
<tr id="EN-US_TOPIC_0000001330488844__row433253213216"><td class="cellrowborder" valign="top" width="15%" headers="mcps1.3.5.6.2.4.1.1 "><p id="EN-US_TOPIC_0000001330488844__p20332932621">Lock type</p>
|
|
</td>
|
|
<td class="cellrowborder" valign="top" width="40%" headers="mcps1.3.5.6.2.4.1.2 "><p id="EN-US_TOPIC_0000001330488844__p463312326517">Shared lock. The <strong id="EN-US_TOPIC_0000001330488844__b1489011863712">VACUUM</strong> operation can be performed in parallel with other operations.</p>
|
|
</td>
|
|
<td class="cellrowborder" valign="top" width="45%" headers="mcps1.3.5.6.2.4.1.3 "><p id="EN-US_TOPIC_0000001330488844__p93324321224">Exclusive lock. All operations based on the table are suspended during execution.</p>
|
|
</td>
|
|
</tr>
|
|
<tr id="EN-US_TOPIC_0000001330488844__row13332532226"><td class="cellrowborder" valign="top" width="15%" headers="mcps1.3.5.6.2.4.1.1 "><p id="EN-US_TOPIC_0000001330488844__p2332132821">Physical space</p>
|
|
</td>
|
|
<td class="cellrowborder" valign="top" width="40%" headers="mcps1.3.5.6.2.4.1.2 "><p id="EN-US_TOPIC_0000001330488844__p145014551353">Not released</p>
|
|
</td>
|
|
<td class="cellrowborder" valign="top" width="45%" headers="mcps1.3.5.6.2.4.1.3 "><p id="EN-US_TOPIC_0000001330488844__p185016555516">Released</p>
|
|
</td>
|
|
</tr>
|
|
<tr id="EN-US_TOPIC_0000001330488844__row183322321522"><td class="cellrowborder" valign="top" width="15%" headers="mcps1.3.5.6.2.4.1.1 "><p id="EN-US_TOPIC_0000001330488844__p4332193211218">Transaction ID</p>
|
|
</td>
|
|
<td class="cellrowborder" valign="top" width="40%" headers="mcps1.3.5.6.2.4.1.2 "><p id="EN-US_TOPIC_0000001330488844__p1633311322219">Not reclaimed</p>
|
|
</td>
|
|
<td class="cellrowborder" valign="top" width="45%" headers="mcps1.3.5.6.2.4.1.3 "><p id="EN-US_TOPIC_0000001330488844__p4333113216219">Reclaimed</p>
|
|
</td>
|
|
</tr>
|
|
<tr id="EN-US_TOPIC_0000001330488844__row183331732829"><td class="cellrowborder" valign="top" width="15%" headers="mcps1.3.5.6.2.4.1.1 "><p id="EN-US_TOPIC_0000001330488844__p14333133214213">Execution overhead</p>
|
|
</td>
|
|
<td class="cellrowborder" valign="top" width="40%" headers="mcps1.3.5.6.2.4.1.2 "><p id="EN-US_TOPIC_0000001330488844__p063416390613">The overhead is low and the operation can be executed periodically.</p>
|
|
<p id="EN-US_TOPIC_0000001330488844__p1563418391565"></p>
|
|
</td>
|
|
<td class="cellrowborder" valign="top" width="45%" headers="mcps1.3.5.6.2.4.1.3 "><p id="EN-US_TOPIC_0000001330488844__p1333313321215">The overhead is high. You are advised to perform it when the disk page space occupied by the database is close to the threshold and the data operations are few.</p>
|
|
</td>
|
|
</tr>
|
|
<tr id="EN-US_TOPIC_0000001330488844__row165015401734"><td class="cellrowborder" valign="top" width="15%" headers="mcps1.3.5.6.2.4.1.1 "><p id="EN-US_TOPIC_0000001330488844__p45117402318">Effect</p>
|
|
</td>
|
|
<td class="cellrowborder" valign="top" width="40%" headers="mcps1.3.5.6.2.4.1.2 "><p id="EN-US_TOPIC_0000001330488844__p08231233191010">It improves the efficiency of operations on the table.</p>
|
|
</td>
|
|
<td class="cellrowborder" valign="top" width="45%" headers="mcps1.3.5.6.2.4.1.3 "><p id="EN-US_TOPIC_0000001330488844__p1182483371016">It greatly improves the efficiency of operations on the table.</p>
|
|
</td>
|
|
</tr>
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<div>
|
|
<div class="familylinks">
|
|
<div class="parentlink"><strong>Parent topic:</strong> <a href="dws_03_0065.html">Database Usage</a></div>
|
|
</div>
|
|
</div>
|
|
|