一、数据导入
greenplum数据导入有五种方式:
1、 insert:通过sql直接插入数据
2.、copy:通过master节点加载,无法实现并行高效数据加载
copy tablename from ‘/home/…/test.cvs’ with delimiter ‘,’;
3.、外部表:
创建外部表,然后插入数据
4.、gpload:外部表的封装
通过编辑gpload控制文件test.yml完成导入
gpload -f test.yml
5.、可执行外部表:不需要启动gpfdist服务
create external web table test1(…)
execute ‘cat /home/…/test.dat’ on master
format ‘text’ (delimiter ‘,’ null as ‘’ escape ‘off’)
encoding ‘’;
insert into test select * from test1;
二、数据导出:
1、copy命令导出
2、可写外部表导出数据:
create writable external table test1
(like test)
location (‘gpfdist://localhost:8888/test.dat’)
format ‘text’ (delimiter ‘,’)
distribute by …;
insert into test1 select * from test;
3、通过 pg_dump导出
pg_dump -f basicmod.sql -h hostname -U username -s -n schema_name db_name # -s 代表只导出schema元信息,不包括数据
4、通过psql进行数据库导出 –
psql “host=XX.XX.XX.XX port=5432 user=XXX password=XXX dbname=XXX” -f table_name.sql
1)选择所要导出库,右键点击选择“命令列界面”
2)步骤如下:
db_name=# show server_encoding;
server_encoding
-----------------
UTF8
(1 row)
SHOW
db_name=# show client_encoding;
client_encoding
-----------------
UNICODE
(1 row)
SHOW
db_name=#
db_name=# set client_encoding to utf8;
SET
db_name=# COPY schema_name.test_03(tjriqi,zhangh,id,name,description,amount,balance,last_balance,kehhao,jiejuh,yuangh,guiyul,shijch,create_time,create_user,modify_time,time_diff,check_time,submit_time) TO '/test_exp/schema_name_test_03.txt' with DELIMITER '&' null as '' ;
COPY 7
db_name=# COPY schema_name.test_05(id,numb,bignumb,amout,balance) TO '/test_exp/schema_name_test_05.txt' with DELIMITER '&' null as '' ;
COPY 3
db_name=#
cmd
chdir /d D:\Program Files\PG SQL\bin
psql -d dbname -h 10.110.1.11 -p 5432 -U gpadmin -w
show server_encoding;
show client_encoding;
set client_encoding to utf8;
\copy (select jigdma||'!',jgmngc||'!',kehhao||'!',kehmch||'!',zhangh||'!',huobdh||'!',hrjine||'!',hcjine||'!',yewupz||'!',hklxin||'!',qsfshi||'!',wbzkzh||'!',hukurq||'!',sbdate||'!',sbtime||'!',sbjigo||'!',cxbzhi||'!',cxtime||'!',status||'!',id||'!',remark||'!',del_flag||'!',create_user||'!',create_time||'!',modified_user||'!',modified_time||'!',check_user||'!',check_time||'!',beizhu||'!',coalesce(cast(ryname as text),'') from schemaname.tablename) TO 'D:\test\00EXPDATA\tablename.txt' with DELIMITER '^' null as '!' ;