GreenPlum入门

《GreenPlum系列》GreenPlum初级教程-GreenPlum详细入门教程 01GreenPlum数据库介绍 02GreenPlum单节点安装 03GreenPlum系统管理 04GreenPlum数据类型 05GreenPlum语言DDL&DML&DQL 06GreenPlum函数 阅读详情

GreenPlum入门

六翁 2016-07-13 14345浏览量
简介: 本文旨在小白入门。 我开始研究GP的动机是因为它在MPP和数仓方面的名声,另外,GP也是集团技术栈的一员。 ### 1 GPDB简介 > Pivotal **Greenplum** Database is a MPP (massively parallel processing) database built on open source [PostgreSQL](https:/

本文旨在小白入门。

我开始研究GP的动机是因为它在MPP和数仓方面的名声,另外,GP也是集团技术栈的一员。
1 GPDB简介

    Pivotal Greenplum Database is a MPP (massively parallel processing) database built on open source PostgreSQL.The system consists of a master node, standby master node, and segment nodes.

    All of the data resides on the segment nodes and the catalog information is stored in the master nodes. Segment nodes run one or more segments, which are modified PostgreSQL database instances and are assigned a content identifier.

    For each table the data is divided among the segment nodes based on the distribution column keys specified by the user in the DDL statement.

    For each segment content identifier there is both a primary segment and mirror segment which are not running on the same physical host.

    When a SQL query enters the master node, it is parsed, optimized and dispatched to all of the segments to execute the query plan and either return the requested data or insert the result of the query into a database table.

从定义上看,GP和此前我比较专注的ES(Elasticsearch)非常类似,它们都是基于成熟的单机技术——PG(PostgreSQL)和Lucene,采用去中心化的分布式技术,实现了对大数据的(MPP和信息检索)支持。
2 准备

多台物理机搭建GPDB集群(1个主节点、1个备节点、n个Segment节点)是最佳的实战环境,但作为入门,GP官方提供的Docker镜像足够用了。使用如下命令拉取这个镜像:

docker pull pivotaldata/gpdb-base

接下来使用如下命令下载GP官方提供的教程示例,然后解压到任意目录(本例使用的路径为/Users/erichan/Downloads/greenplum-db-gpdb-sandbox-tutorials-6794737):

wget https://github.com/greenplum-db/gpdb-sandbox-tutorials/zipball/master

启动GP容器,并挂载上述教程示例:

docker rm $(docker ps -aq)

docker run -ti \
-p 5432:5432 \
--name gp_tutorials \
--hostname gp-tutorials \
-v /Users/erichan/Downloads/greenplum-db-gpdb-sandbox-tutorials-6794737:/tutorials \
pivotaldata/gpdb-base

如下的练习都是在上述这个容器中进行的。

容器内包含的用户/密码信息如下:

    root/pivotal
    gpadmin/pivotal

如下练习均使用gpadmin用户,记得切换:

su - gpadmin

3 创建用户和角色
3.1 Create a user with the createuser utility command

createuser -P user1

Enter password for new role:
Enter it again:
Shall the new role be a superuser? (y/n) n
Shall the new role be allowed to create databases? (y/n) y
Shall the new role be allowed to create more new roles? (y/n) n
NOTICE:  resource queue required -- using default resource queue
"pg_default"

3.2 Create a user with the CREATE USER command

psql template1

template1=# CREATE USER user2 WITH PASSWORD 'pivotal' NOSUPERUSER;

template1=# \du

                       List of roles
 Role name |            Attributes             | Member of
-----------+-----------------------------------+-----------
 gpadmin   | Superuser, Create role, Create DB |
 user1     | Create DB                         |
 user2     |                                   |

3.3 Create a users group and add the users to it

template1=# CREATE ROLE users;
template1=# GRANT users TO user1, user2;

template1=# \du
                       List of roles
 Role name |            Attributes             | Member of
-----------+-----------------------------------+-----------
 gpadmin   | Superuser, Create role, Create DB |
 user1     | Create DB                         | {users}
 user2     |                                   | {users}
 users     | Cannot login                      |

3.4 Exit out of the psql shell

template1=# \q

4 创建和准备数据库
4.1 Create Database

dropdb tutorial
createdb tutorial

psql -l
                  List of databases
   Name    |  Owner  | Encoding |  Access privileges
-----------+---------+----------+---------------------
 gpadmin   | gpadmin | UTF8     |
 postgres  | gpadmin | UTF8     |
 template0 | gpadmin | UTF8     | =c/gpadmin
                                : gpadmin=CTc/gpadmin
 template1 | gpadmin | UTF8     | =c/gpadmin
                                : gpadmin=CTc/gpadmin
 tutorial  | gpadmin | UTF8     |
(5 rows)

4.2 Grant database privileges to users

psql -U gpadmin tutorial

tutorial=# GRANT ALL PRIVILEGES ON DATABASE tutorial TO user1, user2;

tutorial=# \q

psql -l
                  List of databases
   Name    |  Owner  | Encoding |  Access privileges
-----------+---------+----------+---------------------
 gpadmin   | gpadmin | UTF8     |
 postgres  | gpadmin | UTF8     |
 template0 | gpadmin | UTF8     | =c/gpadmin
                                : gpadmin=CTc/gpadmin
 template1 | gpadmin | UTF8     | =c/gpadmin
                                : gpadmin=CTc/gpadmin
 tutorial  | gpadmin | UTF8     | =Tc/gpadmin
                                : gpadmin=CTc/gpadmin
                                : user1=CTc/gpadmin
                                : user2=CTc/gpadmin
(5 rows)

4.3 Create a schema and set a search path

psql -U user1 -h gp-tutorials tutorial

tutorial=> DROP SCHEMA IF EXISTS faa CASCADE;

tutorial=> CREATE SCHEMA faa;

tutorial=> SET SEARCH_PATH TO faa, public, pg_catalog, gp_toolkit;

tutorial=> SHOW search_path;
             search_path
-------------------------------------
 faa, public, pg_catalog, gp_toolkit
(1 row)

tutorial=> \q

5 创建表

cd /tutorials/faa
psql -U gpadmin tutorial
tutorial=#  \i create_dim_tables.sql
tutorial=# \dt

5.1 Data Loading

tutorial=# \d faa.d_cancellation_codes
Table "faa.d_cancellation_codes"
   Column    | Type | Modifiers
-------------+------+-----------
 cancel_code | text |
 cancel_desc | text |
Distributed by: (cancel_code)

5.2 Load data with the INSERT statement

tutorial=# INSERT INTO faa.d_cancellation_codes
tutorial-# VALUES ('A', 'Carrier'),
tutorial-# ('B', 'Weather'),
tutorial-# ('C', 'NAS'),
tutorial-# ('D', 'Security'),
tutorial-#  ('', 'none');
INSERT 0 5

5.3 Load data with the COPY statement

tutorial-# \i copy_into_airports.sql
tutorial-# \i copy_into_airlines.sql
tutorial-# \i copy_into_delay_groups.sql
tutorial-# \i copy_into_distance_groups.sql
tutorial-# \i copy_into_wac.sql
tutorial-# \q

5.4 Load data with gpdist

Execute gpfdist

gpfdist -d /tutorials/faa -p 8081 > /tmp/gpfdist.log 2>&1 &

ps -A | grep gpfdist

 1202 ?        00:00:00 gpfdist

more /tmp/gpfdist.log

...
Serving HTTP on port 8081, directory /tutorials/faa

psql -U gpadmin tutorial

tutorial=#  \i create_load_tables.sql
tutorial=#  \i create_ext_table.sql
tutorial=# INSERT INTO faa.faa_otp_load SELECT * FROM faa.ext_load_otp;

tutorial=#  \x

tutorial=# SELECT DISTINCT relname, errmsg, count(*) FROM faa.faa_load_errors GROUP BY 1,2;
-[ RECORD 1 ]-------------------------------------------------
relname | ext_load_otp
errmsg  | invalid input syntax for integer: "", column deptime
count   | 26526

tutorial=# \q

killall gpfdist

5.5 Load data with gpload

vi gpload.yaml

---
VERSION: 1.0.0.1
# describe the Greenplum database parameters
DATABASE: tutorial
USER: gpadmin
HOST: gp-tutorials
PORT: 5432
# describe the location of the source files
# in this example, the database master lives on the same host as the source files
GPLOAD:
   INPUT:
    - SOURCE:
         LOCAL_HOSTNAME:
           - gp-tutorials
         PORT: 8081
         FILE:
           - /tutorials/faa/otp*.gz
    - FORMAT: csv
    - QUOTE: '"'
    - ERROR_LIMIT: 50000
    - ERROR_TABLE: faa.faa_load_errors
   OUTPUT:
    - TABLE: faa.faa_otp_load
    - MODE: INSERT
   PRELOAD:
    - TRUNCATE: true

gpload -f gpload.yaml -l gpload.log

...
started gpfdist -p 8081 -P 8082 -f "/tutorials/faa/otp*.gz" -t 30
...
running time: 22.41 seconds
...
rows Inserted          = 1024552

5.6 Create and Load fact tables

psql -U gpadmin tutorial
tutorial=#  \i create_fact_tables.sql
tutorial=# \i load_into_fact_table.sql

6 查询和调优
6.1 Analyze the tables

tutorial=# ANALYZE faa.d_airports;
ANALYZE
tutorial=# ANALYZE faa.d_airlines;
ANALYZE
tutorial=# ANALYZE faa.d_wac;
ANALYZE
tutorial=# ANALYZE faa.d_cancellation_codes;
ANALYZE
tutorial=# ANALYZE faa.faa_otp_load;
ANALYZE faa.otp_r;
ANALYZE
tutorial=# ANALYZE faa.otp_r;
ANALYZE
tutorial=# ANALYZE faa.otp_c;
ANALYZE

6.2 View explain plans

tutorial=# \timing on
tutorial=# \i create_sample_table.sql
tutorial=# EXPLAIN SELECT COUNT(*) FROM sample WHERE id > 100;
tutorial=# EXPLAIN ANALYZE SELECT COUNT(*) FROM sample WHERE id > 100;

6.3 Changing optimizers

tutorial=# \q

gpconfig -s optimizer

Values on all segments are consistent
GUC          : optimizer
Master  value: off
Segment value: off

gpconfig -c optimizer -v on --masteronly

gpstop -u

6.4 Indexes and performance

psql -U gpadmin tutorial

tutorial=# \i create_sample_table.sql

tutorial=# SELECT * from sample WHERE big = 12345;
   id    |  big  | wee | stuff
---------+-------+-----+-------
   12345 | 12345 |   0 |
 1012346 | 12345 |   0 |
 2012347 | 12345 |   0 |
(3 rows)

tutorial=# EXPLAIN SELECT * from sample WHERE big = 12345;

tutorial=# CREATE INDEX sample_big_index ON sample(big);

tutorial=# EXPLAIN SELECT * FROM sample WHERE big = 12345;

6.5 Row vs. Column orientation

tutorial=# CREATE TABLE FAA.OTP_C (LIKE faa.otp_r) WITH (appendonly=true,orientation=column)DISTRIBUTED BY (UniqueCarrier, FlightNum) PARTITION BY RANGE(FlightDate)(PARTITION mth START('2009-06-01'::date) END ('2010-10-31'::date) EVERY ('1 mon'::interval));

tutorial=# INSERT INTO faa.otp_c SELECT * FROM faa.otp_r;

tutorial=# \d faa.otp_r

tutorial=# \d faa.otp_c

tutorial=# SELECT pg_size_pretty(pg_relation_size('faa.otp_r'));
 pg_size_pretty
----------------
 256 MB
(1 row)

tutorial=# SELECT pg_size_pretty(pg_total_relation_size('faa.otp_r'));
 pg_size_pretty
----------------
 256 MB
(1 row)

tutorial=# SELECT pg_size_pretty(pg_relation_size('faa.otp_c'));
 pg_size_pretty
----------------
 0 bytes
