Step 4 - Configuring the cluster v6.0.1
Configuring the cluster
The next step in the process is to configure the database and the cluster.
This involves logging into each host and running the pgd
command to create the cluster as the database user.
These steps will vary according to which platform you are using and which version of Postgres you are using.
Cluster name
You will need to choose a name for your cluster. This is the name that will be used to identify the cluster in the PGD CLI and in the database. It will be referred to as <cluster-name>
in the examples. If not specified, the default name is pgd
.
Group names
You will also need to choose a name for the group. This is the name that will be used to identify the group in the PGD CLI and in the database. It will be referred to as <group-name>
in the examples.
The group name must be unique within the cluster.
Node names
You will also need to choose a name for each node. This is the name that will be used to identify the node in the PGD CLI and in the database. It will be referred to as <node-name>
in the examples. This is separate from the host name, which is the name of the machine on which the node is running.
The node name must be unique within the group and within the cluster.
Paths and users
The paths and users used in the examples will vary according to which version of Postgres you are using and which platform you are using.
Postgres User | enterprisedb |
Postgres Port | 5444 |
Postgres Executable files | /usr/lib/edb-as/$PG_VERSION/bin/ |
Postgres Data Directory | /var/lib/edb-as/$PG_VERSION/main/ |
sudo -iu enterprisedb export PG_VERSION=<version> export PATH=$PATH:/usr/lib/edb-as/$PG_VERSION/bin/ export PGDATA=/var/lib/edb-as/$PG_VERSION/main/ export PGPORT=5444
Postgres User | enterprisedb |
Postgres Port | 5444 |
Postgres Executable files | /usr/edb/as$PG_VERSION/bin/ |
Postgres Data Directory | /var/lib/edb/as$PG_VERSION/data/ |
sudo -iu enterprisedb export PG_VERSION=<version> export PATH=$PATH:/usr/edb/as$PG_VERSION/bin/ export PGDATA=/var/lib/edb/as$PG_VERSION/data/ export PGPORT=5444
Postgres User | postgres |
Postgres Port | 5432 |
Postgres Executable files | /usr/lib/edb-pge/$PG_VERSION/bin/ |
Postgres Data Directory | /var/lib/edb-pge/$PG_VERSION/main/ |
sudo -iu postgres export PG_VERSION=<version> export PATH=$PATH:/usr/lib/edb-pge/$PG_VERSION/bin/ export PGDATA=/var/lib/edb-pge/$PG_VERSION/main/ export PGPORT=5432
Postgres User | postgres |
Postgres Port | 5432 |
Postgres Executable files | /usr/edb/pge$PG_VERSION/bin/ |
Postgres Data Directory | /var/lib/edb-pge/$PG_VERSION/data/ |
sudo -iu postgres export PG_VERSION=<version> export PATH=$PATH:/usr/edb/pge$PG_VERSION/bin/ export PGDATA=/var/lib/edb-pge/$PG_VERSION/data/ export PGPORT=5432
Not available
Community PostgreSQL is only operable with PGD Expanded.
On each host
Run the commands from the script/settings above to set the environment variables and paths for the Postgres user on each host.
This will ensure that the pgd
command can find the Postgres executable files and data directory.
- Using the appropriate user, log in as the database user.
sudo -iu <db-user>
- Set the Postgres version environment variable. Don't forget to replace
<version>
with the actual version number you are using, such as17
.
export PG_VERSION=<version>
- Add the Postgres executable files to your path.
export PATH=$PATH:<executable-path>
- Set the Postgres data directory environment variable.
export PGDATA=<data-directory>
- Set the Postgres password environment variable. Don't forget to replace
<db-password>
with the actual password you want for the database user.
export PGPASSWORD=<db-password>
On the first host
The first host in the cluster is also the first node and will be where we begin the cluster creation. On the first host, run the following command to create the cluster:
pgd node <first-node-name> setup --dsn "host=<first-host> user=<db-user> port=<db-port> dbname=<dbname>" --group-name <group-name>
This command will create the data directory and initialize the database, then will create the cluster and the group on the first node.
On the second host
On the second host, run the following command to create the cluster:
pgd node <second-node-name> setup --dsn "host=<second-host> user=<db-user> port=<db-port> dbname=<db-name>" --cluster-dsn "host=<first-host> user=<db-user> port=<db-port> dbname=<db-name>"
This command will create the node on the second host, and then join the cluster using the cluster-dsn setting to connect to the first host.
On the third host
On the third host, run the following command to create the cluster:
pgd node <third-node-name> setup --dsn "host=<third-host> user=<db-user> port=<db-port> dbname=<db-name>" --cluster-dsn "host=<first-host> user=<db-user> port=<db-port> dbname=<db-name>"
This command will create the node on the third host, and then join the cluster using the cluster-dsn setting to connect to the first host.
Worked example
In this example, we will configure the PGD Essential cluster with EDB Postgres Extended Server 17 on a CentOS/RHEL system that we configured and installed in the previous steps.
We will now create a cluster called pgd
with three nodes called node-1
, node-2
, and node-3
.
- The group name will be
group-1
. The hosts arehost-1
,host-2
, andhost-3
. - The Postgres version is 17.
- The database user is
postgres
. - The database port is 5432.
- The database name is
pgddb
. - The Postgres executable files are in
/usr/edb/pge17/bin/
. - The Postgres data directory is in
/var/lib/edb-pge/17/main/
. - The Postgres password is
secret
.
(Note that we assume the Postgres version environment variable PG_VERSION is set to 17
from the previous step, and that we are preserving the environment variable when switching users.)
On the first host
sudo -iu postgres export PG_VERSION=17 export PATH=$PATH:/usr/edb/pge$PG_VERSION/bin/ export PGDATA=/var/lib/edb-pge/$PG_VERSION/data/ export PGPASSWORD=secret pgd node node-1 setup --dsn "host=host-1 user=postgres port=5432 dbname=pgddb" --group-name group-1
On the second host
sudo -iu postgres export PG_VERSION=17 export PATH=$PATH:/usr/edb/pge$PG_VERSION/bin/ export PGDATA=/var/lib/edb-pge/$PG_VERSION/data/ export PGPASSWORD=secret pgd node node-2 setup --dsn "host=host-2 user=postgres port=5432 dbname=pgddb" --cluster-dsn "host=host-1 user=postgres port=5432 dbname=pgddb"
On the third host
sudo -iu postgres export PG_VERSION=17 export PATH=$PATH:/usr/edb/pge$PG_VERSION/bin/ export PGDATA=/var/lib/edb-pge/$PG_VERSION/data/ export PGPASSWORD=secret pgd node node-3 setup --dsn "host=host-3 user=postgres port=5432 dbname=pgddb" --cluster-dsn "host=host-1 user=postgres port=5432 dbname=pgddb"
The next step is to create the database.