Enabling refresh of data and inserting data in replica
The publication defined in the master database must be registered by the replica database so that the replica database can receive refreshes of data from the master database. Updates to data in the replica database are marked for synchronization by using a SAVE statement.
The following sample scripts contain the SQL statements for registering a publication, inserting data in the replica database, and saving the data to be propagated to the master database.
Registering publications allows publication parameters to be validated. This prevents users from accidentally requesting refreshes they do not want, or requesting ad-hoc refreshes.
1 Query the sample table SYNCDEMO to ensure that it does not contain any data in the master or replica database:
SELECT * FROM SYNCDEMO;
0 rows are returned.
2 In the replica database, register the publication, insert two rows in the table, and save the transaction to be propagated to the master, see statements in Sample script: replica2.sql.
3 Query the sample table SYNCDEMO on the replica database to ensure that the database contains two rows.
SELECT * FROM SYNCDEMO;
4 Query the sample table SYNCDEMO on the master database to ensure that the database contains 0 rows.
SELECT * FROM SYNCDEMO;
At this point, the replica database also has two saved statements (in one transaction) waiting to be propagated to the master database.
Sample script: replica2.sql
If you are using the working directories and sample scripts in the samples\smartflow\ directory, go the solidDB installation root directory and run the following commands:
▪ -O eval.out is an optional parameter that defines the output file for results,
▪ "tcp 1315" is the network protocol and address of the server (you might need to customize this part of the command),
▪ dba and dba_password are user name and password respectively.
You can view the results in eval.out with any text editor.
--********************************************************* -- replica2.sql -- This script registers to publication PUB_DEMO, inserts two -- rows to the REPLICA database and -- saves the transaction to be propagated to the MASTER -- -- Execute in the REPLICA database --********************************************************* -- register to publication SET CATALOG sync_demo_catalog ; MESSAGE REG_PUBL BEGIN; MESSAGE REG_PUBL APPEND REGISTER PUBLICATION PUB_DEMO; MESSAGE REG_PUBL END; COMMIT WORK; MESSAGE REG_PUBL FORWARD TIMEOUT FOREVER; COMMIT WORK;