(1 row)

tutorial=# SELECT pg_size_pretty(pg_total_relation_size('faa.otp_c'));
 pg_size_pretty
----------------
 288 kB
(1 row)

tutorial=#
tutorial=# SELECT pg_size_pretty(pg_total_relation_size('faa.otp_c'));
 pg_size_pretty
----------------
 288 kB
(1 row)

6.6 Check for even data distribution on segments

tutorial=# SELECT gp_segment_id, COUNT(*) FROM faa.otp_c GROUP BY gp_segment_id ORDER BY gp_segment_id;

6.7 About partitioning

tutorial=# \timing on

tutorial=#  SELECT MAX(depdelay) FROM faa.otp_c WHERE UniqueCarrier = 'UA';

tutorial=# SELECT MAX(depdelay) FROM faa.otp_c WHERE flightdate ='2009-11-01';

7 集成分析工具

    http://madlib.incubator.apache.org
    https://zeppelin.incubator.apache.org

8 备份和恢复操作

    To run a full backup:gpcrondump -x tutorial -u /tmp -a -r
    To view the backups:ls -al /tmp/db_dumps
    To restore the data:gpdbrestore -T faa.otp_r -s tutorial -u /tmp -a

9 Reference

    http://greenplum.org/gpdb-sandbox-tutorials
    https://github.com/pivotaldata/gpdb-docker

 

GreenPlum简介 快速入门 GreenPlum是一个底层是多台PostgreSQL分表分库的分布式数据库,它有如下特点 支持标准SQL,几乎所有PostgreSQL支持的SQL,greenplum都支持 支持ACID、分布式事务 支持上百台集群(这一点有点不好,hadoop可以万台) 系统架构 Master Host 处理用户请求,生成执行计划,以及在执行计划执行必要的聚合操作(avg)或者排序 内部有一个P... 阅读详情

相关推荐

理论+实例,带你入门Greenplum机器学习框架MADlib

本文由瀚高基础软件...

Greenplum中文社区 1256

小白快速入门greenplum

数据时代的到来,数据分析业务越来越吃香,分析型MPP数据库-greenplum由开源大佬-pivotal出品(java中出品spring、springboot、springcloud等产品公司),greenplum简单来说也是系出名门,作OLAP非常适合,效率非常高,能像使用mysql和oracle一样,操作单表几百亿数据。软件老王目前项目中还在使用greenplum,假如有朋友有什么问题,可以给老王留言,交流下。课程附件包含greenplum、gpcc、keepalived的完整安装文档。课程目录: 第一章 课程介绍第二章 greenplum之背景介绍与下载第三章 greenplum之系统架构与技术架构说明第四章 greenplum之完整部署与说明第五章 greenplum之greenplum-cc-web安装第六章 greenplum之我对gp的理解第七章 greenplum之高可用方案第八章 greenplum之问题总结第九章 课程总结

Greenplum入门——概览

本文内容为博主阅读《Greenplum企业应用实战》的读书笔记,对书中主要知识点进行了归纳和梳理。有兴趣的同学可以买一本原书读一读。如果认为文中内容涉嫌侵权,请及时联系博主删除文章。OLTP 与 OLAP数据库系统分为两种。 - OLTP 面向前台应用,重吞吐和高并发 - OLAP 对大数据集进行统计分析,重计算Greenplum属于OLAPOLTPOLTP 联机事务处理 On-Line Tra

在咖啡里溺水的鱼 2603

Greenplum入门篇_Greenplum企业应用实战

Bitmap位图索引:适合只有几个固定值的列;如性别,婚姻状况,它会通过对该列的几个固定值构建出向量,之后在where条件中通过固定值对应的向量返回值 第二章 greenplum快速入门 Master主机与segment主机对比  Master主机 1) 建立与客户端会话连接和管理 2) Sql解析并形成分布式执行计划 3) 将生成好的执行计划分发到每个segment上执行 4) 收集segment执行结果 5) Master不存储业务数据,只存储数据字典 6) Master主机可一主一备,分布在两台

weixin_41636030的博客 736

