Importing Data In Parallel Using GDS
INSERT and COPY statements can be used only for serially importing a small volume of data. To import a large volume of data to GaussDB(DWS), you can use GDS to import data in parallel using a foreign table.
In the current GDS version, you can import data to databases from pipe files.
- 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.
- To clean data before importing, you can compile a program as needed and write the data to be processed into a pipe file.
- The current version does not support data import through GDS in SSL mode. Do not use GDS in SSL mode.
- All pipe files mentioned in this section refer to named pipes on Linux.
- To ensure the correctness of data import or export using GDS, you need to import or export data in the same compatibility mode.
For example, data imported or exported in MySQL compatibility mode can be exported or imported only in MySQL compatibility mode.
Overview
You can import data in parallel from the common file system (excluding HDFS) of a server to GaussDB(DWS).
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. Figure 1 shows an example.
- The CN only plans data import tasks and delivers the tasks to DNs. In this case, the CN is released to process other tasks.
- In this way, the computing capacities and bandwidths of all the DNs are fully leveraged to import data, improving the import performance.
The concepts mentioned in the preceding figure are described as follows:
- CN: coordinator of GaussDB(DWS). After receiving import SQL requests from an application or client, the CN plans import tasks and delivers the tasks to DNs.
- DN (Datanode): data node of GaussDB(DWS). 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.
- Source data file: a file that stores data to be imported.
- Data server: a server that stores source data files. For security purposes, it is recommended that the data server and GaussDB(DWS) be on the same intranet.
- Foreign table: 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.
- Target table: 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.
Parallel Import Using GDS
- 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 Figure 2.
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.
- If data is stored on data servers, and both GaussDB(DWS) and the data servers have available I/O resources, you can use GDS for multi-thread concurrent import.
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 INSERT statement is an import transaction.
- Fully use resources and improve the concurrent import efficiency when you import multiple tables to the database.
- Speed up the import of a table with a large volume of data.
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.
Import Process
Procedure |
Description |
---|---|
Prepare source data. |
Prepare the source data files to be imported to the database and upload the files to the data server. For details, see Preparing Source Data. |
Start GDS. |
Install, configure, and enable GDS on the data server. For details, see Installing, Configuring, and Starting GDS. |
Create a foreign table. |
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. For details, see Creating a GDS Foreign Table. |
Import data. |
After creating the foreign table, run the INSERT statement to quickly import data to the target table. For details, see Importing Data. |
Handle the error table. |
If errors occur during parallel data import, handle errors based on the error information to ensure data integrity. For details, see Handling Import Errors. |
Improve query efficiency. |
After data is imported, run the ANALYZE statement to generate table statistics. The ANALYZE statement stores the statistics in the PG_STATISTIC system catalog. The execution plan generator uses the statistics to generate the most efficient query execution plan. |
Stop GDS. |
After data import is complete, log in to each data server and stop GDS. For details, see Stopping GDS. |
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbot