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.
  • 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:
      CREATE TABLE quicktest ( id SERIAL PRIMARY KEY, value INT ); 
    • On node-one, populate the table:
      INSERT INTO quicktest (value) SELECT random()*10000 FROM generate_series(1,10000);
    • On node-one, monitor performance:
      select * from bdr.node_replication_rates;
    • On node-one, get a sum of the value column (for checking):
      select COUNT(*),SUM(value) from quicktest;
  • 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):
      select COUNT(*),SUM(value) from quicktest;
    • 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):
      select COUNT(*),SUM(value) from quicktest;
    • Compare with the result from node-one and node-two.

Worked example

Preparation

Log in to host-one's Postgres server.

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

This is your connection to PGD's node-one.

Ensure the cluster is ready

To ensure that the cluster is ready to go, run:

select bdr.wait_slot_confirm_lsn(NULL, NULL)

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:

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

Create data

On node-one, create a table

Run:

CREATE TABLE quicktest ( id SERIAL PRIMARY KEY, value INT ); 

On node-one, populate the table

INSERT INTO quicktest (value) SELECT random()*10000 FROM generate_series(1,10000);

This command generates a table of 10000 rows of random values.

On node-one, monitor performance

As soon as possible, run:

select * from bdr.node_replication_rates;

The command shows statistics about how quickly that data was replicated to the other two nodes:

bdrdb=# select * from bdr.node_replication_rates;
 peer_node_id | target_name | sent_lsn  | replay_lsn | replay_lag | replay_lag_bytes | replay_lag_size | apply_rate | catchup_interv
al
--------------+-------------+-----------+------------+------------+------------------+-----------------+------------+---------------
---
   1954860017 | node-three  | 0/DDAA908 | 0/DDAA908  | 00:00:00   |                0 | 0 bytes         |      13682 | 00:00:00
   2299992455 | node-two    | 0/DDAA908 | 0/DDAA908  | 00:00:00   |                0 | 0 bytes         |      13763 | 00:00:00
(2 rows)

And it's already replicated.

On node-one get a checksum

Run:

select COUNT(*),SUM(value) from quicktest;

This command gets some values from the generated data:

bdrdb=# select COUNT(*),SUM(value) from quicktest;
Output
 count  |    sum
--------+-----------
 100000 | 498884606
(1 row)

Check data

Log in to host-two's Postgres server

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

This is your connection to PGD's node-two.

On node-two, get a checksum

Run:

select COUNT(*),SUM(value) from quicktest;

This command gets node-two's values for the generated data:

bdrdb=# select COUNT(*),SUM(value) from quicktest;
Output
 count  |    sum
--------+-----------
 100000 | 498884606
(1 row)

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

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

This is your connection to PGD's node-three.

On node-three, get a checksum

Run:

select COUNT(*),SUM(value) from quicktest;

This command gets node-three's values for the generated data:

bdrdb=# select COUNT(*),SUM(value) from quicktest;
Output
 count  |    sum
--------+-----------
 100000 | 498884606
(1 row)

Compare with the result from node-one and node-two

The values are identical.