Adding a Node with pgBackRest
You can use a pgBackRest backup to populate a new cluster node, and then
add that node to your cluster with the Spock extension. In the following
high-level walkthrough, we walk through the steps you can use to add a
fourth node (n4) to a three-node cluster (n1, n2, and n3).
-
Create a pgBackRest stanza. This step is required as the stanza defines the cluster configuration, which is essential for backup and restore operations.
-
Perform a full backup of your primary node,
n1. The backup can be stored in an S3 bucket, a network-shared folder, or a local directory (if all nodes are on the same machine). -
Restore the backup from
n1to the data directory ofn4. This preparesn4to become a replica ofn1. -
Configure streaming replication on
n4, making the node a replica ofn1. This ensures thatn4contains all transactions onn1since the backup was taken, ensuringn4is 100 percent synchronized withn1. -
Use the
ALTERcommand to set nodesn1,n2, andn3to read-only mode and reload the configuration on these nodes to apply the changes. This step is crucial becausen4has configurations copied fromn1that are not valid forn4. By making the nodes read-only, you ensure no transactions occur while you modify the configurations. -
Terminate all ongoing transactions on
n1,n2, andn3. This prevents any long-running queries from interfering during the configuration changes. -
Edit the
shared_preload_librariesparameter onn4, removingspock. This prevents Spock from using the old configuration fromn1onn4. -
Start
n4, allowing the node to become a replica ofn1. This step ensures thatn4contains all transactions fromn1. -
Promote
n4to the role of primary node or configure the node as a standalone node with Spock disabled. This step finalizesn4as the new primary node in your replication setup. -
Remove all replication sets and nodes from the configuration. This clears any old replication configurations that are no longer needed.
-
Re-add
spockto theshared_preload_librariesparameter onn4. This preparesn4to handle replication in the new role. -
Restart
n4to apply the changes made in the previous steps. -
Reintegrate
n4into the replication cluster withn1,n2, andn3. -
Remove the read-only mode from
n1,n2, andn3, allowing them to resume normal operations. -
Add the following subscriptions between the new node (
n4) and Nodes 1, 2, and 3 (n1,n2,n3):- The
subn1n4subscription syncs n1 with n4. - The
subn2n4subscription syncs n2 with n4. - The
subn3n4subscription syncs n3 with n4. - The
subn4n1subscription syncs n4 with n1. - The
subn4n2subscription syncs n4 with n2. - The
subn4n3subscription syncs n4 with n3.
- The
-
Verify that all nodes (
n1,n2,n3, andn4) are properly configured and synchronized within the cluster. Ensure that replication is functioning as expected by checking the status of all nodes.