zl程序教程

您现在的位置是:首页 >  数据库

当前栏目

GreenPlum的学习心得和知识总结(一)|GreenPlum数据库源码编译安装及学习资料汇总

数据库安装源码学习 总结 编译 知识 汇总
2023-09-14 09:15:34 时间

注:提前言明 本文借鉴了以下博主、书籍或网站的内容,其列表如下:

1、GreenPlum中文官网首页,点击前往
2、GreenPlum git仓库,点击前往本人GreenPlum gitee仓库,点击前往
3、PostgreSQL数据库仓库链接,点击前往
4、YouTube greenplum视频主页,点击前往
5、Bilibili greenplum视频主页,点击前往


1、本文内容全部来源于开源社区 GitHub和以上博主的贡献,本文也免费开源(可能会存在问题,评论区等待大佬们的指正)
2、本文目的:开源共享 抛砖引玉 一起学习
3、本文不提供任何资源 不存在任何交易 与任何组织和机构无关
4、大家可以根据需要自行 复制粘贴以及作为其他个人用途,但是不允许转载 不允许商用 (写作不易,还请见谅 💖)


GreenPlum数据库源码编译安装及学习资料汇总



文章快速说明索引

学习目标:

开源、多云、并行的大数据平台。Greenplum 是全球领先的大数据分析引擎,专为分析、机器学习和AI而打造!接下来一段时间,除了PostgreSQL数据库的相关内容分享 也会把GreenPlum数据库的学习心得及相关知识总结记录下来!后面我可能会去gp工作,不管怎么说 gp都是非常值得一学和大力推广!


学习内容:(详见目录)

1、GreenPlum数据库 源码编译安装及学习资料汇总


学习时间:

2022年05月23日 10:48:52


学习产出:

1、PostgreSQL数据库基础知识回顾 1个
2、CSDN 技术博客 1篇


学习资料相关分享

注:毕竟GreenPlum来源于PostgreSQL,相关的数据库知识还是一致的!

  1. 本人PostgreSQL学习资料汇总:PostgreSQL的学习心得和知识总结(一)|简介和学习资源分享,点击前往
  2. GreenPlum英文官网首页,点击前往GreenPlum中文官网首页,点击前往
  3. GreenPlum中文社区(含一些开源项目),点击前往
  4. GreenPlum git仓库,点击前往本人GreenPlum gitee仓库,点击前往
  5. PostgreSQL数据库 git仓库链接,点击前往
  6. YouTube greenplum视频主页,点击前往
  7. Bilibili greenplum视频主页,点击前往
  8. GreenPlum官方手册(英文版),点击前往GreenPlum官方手册(中文版),点击前往
  9. Greenplum中文社区 稀土掘金,点击前往
  10. Stackoverflow:Questions tagged greenplum,点击前往

下面介绍一位我的好友 GreenPlum员工,阿福Chris,CSDN博客主页,点击前往。下面有兴趣的小伙伴可以看一下GreenPlum的生态介绍:


因为在下是做PostgreSQL数据库内核开发的,这里只介绍一本书:


源码编译安装演示

一、建议直接去获取源码包,例如:

https://github.com/greenplum-db/gpdb/releases/tag/6.20.3

二、git仓库方式 (建议不要用git仓库,因为后面执行README.CentOS.bash安装相关python的东西 会失败):

# git clone https://gitee.com/lucky912_admin/gpdb.git

# git checkout -b 6.20.3 6.20.3

[postgres@song149 gpdb]$ pwd
/home/postgres/gpdb
[postgres@song149 gpdb]$ 
[postgres@song149 gpdb]$ git branch
* 6.20.3
  master
