doc-exports/docs/dws/dev/dws_04_0190.html
Lu, Huayi a24ca60074 DWS DEVELOPER 811 version
Reviewed-by: Hasko, Vladimir <vladimir.hasko@t-systems.com>
Co-authored-by: Lu, Huayi <luhuayi@huawei.com>
Co-committed-by: Lu, Huayi <luhuayi@huawei.com>
2023-01-19 13:37:49 +00:00

87 lines
15 KiB
HTML

<a name="EN-US_TOPIC_0000001099134954"></a><a name="EN-US_TOPIC_0000001099134954"></a>
<h1 class="topictitle1">Importing Data In Parallel Using GDS</h1>
<div id="body8662426"><p id="EN-US_TOPIC_0000001099134954__p14591548175315"><strong id="EN-US_TOPIC_0000001099134954__b42744915911">INSERT</strong> and <strong id="EN-US_TOPIC_0000001099134954__b82719493915">COPY</strong> statements are serially executed to import a small volume of data. To import a large volume of data to <span id="EN-US_TOPIC_0000001099134954__text445408939">GaussDB(DWS)</span>, you can use GDS to import data in parallel using a foreign table.</p>
<p id="EN-US_TOPIC_0000001099134954__p877219818236">In the current GDS version, you can import data to databases from pipe files.</p>
<ul id="EN-US_TOPIC_0000001099134954__ul1773711507206"><li id="EN-US_TOPIC_0000001099134954__li1743110228237">If the local disk space of the GDS user is insufficient:<ul id="EN-US_TOPIC_0000001099134954__ul2425112912316"><li id="EN-US_TOPIC_0000001099134954__li97371350132010">Data in HDFS can be directly written to a pipe file without occupying extra disk space.</li></ul>
</li><li id="EN-US_TOPIC_0000001099134954__li1260010253232">If you need to cleanse data before importing data:<ul id="EN-US_TOPIC_0000001099134954__ul1530984192310"><li id="EN-US_TOPIC_0000001099134954__li81881239152312">You can compile a program as needed and write the data to be processed into a pipe file.</li></ul>
<div class="note" id="EN-US_TOPIC_0000001099134954__note659914514569"><img src="public_sys-resources/note_3.0-en-us.png"><span class="notetitle"> </span><div class="notebody"><ul id="EN-US_TOPIC_0000001099134954__ul2058214284424"><li id="EN-US_TOPIC_0000001099134954__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_0000001099134954__li1458214286429">All pipe files mentioned in this section refer to named pipes on Linux.</li></ul>
</div></div>
</li></ul>
<div class="section" id="EN-US_TOPIC_0000001099134954__s613b6bcff6ac43fd90c59471ce1385cb"><h4 class="sectiontitle">Overview</h4><p id="EN-US_TOPIC_0000001099134954__p1358114671311">You can import data in parallel from the common file system (excluding HDFS) of a server to <span id="EN-US_TOPIC_0000001099134954__text87605763">GaussDB(DWS)</span>.</p>
<p id="EN-US_TOPIC_0000001099134954__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_0000001099134954__fc07608abaf6e4b509fbbfe774a8a548e">Figure 1</a> shows an example.</p>
<ul id="EN-US_TOPIC_0000001099134954__ul318614117330"><li id="EN-US_TOPIC_0000001099134954__ld944543d06794b2da1760ac5d107aebe">The CN only plans data import tasks and delivers the tasks to DNs. Then the CN is released to process other tasks.</li><li id="EN-US_TOPIC_0000001099134954__en-us_topic_0085031681_li52315236312">In this way, the computing capability and bandwidth of all the DNs are fully leveraged to improve the data import performance.</li></ul>
<div class="p" id="EN-US_TOPIC_0000001099134954__p369661452718">You can pre-process data, such as replacing invalid characters and processing fault tolerance, by configuring parameters in a foreign table.<div class="fignone" id="EN-US_TOPIC_0000001099134954__fc07608abaf6e4b509fbbfe774a8a548e"><a name="EN-US_TOPIC_0000001099134954__fc07608abaf6e4b509fbbfe774a8a548e"></a><a name="fc07608abaf6e4b509fbbfe774a8a548e"></a><span class="figcap"><b>Figure 1 </b>Importing data in parallel</span><br><span><img class="vsd" id="EN-US_TOPIC_0000001099134954__image1814001482219" src="figure/en-us_image_0000001099135208.png"></span></div>
</div>
<p id="EN-US_TOPIC_0000001099134954__p116415554912">The concepts mentioned in the preceding figure are described as follows:</p>
<ul id="EN-US_TOPIC_0000001099134954__ul245452019502"><li id="EN-US_TOPIC_0000001099134954__li204541120145012"><strong id="EN-US_TOPIC_0000001099134954__b971674618817">CN</strong>: Coordinator of <span id="EN-US_TOPIC_0000001099134954__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_0000001099134954__li4694144382510"><strong id="EN-US_TOPIC_0000001099134954__b43231732153310">DN</strong>: Datanode of <span id="EN-US_TOPIC_0000001099134954__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 using a foreign table.</li><li id="EN-US_TOPIC_0000001099134954__li1547012012506"><strong id="EN-US_TOPIC_0000001099134954__b1838372143515">Source data file</strong>: a file that stores data to be imported.</li><li id="EN-US_TOPIC_0000001099134954__li14508171292716"><strong id="EN-US_TOPIC_0000001099134954__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_0000001099134954__text555682266">GaussDB(DWS)</span> be on the same intranet.</li><li id="EN-US_TOPIC_0000001099134954__li1845416205506"><strong id="EN-US_TOPIC_0000001099134954__b207767585146">Foreign table</strong>: a table that stores information of a source data file, such as location, format, destination location, encoding format, and data delimiter. It is used to associate source data files with the target table.</li><li id="EN-US_TOPIC_0000001099134954__li3691339162510"><strong id="EN-US_TOPIC_0000001099134954__b1069871419439">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_0000001099134954__section112845417375"><h4 class="sectiontitle">Parallel Import Using GDS</h4><ul id="EN-US_TOPIC_0000001099134954__ul12456145312357"><li id="EN-US_TOPIC_0000001099134954__li1145625311358">If a large volume of data is stored on multiple servers, install, 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_0000001099134954__fig208886410250">Figure 2</a>.<div class="fignone" id="EN-US_TOPIC_0000001099134954__fig208886410250"><a name="EN-US_TOPIC_0000001099134954__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_0000001099134954__image7717811181817" src="figure/en-us_image_0000001098815222.png"></span></div>
<div class="notice" id="EN-US_TOPIC_0000001099134954__n09b4ca4060cc455abcfbd4fc9d7f401c"><span class="noticetitle"><img src="public_sys-resources/notice_3.0-en-us.png"> </span><div class="noticebody"><p id="EN-US_TOPIC_0000001099134954__p337117135415">The number of GDS processes cannot exceed that of DNs. If multiple GDS processes are connected to one DN, some of the processes may become abnormal.</p>
</div></div>
</li><li id="EN-US_TOPIC_0000001099134954__li134563536356">If data is stored on one data server and both <span id="EN-US_TOPIC_0000001099134954__text816071258">GaussDB(DWS)</span> and the data server have available I/O resources, you can use GDS for multi-thread concurrent import.<p id="EN-US_TOPIC_0000001099134954__p593795312384">GDS determines the number of threads based on the number of concurrent import transactions. That is, 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_0000001099134954__b14914115805116">INSERT</strong> statement is an import transaction.</p>
<p id="EN-US_TOPIC_0000001099134954__p11122193020019">Multi-thread concurrent import enables you to:</p>
<ul id="EN-US_TOPIC_0000001099134954__ul10778164417013"><li id="EN-US_TOPIC_0000001099134954__li5903400018">Fully use resources and improve the concurrent import efficiency when you import multiple tables to the database.</li><li id="EN-US_TOPIC_0000001099134954__li4874153651017">Speed up the import of a table with a large volume of data.<p id="EN-US_TOPIC_0000001099134954__p9608737201010"><a name="EN-US_TOPIC_0000001099134954__li4874153651017"></a><a name="li4874153651017"></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>
</li></ul>
</div>
<div class="section" id="EN-US_TOPIC_0000001099134954__sc6930ad8b9174c1494c30576cd8a0aec"><h4 class="sectiontitle">Import Process</h4><div class="fignone" id="EN-US_TOPIC_0000001099134954__f532a0a73f91f474789e53b856d4b6411"><span class="figcap"><b>Figure 3 </b>Concurrent import process using GDS</span><br><span><img class="vsd" id="EN-US_TOPIC_0000001099134954__ib5bdd9927ce74663ad08b8bb4928366b" src="figure/en-us_image_0000001145895199.png"></span></div>
<div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" id="EN-US_TOPIC_0000001099134954__t121408f06a794a468a720e71bbfadbfa" frame="border" border="1" rules="all"><caption><b>Table 1 </b>Process description</caption><thead align="left"><tr id="EN-US_TOPIC_0000001099134954__rd0a76376a163440dbbf4facbdbd1de52"><th align="left" class="cellrowborder" valign="top" width="21%" id="mcps1.3.6.3.2.3.1.1"><p id="EN-US_TOPIC_0000001099134954__ad28977dc3c014a49a0b79e1c35a0a454">Process</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_0000001099134954__a8dd67e66796e454891ed4a3be7b4e4de">Description</p>
</th>
</tr>
</thead>
<tbody><tr id="EN-US_TOPIC_0000001099134954__rb34472e732fd4860aa8237f11f08d0da"><td class="cellrowborder" valign="top" width="21%" headers="mcps1.3.6.3.2.3.1.1 "><p id="EN-US_TOPIC_0000001099134954__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_0000001099134954__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_0000001099134954__a0b6d8dc99c8f40b997faaf390335fc7d">For details, see <a href="dws_04_0192.html">Preparing Source Data</a>.</p>
</td>
</tr>
<tr id="EN-US_TOPIC_0000001099134954__r3f9c9c16abf94615a6e394303a269ce8"><td class="cellrowborder" valign="top" width="21%" headers="mcps1.3.6.3.2.3.1.1 "><p id="EN-US_TOPIC_0000001099134954__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_0000001099134954__a426509d949c74f2a890abc5153c4b9b0">Install, configure, and start GDS on the data server.</p>
<p id="EN-US_TOPIC_0000001099134954__a6bfdf0b7f0fb43028d84b7b11cbe7da4">For details, see <a href="dws_04_0193.html">Installing, Configuring, and Starting GDS</a>.</p>
</td>
</tr>
<tr id="EN-US_TOPIC_0000001099134954__r3c02acb999c842e29c4e2f0fc4475d5d"><td class="cellrowborder" valign="top" width="21%" headers="mcps1.3.6.3.2.3.1.1 "><p id="EN-US_TOPIC_0000001099134954__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_0000001099134954__ae8b9fcaae7a44ed387d8a60a843a21f0">A foreign table is used to identify source files. The foreign table stores information of a source data file, such as location, format, destination location, encoding format, and data delimiter.</p>
<p id="EN-US_TOPIC_0000001099134954__aab33fd7490064dfdaf6309a0ece547a3">For details, see <a href="dws_04_0194.html">Creating a GDS Foreign Table</a>.</p>
</td>
</tr>
<tr id="EN-US_TOPIC_0000001099134954__rce72db3e8abf462bb465879efa54ea57"><td class="cellrowborder" valign="top" width="21%" headers="mcps1.3.6.3.2.3.1.1 "><p id="EN-US_TOPIC_0000001099134954__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_0000001099134954__ae482a8f3e78e4e30bff07c3983358b69">After creating the foreign table, run the <strong id="EN-US_TOPIC_0000001099134954__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_0000001099134954__re46272df86b847eea88b6aa99a9431fd"><td class="cellrowborder" valign="top" width="21%" headers="mcps1.3.6.3.2.3.1.1 "><p id="EN-US_TOPIC_0000001099134954__a26cc6738d3b34bc98fc4dc264641af87">Handle import errors.</p>
</td>
<td class="cellrowborder" valign="top" width="79%" headers="mcps1.3.6.3.2.3.1.2 "><p id="EN-US_TOPIC_0000001099134954__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_0000001099134954__a80bbf913f4ea42369b62c7df7f761ca5">For details, see <a href="dws_04_0196.html">Handling Import Errors</a>.</p>
</td>
</tr>
<tr id="EN-US_TOPIC_0000001099134954__r69ad5674ec014a17bf117024ee19f287"><td class="cellrowborder" valign="top" width="21%" headers="mcps1.3.6.3.2.3.1.1 "><p id="EN-US_TOPIC_0000001099134954__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_0000001099134954__a44a8d6da836243f7a3c8f33cdcb53a02">After data is imported, run the <strong id="EN-US_TOPIC_0000001099134954__b84235270618957">ANALYZE</strong> statement to generate table statistics. The <strong id="EN-US_TOPIC_0000001099134954__b842352706195230">ANALYZE</strong> statement stores the statistics in the <strong id="EN-US_TOPIC_0000001099134954__b842352706195225">PG_STATISTIC</strong> system catalog. When you run the plan generator, the statistics help you generate an efficient query execution plan.</p>
</td>
</tr>
<tr id="EN-US_TOPIC_0000001099134954__re13f60434e1b44ab8ae8d5759c075e51"><td class="cellrowborder" valign="top" width="21%" headers="mcps1.3.6.3.2.3.1.1 "><p id="EN-US_TOPIC_0000001099134954__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_0000001099134954__a04e73b8467104de383a92b36fea96904">After data is imported, log in to each data server and stop GDS.</p>
<p id="EN-US_TOPIC_0000001099134954__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>