Step 6 - Checking the cluster v5
Checking the cluster
With the cluster up and running, it's worthwhile 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 the cluster is ready:
- Log in to the database on host-one/node-one.
- Run
select bdr.wait_slot_confirm_lsn(NULL, NULL);
. - When the query returns, the cluster is ready.
- Ensure the cluster is ready:
- Create data
The simplest way to test that the cluster is replicating is to log in to one node, create a table, and populate it.
- On node-one, create a table:
- On node-one, populate the table:
- On node-one, monitor performance:
- On node-one, get a sum of the value column (for checking):
- Check data
- Log in to node-two. Log in to the database on host-two/node-two.
- On node-two, get a sum of the value column (for checking):
- Compare with the result from node-one.
- Log in to node-three. Log in to the database on host-three/node-three.
- On node-three, get a sum of the value column (for checking):
- Compare with the result from node-one and node-two.
Worked example
Preparation
Log in to host-one's Postgres server.
This is your connection to PGD's node-one.
Ensure the cluster is ready
To ensure that the cluster is ready to go, run:
This query blocks while the cluster is busy initializing and returns when the cluster is ready.
In another window, log in to host-two's Postgres server:
Create data
On node-one, create a table
Run:
On node-one, populate the table
This command generates a table of 10000 rows of random values.
On node-one, monitor performance
As soon as possible, run:
The command shows statistics about how quickly that data was replicated to the other two nodes:
And it's already replicated.
On node-one get a checksum
Run:
This command gets some values from the generated data:
Check data
Log in to host-two's Postgres server
This is your connection to PGD's node-two.
On node-two, get a checksum
Run:
This command gets node-two's values for the generated data:
Compare with the result from node-one
The values are identical.
You can repeat the process with node-three or generate new data on any node and see it replicate to the other nodes.
Log in to host-three's Postgres server
This is your connection to PGD's node-three.
On node-three, get a checksum
Run:
This command gets node-three's values for the generated data:
Compare with the result from node-one and node-two
The values are identical.