[postgres@song149 gpdb]$ ls
aclocal.m4  configure.in  getversion      gpdb-doc  LICENSE             PULL_REQUEST_TEMPLATE.md           README.amazon_linux  README.git         README.md           src
concourse   contrib       GNUmakefile.in  gpMgmt    logo-greenplum.png  putversion                         README.CentOS.bash   README.linux.md    README.PostgreSQL
config      COPYRIGHT     gpAux           HISTORY   Makefile            python-dependencies.txt            README.conda.md      README.macOS.bash  README.ubuntu.bash
configure   doc           gpcontrib       hooks     NOTICE              python-developer-dependencies.txt  README.docker.md     README.macOS.md    README.windows.md
[postgres@song149 gpdb]$
[postgres@song149 gpdb]$ ./configure --help
`configure' configures Greenplum Database 6.0.0-beta.1 to adapt to many kinds of systems.

Usage: ./configure [OPTION]... [VAR=VALUE]...

To assign environment variables (e.g., CC, CFLAGS...), specify them as
VAR=VALUE.  See below for descriptions of some of the useful variables.

Defaults for the options are specified in brackets.

Configuration:
  -h, --help              display this help and exit
      --help=short        display options specific to this package
      --help=recursive    display the short help of all the included packages
  -V, --version           display version information and exit
  -q, --quiet, --silent   do not print `checking ...' messages
      --cache-file=FILE   cache test results in FILE [disabled]
  -C, --config-cache      alias for `--cache-file=config.cache'
  -n, --no-create         do not create output files
      --srcdir=DIR        find the sources in DIR [configure dir or `..']

Installation directories:
  --prefix=PREFIX         install architecture-independent files in PREFIX
                          [/usr/local/gpdb]
  --exec-prefix=EPREFIX   install architecture-dependent files in EPREFIX
                          [PREFIX]

