doc-exports/docs/dws/dev/dws_04_0190.html
Lu, Huayi e6fa411af0 DWS DEV 830.201 version
Reviewed-by: Pruthi, Vineet <vineet.pruthi@t-systems.com>
Co-authored-by: Lu, Huayi <luhuayi@huawei.com>
Co-committed-by: Lu, Huayi <luhuayi@huawei.com>
2024-05-16 07:24:04 +00:00

86 lines
15 KiB
HTML

<a name="EN-US_TOPIC_0000001233883381"></a><a name="EN-US_TOPIC_0000001233883381"></a>
<h1 class="topictitle1">Importing Data In Parallel Using GDS</h1>
<div id="body8662426"><p id="EN-US_TOPIC_0000001233883381__p14591548175315"><strong id="EN-US_TOPIC_0000001233883381__b42744915911">INSERT</strong> and <strong id="EN-US_TOPIC_0000001233883381__b82719493915">COPY</strong> statements can be used only for serially importing a small volume of data. To import a large volume of data to <span id="EN-US_TOPIC_0000001233883381__text445408939">GaussDB(DWS)</span>, you can use GDS to import data in parallel using a foreign table.</p>
<p id="EN-US_TOPIC_0000001233883381__p877219818236">In the current GDS version, you can import data to databases from pipe files.</p>
<ul id="EN-US_TOPIC_0000001233883381__ul1773711507206"><li id="EN-US_TOPIC_0000001233883381__li1743110228237">When the local disk space of the GDS user is insufficient, HDFS data can be directly written to the pipe file without occupying extra disk space.</li><li id="EN-US_TOPIC_0000001233883381__li1260010253232">To clean data before importing, you can compile a program as needed and write the data to be processed into a pipe file.<div class="note" id="EN-US_TOPIC_0000001233883381__note659914514569"><img src="public_sys-resources/note_3.0-en-us.png"><span class="notetitle"> </span><div class="notebody"><ul id="EN-US_TOPIC_0000001233883381__ul2058214284424"><li id="EN-US_TOPIC_0000001233883381__li65827285425">The current version does not support data import through GDS in SSL mode. Do not use GDS in SSL mode.</li><li id="EN-US_TOPIC_0000001233883381__li1458214286429">All pipe files mentioned in this section refer to named pipes on Linux.</li><li id="EN-US_TOPIC_0000001233883381__li518213813216">To ensure the correctness of data import or export using GDS, you need to import or export data in the same compatibility mode.<p id="EN-US_TOPIC_0000001233883381__p151351740163216"><a name="EN-US_TOPIC_0000001233883381__li518213813216"></a><a name="li518213813216"></a>For example, data imported or exported in MySQL compatibility mode can be exported or imported only in MySQL compatibility mode.</p>
</li></ul>
</div></div>
</li></ul>
<div class="section" id="EN-US_TOPIC_0000001233883381__s613b6bcff6ac43fd90c59471ce1385cb"><h4 class="sectiontitle">Overview</h4><p id="EN-US_TOPIC_0000001233883381__p1358114671311">You can import data in parallel from the common file system (excluding HDFS) of a server to <span id="EN-US_TOPIC_0000001233883381__text87605763">GaussDB(DWS)</span>.</p>
<p id="EN-US_TOPIC_0000001233883381__p672331315551">Data files to be imported are specified based on the import policy and data formats set in a foreign table. Data is imported in parallel through multiple DNs from source data files to the database, which improves the overall data import performance. <a href="#EN-US_TOPIC_0000001233883381__fc07608abaf6e4b509fbbfe774a8a548e">Figure 1</a> shows an example.</p>
<ul id="EN-US_TOPIC_0000001233883381__ul318614117330"><li id="EN-US_TOPIC_0000001233883381__ld944543d06794b2da1760ac5d107aebe">The CN only plans data import tasks and delivers the tasks to DNs. In this case, the CN is released to process other tasks.</li><li id="EN-US_TOPIC_0000001233883381__en-us_topic_0085031681_li52315236312">In this way, the computing capacities and bandwidths of all the DNs are fully leveraged to import data, improving the import performance.</li></ul>
<div class="p" id="EN-US_TOPIC_0000001233883381__p369661452718">You can pre-process data (such as invalid character replacement and fault tolerance processing) by setting parameters in a foreign table.<div class="fignone" id="EN-US_TOPIC_0000001233883381__fc07608abaf6e4b509fbbfe774a8a548e"><a name="EN-US_TOPIC_0000001233883381__fc07608abaf6e4b509fbbfe774a8a548e"></a><a name="fc07608abaf6e4b509fbbfe774a8a548e"></a><span class="figcap"><b>Figure 1 </b>Importing data in parallel</span><br><span><img id="EN-US_TOPIC_0000001233883381__image821584871717" src="figure/en-us_image_0000001799299941.png"></span></div>
</div>
<p id="EN-US_TOPIC_0000001233883381__p116415554912">The concepts mentioned in the preceding figure are described as follows:</p>
<ul id="EN-US_TOPIC_0000001233883381__ul245452019502"><li id="EN-US_TOPIC_0000001233883381__li204541120145012"><strong id="EN-US_TOPIC_0000001233883381__b971674618817">CN</strong>: coordinator of <span id="EN-US_TOPIC_0000001233883381__text1089491752">GaussDB(DWS)</span>. After receiving import SQL requests from an application or client, the CN plans import tasks and delivers the tasks to DNs.</li><li id="EN-US_TOPIC_0000001233883381__li4694144382510"><strong id="EN-US_TOPIC_0000001233883381__b43231732153310">DN (Datanode)</strong>: data node of <span id="EN-US_TOPIC_0000001233883381__text1040010907">GaussDB(DWS)</span>. After receiving the import tasks delivered by the CN, DNs import data from the source data file to the target table in the database through a foreign table.</li><li id="EN-US_TOPIC_0000001233883381__li1547012012506"><strong id="EN-US_TOPIC_0000001233883381__b1838372143515">Source data file</strong>: a file that stores data to be imported.</li><li id="EN-US_TOPIC_0000001233883381__li14508171292716"><strong id="EN-US_TOPIC_0000001233883381__en-us_topic_0117407668_a71a5ece9269e4f94af8e3e38ee110ec2">Data server</strong>: a server that stores source data files. For security purposes, it is recommended that the data server and <span id="EN-US_TOPIC_0000001233883381__text555682266">GaussDB(DWS)</span> be on the same intranet.</li><li id="EN-US_TOPIC_0000001233883381__li1845416205506"><strong id="EN-US_TOPIC_0000001233883381__b207767585146">Foreign table</strong>: a table that stores information, such as the source location, format, destination location, encoding format, and data delimiter of a source data file. It is used to associate source data files with the target table.</li><li id="EN-US_TOPIC_0000001233883381__li3691339162510"><strong id="EN-US_TOPIC_0000001233883381__b17912224151310">Target table</strong>: a table in the database. It can be a row-store table or column-store table. Data in the source data files will be imported to this table.</li></ul>
</div>
<div class="section" id="EN-US_TOPIC_0000001233883381__section112845417375"><h4 class="sectiontitle">Parallel Import Using GDS</h4><ul id="EN-US_TOPIC_0000001233883381__ul12456145312357"><li id="EN-US_TOPIC_0000001233883381__li1145625311358">If a large volume of data is stored on multiple servers, deploy, configure, and start GDS on each server. Then, data on all the servers can be imported in parallel, as shown in <a href="#EN-US_TOPIC_0000001233883381__fig208886410250">Figure 2</a>.<div class="fignone" id="EN-US_TOPIC_0000001233883381__fig208886410250"><a name="EN-US_TOPIC_0000001233883381__fig208886410250"></a><a name="fig208886410250"></a><span class="figcap"><b>Figure 2 </b>Parallel import from multiple data servers</span><br><span><img class="vsd" id="EN-US_TOPIC_0000001233883381__image7717811181817" src="figure/en-us_image_0000001188163822.png"></span></div>
<div class="notice" id="EN-US_TOPIC_0000001233883381__n09b4ca4060cc455abcfbd4fc9d7f401c"><span class="noticetitle"><img src="public_sys-resources/notice_3.0-en-us.png"> </span><div class="noticebody"><p id="EN-US_TOPIC_0000001233883381__p337117135415">The number of GDS processes cannot exceed that of DNs. If multiple GDS processes are connected to one DN, some of the processes will probably become abnormal.</p>
</div></div>
</li><li id="EN-US_TOPIC_0000001233883381__li134563536356">If data is stored on data servers, and both <span id="EN-US_TOPIC_0000001233883381__text816071258">GaussDB(DWS)</span> and the data servers have available I/O resources, you can use GDS for multi-thread concurrent import.<p id="EN-US_TOPIC_0000001233883381__p593795312384">GDS determines the number of threads based on the number of concurrent import transactions. Even if multi-thread import is configured before GDS startup, the import of a single transaction will not be accelerated. By default, an <strong id="EN-US_TOPIC_0000001233883381__b14914115805116">INSERT</strong> statement is an import transaction.</p>
</li></ul>
<div class="p" id="EN-US_TOPIC_0000001233883381__p21808072413">Multi-thread concurrent import enables you to:<ul id="EN-US_TOPIC_0000001233883381__ul13844357142310"><li id="EN-US_TOPIC_0000001233883381__li138441857132317">Fully use resources and improve the concurrent import efficiency when you import multiple tables to the database.</li><li id="EN-US_TOPIC_0000001233883381__li188441657152315">Speed up the import of a table with a large volume of data.<p id="EN-US_TOPIC_0000001233883381__p2084415574237"><a name="EN-US_TOPIC_0000001233883381__li188441657152315"></a><a name="li188441657152315"></a>Table data is split into multiple data files, and multi-thread concurrent import is implemented by importing data using multiple foreign tables at the same time. Ensure that a data file can be read only by one foreign table.</p>
</li></ul>
</div>
</div>
<div class="section" id="EN-US_TOPIC_0000001233883381__sc6930ad8b9174c1494c30576cd8a0aec"><h4 class="sectiontitle">Import Process</h4><div class="fignone" id="EN-US_TOPIC_0000001233883381__f532a0a73f91f474789e53b856d4b6411"><span class="figcap"><b>Figure 3 </b>Concurrent import procedure of GDS</span><br><span><img class="vsd" id="EN-US_TOPIC_0000001233883381__ib5bdd9927ce74663ad08b8bb4928366b" src="figure/en-us_image_0000001188482352.png"></span></div>
<div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" id="EN-US_TOPIC_0000001233883381__t121408f06a794a468a720e71bbfadbfa" frame="border" border="1" rules="all"><caption><b>Table 1 </b>Process description</caption><thead align="left"><tr id="EN-US_TOPIC_0000001233883381__rd0a76376a163440dbbf4facbdbd1de52"><th align="left" class="cellrowborder" valign="top" width="21%" id="mcps1.3.6.3.2.3.1.1"><p id="EN-US_TOPIC_0000001233883381__ad28977dc3c014a49a0b79e1c35a0a454">Procedure</p>
</th>
<th align="left" class="cellrowborder" valign="top" width="79%" id="mcps1.3.6.3.2.3.1.2"><p id="EN-US_TOPIC_0000001233883381__a8dd67e66796e454891ed4a3be7b4e4de">Description</p>
</th>
</tr>
</thead>
<tbody><tr id="EN-US_TOPIC_0000001233883381__rb34472e732fd4860aa8237f11f08d0da"><td class="cellrowborder" valign="top" width="21%" headers="mcps1.3.6.3.2.3.1.1 "><p id="EN-US_TOPIC_0000001233883381__aa58fa7b828b946d4a052cca7cd9e8327">Prepare source data.</p>
</td>
<td class="cellrowborder" valign="top" width="79%" headers="mcps1.3.6.3.2.3.1.2 "><p id="EN-US_TOPIC_0000001233883381__a3f95c86bd74b4557896053e11f293df5">Prepare the source data files to be imported to the database and upload the files to the data server.</p>
<p id="EN-US_TOPIC_0000001233883381__a0b6d8dc99c8f40b997faaf390335fc7d">For details, see <a href="dws_04_0192.html">Preparing Source Data</a>.</p>
</td>
</tr>
<tr id="EN-US_TOPIC_0000001233883381__r3f9c9c16abf94615a6e394303a269ce8"><td class="cellrowborder" valign="top" width="21%" headers="mcps1.3.6.3.2.3.1.1 "><p id="EN-US_TOPIC_0000001233883381__en-us_topic_0117407659_p898372992419">Start GDS.</p>
</td>
<td class="cellrowborder" valign="top" width="79%" headers="mcps1.3.6.3.2.3.1.2 "><p id="EN-US_TOPIC_0000001233883381__a426509d949c74f2a890abc5153c4b9b0">Install, configure, and enable GDS on the data server.</p>
<p id="EN-US_TOPIC_0000001233883381__a6bfdf0b7f0fb43028d84b7b11cbe7da4">For details, see <a href="dws_04_0193.html">Installing, Configuring, and Starting GDS</a>.</p>
</td>
</tr>
<tr id="EN-US_TOPIC_0000001233883381__r3c02acb999c842e29c4e2f0fc4475d5d"><td class="cellrowborder" valign="top" width="21%" headers="mcps1.3.6.3.2.3.1.1 "><p id="EN-US_TOPIC_0000001233883381__adbf12c198b044dc9aa6fad2bc3b34851">Create a foreign table.</p>
</td>
<td class="cellrowborder" valign="top" width="79%" headers="mcps1.3.6.3.2.3.1.2 "><p id="EN-US_TOPIC_0000001233883381__ae8b9fcaae7a44ed387d8a60a843a21f0">A foreign table is used to identify source files. The foreign table stores information, such as the source location, format, destination location, encoding format, and inter-data delimiter of a source data file.</p>
<p id="EN-US_TOPIC_0000001233883381__aab33fd7490064dfdaf6309a0ece547a3">For details, see <a href="dws_04_0194.html">Creating a GDS Foreign Table</a>.</p>
</td>
</tr>
<tr id="EN-US_TOPIC_0000001233883381__rce72db3e8abf462bb465879efa54ea57"><td class="cellrowborder" valign="top" width="21%" headers="mcps1.3.6.3.2.3.1.1 "><p id="EN-US_TOPIC_0000001233883381__a50f6120ccd4e4015ac3aa8d07c576c4d">Import data.</p>
</td>
<td class="cellrowborder" valign="top" width="79%" headers="mcps1.3.6.3.2.3.1.2 "><p id="EN-US_TOPIC_0000001233883381__ae482a8f3e78e4e30bff07c3983358b69">After creating the foreign table, run the <strong id="EN-US_TOPIC_0000001233883381__b842352706163840">INSERT</strong> statement to quickly import data to the target table. For details, see <a href="dws_04_0195.html">Importing Data</a>.</p>
</td>
</tr>
<tr id="EN-US_TOPIC_0000001233883381__re46272df86b847eea88b6aa99a9431fd"><td class="cellrowborder" valign="top" width="21%" headers="mcps1.3.6.3.2.3.1.1 "><p id="EN-US_TOPIC_0000001233883381__a26cc6738d3b34bc98fc4dc264641af87">Handle the error table.</p>
</td>
<td class="cellrowborder" valign="top" width="79%" headers="mcps1.3.6.3.2.3.1.2 "><p id="EN-US_TOPIC_0000001233883381__a5348668ef7a44bcea9ccc1a2ae34a50d">If errors occur during parallel data import, handle errors based on the error information to ensure data integrity.</p>
<p id="EN-US_TOPIC_0000001233883381__a80bbf913f4ea42369b62c7df7f761ca5">For details, see <a href="dws_04_0196.html">Handling Import Errors</a>.</p>
</td>
</tr>
<tr id="EN-US_TOPIC_0000001233883381__r69ad5674ec014a17bf117024ee19f287"><td class="cellrowborder" valign="top" width="21%" headers="mcps1.3.6.3.2.3.1.1 "><p id="EN-US_TOPIC_0000001233883381__a36cb2e568d724b22a80b7c206ee3ba07">Improve query efficiency.</p>
</td>
<td class="cellrowborder" valign="top" width="79%" headers="mcps1.3.6.3.2.3.1.2 "><p id="EN-US_TOPIC_0000001233883381__a44a8d6da836243f7a3c8f33cdcb53a02">After data is imported, run the <strong id="EN-US_TOPIC_0000001233883381__b84235270618957">ANALYZE</strong> statement to generate table statistics. The <strong id="EN-US_TOPIC_0000001233883381__b15633026326">ANALYZE</strong> statement stores the statistics in the <strong id="EN-US_TOPIC_0000001233883381__b17634628324">PG_STATISTIC</strong> system catalog. The execution plan generator uses the statistics to generate the most efficient query execution plan.</p>
</td>
</tr>
<tr id="EN-US_TOPIC_0000001233883381__re13f60434e1b44ab8ae8d5759c075e51"><td class="cellrowborder" valign="top" width="21%" headers="mcps1.3.6.3.2.3.1.1 "><p id="EN-US_TOPIC_0000001233883381__a3ee415a413cf4b968edfff0149fd5804">Stop GDS.</p>
</td>
<td class="cellrowborder" valign="top" width="79%" headers="mcps1.3.6.3.2.3.1.2 "><p id="EN-US_TOPIC_0000001233883381__a04e73b8467104de383a92b36fea96904">After data import is complete, log in to each data server and stop GDS.</p>
<p id="EN-US_TOPIC_0000001233883381__a75a764020044430181444e153852a77b">For details, see <a href="dws_04_0197.html">Stopping GDS</a>.</p>
</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
<div>
<div class="familylinks">
<div class="parentlink"><strong>Parent topic:</strong> <a href="dws_04_0189.html">Using GDS to Import Data from a Remote Server</a></div>
</div>
</div>