Skip to main content


This tutorial describes how to run an example that demonstrates one possible use of the user-defined extensions for replication by providing detailed logging of the replication subsystem.

To exercise replication to monitor its behavior, compile ctrepluser.c with #define REPLUSER_LOGGING uncommented. This will enable code that calls a function to log a message to the file ctrepluser.log each time one of the callback functions is called. The sample code also tracks the number of calls made to each callback function using the #define REPLUSER_LOGGING logic discussed in replication logging.


This is only one simple use of the callback extension. By reviewing the code in ctrepluser.c, you will be able to explore many alternate uses for this technology.

To begin the tutorial, we will execute some scripts to build the data on the source server and target server. With data on both servers, we can insert data and delete data in the table we built. We will connect to the source and watch the Replication Agent replicating data to the target server.

Figure 1. The Replication Agent replicates data to the target server
The Replication Agent replicates data to the target server

To enable replication:
  1. Set the keyword in the ctsrvr.cfg file on the source server to tell the source server to replicate all its files:


    This configuration only takes effect during server initialization.

  2. Start/restart the source server.

  3. Start the target server if it is not already running.


    Both servers must be running.

  1. Execute the ctreplagent command to start replication.


    Once the Replication Agent is started, you can now run the scripts to insert and delete data.

    # ./ctreplagent
  2. Ensure your screen appears like Figure 2, “Callback tutorial, if not please check your compilation.

    Figure 2. Callback tutorial
    Callback tutorial

  1. Run the following SQL command using FairCom DB SQL Explorer, or the ISQL command-line utility to create data on the source and target servers.

    CREATE TABLE custmast (cm_custnumb CHAR(4), cm_custzipc CHAR(9), cm_custstat CHAR(2), cm_custrtng CHAR(1), cm_custname VARCHAR(47), cm_custaddr VARCHAR(47), cm_custcity VARCHAR(47));
  2. Observe the Create.bat batch file that uses ISQL to execute a script.


    The Create.bat file uses ISQL to execute a script, create.sql, that contains the commands shown in Step 1.

    Figure 3. Create.bat batch file
    Create.bat batch file

  1. Insert some sample data into the database to be replicated.

    INSERT INTO custmast VALUES ('1000','92867','CA','1','Bryan Williams','2999 Regency','Orange');
    INSERT INTO custmast VALUES ('1001','61434','CT','1','Michael Jordan','13 Main','Harford');
    INSERT INTO custmast VALUES ('1002','73677','GA','1','Joshua Brown','4356 Cambridge','Atlanta');
    INSERT INTO custmast VALUES ('1003','10034','MO','1','Keyon Dooling','19771 Park Avenue','Columbia');
  2. Observe ISQL running a SQL script that executes the commands in Insert data.

    Figure 4. ISQL running a SQL script
    ISQL running a SQL script

  1. Delete the data to test replication.

    DELETE FROM custmast;
  2. Observe a Delete.bat file that deletes using ISQL by executing a delete.sql script that contains the commands in Step 1.

    Figure 5. Delete.bat file
    Delete.bat file

  1. Check the results of the executed callback functions.

  2. Observe the sequence of events seen while inserting data.

    Figure 6. Inserting data sequence
    Inserting data sequence