By default, `make install' will install all the files in
`/usr/local/gpdb/bin', `/usr/local/gpdb/lib' etc.  You can specify
an installation prefix other than `/usr/local/gpdb' using `--prefix',
for instance `--prefix=$HOME'.

For better control, use the options below.

Fine tuning of the installation directories:
  --bindir=DIR            user executables [EPREFIX/bin]
  --sbindir=DIR           system admin executables [EPREFIX/sbin]
  --libexecdir=DIR        program executables [EPREFIX/libexec]
  --sysconfdir=DIR        read-only single-machine data [PREFIX/etc]
  --sharedstatedir=DIR    modifiable architecture-independent data [PREFIX/com]
  --localstatedir=DIR     modifiable single-machine data [PREFIX/var]
  --libdir=DIR            object code libraries [EPREFIX/lib]
  --includedir=DIR        C header files [PREFIX/include]
  --oldincludedir=DIR     C header files for non-gcc [/usr/include]
  --datarootdir=DIR       read-only arch.-independent data root [PREFIX/share]
  --datadir=DIR           read-only architecture-independent data [DATAROOTDIR]
  --infodir=DIR           info documentation [DATAROOTDIR/info]
  --localedir=DIR         locale-dependent data [DATAROOTDIR/locale]
  --mandir=DIR            man documentation [DATAROOTDIR/man]
  --docdir=DIR            documentation root
                          [DATAROOTDIR/doc/greenplum-database]
  --htmldir=DIR           html documentation [DOCDIR]
  --dvidir=DIR            dvi documentation [DOCDIR]
  --pdfdir=DIR            pdf documentation [DOCDIR]
  --psdir=DIR             ps documentation [DOCDIR]

System types:
  --build=BUILD     configure for building on BUILD [guessed]
  --host=HOST       cross-compile to build programs to run on HOST [BUILD]

Optional Features:
  --disable-option-checking  ignore unrecognized --enable/--with options
  --disable-FEATURE       do not include FEATURE (same as --enable-FEATURE=no)
  --enable-FEATURE[=ARG]  include FEATURE [ARG=yes]
  --disable-integer-datetimes
                          disable 64-bit integer date/time support
  --disable-rpath         do not embed shared library search path in
                          executables
  --disable-spinlocks     do not use spinlocks
  --disable-atomics       do not use atomic operations
  --disable-gpfdist       do not use gpfdist
  --enable-debug-extensions
                          include debug extensions in gpcontrib
  --enable-orafce         build with Oracle compatibility functions
  --enable-gpperfmon      build with gpperfmon
  --enable-debug          build with debugging symbols (-g)
  --enable-profiling      build with profiling enabled
  --enable-coverage       build with coverage testing instrumentation
  --enable-dtrace         build with DTrace support
  --enable-tap-tests      enable TAP tests (requires Perl and IPC::Run)
  --enable-depend         turn on automatic dependency tracking
  --enable-cassert        enable assertion checks (for debugging)
  --enable-debugntuplestore
                          enable debug_ntuplestore (for debugging)
  --disable-orca          disable ORCA optimizer
  --enable-mapreduce      enable Greenplum Mapreduce support
  --disable-gpcloud       disable gpcloud support
  --enable-ic-proxy       enable interconnect proxy mode (requires libuv
                          library)
  --disable-thread-safety disable thread-safety in client libraries
  --disable-largefile     omit support for large files

Optional Packages:
  --with-PACKAGE[=ARG]    use PACKAGE [ARG=yes]
  --without-PACKAGE       do not use PACKAGE (same as --with-PACKAGE=no)
  --with-extra-version=STRING
                          append STRING to version
  --with-template=NAME    override operating system template
  --with-includes=DIRS    look for additional header files in DIRS
  --with-libraries=DIRS   look for additional libraries in DIRS
  --with-libs=DIRS        alternative spelling of --with-libraries
  --with-pgport=PORTNUM   set default port number [5432]
  --with-blocksize=BLOCKSIZE
                          set table block size in kB [8]
  --with-segsize=SEGSIZE  set table segment size in GB [1]
  --with-wal-blocksize=BLOCKSIZE
                          set WAL block size in kB [8]
  --with-wal-segsize=SEGSIZE
                          set WAL segment size in MB [16]
  --with-CC=CMD           set compiler (deprecated)
  --with-tcl              build Tcl modules (PL/Tcl)
  --with-tclconfig=DIR    tclConfig.sh is in DIR
  --with-perl             build Perl modules (PL/Perl)
  --with-python           build Python modules (PL/Python)
  --with-gssapi           build with GSSAPI support
  --with-krb-srvnam=NAME  default service principal name in Kerberos (GSSAPI)
                          [postgres]
  --with-pam              build with PAM support
  --with-ldap             build with LDAP support
  --with-bonjour          build with Bonjour support
  --with-openssl          build with OpenSSL support
  --with-selinux          build with SELinux support
  --without-readline      do not use GNU Readline nor BSD Libedit for editing
  --with-libedit-preferred
                          prefer BSD Libedit over GNU Readline
  --with-uuid=LIB         build contrib/uuid-ossp using LIB (bsd,e2fs,ossp)
  --with-ossp-uuid        obsolete spelling of --with-uuid=ossp
  --with-libxml           build with XML support
  --with-libxslt          use XSLT support when building contrib/xml2
  --with-system-tzdata=DIR
                          use system time zone data in DIR
  --without-zlib          do not use Zlib
  --without-libbz2        do not use bzip2
  --without-zstd          do not build with Zstandard
  --with-quicklz          build with QuickLZ support (requires quicklz
                          library)
  --without-rt            do not use Realtime Library
  --without-libcurl       do not use libcurl
  --with-apr-config=PATH  path to apr-1-config utility
  --with-apu-config=PATH  path to apu-1-config utility
  --with-gnu-ld           assume the C compiler uses GNU ld [default=no]

Some influential environment variables:
  CC          C compiler command
  CFLAGS      C compiler flags
  LDFLAGS     linker flags, e.g. -L<lib dir> if you have libraries in a
              nonstandard directory <lib dir>
  LIBS        libraries to pass to the linker, e.g. -l<library>
  CPPFLAGS    (Objective) C/C++ preprocessor flags, e.g. -I<include dir> if
              you have headers in a nonstandard directory <include dir>
  CXX         C++ compiler command
  CXXFLAGS    C++ compiler flags
  CPP         C preprocessor
  LDFLAGS_EX  extra linker flags for linking executables only
  LDFLAGS_SL  extra linker flags for linking shared libraries only
  DOCBOOKSTYLE
              location of DocBook stylesheets

Use these variables to override the choices made by `configure' or to help
it to find libraries and programs with nonstandard names/locations.

Report bugs to <support@greenplum.org>.
[postgres@song149 gpdb]$

我们这里只解释一下个别参数,如下:

--enable-orafce         build with Oracle compatibility functions

