solidDB Help : Replication : C Replicator : Example scripts
  
Example scripts
For a more complex scenario, see the C Replicator (CREP) sample that is included with solidDB, see C Replicator sample.
The following set of scripts sets up a simple topology, a two-server system with one table in one partition. First, the replication is set up to be one-way only. After one row is successfully replicated, the system is configured to run two-way replication. Note that roles of servers are reversed when two-way replication is set up. Pay attention to server addresses.
Source database (tcp 1323): Create the table and define the partition that contains the table:
CREATE TABLE mytable (i INTEGER, j VARCHAR);
COMMIT;
CREATE REPLICATION PARTITION oneway_part;
ALTER REPLICATION PARTITION oneway_part ADD TABLE mytable;
COMMIT;
Target database (tcp 2323): Create the table, set up the connection, and start replication:
CREATE TABLE mytable (i INTEGER, j VARCHAR);
COMMIT;
CREATE REPLICATION CONNECTION oneway_conn CONNECT TO 'tcp 1323' USING NAME dba PASSWORD dba;
COMMIT;
CREATE REPLICATION SUBSCRIPTION oneway_subs PARTITION oneway_part CONNECT TO oneway_conn:
COMMIT;
START REPLICATION SUBSCRIPTION oneway_subs;
COMMIT;
Source database (tcp 1323): Insert a row in the source database:
INSERT INTO mytable VALUES(1, 'row1');
COMMIT;
Target database (tcp 2323): Validate that the row is replicated to the target database:
SELECT i FROM mytable;
COMMIT;
After these steps have been successfully executed, the system is now set up for one-way replication. To set up the replication in the opposite direction, the roles of the source and target databases are reversed. Pay attention to the addresses of the following nodes.
Original target becomes new source database (tcp 2323): Define the replication partition in the same way as you did for the original source database:
CREATE REPLICATION PARTITION otherway_part;
ALTER REPLICATION PARTITION otherway_part ADD TABLE mytable;
COMMIT;
Original source becomes new target database (tcp 1323): Set up the replication connection and subscription and start replicating in the same way as you did for the original target database:
CREATE REPLICATION CONNECTION otherway_conn CONNECT TO 'tcp 2323' USING NAME dba PASSWORD dba;
COMMIT;
CREATE REPLICATION SUBSCRIPTION otherway_subs PARTITION otherway_part CONNECT TO otherway_conn LOAD NONE;
COMMIT;
START REPLICATION SUBSCRIPTION otherway_subs;
COMMIT;
New source database (tcp 2323): Insert another row into the table on the new source database:
INSERT INTO mytable VALUES(2, 'row2');
COMMIT;
New target database (tcp 1323): Validate that the row was replicated to the new target database:
SELECT i FROM mytable;
COMMIT;
Go up to
C Replicator