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

Example 2: Importing Data in Shared Mode

  1. Prepare for data import.
    This section assumes that a source data file foreign_tpcds_reasons.dat.0 in text format is stored in the /input_data directory on the 192.168.0.90 server.
    1. Configure the NFS service on the data server. For details, see SUSE DOC: Administration Guide – Configuring NFS Server.

      The security of the NFS service and data transmission is ensured by users. You are advised to use the NFS service in a trusted domain.

    2. Start the NFS service on the data server.
      service nfs start
    3. Log in as a common user to each server where GaussDB DNs reside, create the /input_data directory on each server, and mount each data server storing source data files to this directory.
      cd /input_data
      mount -t nfs 192.168.0.90:/input_data /input_data
  2. Log in as the OS user omm to the host where the CN is located.
  3. Run the following command to connect to the database:
    gsql -d postgres -p 8000

    postgres is the name of the database, and 8000 is the port number of the CN.

    If information similar to the following is displayed, the connection succeeds:

    gsql((GaussDB Kernel VxxxRxxxCxx build f521c606) compiled at 2021-09-16 14:55:22 commit 2935 last mr 6385 release)
    Non-SSL connection (SSL connection is recommended when requiring high-security)
    Type "help" for help.
    
    openGauss=# 
  4. Create the target table reasons.
    1
    2
    3
    4
    5
    6
    openGauss=# CREATE TABLE reasons
    (
      r_reason_sk integer not null,
      r_reason_id char(16) not null,
      r_reason_desc char(100)
    );
    
  5. Create the foreign table foreign_tpcds_reasons for the source data.
    1
    2
    3
    4
    5
    6
    openGauss=# CREATE FOREIGN TABLE foreign_tpcds_reasons
    (
      r_reason_sk integer not null,
      r_reason_id char(16) not null,
      r_reason_desc char(100)
    ) SERVER gsmpp_server OPTIONS (location 'file:///input_data/foreign_tpcds_reasons.dat.0', format 'TEXT', mode 'shared', delimiter E'\x20',  NULL '');
    
  6. Import data to the reasons table.
    1
    openGauss=# INSERT INTO reasons SELECT * FROM foreign_tpcds_reasons;