--disable-orca          disable ORCA optimizer
/*
* Currently, GPDB is built with GPORCA by default. 
* If you want to build GPDB without GPORCA, configure requires --disable-orca flag to be set.
*/ 

关于ORCA,介绍如下:

======================================================================
                 __________  ____  ____  _________
                / ____/ __ \/ __ \/ __ \/ ____/   |
               / / __/ /_/ / / / / /_/ / /   / /| |
              / /_/ / ____/ /_/ / _, _/ /___/ ___ |
              \____/_/    \____/_/ |_|\____/_/  |_|
                  The Greenplum Query Optimizer
              Copyright (c) 2015, VMware, Inc. or its affiliates.
            Licensed under the Apache License, Version 2.0
======================================================================
Welcome to GPORCA, the Greenplum Next Generation Query Optimizer!

To understand the objectives and architecture of GPORCA please refer to the following articles:

下面看一下代码结构,如下:

[postgres@song149 gpdb]$ ls
aclocal.m4  configure.in  getversion      gpdb-doc  LICENSE             PULL_REQUEST_TEMPLATE.md           README.amazon_linux  README.git         README.md           src
concourse   contrib       GNUmakefile.in  gpMgmt    logo-greenplum.png  putversion                         README.CentOS.bash   README.linux.md    README.PostgreSQL
config      COPYRIGHT     gpAux           HISTORY   Makefile            python-dependencies.txt            README.conda.md      README.macOS.bash  README.ubuntu.bash
configure   doc           gpcontrib       hooks     NOTICE              python-developer-dependencies.txt  README.docker.md     README.macOS.md    README.windows.md
[postgres@song149 gpdb]$

存储库的目录布局遵循与上游 PostgreSQL 相同的一般布局。 与 PostgreSQL 相比,整个代码库都有一些变化,但值得注意的是一些更大的补充:

  • gpMgmt/

包含用于管理集群的特定于 Greenplum 的命令行工具。 gpinit、gpstart、gpstop 等脚本都在这里,它们大多是用 Python 编写的。

  • gpAux/

包含特定于 Greenplum 的发布管理脚本和供应商的依赖项。一些额外的目录是子模块,将随着时间的推移而可用。

  • gpcontrib/

与 PostgreSQL contrib/ 目录非常相似,该目录包含诸如 gpfdist、PXF 和 gpmapreduce 等 Greenplum 特定的扩展。

  • doc/

在 PostgreSQL 中,用户手册位于此处。在 Greenplum 中,用户手册是单独维护的,这里只有用于构建手册页的参考页。

  • gpdb-doc/

包含 DITA XML 格式的 Greenplum 文档。 有关如何构建和使用文档的信息,请参阅 gpdb-doc/README.md

  • ci/

包含 GPDB 持续集成系统的配置文件。

[postgres@song149 backend]$ ls
access     catalog  commands   executor  fts    gporca  libpq  Makefile  nls.mk  optimizer  po    postmaster  replication  snowball  tcop     utils
bootstrap  cdb      common.mk  foreign   gpopt  lib     main   mock.mk   nodes   parser     port  regex       rewrite      storage   tsearch
[postgres@song149 backend]$ 
[postgres@song149 backend]$ pwd
/home/postgres/gpdb/src/backend
[postgres@song149 backend]$
  • src/backend/cdb/

包含更大的 Greenplum 特定的后端模块。 例如,segment之间的通信,将计划变成可并行化的计划,镜像,分布式事务和快照管理等。cdb 代表 Cluster Database - 它是早期使用的工作名称。 该名称不再使用,但 cdb 前缀仍然存在。

  • src/backend/gpopt/

包含所谓的转换器库,用于将 GPORCA 优化器与 Greenplum 一起使用。 转换器库是用 C++ 代码编写的,包含用于在 GPORCA 使用的 DXL 格式和 PostgreSQL 内部表示之间转换计划和查询的胶水代码。

  • src/backend/gporca/

包含 GPORCA 优化器代码和测试。 这是用 C++ 编写的。 有关更多信息以及如何对 GPORCA 进行单元测试,请参阅 README.md

  • src/backend/fts/

