Step 5 - Creating the PGD Cluster v5

Creating the PGD cluster

  • Create connection strings for each node.
    For each node we want to create a connection string which will allow PGD to perform replication.

    The connection string is a key/value string which starts with a host= and the IP address of the host (or if you have resolvable named hosts, the name of the host).

    That is followed by the name of the database; dbname=bdrdb as we created a bdrdb database when installing the software.

    We recommend you also add the port number of the server to your connection string as port=5444 for EDB Postgres Advanced Server and port=5432 for EDB Postgres Extended and Community PostgreSQL.

  • Prepare the first node. To create the cluster, we select and log into one of the hosts Postgres server's bdrdb database.
  • Create the first node.
    Run bdr.create_node and give the node a name and its connection string where other nodes may connect to it.
    • Create the top-level group. Create a top-level group for the cluster with bdr.create_node_group giving it a single parameter, the name of the top-level group.
    • Create a sub-group. Create a sub-group as a child of the top-level group with bdr.create_node_group giving it two parameters, the name of the sub-group and the name of the parent (and top-level) group. This initializes the first node.
  • Adding the second node.
    • Create the second node.
      Log into another initialized node's bdrdb database. Run bdr.create_node and give the node a different name and its connection string where other nodes may connect to it.
    • Join the second node to the cluster Next, run bdr.join_node_group passing two parameters, the connection string for the first node and the name of the sub-group you want the node to join.
  • Adding the third node.
    • Create the third node Log into another initialized node's bdrdb database. Run bdr.create_node and give the node a different name and its connection string where other nodes may connect to it.
    • Join the third node to the cluster Next, run bdr.join_node_group passing two parameters, the connection string for the first node and the name of the sub-group you want the node to join.

Worked example

So far, we have:

  • Created three Hosts.
  • Installed a Postgres server on each host.
  • Installed Postgres Distributed on each host.
  • Configured the Postgres server to work with PGD on each host.

To create the cluster, we will tell host-one's Postgres instance that it is a PGD node - node-one and create PGD groups on that node. Then we will tell host-two and host-three's Postgres instances that they are PGD nodes - node-two and node-three and that they should join a group on node-one.

Create connection strings for each node

We calculate the connection strings for each of the node in advance. Below are the connection strings for our 3 node example:

NameNode NamePrivate IPConnection string
host-onenode-one192.168.254.166host=host-one dbname=bdrdb port=5444
host-twonode-two192.168.254.247host=host-two dbname=bdrdb port=5444
host-threenode-three192.167.254.135host=host-three dbname=bdrdb port=5444

Preparing the first node

Log into host-one's Postgres server.

ssh admin@host-one
sudo -iu enterprisedb psql bdrdb

Create the first node

Call the bdr.create_node function to create a node, passing it the node name and a connection string which other nodes can use to connect to it.

select bdr.create_node('node-one','host=host-one dbname=bdrdb port=5444');

Create the top-level group

Call the bdr.create_node_group function to create a top-level group for your PGD cluster. Passing a single string parameter will create the top-level group with that name. For our example, we will create a top-level group named pgd.

select bdr.create_node_group('pgd');

Create a sub-group

Using sub-groups to organize your nodes is preferred as it allows services like PGD proxy, which we will be configuring later, to coordinate their operations. In a larger PGD installation, multiple sub-groups can exist providing organizational grouping that enables geographical mapping of clusters and localized resilience. For that reason, in this example, we are creating a sub-group for our first nodes to enable simpler expansion and use of PGD proxy.

Call the bdr.create_node_group function again to create a sub-group of the top-level group. The sub-group name is the first parameter, the parent group is the second parameter. For our example, we will create a sub-group dc1 as a child of pgd.

select bdr.create_node_group('dc1','pgd');

Adding the second node

Log into host-two's Postgres server

ssh admin@host-two
sudo -iu enterprisedb psql bdrdb

Create the second node

We call the bdr.create_node function to create this node, passing it the node name and a connection string which other nodes can use to connect to it.

select bdr.create_node('node-two','host=host-two dbname=bdrdb port=5444');

Join the second node to the cluster

Using bdr.join_node_group we can ask node-two to join node-one's dc1 group. The function takes as a first parameter the connection string of a node already in the group, and the group name as a second parameter.

select bdr.join_node_group('host=host-one dbname=bdrdb port=5444','dc1');

Adding the third node

Log into host-three's Postgres server

ssh admin@host-three
sudo -iu enterprisedb psql bdrdb

Create the third node

We call the bdr.create_node function to create this node, passing it the node name and a connection string which other nodes can use to connect to it.

select bdr.create_node('node-three','host=host-three dbname=bdrdb port=5444');

Join the third node to the cluster

Using bdr.join_node_group we can ask node-three to join node-one's dc1 group. The function takes as a first parameter the connection string of a node already in the group, and the group name as a second parameter.

select bdr.join_node_group('host=host-one dbname=bdrdb port=5444','dc1');

We have now created a PGD cluster.