Compute
Elastic Cloud Server
Huawei Cloud Flexus
Bare Metal Server
Auto Scaling
Image Management Service
Dedicated Host
FunctionGraph
Cloud Phone Host
Huawei Cloud EulerOS
Networking
Virtual Private Cloud
Elastic IP
Elastic Load Balance
NAT Gateway
Direct Connect
Virtual Private Network
VPC Endpoint
Cloud Connect
Enterprise Router
Enterprise Switch
Global Accelerator
Management & Governance
Cloud Eye
Identity and Access Management
Cloud Trace Service
Resource Formation Service
Tag Management Service
Log Tank Service
Config
OneAccess
Resource Access Manager
Simple Message Notification
Application Performance Management
Application Operations Management
Organizations
Optimization Advisor
IAM Identity Center
Cloud Operations Center
Resource Governance Center
Migration
Server Migration Service
Object Storage Migration Service
Cloud Data Migration
Migration Center
Cloud Ecosystem
KooGallery
Partner Center
User Support
My Account
Billing Center
Cost Center
Resource Center
Enterprise Management
Service Tickets
HUAWEI CLOUD (International) FAQs
ICP Filing
Support Plans
My Credentials
Customer Operation Capabilities
Partner Support Plans
Professional Services
Analytics
MapReduce Service
Data Lake Insight
CloudTable Service
Cloud Search Service
Data Lake Visualization
Data Ingestion Service
GaussDB(DWS)
DataArts Studio
Data Lake Factory
DataArts Lake Formation
IoT
IoT Device Access
Others
Product Pricing Details
System Permissions
Console Quick Start
Common FAQs
Instructions for Associating with a HUAWEI CLOUD Partner
Message Center
Security & Compliance
Security Technologies and Applications
Web Application Firewall
Host Security Service
Cloud Firewall
SecMaster
Anti-DDoS Service
Data Encryption Workshop
Database Security Service
Cloud Bastion Host
Data Security Center
Cloud Certificate Manager
Edge Security
Managed Threat Detection
Blockchain
Blockchain Service
Web3 Node Engine Service
Media Services
Media Processing Center
Video On Demand
Live
SparkRTC
MetaStudio
Storage
Object Storage Service
Elastic Volume Service
Cloud Backup and Recovery
Storage Disaster Recovery Service
Scalable File Service Turbo
Scalable File Service
Volume Backup Service
Cloud Server Backup Service
Data Express Service
Dedicated Distributed Storage Service
Containers
Cloud Container Engine
SoftWare Repository for Container
Application Service Mesh
Ubiquitous Cloud Native Service
Cloud Container Instance
Databases
Relational Database Service
Document Database Service
Data Admin Service
Data Replication Service
GeminiDB
GaussDB
Distributed Database Middleware
Database and Application Migration UGO
TaurusDB
Middleware
Distributed Cache Service
API Gateway
Distributed Message Service for Kafka
Distributed Message Service for RabbitMQ
Distributed Message Service for RocketMQ
Cloud Service Engine
Multi-Site High Availability Service
EventGrid
Dedicated Cloud
Dedicated Computing Cluster
Business Applications
Workspace
ROMA Connect
Message & SMS
Domain Name Service
Edge Data Center Management
Meeting
AI
Face Recognition Service
Graph Engine Service
Content Moderation
Image Recognition
Optical Character Recognition
ModelArts
ImageSearch
Conversational Bot Service
Speech Interaction Service
Huawei HiLens
Video Intelligent Analysis Service
Developer Tools
SDK Developer Guide
API Request Signing Guide
Terraform
Koo Command Line Interface
Content Delivery & Edge Computing
Content Delivery Network
Intelligent EdgeFabric
CloudPond
Intelligent EdgeCloud
Solutions
SAP Cloud
High Performance Computing
Developer Services
ServiceStage
CodeArts
CodeArts PerfTest
CodeArts Req
CodeArts Pipeline
CodeArts Build
CodeArts Deploy
CodeArts Artifact
CodeArts TestPlan
CodeArts Check
CodeArts Repo
Cloud Application Engine
MacroVerse aPaaS
KooMessage
KooPhone
KooDrive

Parallel Data Import

Updated on 2024-10-14 GMT+08:00

The INSERT (Running the INSERT Statement to Insert Data) and COPY (Running the COPY FROM STDIN Statement to Import Data) statements can be used only for serially importing a small volume of data. To import a large volume of data to GaussDB, you can import data in parallel through a foreign table. To import foreign tables in parallel, you must enable the stream operator (controlled by the GUC parameter enable_stream_operator).