FTS是一个运行在coordinator节点上的进程,周期性的轮询segment,维护每个segment的状态。


下面进行源码编译安装,在开始之前 需要先行注意一些东西:

这里的环境背景 两台机器(master+standby):192.71.0.149 + 192.71.0.147


https://github.com/greenplum-db/gpdb/releases 对应版本的tag的源码包下下来 把ext目录的文件复制上。若是本身就用的源码包编译的话,这些文件都有了!
在这里插入图片描述

[postgres@song149 gpdb]$ uname -a
Linux song149 3.10.0-693.el7.x86_64 #1 SMP Tue Aug 22 21:09:27 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux
[postgres@song149 gpdb]$ 
[postgres@song149 gpdb]$ cat /etc/os-release 
NAME="CentOS Linux"
VERSION="7 (Core)"
ID="centos"
ID_LIKE="rhel fedora"
VERSION_ID="7"
PRETTY_NAME="CentOS Linux 7 (Core)"
ANSI_COLOR="0;31"
CPE_NAME="cpe:/o:centos:centos:7"
HOME_URL="https://www.centos.org/"
BUG_REPORT_URL="https://bugs.centos.org/"

CENTOS_MANTISBT_PROJECT="CentOS-7"
CENTOS_MANTISBT_PROJECT_VERSION="7"
REDHAT_SUPPORT_PRODUCT="centos"
REDHAT_SUPPORT_PRODUCT_VERSION="7"

[postgres@song149 gpdb]$

sudo yum install libzstd
sudo yum install libzstd-devel

sudo yum install apr-devel

sudo yum install libevent-devel

sudo yum install xerces-c-devel

sudo yum install perl-ExtUtils-Embed -y

sudo yum install epel-release

sudo yum install -y python-pip

pip install --upgrade pip
# 根据你的系统运行
# git仓库拉取的 执行./README.CentOS.bash

[postgres@song149 gpdb]$ ./configure --prefix=/home/postgres/gpdbtest --enable-debug --with-libxml --with-perl --with-python --with-gssapi
[postgres@song149 gpdb]$ make
[postgres@song149 gpdb]$ make install

注:第二台机器 也是如此安装!完成之后,如下:

[postgres@song149 ~]$ cd gpdbtest/
[postgres@song149 gpdbtest]$ ls
bin  docs  greenplum_path.sh  include  lib  libexec  sbin  share
[postgres@song149 gpdbtest]$ 
[postgres@song149 gpdbtest]$ cat greenplum_path.sh 
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd)"
if [ ! -L "${SCRIPT_DIR}" ]; then
    GPHOME=${SCRIPT_DIR}
else
    GPHOME=$(readlink "${SCRIPT_DIR}")
fi
PYTHONPATH="${GPHOME}/lib/python"
PATH="${GPHOME}/bin:${PATH}"
LD_LIBRARY_PATH="${GPHOME}/lib${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH}"

if [ -e "${GPHOME}/etc/openssl.cnf" ]; then
        OPENSSL_CONF="${GPHOME}/etc/openssl.cnf"
fi

export GPHOME
export PATH
export PYTHONPATH
export LD_LIBRARY_PATH
export OPENSSL_CONF
[postgres@song149 gpdbtest]$

配置如下:

[postgres@song149 bin]$ vim cluster.conf
[postgres@song149 bin]$ 
[postgres@song149 bin]$ mkdir ~/gpdata/primary -p
[postgres@song149 bin]$ mkdir ~/gpdata/master
[postgres@song149 bin]$ 
[postgres@song149 bin]$ cat cluster.conf 
CLUSTER_NAME="gpdb"
SEG_PREFIX=gp
PORT_BASE=40000
DATA_DIRECTORY=(/home/postgres/gpdata/primary /home/postgres/gpdata/primary)
MASTER_DIRECTORY=/home/postgres/gpdata/master
MASTER_HOSTNAME=song149
MASTER_PORT=5432
IP_ALLOW=0.0.0.0/0
TRUSTED_SHELL=/usr/bin/ssh                                                                                                                                                             
CHECK_POINT_SEGMENTS=8
ENCODING=UNICODE

