Updated on 2023-12-28 GMT+08:00

GDS Practice Guide

  • Before installing GDS, ensure that the system parameters of the server where GDS is deployed are consistent with those of the database cluster.
  • Ensure the physical network works properly for communication between GDS and GaussDB(DWS). A 10GE network is recommended. The 1GE network cannot guarantee smooth communication between GDS and GaussDB(DWS), because it cannot bear the high-speed data transmission pressure and is prone to disconnection. To maximize the import rate of a single file, ensure that a 10GE network is used and the data disk group I/O rate is greater than the upper limit of the GDS single-core processing capability (about 400 MB/s).
  • Plan service deployment in advance. It is recommended that one or two GDSs be deployed on a RAID of a data server. It is recommended that the ratio of GDS quantity to DN quantity be in the range of 1:3 to 1:6. Do not deploy too many GDS processes on a loader. Deploy only one GDS process if an 1GE NIC is used, and no more than four GDS processes if a 10GE NIC is used.
  • Hierarchically divide the data directories for data imported and exported by GDS in advance. Do not put too many files under a data directory, and delete expired files in a timely manner.
  • Properly plan the character set of the target database. You are advised to use UTF8 instead of the SQL_ASCII characters which can easily incur mixed encoding. When exporting data using GDS, ensure that the character set of the foreign table is the same as that of the client. When importing data, ensure that the client and data file content use the same encoding method.
  • If the character set of the database, client, or foreign table cannot be changed, run the iconv command to manually change the character set.
    1
    2
    #Note: -f indicates the character set of the source file, and -t indicates the target character set.
    iconv -f utf8 -t gbk utf8.txt -o gbk.txt
    
  • For details about GDS import practices, see Using GDS to Import Data.

  • GDS supports CSV, TEXT, and FIXED formats. The default format is TEXT. The binary format is not supported. However, the encode/decode function can be used to process data of the binary type. Example:

    Export a binary table.
     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    -- Create a table.
    CREATE TABLE blob_type_t1 
    (
        BT_COL BYTEA
    ) DISTRIBUTE BY REPLICATION;
    -- Create a foreign table.
    CREATE FOREIGN TABLE f_blob_type_t1( BT_COL  text ) SERVER gsmpp_server OPTIONS (LOCATION 'gsfs://127.0.0.1:7789/', FORMAT 'text', DELIMITER E'\x08',  NULL '', EOL '0x0a' ) WRITE ONLY;
    INSERT INTO blob_type_t1 VALUES(E'\\xDEADBEEF');
    INSERT INTO blob_type_t1 VALUES(E'\\xDEADBEEF');
    INSERT INTO blob_type_t1 VALUES(E'\\xDEADBEEF');
    INSERT INTO blob_type_t1 VALUES(E'\\xDEADBEEF');
    INSERT INTO f_blob_type_t1 select encode(BT_COL,'base64') from blob_type_t1;
    

    Import a binary table.

     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    14
    15
    16
    -- Create a table.
    CREATE TABLE blob_type_t2 
    (
        BT_COL BYTEA
    ) DISTRIBUTE BY REPLICATION;
    -- Create a foreign table.
    CREATE FOREIGN TABLE f_blob_type_t2( BT_COL  text ) SERVER gsmpp_server OPTIONS (LOCATION 'gsfs://127.0.0.1:7789/f_blob_type_t1.dat.0', FORMAT 'text', DELIMITER E'\x08',  NULL '', EOL '0x0a' );
    insert into  blob_type_t2 select decode(BT_COL,'base64') from f_blob_type_t2;
    SELECT * FROM blob_type_t2;
       bt_col
    ------------
     \xdeadbeef
     \xdeadbeef
     \xdeadbeef
     \xdeadbeef
    (4 rows)
    
  • Do not repeatedly export data from the same foreign table. Otherwise, the previously exported file will be overwritten.

  • If you are not sure whether the file is in the standard CSV format, you are advised to set quote parameter to invisible characters such as 0x07, 0x08, or 0x1b to import and export data using GDS. This prevents task failures caused by incorrect file format.
    1
    2
    3
    4
    5
    CREATE FOREIGN TABLE foreign_HR_staffS_ft1
    (
      MANAGER_ID     NUMBER(6),
      section_ID     NUMBER(4)
    ) SERVER gsmpp_server OPTIONS (location 'file:///input_data/*', format 'csv', mode 'private', quote '0x07', delimiter ',') WITH err_HR_staffS_ft1;
    
  • GDS supports concurrent import and export. The gds -t parameter is used to set the size of the thread pool and control the maximum number of concurrent working threads. But it does not accelerate a single SQL task. The default value of gds -t is 8, and the upper limit is 200. When using the pipe function to import and export data, ensure that the value of -t is greater than or equal to the number of concurrent services.

  • If the delimiter of a GDS foreign table consists of multiple characters, do not use the same characters in the TEXT format, for example ---.
  • GDS imports a single file through multiple tables in parallel to improve data import performance. (Only CSV and TXT files can be imported.)
    -- Create a target table.
    CREATE TABLE pipegds_widetb_1 (city integer, tel_num varchar(16), card_code  varchar(15), phone_code vcreate table pipegds_widetb_3 (city integer, tel_num varchar(16), card_code varchar(15), phone_code varchar(16), region_code varchar(6), station_id varchar(10), tmsi varchar(20), rec_date integer(6), rec_time integer(6), rec_type numeric(2), switch_id  varchar(15), attach_city varchar(6), opc varchar(20), dpc varchar(20));
    
    -- Create a foreign table that contains the file_sequence column.
    CREATE FOREIGN TABLE gds_pip_csv_r_1( like pipegds_widetb_1) SERVER gsmpp_server  OPTIONS (LOCATION 'gsfs://127.0.0.1:8781/wide_tb.txt', FORMAT 'text', DELIMITER E'|+|', NULL '', file_sequence '5-1');  
    
    CREATE FOREIGN TABLE gds_pip_csv_r_2( like pipegds_widetb_1) SERVER gsmpp_server  OPTIONS (LOCATION 'gsfs://127.0.0.1:8781/wide_tb.txt', FORMAT 'text', DELIMITER E'|+|', NULL '', file_sequence '5-2');
    
    CREATE FOREIGN TABLE gds_pip_csv_r_3( like pipegds_widetb_1) SERVER gsmpp_server  OPTIONS (LOCATION 'gsfs://127.0.0.1:8781/wide_tb.txt', FORMAT 'text', DELIMITER E'|+|', NULL '', file_sequence '5-3'); 
    
    CREATE FOREIGN TABLE gds_pip_csv_r_4( like pipegds_widetb_1) SERVER gsmpp_server  OPTIONS (LOCATION 'gsfs://127.0.0.1:8781/wide_tb.txt', FORMAT 'text', DELIMITER E'|+|', NULL '', file_sequence '5-4');  
     
    CREATE FOREIGN TABLE gds_pip_csv_r_5( like pipegds_widetb_1) SERVER gsmpp_server  OPTIONS (LOCATION 'gsfs://127.0.0.1:8781/wide_tb.txt', FORMAT 'text', DELIMITER E'|+|', NULL '', file_sequence '5-5');
    
    -- Import the wide_tb.txt file to the pipegds_widetb_1 table in parallel.
    \parallel on
    INSERT INTO pipegds_widetb_1 SELECT * FROM gds_pip_csv_r_1;
    INSERT INTO pipegds_widetb_1 SELECT * FROM gds_pip_csv_r_2;
    INSERT INTO pipegds_widetb_1 SELECT * FROM gds_pip_csv_r_3;
    INSERT INTO pipegds_widetb_1 SELECT * FROM gds_pip_csv_r_4;
    INSERT INTO pipegds_widetb_1 SELECT * FROM gds_pip_csv_r_5;
    \parallel off

    For details about file_sequence, see CREATE FOREIGN TABLE (for GDS Import and Export).