Overview

GDS imports data in parallel from the common file system of a server to GaussDB.

Source data files to import 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 overall data import performance. Figure 1 shows an example.

  • The CN only plans data import tasks and delivers the tasks to DNs. Then 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 import efficiency.
You can preprocess data (such as invalid character replacement and fault tolerance processing) by setting parameters in a foreign table. For details, see CREATE FOREIGN TABLE (for Import and Export).
Figure 1 Importing data in parallel

The concepts mentioned in this figure are as follows:

  • CN: coordinator node of GaussDB. After receiving import SQL requests from an application or client, the CN plans import tasks and delivers the tasks to DNs.
  • DN: data node of GaussDB. After receiving 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 import.
  • Data server: a server that stores source data files. For security purposes, it is recommended that the data server and GaussDB cluster be on the same intranet.
  • Foreign table: a table that stores information, such as the current 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.

Loading Policies

To fully use computing resources for parallel import, import tasks are pushed down to DNs. The CN delivers tasks but does not import data. In this case, user data managers, correct and unique data allocation to DNs, and the uniqueness of data imported into databases must be first considered. GaussDB provides the following import policies:
  • Normal: GDS is used to load source data into DNs. This policy is used for importing data to a cluster from hosts outside the cluster.
  • Shared: The network file system (NFS) is used to load source data into DNs. After you configure NFS on a data server, mount the data server to the same directory of each DN. This policy is used for importing data to a cluster from hosts outside the cluster. In this policy, the CN scans all data files during task planning and evenly allocates source data files to each DN.
  • Private: Users upload source data files to each DN. Before uploading data files, create a directory named after the DN name on each DN. Each DN searches for unloaded data files in its corresponding directory and loads them, until all data has been loaded.

As shown in Table 1, the Normal policy is recommended because it is scalable, easy to prepare, and has no limit on the size of a single row of data to be imported. The foreign tables in Private and Shared modes require the initial user permissions or the O&M administrator permissions in operation_mode. This section describes how to use GDS to import data in parallel. For details on the other policies, see Example 2: Importing Data in Shared Mode and Example 3: Importing Data in Private Mode.

Table 1 Import policies

Import Policy

Preparation for Data Import

Data Format

Normal

Deploy GDS on data servers. Multi-GDS concurrent import is supported.

CSV, TEXT, and FIXED

Shared

Configure NFS on data servers and mount the data servers to the same directory of each DN. The mount directory on each DN must be the same.

TEXT

The size of data in a single row must be less than 1 GB.

Private

Evenly allocate source data files to DN servers.

Data files in each folder named after a DN name under the same directory of hosts should not be duplicate.

CSV, TEXT, and FIXED

The size of data in a single row must be less than 1 GB.

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.
    Figure 2 Parallel import from multiple data servers
    NOTICE:

    The number of GDS processes cannot exceed that of DNs. If the number of connections exceeds the maximum, one DN may be connected to multiple GDS processes. As a result, some GDS processes may run abnormally, and the error message "Session doesn't exist" may be displayed. If the number of GDSs involved in an import is greater than the number of DNs, a warning "It is recommended that the number of GDS should not be greater than the number of datanode" is returned when the import starts.

  • If data is stored on one data server, and both GaussDB and the data server have available I/O resources, you can use GDS for multi-thread parallel import.

    GDS determines the number of threads based on the number of parallel 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.

    Multi-thread parallel import enables you to:

    • Make full use of resources and improve the parallel 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 parallel import is implemented by importing data using multiple foreign tables at the same time. Ensure that a data file is read only by one foreign table.

Import Process

Figure 3 Parallel import process
Table 2 Process description

Process

Description

Prepare source ata

Prepare source data files to import 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 data in a source data file. Foreign tables store the location, file format, encoding format, and delimiters information about the data source files.

For details, see Creating a GDS Foreign Table.

Import data

After creating the foreign table, execute the INSERT statement to efficiently import data to the target table. For details, see Importing Data.

Handle import errors

If there are errors 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 system catalog PG_STATISTIC. The statistics data is useful when you run the planner, which provides you with an efficient query execution plan.

For details, see Analyzing Tables.

Stop GDS

After data import is complete, log in to each data server and stop GDS.

For details, see Stopping GDS.

We use cookies to improve our site and your experience. By continuing to browse our site you accept our cookie policy. Find out more

Feedback

Feedback

Feedback

0/500

Selected Content

Submit selected content with the feedback