[postgres@song149 bin]$ vim hostfile
[postgres@song149 bin]$ 
[postgres@song149 bin]$ cat hostfile 
song149
song147
[postgres@song149 bin]$

一、互信:

  1. 关闭防火墙
  2. 禁用安全策略
    在这里插入图片描述
  3. 配置/etc/hosts,增加主机名与IP对应关系(song149 song147)
  4. hostfile如下
  5. 删除这两台机器的家目录下.ssh目录
  6. 重新生成密钥,仅在主节点(song149)上执行如下命令,如下
    在这里插入图片描述
  7. 将公钥内容输出到authorized_keys文件中,仅在主节点上执行如下命令:cp ~/.ssh/id_rsa.pub ~/.ssh/authorized_keys
  8. 实现主节点到其他节点的免密访问,即 "1-n passwordless SSH",仅在主节点使用如下命令:
    在这里插入图片描述
  9. 实现互信,即"n-n passwordless SSH",执行如下命令:
    在这里插入图片描述

注:通过gpssh -h 主机名,可不输入密码,直接登录其他服务器节点,说明配置成功!

[postgres@song149 bin]$ ./gpssh -h song147
=> ls
[song147] Desktop    insert-set-v4.patch                 pgNodeGraph   test
[song147] Documents  Music                       Pictures      update_alias.patch
[song147] Downloads  newrownum.patch             postgres      Videos
[song147] gpdata           oracle_decode.patch           Public
[song147] gpdb     oracle_function_decode.patch  rownum.patch
[song147] gpdbtest   patch                       Templates
=> exit

[postgres@song149 bin]$ 

[postgres@song147 bin]$ source ../greenplum_path.sh 
[postgres@song147 bin]$ 
[postgres@song147 bin]$ ./gpssh -h song149
=> ls
[song149] deleteIsOk   insert-set-v4.patch         postgres
[song149] Desktop      Music                       Public
[song149] Documents    newrownum.patch             rownum.patch
[song149] Downloads    oracle_decode.patch         Templates
[song149] gpAdminLogs  oracle_function_decode.patch  test
[song149] gpdata             patch                         update_alias.patch
[song149] gpdb       pgNodeGraph                   Videos
[song149] gpdbtest     Pictures
=> exit

[postgres@song147 bin]$ 

二、初始化

[postgres@song149 bin]$ ./gpinitsystem -c ./cluster.conf -h hostfile 
...
20220523:16:42:45:108847 gpinitsystem:song149:postgres-[WARN]:-*******************************************************
20220523:16:42:45:108847 gpinitsystem:song149:postgres-[INFO]:-Greenplum Database instance successfully created
20220523:16:42:45:108847 gpinitsystem:song149:postgres-[INFO]:-------------------------------------------------------
20220523:16:42:45:108847 gpinitsystem:song149:postgres-[INFO]:-To complete the environment configuration, please 
20220523:16:42:45:108847 gpinitsystem:song149:postgres-[INFO]:-update postgres .bashrc file with the following
20220523:16:42:45:108847 gpinitsystem:song149:postgres-[INFO]:-1. Ensure that the greenplum_path.sh file is sourced
20220523:16:42:45:108847 gpinitsystem:song149:postgres-[INFO]:-2. Add "export MASTER_DATA_DIRECTORY=/home/postgres/gpdata/master/gp-1"
20220523:16:42:45:108847 gpinitsystem:song149:postgres-[INFO]:-   to access the Greenplum scripts for this instance:
20220523:16:42:45:108847 gpinitsystem:song149:postgres-[INFO]:-   or, use -d /home/postgres/gpdata/master/gp-1 option for the Greenplum scripts
20220523:16:42:45:108847 gpinitsystem:song149:postgres-[INFO]:-   Example gpstate -d /home/postgres/gpdata/master/gp-1
20220523:16:42:45:108847 gpinitsystem:song149:postgres-[INFO]:-Script log file = /home/postgres/gpAdminLogs/gpinitsystem_20220523.log
20220523:16:42:45:108847 gpinitsystem:song149:postgres-[INFO]:-To remove instance, run gpdeletesystem utility
20220523:16:42:45:108847 gpinitsystem:song149:postgres-[INFO]:-To initialize a Standby Master Segment for this Greenplum instance
20220523:16:42:45:108847 gpinitsystem:song149:postgres-[INFO]:-Review options for gpinitstandby
20220523:16:42:45:108847 gpinitsystem:song149:postgres-[INFO]:-------------------------------------------------------
20220523:16:42:45:108847 gpinitsystem:song149:postgres-[INFO]:-The Master /home/postgres/gpdata/master/gp-1/pg_hba.conf post gpinitsystem
20220523:16:42:45:108847 gpinitsystem:song149:postgres-[INFO]:-has been configured to allow all hosts within this new
20220523:16:42:45:108847 gpinitsystem:song149:postgres-[INFO]:-array to intercommunicate. Any hosts external to this
20220523:16:42:45:108847 gpinitsystem:song149:postgres-[INFO]:-new array must be explicitly added to this file
20220523:16:42:45:108847 gpinitsystem:song149:postgres-[INFO]:-Refer to the Greenplum Admin support guide which is
20220523:16:42:45:108847 gpinitsystem:song149:postgres-[INFO]:-located in the /home/postgres/gpdbtest/docs directory
20220523:16:42:45:108847 gpinitsystem:song149:postgres-[INFO]:-------------------------------------------------------
[postgres@song149 bin]$ 

