Greenplum利用gpload,gpfist实现数据入库

转载:http://blog.csdn.net/stoneliul/article/details/8126700


1.python版本要求2.4.4以上

[python]  view plain  copy
  1. [root@test install]# python  
  2. Python 2.6.2 (r262:71600, May 14 200910:46:21)   
  3. [GCC 4.1.2 20080704 (Red Hat 4.1.2-44)] on linux2  
  4. Type "help""copyright""credits" or "license" for more information.  
  5. >>>   

2.PyYAML 3.10包配置

YAML parser and emitter for Python

YAML is a data serialization format designed for human readability and interaction with scripting languages. PyYAML is a YAML parser and emitter for Python.

PyYAML features a complete YAML 1.1 parser, Unicode support, pickle support, capable extension API, and sensible error messages. PyYAML supports standard YAML tags and provides Python-specific tags that allow to represent an arbitrary Python object.

PyYAML is applicable for a broad range of tasks from complex configuration files to object serialization and persistance.

[sql]  view plain  copy
  1. [root@test dataload]# tar -zxvf PyYAML-3.10.tar.gz  
[sql]  view plain  copy
  1. [root@test PyYAML-3.10]# python setup.py install  

3.yaml-0.1.4配置

下载源代码包:http://pyyaml.org/download/libyaml/yaml-0.1.4.tar.gz。编译和安装LibYAML

[sql]  view plain  copy
  1. [root@test dataload]# tar -zxvf yaml-0.1.4.tar.gz  
[sql]  view plain  copy
  1. [root@test dataload]# cd yaml-0.1.4  
[sql]  view plain  copy
  1. [root@test yaml-0.1.4]# ./configure  
[sql]  view plain  copy
  1. [root@test yaml-0.1.4]# make && make install  

4.gpload.gpfdist工具配置

下载:greenplum-loaders-4.2.1.0-build-2-RHEL5-x86_64.zip

[sql]  view plain  copy
  1. [root@test dataload]# ./greenplum-loaders-4.2.1.0-build-2-RHEL5-x86_64.bin   

[sql]  view plain  copy
  1. ********************************************************************************  
  2.     Do you accept the Greenplum Loaders license agreement? [yes | no]  
  3. ********************************************************************************  
  4.   
  5.    

选择:yes 到安装完成

修改greenplum_loaders_path.sh中GPHOME_LOADERS改为你安装的路径

.bash_profile中添加环境GP变量:

[sql]  view plain  copy
  1. export PGDATABASE=gptest  
  2. export PGHOST=127.0.0.1  
  3. export PGPORT=5432  
  4. export PGUSER=gpadmin  
  5. export PGPASSWORD=gpadmin  

[sql]  view plain  copy
  1. source  ~/.bash_profile  
  2. 在相应文件夹中启动gpfdist

5.编写数据入库yaml控制文件

[sql]  view plain  copy
  1. [root@test bin]# more gpload.yml   
  2. ---  
  3. VERSION: 1.0.0.1  
  4. DATABASE: gptest  
  5. USER: gpadmin  
  6. HOST: 127.0.0.1  
  7. PORT: 5432  
  8. GPLOAD:  
  9.   INPUT:  
  10.     - SOURCE:  
  11.         LOCAL_HOSTNAME:  
  12.           - test  
  13.         PORT: 55555  
  14.         FILE:  
  15.           - /home/tmp/test1  
  16.     - COLUMNS:  
  17.         - id: int  
  18.         - name: text  
  19.         - aa: text  
  20.         - timetimestamp without time zone  
  21.         - bb: text  
  22.         - cc: text  
  23.         - dd: int  
  24.         - ee: int  
  25.         - ff: text  
  26.         - gg: text  
  27.         - hh: text  
  28.         - ii: text  
  29.         - jj: text  
  30.         - kk: text  
  31.         - ll: text  
  32.     - FORMAT: text  
  33.     - DELIMITER: ','  
  34.     - ERROR_LIMIT: 25  
  35.   OUTPUT:  
  36.     - TABLE: test_gpload  
  37.     - MODE: INSERT  
注:COLUMNS中字段应与数据库中表字段及数据类型匹配

7.执行gpload

[sql]  view plain  copy
  1. [root@test bin]# gpload -f gpload.yml  
  2. 2012-10-30 00:06:42|INFO|gpload session started 2012-10-30 00:06:42  
  3. 2012-10-30 00:06:43|INFO|started gpfdist -p 55555 -P 55556 -f "/home/tmp/test" -t 30  
  4. 2012-10-30 00:06:50|INFO|running time: 7.92 seconds  
  5. 2012-10-30 00:06:50|INFO|rows Inserted          = 205092  
  6. 2012-10-30 00:06:50|INFO|rows Updated           = 0  
  7. 2012-10-30 00:06:50|INFO|data formatting errors = 0  
  8. 2012-10-30 00:06:50|INFO|gpload succeeded  

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
greenplum是一款高性能、可扩展的开源分布式数据库管理系统,用于处理大数据量的存储和分析。在数据处理场景中,数据的同步是一个关键的问题。 Greenplum数据的同步有多种方式,我们可以根据实际需求选择合适的方法。一种常见的数据同步方式是使用ETL工具,如Informatica、Talend等,通过配置数据源和目标,将数据从源系统提取、转换和加载到Greenplum中。这种方式可以根据需求定时或实时同步数据。 除了ETL工具,还可以使用数据库复制技术来实现数据的同步。Greenplum支持异步复制和同步复制两种方式。异步复制通过将数据变更记录发送给备份节点,减少了主节点的负载,但有一定的延迟。同步复制则要求主节点等待备份节点确认数据变更,确保数据的一致性和可靠性,但会增加主节点的负载。 此外,还可以使用消息队列来实现数据的异步同步。消息队列作为中介,将源系统中的数据发送到队列中,再由消费者将数据加载到Greenplum中。这种方式可以实现高可用性和容错性。 另外,也可以通过编写自定义的脚本或程序来实现数据的同步。例如,可以使用Python或Java编写脚本,通过API连接到Greenplum和源系统,实现数据的抽取和加载。 总之,根据具体需求和场景,可以选择合适的数据同步方式。无论是使用ETL工具、数据库复制、消息队列还是自定义脚本,都能够满足数据同步的需求,确保数据的准确性和及时性。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值