greenplum gpfdist应用

服务启动


先试用root账户登录

mkdir -p /data/gpfdist/data
mkdir -p /data/gpfdist/log
chown -R gpadmin:gpadmin /data/gpfdist
su - gpadmin


启动服务

gpfdist -d /data/gpfdist/data -p 9091 -l /data/gpfdist/log/gpfdist_9091.log &


查看服务运行情况

 ps -ef|grep gpfdist

报错

gpfdist: error while loading shared libraries: libevent-2.0.so.5: cannot open shared object file: No such file or directory


解决:
从编译源拷贝这些so文件

cp -rd /usr/lib64/libevent* lib/​
cp -rd ​/usr/lib64/libapr* lib/

创建数据源


在源数据库中先随便弄一个test表,弄点数据。
创建测试数据表,作为数据源

CREATE TABLE "test"."test" (
  "test_id" int4 NOT NULL,
  "test_name" varchar(255),
  CONSTRAINT "test_pkey" PRIMARY KEY ("test_id")
)
;
INSERT INTO "test"."test"("test_id", "test_name") VALUES (1, '张三');
INSERT INTO "test"."test"("test_id", "test_name") VALUES (2, '李四');
INSERT INTO "test"."test"("test_id", "test_name") VALUES (3, '王五');
INSERT INTO "test"."test"("test_id", "test_name") VALUES (4, '测试用户4');
INSERT INTO "test"."test"("test_id", "test_name") VALUES (5, '测试用户5');
INSERT INTO "test"."test"("test_id", "test_name") VALUES (6, '测试用户6');
INSERT INTO "test"."test"("test_id", "test_name") VALUES (7, '测试用户7');
INSERT INTO "test"."test"("test_id", "test_name") VALUES (8, '测试用户8');
INSERT INTO "test"."test"("test_id", "test_name") VALUES (9, '测试用户9');
INSERT INTO "test"."test"("test_id", "test_name") VALUES (10, '测试用户10');
INSERT INTO "test"."test"("test_id", "test_name") VALUES (11, '测试用户11');
INSERT INTO "test"."test"("test_id", "test_name") VALUES (12, '测试用户12');
INSERT INTO "test"."test"("test_id", "test_name") VALUES (13, '测试用户13');
INSERT INTO "test"."test"("test_id", "test_name") VALUES (14, '测试用户14');
INSERT INTO "test"."test"("test_id", "test_name") VALUES (15, '测试用户15');
INSERT INTO "test"."test"("test_id", "test_name") VALUES (16, '测试用户16');
INSERT INTO "test"."test"("test_id", "test_name") VALUES (17, '测试用户17');
INSERT INTO "test"."test"("test_id", "test_name") VALUES (18, '测试用户18');
INSERT INTO "test"."test"("test_id", "test_name") VALUES (19, '测试用户19');
INSERT INTO "test"."test"("test_id", "test_name") VALUES (20, '测试用户20');

创建外部表用于导出数据
注意:外部表需要指定gpfdist的ip和端口,还有详细的目录地址,其中文件名支持通配符。可以编写多个gpfdist的地址,但是不能超过总的segment数
注意:单节点greenplum无法使用,因为segment数量为0。

源数据库创建只写的扩展表,仅用于写入数据

create writable external table test1
(like test)
location ('gpfdist://192.168.81.154:9091/test.dat')
Format 'TEXT' (delimiter as E'|' null as '' escape 'OFF');

导入数据

insert into test1 select * from test;


导入数据后,打开 /data/gpfdist/data/test.dat 即可以看到刚才导入的数据。

删除扩展表

drop external table test1

创建外部表用于导入数据

在目标数据库中创建只读的扩展表,挂载gpfdist服务地址,此地址对应上面的导出数据文件,当然,此文件也可以视网络情况拷贝迁移,挂载到目标数据库就近的gpfdist服务器上。

create READABLE external table test2
(like test)
location ('gpfdist://192.168.81.154:9091/test.dat')
Format 'TEXT' (delimiter as E'|' null as '' escape 'OFF');

查询数据
验证下外部表是否可用。

select * from  test2

导入数据
将数据从外部表导入到目标表。

insert into target select * from test2

核对数据
核对下目标表的数据,已经都过来了。

select * from   target 

删除扩展表

drop external table test2
发布了437 篇原创文章 · 获赞 39 · 访问量 15万+

猜你喜欢

转载自blog.csdn.net/whq12789/article/details/105486179