三、查看状态
在这里插入图片描述

[postgres@song149 bin]$ ./gpstate -s
20220523:16:44:21:113489 gpstate:song149:postgres-[INFO]:-Starting gpstate with args: -s
20220523:16:44:21:113489 gpstate:song149:postgres-[CRITICAL]:-gpstate failed. (Reason='Environment Variable MASTER_DATA_DIRECTORY not set!') exiting...
[postgres@song149 bin]$ export MASTER_DATA_DIRECTORY=/home/postgres/gpdata/master/gp-1
[postgres@song149 bin]$ 
[postgres@song149 bin]$ ./gpstate -s

在这里插入图片描述
四、建表 插入数据

postgres=# select version();
                                                                          version                                                                          
-----------------------------------------------------------------------------------------------------------------------------------------------------------
 PostgreSQL 9.4.26 (Greenplum Database 6.20.3 build dev) on x86_64-unknown-linux-gnu, compiled by gcc (GCC) 7.1.0, 64-bit compiled on May 23 2022 16:33:19
(1 row)

postgres=# CREATE TABLE foo (a int) WITH (appendonly=true, compresstype=zlib, compresslevel=5);
NOTICE:  Table doesn't have 'DISTRIBUTED BY' clause -- Using column named 'a' as the Greenplum Database data distribution key for this table.
HINT:  The 'DISTRIBUTED BY' clause determines the distribution of data. Make sure column(s) chosen are the optimal data distribution key to minimize skew.
CREATE TABLE
postgres=# \d+ foo
                   Append-Only Table "public.foo"
 Column |  Type   | Modifiers | Storage | Stats target | Description 
--------+---------+-----------+---------+--------------+-------------
 a      | integer |           | plain   |              | 
Compression Type: zlib
Compression Level: 5
Block Size: 32768
Checksum: t
Distributed by: (a)
Options: appendonly=true, compresstype=zlib, compresslevel=5

postgres=# insert into foo values (generate_series(1,10000));
INSERT 0 10000
postgres=#
postgres=# select gp_segment_id,count(*) from foo group by gp_segment_id;
 gp_segment_id | count 
---------------+-------
             1 |  4987
             0 |  5013
(2 rows)

postgres=#

五、初始化standby,如下:

[postgres@song149 bin]$ ./gpinitstandby -s 192.71.0.147 -P 5432

在这里插入图片描述
此时的状态查看,如下:
在这里插入图片描述

六、停止整个服务,如下:
在这里插入图片描述
注:此时standby的也停止了!

七、启动整个服务,如下:
在这里插入图片描述
八、主备切换,如下:

下面把主master的协调节点停止,将备激活为主协调节点:
在这里插入图片描述
在这里插入图片描述

在这里插入图片描述

OK,环境搭建(song149主,song147备)完成!