Example 3: Importing Data in Private Mode
- Log in as the OS user omm to the host where the CN is located.
- 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=#
- Query DN names on each node.
1
openGauss=# SELECT node_name,node_host FROM pgxc_node WHERE node_type='D';
Example:
1 2 3 4 5 6 7 8 9 10 11 12
openGauss=# SELECT node_name,node_host FROM pgxc_node WHERE node_type='D'; node_name | node_host --------------+---------------- dn_6001_6002 | 192.168.0.11 dn_6003_6004 | 192.168.0.11 dn_6005_6006 | 192.168.0.12 dn_6007_6008 | 192.168.0.12 dn_6009_6010 | 192.168.0.13 dn_6011_6012 | 192.168.0.13 dn_6013_6014 | 192.168.0.14 dn_6015_6016 | 192.168.0.14 (8 rows)
- Upload the source data files to the nodes where DNs are located.
- Log in to each cluster node as a common user. Create the /input_data directory to store data files and create sub-directories named after DNs on each node.
The following uses the node with the IP address 192.168.0.11 which is queried in 3 as an example. Two DNs, dn_6001_6002 and dn_6003_6004, are on the node.
mkdir -p /input_data mkdir -p /input_data/dn_6001_6002 mkdir -p /input_data/dn_6003_6004
- Evenly distribute source data files to the sub-directories created on each node.
- Change the owner of data source files to be imported and the /input_data directory on each cluster node to omm.
chown -R omm:dbgrp /input_data
- Log in to each cluster node as a common user. Create the /input_data directory to store data files and create sub-directories named after DNs on each node.
- 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) );
- Create the foreign table foreign_tpcds_reasons for the source data.
Set import mode parameters as follows:
- Set the import mode to Private.
- The source data files are stored in sub-directories named after DNs on the nodes, and can be locally accessed. Therefore, set location to file:///input_data/*.
Information about the data format is set based on data format parameters specified during data export. The parameter settings are as follows:
- format is set to CSV.
- delimiter is set to a comma (,).
- quote is set to 0x1b.
- null is set to an empty string without quotation marks.
Set import error tolerance parameters as follows:
- Set PER NODE REJECT LIMIT (number of allowed data format errors) to unlimited. In this case, all the data format errors detected during data import will be tolerated.
- Set LOG INTO to err_tpcds_reasons. The data format errors detected during data import will be recorded in the err_tpcds_reasons table.
1 2 3 4 5 6 7
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/*', format 'CSV', mode 'private', delimiter ',', quote E'\x1b', null '')LOG INTO err_tpcds_reasonS PER NODE REJECT LIMIT 'unlimited';
- Import data to the reasons table.
1
openGauss=# INSERT INTO reasons SELECT * FROM foreign_tpcds_reasons;
- Query data import errors in the err_tpcds_reasons table and rectify the errors (if any). For details, see Handling Import Errors.
1
openGauss=# SELECT * FROM err_tpcds_reasons;
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