还是青梅小萌新?这些资料帮你入门Greenplum

...

Greenplum中文社区 453

【GP】Greenplum入门解析(一)

一、Greenplum概述 【1】Greenplum简介 Greenplum(以下简称GP)是一款开源数据仓库。基于开源的PostgreSQL改造,主要用来处理大规模数据分析任务,相比Hadoop,Greenplum更适合做大数据的存储、计算和分析引擎 GP是典型的Master/Slave架构,在GP集群中,存在2个Master节点(一个Primary节点和一个Standby)和多个Segment节点,其中每个节点上可以运行多个数据库。GP采用shared nothing架构(MPP)。是典型的Shared

Together 1万+

knn的python代码_KNN-python代码实现

KNN属于机器学习中的监督学习,其核心思想即“物以类聚,人以群分”。监督学习算法的基本流程1.归一化数据样本集2.划分样本集为训练集和测试集3、以训练集为算法参考系,测试集来测试算法4、计算预测样品标签和真实样品标签的比值来评估算法的准确率5、调节不同的参数找到最优算法参数代码实现1.调用KNN函数来实现分类 (数据采用的是经典的iris数据,是三分类问题)# 读取相应的库from sk...

weixin_39717152的博客 612

Greenplum学习指南:从入门到精通

本文全面介绍Greenplum分布式数据库的核心特性和应用实践。Greenplum基于PostgreSQL开发,采用MPP架构实现PB级数据的高效处理,具备并行查询、高可用性和灵活存储等特性。文章详细解析了其架构原理、安装配置流程、SQL使用技巧及性能优化方法,包括资源管理、查询优化和存储策略。同时探讨了扩容、高可用、混合负载等高级主题,展示了Greenplum在数据仓库和大数据分析领域的优势。通过系统学习,读者可掌握构建高效数据仓库的关键技术,满足企业实时分析需求。

guse1125的博客 662

GreenPlum快速入门实践

文章目录1. 表创建1.1 获取帮助1.2 指定分布键1.3 其它创建方式1.4 SELECT 查询结果展现顺序2. 分区表2.1 range分区2.2 list分区2.3 分区管理3. 数据加载3.1 Insert3.2 Copy3.3 外部表3.3.1 介绍3.3.2 实践示例3.3.3 可执行外部表3.3.4 可写外部表 数据导出3.4 gpload4. 拉链表实现5. 数据字典OID6. 集群维护 1. 表创建 1.1 获取帮助 -- 获取帮助 \h create table 1.2 指定分布键

飞虹的专栏 2204

Greenplum详细使用手册(新手必备)

Greenplum详细使用手册(新手必备手册),安装,卸载,初始化及集群维护监控管理。全网最全手册。

GreenPlum入门学习手册

无共享、大规模并行处理(massively parallel processing (MPP))的数据库软件产品GreenPlum;分布式数据仓库。

GreenPlum的学习心得和知识总结(三)|Greenplum数据库快速入门

Greenplum数据库快速入门

孤傲小二~阿沐的博客 7918

手把手教你用GD32F407VET6的EXMC驱动外部SRAM,搞定大内存需求

本文详细介绍了如何使用GD32F407VET6的EXMC外设驱动外部SRAM,解决嵌入式开发中的大内存需求问题。通过硬件连接方案、EXMC时序配置与初始化步骤,以及软件集成与内存管理技巧,帮助开发者快速实现内存扩展。特别适合需要处理图形显示缓冲、音频处理等大内存场景的GD32F407开发者。

weixin_30752699的博客 346

视频课程《小白快速入门greenplum》在csdn学院上线了

1.场景描述 视频课程《小白快速入门greenplum》在csdn学院上线了,有需要的朋友可以直接点击链接观看。 2. 课程内容 课程地址:https://edu.youkuaiyun.com/course/detail/27801?utm_source=xueyuanjuhe 课程目录: 目录 第一章 课程介绍 第二章 greenplum之背景介绍与下载 第三章 greenplum之系统架构与技术架构说明 ...

软件老王 1097

LLC谐振变换器中的软开关艺术:ZVS与ZCS的协同设计

