Exploring replication with PGD v5
Explore replication with PGD
With the cluster up and running, it's useful to run some basic checks to see how effectively it's replicating.
The following example shows one quick way to do this, but you must ensure that any testing you perform is appropriate for your use case.
Preparation
Ensure your cluster is ready to perform replication. If you haven't installed a cluster yet, use one of the quick start guides to get going.
- Log in to the database on the first host.
- Run
select bdr.wait_slot_confirm_lsn(NULL, NULL);
.
When the query returns, the cluster is ready.
Create data
The simplest way to test that the cluster is replicating is to log in to a node, create a table, populate it, and see the data you populated appear on a second node. On the first node:
- Create a table:
- Populate the table:
- Monitor replication performance:
- Get a sum of the value column (for checking):
Check data
- To confirm the data was successfully replicated, log in to a second node.
- Get a sum of the value column (for checking):
- Compare with the result from the first node.
- Log in to a third node.
- Get a sum of the value column (for checking):
- Compare with the result from the first and second nodes.
Worked example
Preparation
The cluster in this example has three data nodes: kaboom, kaftan, and kaolin. The example uses kaboom as the first node. Log in to kaboom and then into kaboom's Postgres server:
Ensure the cluster is ready
To ensure that the cluster is ready to go, run:
If the cluster is busy initializing, this query waits and returns when the cluster is ready.
Create data
On the first node (kaboom), create a table
Run:
On kaboom, populate the table
This command generates a table of 10000 rows of random values:
On kaboom, monitor performance
As soon as possible, run the following command. It shows statistics about how quickly that data was replicated to the other two nodes.
The replay_lag
values are 0, showing no lag. The LSN values are in sync, meaning the data is already replicated.
On kaboom get a checksum
Run:
This command calculates a sum of the values from the generated data:
Your sum will be different because the values in the table are random numbers, but the count will be 100000.
Check data
The second host is kaftan. In another window or session, log in to kaftan's Postgres server:
On the second node (kaftan), get a checksum
Run:
This command gets the second node's values for the generated data:
Compare with the result from the first node (kaboom)
The values are identical.
You can repeat the process with the third node (kaolin), or generate new data on any node and see it replicate to the other nodes.
Log in to the third node (kaolin)
The third and last node is kaolin. In another window or session, log in to kaolin and then to kaolin's Postgres server:
On kaolin, get a checksum
Run:
This command gets kaolin's values for the generated data:
Compare the results
Compare the result from the first and second nodes (kaboom and kaftan) with the result from kaolin. The values are identical on all three nodes.