1. GP Expansion

Greenplum expansion can be divided into vertical and horizontal scaling. Vertical scaling increases the number of segments on a single machine, while horizontal scaling adds more machines.

2. Vertical Expansion

2.1 Expansion without Mirrors

  1. Configure the expansion input file
    Format as follows:
<hostname>|<address>|<port>|<datadir>|<dbid>|<content>|<preferred_role>

|Field|Description|
|-|-|
|hostname|The hostname of the node host|
|address|The address of the node host|
|port|The listening port for the new segment, which should be incremented on top of the existing nodes' ports.|
|datadir|Node data directory location based on the gp_segment_configuration system catalog|
|dbid|Database ID for the segment. The user input should be sequentially incremental starting from the existing dbid values shown in the system directory gp_segment_configuration. For example, to add four nodes to an existing array with ten segments (dbid values from 1-10), the new dbid values to list are 11, 12, 13, and 14, regardless of the presence of mirror nodes.|
|content|Content ID for the segment, a primary node and its mirror should have the same content ID, and it should start incrementing from the existing values. For more information, see content in the reference of gp_segment_configuration.|
|preferred_role|The value is p or m, determining whether this segment is a primary node or a mirror. Specifying p means the primary node, and m stands for mirror.|

Suppose there are 2 existing machines, named engine1 and engine2, each with 1 segment. We are now adding an additional segment to each machine, the file is named as gpexpand_inputfile, and the contents are as follows:

engine1|engine1|25433|/opt/hengshi/engine-cluster/data/SegDataDir1|4|2|p
engine2|engine2|25433|/opt/hengshi/engine-cluster/data/SegDataDir2|5|3|p
  1. Expansion
    Execute the following command to perform the expansion:
source /opt/hengshi/engine-cluster/export-cluster.sh
gpexpand -i gpexpand_inputfile

Note:
During expansion, a new schema named gpexpand will be created under Postgres.

  1. Redistributing Tables

Note:

After expansion, new tables will be distributed across all segments, but existing tables before expansion will not automatically redistribute.

When performing Table Redistributing, the larger the amount of data, the longer it will take. It is recommended to execute it during off-peak periods. If it takes too long, you can use -d / -e, refer to gpexpand for more details.

Refer to Redistributing Tables for more detailed information.

Execute the following command:

source /opt/hengshi/engine-cluster/export-cluster.sh
gpexpand
  1. Removing the Schema Generated by Expansion
source /opt/hengshi/engine-cluster/export-cluster.sh
gpexpand -c

2.2 Expansion with Mirrors

The expansion with mirrors differs from the expansion without mirrors in configuring the expansion input file—remaining steps are the same.

Assuming we now have two hosts, engine1 and engein2, each with 1 segment, and each segment has 1 mirror.

We need to add one more segment, and each segment will have 1 mirror, so configure as follows:

engine1|engine1|25434|/opt/hengshi/engine-cluster/data/SegDataDir1|6|2|p
engine2|engine2|25434|/opt/hengshi/engine-cluster/mirror/SegDataDir1|7|2|m
engine2|engine2|25435|/opt/hengshi/engine-cluster/data/SegDataDir2|8|3|p
engine1|engine1|25435|/opt/hengshi/engine-cluster/mirror/SegDataDir2|9|3|m

3. Horizontal Expansion (Adding New Machines)

3.1 Preparation

  1. Add the hengshi user on the new machine
grep hengshi /etc/passwd > /dev/null || sudo useradd -m hengshi
sudo mkdir -p /opt/hengshi && sudo chown hengshi:hengshi /opt/hengshi
  1. Configure ssh password-less login
    (Omitted)

  2. Create the installation path /opt/hengshi

sudo mkdir -p /opt/hengshi && sudo chown hengshi:hengshi /opt/hengshi
  1. Install hengshi-sense
sudo su - hengshi                                           # Switch to product run user
cd ~/pkgs/hengshi-sense-[version]                          # Switch to the target decompression directory
./hs_install -p /opt/hengshi                                # Execute the installation
  1. Initialize the OS
sudo su - hengshi                                           # Switch to product run user
cd /opt/hengshi                                             # Enter the installation target directory
bin/hengshi-sense-bin init-os all                           # Initialize the OS

3.2 Expansion

Same as vertical expansion.

4. Rollback

If an error occurs during the upgrade, you can execute the following command to restore Greenplum:

source /opt/hengshi/engine-cluster/export-cluster.sh
gpexpand -r