BDR Documentation | |||
---|---|---|---|
Prev | Up | Chapter 1. Getting started | Next |
Create the databases for this demo on each node/instance from the command line of your operating system:
createdb -p 5598 -U postgres bdrdemo createdb -p 5599 -U postgres bdrdemo
On the first node/instance in database "bdrdemo" as postgreSQL superuser, create the extensions necessary for BDR:
psql -p 5598 -U postgres bdrdemo CREATE EXTENSION btree_gist; CREATE EXTENSION bdr;
Then you run a function that identifies a BDR group that delineates a connection string for other nodes to communicate with (for the first node, we will use port 5598) from the same SQL session as above on port 5598:
SELECT bdr.bdr_group_create( local_node_name := 'node1', node_external_dsn := 'port=5598 dbname=bdrdemo' );
To ensure that the node is ready to replicate, run this function from the same SQL session as above on port 5598:
SELECT bdr.bdr_node_join_wait_for_ready();
On the second node/instance on port 5599 in database "bdrdemo" as postgreSQL superuser, create the extensions necessary for BDR:
psql -p 5599 -U postgres bdrdemo CREATE EXTENSION btree_gist; CREATE EXTENSION bdr;
Then run a function that joins this node/instance to your BDR group you created above (for the second node, we will use port 5599) from the same SQL session as above on port 5599:
SELECT bdr.bdr_group_join( local_node_name := 'node2', node_external_dsn := 'port=5599 dbname=bdrdemo' join_using_dsn := 'port=5598 dbname=bdrdemo' );
To ensure that the node/instance is ready to replicate, run this function from the same SQL session as above on port 5599:
SELECT bdr.bdr_node_join_wait_for_ready();
Create a table and insert rows from your first node/instance:
psql -p 5598 -U postgres bdrdemo CREATE TABLE t1bdr (c1 INT, PRIMARY KEY (c1)); INSERT INTO t1bdr VALUES (1); INSERT INTO t1bdr VALUES (2); -- you will see two rows SELECT * FROM t1bdr;
Check that the rows are there on your second node/instance. Now, delete a row:
psql -p 5599 -U postgres bdrdemo -- you will see two rows SELECT * FROM t1bdr; DELETE FROM t1bdr WHERE c1 = 2; -- you will see one row SELECT * FROM t1bdr;
Check that one row has been deleted from the first node/instance::
psql -p 5598 -U postgres bdrdemo -- you will see one row SELECT * FROM t1bdr;