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.
For example, data imported or exported in MySQL compatibility mode can be exported or imported only in MySQL compatibility mode.
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 concepts mentioned in the preceding figure are described as follows:
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.
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.
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.
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. |