GreenPlum数据库集群安装说明及使用手册开心十二月总结****年**月**日目录1体系结构介绍 (4)2安装 (10)2.1安装 (10)2.1.1安装准备 (10)2.1.2安装gp-db (11)2.1.3配置通讯 (13)2.1.4建立数据存储池 (17)2.1.5同步系统时间 (17)2.1.6验证安装是否成功 (17)2.1.7初始化 (17)2.1.8数据库的启停 (18)2.2Master双机热备 (19)2.3Segment节点互备 (20)3GP数据库的使用 (22)3.1pgAdminIII工具 (22)3.1.1安装和第一次使用pgAdminIII (22)3.1.2主窗体 (23)3.1.3导航菜单 (23)3.1.4工具栏介绍 (24)3.1.5数据库与表的创建 (25)3.1.6使用pgAdminIII备份数据库 (25)3.2JDBC配置 (26)3.3GP数据库两个重要概念 (27)3.3.1什么是Schema (27)3.3.2数据分布存储 (28)3.4GP的SQL语法 (28)3.4.1数据加载 (28)3.4.2SQL并行查询 (32)3.4.3聚合函数 (32)3.4.4索引 (32)3.4.5分区 (34)3.4.6函数 (35)4维护数据库 (39)4.1数据库启动gpstart (39)4.2数据库停止gpstop (41)4.3查看实例配置和状态 (41)4.4查看数据库运行状态gpstate (42)4.5查看用户会话和提交的查询等信息 (43)4.6查看数据库、表占用空间 (43)4.7查看数据分布情况 (44)4.8实例恢复gprecoverseg (44)4.9查看锁信息 (44)4.10数据库的备份与恢复 (44)5调优、排错 (44)6附件 (44)6.1DBA常用命令 (44)7Q&A (45)7.1不支持触发器 (45)7.2更新操作中的若干问题 (45)1体系结构介绍Greenplum数据库产品——下一代数据仓库引擎和分析方法Greenplum公司是企业数据云计算解决方案的创始人,为客户提供灵活的数据商业智能和分析方法。
能够以极低的成本代价,提供业界领先的计算性能。
客户遍及美国知名企业:Nasdaq、NYSE、Ebay、Fox Interactive Media……等。
Greenplum公司的Greenplum数据库产品是用于建造下一代数据仓库和巨大规模分析系统的软件解决方案。
支持SQL和MapReduce并行处理,更适合管理TB级~PB级的海量数据,并以极低的成本代价提供了业界领先的计算性能。
使用独有的sharing-nothing MPP架构,服务器的集群工作起来,就像是一个独立的超级计算机!优化了BI和分析方法,自动化分区数据和并行查询,比传统数据库执行速度提高10倍~100倍!Greenplum数据库的特色:➢大规模地并行分析处理能力Greenplum数据库可以跨越100~1000颗CPU,实现统一的并行操作引擎,让处理过程尽可能地靠近数据。
Greenplum是业界最快的和最普及的高端数据仓库解决方案!用传统方式需花费数天才能完成的复杂查询,现在使用Greenplum只需要几分钟完成!➢核心的MPP架构Greenplum数据库提供数据和查询的自动化并行:数据被自动分区跨越集群中的所有节点;查询以高度协作的方式,在集群的所有节点上执行。
➢高速PB级数据装载利用独有的MPP Scatter/Gather Streaming技术,实现高速的数据装载。
每增加1个节点,每小时装载吞吐量提高4TB!➢数据库内部压缩利用业界领先的压缩技术提高性能和降低存储空间。
在有效较少1/3~1/10空间的同时,相应地提高了I/O性能。
➢多级容错能力Greenplum数据库利用多级冗余技术,在硬件或软件故障时,保障操作可以继续执行。
➢在线系统扩展为提高存储容量、处理性能,增加新的服务器到集群中,扩展的操作在后台完成,数据库可以继续保持正常工作状态不受影响。
处理性能和存储容量,随服务器的个数增加成正比显著提高!➢自有的MapReduce技术MapReduce是Google和Yahoo的大规模数据分析方法。
Greenplum使用独有的并行引擎执行MapReduce。
Greenplum数据库架构原理解密:Greenplum数据库通过分布负载到多个服务器主机,实现操作存储和处理大规模的数据。
数据库实际上由1个Master服务器和若干个独立的Segment服务器组成,一起协调工作,每个服务器都是独立的PostgreSQL数据库。
如图1所示,Master服务器是数据库的入口,验证客户端,处理输入的SQL,分布工作到若干Segment服务器,统一协调各个Segment返回的结果,汇总最终结果返回客户端。
Master不存储任何用户数据,只有全局系统视图。
图1:Greenplum数据库架构如图2所示,Segment服务器是真正数据存储的地方,并承担主要的查询工作。
用户数据(表、索引)被分布存储到有效的若干Segment,通过Hash算法,每个Segment存放数据的不同部分。
图2:Segment服务器真正存储数据图3展示了一套完整的Greenplum数据仓库实施架构示例。
独立的Master服务器,通过千兆网络连接在一起的若干Segment服务器,每个Segment服务器挂载独立的RAID 存储。
服务器基于X86-64位硬件平台,安装Linux操作系统,获得极高的性价比。
图3:Greenplum数据库完整实施架构示例图4记录了一次完整的MPP并行查询过程。
Master作为查询调度器,为客户端提供连接工作;Segment独立管理数据片和数据操作。
调度过程如下:1.Master验证客户端用户。
2.Master连接到所有远程Segment实例。
3.Master解析SQL语句。
4.Master建立1个优化的并行查询计划。
5.Master分布查询计划到所有的Segment实例。
6.Master协调查询计划在所有Segment上并行执行。
7.Master收集所有Segment的查询结果并返回到客户端。
图4:一次查询调度过程Greenplum 独有的Sharing -Nothing 架构:数据仓库在执行全表扫描查询时,通常速度被存储的带宽限制,即瓶颈大多集中在I/O 。
Greenplum 的Sharing-Nothing 架构物理分离数据,存储到若干Segment 服务器,每个Segment 使用多个、专用的、独立的、高速的通道独立连接到磁盘,并把管理数据库资源:buffer 、lock 、block 的职责委派到各个Segment ,不使用Master 统一管理资源!从图5中可以看出与Sharing-Everything 架构(如Oracle RAC )对比,存在2个明显区别:图5:sharing-everying 对比sharing-nothing 数据库架构1) 数据库物理存储方式不同:在RAC 环境下,数据库集中存储,集群中的所有节点共享I/O 通道访问数据,随着TB 级别海量数据的增加,I/O 瓶颈可想而知。
Segment1 Segmentn Segment22)集群节点间内部通信管理方式不同:如图6,RAC使用GRD(Global Resource Directory)统一管理数据库资源,管理内部节点间通信。
用户对每个block的访问,都要经过GRD的协调调度,极其繁琐且需要额外的进程通信负担;随着节点个数的增加,GRD会增加管理的复杂度,可能会导致产生性能问题!图6:Oracle RAC的GRD架构2安装2.1安装2.1.1安装准备CentOS-6.3-x86_64-bin-DVD1.isoVMware Workstationgreenplum-db-4.2.1.0-build-3-CommunityEdition-RHEL5-x86_64.zip 2.1.1.1os的配置以root用户操作2.1.1.2检查系统条件检查系统名称,版本,内核.# uname -a检查磁盘空间# df -h2.1.1.3设置主机名#vi /etc/sysconfig/networkHOSTNAME=*single* (*变量*,以后出现*string*,均指变量)2.1.1.4设置集群各个机器ip与主机的对应表#vi /etc/hosts127.0.0.1 single localhost配置运行参数:#vi /etc/sysctl.conf添加修改:kernel.sem = 250 64000 100 512kernel.shmmax = 500000000(最大共享内存)kernel.shmmni = 4096kernel.shmall = 4000000000(共享内存总量)kernel.sem = 250 64000 100 512kernel.sysrq = 1kernel.core_uses_pid = 1kernel.msgmnb = 65536kernel.msgmax = 65536net.ipv4.tcp_syncookies = 1net.ipv4.ip_forward = 0net.ipv4.conf.default.accept_source_route = 0net.ipv4.tcp_tw_recycle=1net.ipv4.tcp_max_syn_backlog=4096net.ipv4.conf.all.arp_filter = 1dev_max_backlog=10000vm.overcommit_memory=2#vi /etc/security/limits.conf添加修改* soft nofile 65536* hard nofile 65536* soft nproc 131072* hard nproc 1310722.1.1.5关闭iptables[root@localhost ~]# service iptables stopiptables:清除防火墙规则:[确定] iptables:将链设置为政策ACCEPT:filter [确定] iptables:正在卸载模块:[确定] [root@localhost ~]# chkconfig iptables off[root@localhost ~]# service ip6tables stopip6tables:清除防火墙规则:[确定] ip6tables:将chains 设置为ACCEPT 策略:filter [确定] :正在卸载模块:[确定] [root@localhost ~]# chkconfig ip6tables off2.1.2安装gp-db创建gpadmin用户# useradd gpadmin# passwd gpadmin# New password: gpadmin# Retype new password: gpadmin2.1.2.1解压zip包例如:把安装包copy到/home/gpadmin目录下#su gpadmin#cd /home/gpadmin#unzip greenplum-db-4.2.1.0-build-3-CommunityEdition-RHEL5-x86_64.zip2.1.2.2执行安装文件./greenplum-db-4.2.1.0-build-3-RHEL5-x86_64.bin安装过程比较容易,但是注意要修改一下安装路径为/home/gpadmin/greenplum-db-4.2.1.0下图打印了安装时的情况:出现如下提示:********************************************************************************Do you accept the Greenplum Database license agreement? [yes|no]********************************************************************************yes********************************************************************************Provide the installation path for Greenplum Database or press ENTER toaccept the default installation path: /home/gpadmingreenplum-db-4.2.1.0********************************************************************************/home/gpadmin/greenplum-db-4.2.1.0********************************************************************************Install Greenplum Database into </home/gpadmin/greenplum-db-4.2.1.0>? [yes|no]********************************************************************************yes********************************************************************************/home/gpadmin/greenplum-db-4.2.1.0 does not exist.Create /home/gpadmin/greenplum-db-4.2.1.0 ? [yes|no](Selecting no will exit the installer)********************************************************************************yes******************************************************************************** [Optional] Provide the path to a previous installation of Greenplum Database,or press ENTER to skip this step. e.g. /home/gpadmingreenplum-db-4.1.1.3This installation step will migrate any Greenplum Database extensions from theprovided path to the version currently being installed. This step is optionaland can be run later with:gppkg --migrate <path_to_old_gphome> /home/gpadmin/greenplum-db-4.2.1.0 ******************************************************************************** Extracting product to /home/gpadmin/greenplum-db-4.2.1.0Extracting product to /home/gpadmin/greenplum-db-4.2.1.0Skipping migration of Greenplum Database extensions...******************************************************************************** Installation complete.Greenplum Database is installed in /home/gpadmin/greenplum-db-4.2.1.0 Greenplum Database documentation is available for downloadat .********************************************************************************安装成功!2.1.3配置通讯登录master机器source一下greenplum_path.sh文件# source /home/gpadmin/greenplum-db/greenplum_path.sh2.1.3.1编辑一个主机列表列表为主机名.#cd /home/gpadmin#vi all_hosts_file*host1**host2**host3*…2.1.3.2打通root的ssh通道执行gpssh-keys命令.#su – root# gpssh-exkeys -f all_hosts_filegpssh-exkeys 将要求对每台机器鉴权.提示:后输入用户名密码***Enter password for root@hostname: root password提示:[STEP 1 of 5] create local ID and authorize on local host[STEP 2 of 5] keyscan all hosts and update known_hosts file[STEP 3 of 5] authorize current user on remote hosts[STEP 4 of 5] determine common authentication file content[STEP 5 of 5] copy authentication files to all remote hosts[INFO] completed successfully2.1.3.3为每台机器创建gpadmin用户# su – root(以root用户登录各节点机器来创建用户)# gpssh -f all_hosts_file '/usr/sbin/useradd gpadmin -d /home/gpadmin -s /bin/bash'2.1.3.4为每台机器添加gpadmin的密码# gpssh -f all_hosts_file 'echo password | passwd gpadmin --stdin'2.1.3.5修改目录拥有者# chown -R gpadmin:gpadmin /home/gpadmin/*2.1.3.6打通gpadmin的ssh通道执行gpssh-keys命令.#su gpadmin#source /home/gpadmin/greenplum-db/greenplum_path.sh # gpssh-exkeys -f all_hosts_filegpssh-exkeys 将要求对每台机器鉴权.提示:后输入用户名密码***Enter password for root@hostname: root password提示:[STEP 1 of 5] create local ID and authorize on local host [STEP 2 of 5] keyscan all hosts and update known_hosts file [STEP 3 of 5] authorize current user on remote hosts[STEP 4 of 5] determine common authentication file content [STEP 5 of 5] copy authentication files to all remote hosts [INFO] completed successfully2.1.3.7把master的gp-db服务copy到各个slave机器上.在master上把gp-db打包.# cd /home/gpadmin# source /home/gpadmin/greenplum-db/greenplum_path.sh # gtar -cvf /home/gpadmin/gp.tar greenplum-db-4.0.x.x2.1.3.8做主机列表(不能有空行和空格)#vi seg_hosts_file*sdw1-1**sdw2-1**sdw3-1*2.1.3.9copy到各个seg机器上# gpscp -f seg_hosts_file /home/gpadmin/gp.tar =:/home/gpadmin2.1.3.10登录到各个slave机器# gpssh -f seg_hosts_file2.1.3.11解压tar包=> gtar --directory /home/gpadmin -xvf /home/gpadmin/gp.tar2.1.3.12查看服务=> ls /home/gpadmin/greenplum-db-4.0.x.x2.1.3.13建立链接=> ln -s /home/gpadmin/greenplum-db-4.2.1.0 /home/gpadmin/greenplum-db 2.1.3.14更改用户组=> chown -R gpadmin:gpadmin /home/gpadmin/greenplum-db2.1.3.15删除tar包=> rm /home/gpadmingp.tar2.1.3.16退出远程登录Exit gpssh=>exit2.1.3.17激活#source /home/gpadmin/greenplum-db/greenplum_path.sh #source ~/.bashrc2.1.4建立数据存储池2.1.4.1建立master的数据结构存储地# su gpadmin# cd /home/gpadmin# mkdir gpmaster2.1.4.2建立业务数据存储地登录到每台节点机上创建目录,gpadmin有操作权限su - gpadmin# cd /home/gpadmin$ mkdir gpdata1# chown –R gpadmin:gpadmin gpdata12.1.5同步系统时间同步系统时间:$ gpssh -f seg_hosts_file -v date同步NTP时间:$ gpssh -f seg_hosts_file -v ntpd2.1.6验证安装是否成功# gpcheck -f all_hosts_file2.1.7初始化设置变量:#su gpadmin#vi .bash_profileGPHOME=/home/gpadminexport GPHOMEMASTER_DATA_DIRECTORY=/home/gpadmin/gpmaster/gpseg-1export MASTER_DATA_DIRECTORY# source ~/.bashrc# source .bash_profile建立初始化文件:#vi gp_init_configARRAY_NAME="Greenplum"MACHINE_LIST_FILE=/home/gpadmin/seg_hosts_fileSEG_PREFIX=gpsegPORT_BASE=50000declare -a DATA_DIRECTORY=(/home/gpadmin/gpdata1)MASTER_HOSTNAME=masterMASTER_DIRECTORY=/home/gpadmin/gpmasterMASTER_PORT=5432TRUSTED_SHELL=sshCHECK_POINT_SEGMENTS=8ENCODING=UTF8DATABASE_NAME=test执行初始化:# source /home/gpadmin/greenplum-db/greenplum_path.sh# gpinitsystem -c /home/gpadmin/gp_init_config修改master机器上的路径下/home/gpadmin/gpmaster/gpseg-1的文件pg_hba.conf,在文件里面添加内容:host all gpadmin 0.0.0.0/0 trust这部分添加的内容要在文件中和这个文件内容类似的地方添加修改master机器上的路径下/home/gpadmin/gpmaster/gpseg-1的文件postgresql.conf,将内容#listen_addresses = '*' 的# 符号去掉,即为将监听打开2.1.8数据库的启停1)启动数据库服务在master节点上,请以gpadmin用户登入OS,执行命令gpstart,系统会自检,并提示是否启动服务,选择y,启动服务。