本文深入解析了LLC谐振变换器如何通过巧妙的电路设计,协同实现零电压开关(ZVS)与零电流开关(ZCS),从而大幅降低开关损耗与电磁干扰,提升电源效率。文章结合设计实战,详细阐述了谐振参数计算、器件选型及调试避坑指南,为高效、高功率密度电源设计提供了核心思路与解决方案。

weixin_29216957的博客 349

【PLC】三菱PLC控件安装疑难解析:Error Number:-119的全面解决方案

本文针对三菱PLC控件安装过程中常见的Error Number:-119错误,提供了深度解析与实战解决方案。该错误通常源于Windows系统权限限制或文件冲突。文章从理解错误本质入手,逐步介绍了以管理员身份运行、手动注册DLL文件、采用新版环境搭配旧版控件的黄金组合以及系统环境修复等四大招法,帮助用户彻底解决这一安装难题,确保工控软件稳定运行。

jj890的博客 496

Greenplum入门介绍

Greenplum数据库是在postgreSQL开发出来的,基于MPP(massively parallel processing)和shared-Nothing架构(Oracle RAC是shared everything架构)。 主要用在数据仓库中,做大规模数据和复杂的查询功能所涉及。 与现有的数据仓库解决方案(Oracle、IBM、Microsoft、Sybase和Teradata)

VRML_0504的专栏 1133

数据库迁移策略实战:MySQL到PostgreSQL

数据库迁移是一项复杂且细致的任务,需要充分的准备工作、合适的迁移策略和严格的验证与优化步骤。通过选择合适的迁移工具、进行手动迁移和应用程序适配、以及迁移后的验证与优化,可以确保数据迁移的成功和业务的连续性。希望本文的分享能够为大家在MySQL到PostgreSQL的数据库迁移实战中提供一些有用的参考和启示。

shejizuopin的博客 1731

视频教程-小白快速入门greenplum-其他

小白快速入门greenplum 研究生学历,软考高级/中级职称,10年以上大...

weixin_34341755的博客 536

HMC5883L磁力计在STM32F4上的I2C驱动与数据校准实战

本文详细介绍了HMC5883L磁力计在STM32F4平台上的I2C驱动开发与数据校准实战。通过解析寄存器配置、数据读取处理和椭圆拟合校准算法,帮助开发者实现精准的地磁测量,特别适用于无人机导航和机器人系统中的航向确定与陀螺仪漂移修正。

2y3u4i5o6p的博客 1037

【AI应用实战-claude】在飞书上接入claudecode进行远程使用(十三)

本文介绍了三种将ClaudeCode接入飞书的方案,包括官方飞书CLI工具(推荐)、cc-connect中转工具和MCP协议集成。官方飞书CLI适合自动化办公场景,通过简单配置即可实现消息发送和文档管理;cc-connect适用于远程调用Claude功能,通过飞书群聊触发响应;MCP协议则适合开发者构建复杂工作流。文章提供了详细的操作步骤,并针对不同使用场景给出了选择建议。

1013

Greenplum入门——基础知识、安装、常用函数

本文为博主在学习Greenplum时阅读的《Greenplum企业应用实战》时的笔记,对书中章节的知识要点进行了归纳和梳理。有兴趣的同学可以找原书学习下。如果认为文中内容涉嫌侵权请及时联系博主删除文章。软件安装及数据库初始化Greenplum架构Master主机与Segment主机的职责Master 建立与客户端的会话连接和管理 SQL的解析并形成分布式的执行计划 将生成好的执行计划分发到每个Seg

在咖啡里溺水的鱼 1万+

多模态论文笔记——VQ-VAE和VQ-VAE-2

本文详细介绍VQ-VAE和VQ-VAE-2的原理和训练过程,为后面的dVAE在DALLE中的使用打下坚实的基础。

haopinglianlian的博客 3299
上一篇: Docker启动单机版GreenPlum(GPDB)数据库
下一篇: docker如何查看一个正在运行的容器当时创建的命令
qq_34412985
博客等级 码龄11年 143粉丝 983原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值