Replication Guide and Reference

Setting up your replication environment

This chapter describes the steps for setting up and starting replication. It does not include specifics about operating the Capture and Apply programs for each operating system. See Operations for such specifics.

To set up the replication environment, you will complete the following general steps:

  1. Create control tables in the logical source, target, and control servers
  2. Define replication sources
  3. Create subscription sets and add members to the sets

You can use either the DB2 Control Center or the DB2 DataJoiner Replication Administration (DJRA) tool to define sources and targets for replication, to set the schedule for updating the targets, to specify the enhancements to the target data, and to define any triggers that initiate replication. You can use the DB2 Control Center to administer replication only when your source and target tables are in DB2 Universal Database databases (for any operating-system environment), but you can use DJRA to administer replication when your source and target tables are in DB2 Universal Database databases (for any operating-system environment) or in supported non-IBM databases.

The administration tasks described in this chapter set up the control information that both the Capture and Apply programs use to capture changed data and replicate it to the target tables, in the proper format, and at the appropriate interval.


Using the DB2 Control Center to set up replication

When setting up the replication environment, you can use the DB2 Control Center to manage the source and target table definitions and the control tables. Use the following high-level steps to administer your replication objects:

  1. Check, and optionally update, the default settings in the Tools Settings notebook. See Setting replication preferences in the DB2 Tools Settings notebook for more information.
  2. Review the DPCNTL file for your platform to determine whether you need to customize the control tables for your site.
  3. Optionally customize the DPCNTL file for your platform and site requirements. See Defining replication control tables for more information.
  4. Define and manage replication sources. See Defining replication sources for more information.
  5. Define and manage replication subscriptions. See Defining replication subscription sets for more information.

After you create the control tables and define the replication sources and targets, you need to configure and run the Capture and Apply programs to begin replicating data.

You can access your replication sources and targets through the Control Center. There are three containers in the Control Center for organizing the objects that you use to set up and maintain your replication environment:

Tables folder
The folder containing DB2 tables.

Replication Sources folder
The folder containing tables that have been defined as replication sources: DB2 tables, views, or target tables redefined as sources for replication.

Replication Subscription folder
The folder containing subscription-set definitions for copying source data or source-data changes to target tables.

Each object also has a menu for the actions that can be performed with the object.

Configuring the Control Center for host RDBMSs

If you are connecting to a DB2 for MVS/ESA, DB2 for VSE, DB2 for VM, or DB2 for AS/400 server from the Control Center, you must configure connectivity to the remote database, catalog the remote databases, and bind packages to the remote databases.

To bind the database:

  1. Change to the directory where the Capture program bind files are located, which is usually the \SQLLIB\BND directory on the drive where you installed DB2 Universal Database or the client application enabler (CAE).
  2. Create and bind the DB2 for MVS/ESA, VSE, VM, or AS/400 package to the DB2 database by issuing the following commands:
    DB2 CONNECT TO dbname USER userid USING password
    DB2 BIND @DDCSxxx.LST ISOLATION CS BLOCKING ALL SQLERROR CONTINUE
    

    Where CS specifies the cursor stability isolation level, and xxx specifies the platform name: MVS, VSE, VM, or AS/400.

    If the user ID and password are different than the local logon ID and password for the Control Center workstation, you must explicitly connect to the database server using the Connect menu choice from the pop-up menu for your remote database object.

Setting replication preferences in the DB2 Tools Settings notebook

The Tools Settings notebook contains default preferences for the DB2 Universal Database administration tools. You can set replication default values on the Replication page of the notebook, as shown in Figure 19. These default values are used for all replication activities administered by the Control Center.

Figure 19. The Replication Page of the Tools Settings Notebook. Use this page to specify default preferences for replication.


The Replication page of the Tools Settings notebook

Customizing CD table, index, and tablespace names

You can customize CD table names, index names, and tablespace names while defining replication sources or subscription sets. You can edit the template file DPREPL.DFT, found in the working directory for the Control Center (\sqllib\bin or \sqllib\java), to change these names. See the instructions in the file for syntax and examples.

You specify that you want to use this file from the Replication page of the Tools Settings notebook. See Figure 19.


Using the DB2 DataJoiner Replication Administration tool to set up replication

When you use the DB2 DataJoiner Replication Administration (DJRA) tool to perform replication administration tasks, DJRA connects to the source, target, or control server to create and update the control information and target tables on the server (depending on the operation performed). The client workstation where DJRA is located must be authorized and able to connect to all source, target, and control servers that are managed by DJRA.

DJRA provides objects and actions that define and manage source and target table definitions. Working through DB2 DataJoiner, DJRA creates:

The Apply program reads from and writes to DB2 DataJoiner nicknames, which eliminates the need to connect explicitly to non-IBM databases.

If the source database is a DB2 database, the Capture program for that database captures the changes, therefore, the Capture triggers and DB2 DataJoiner are not involved. If the target database is a DB2 database, the Apply program writes the changed data to the DB2 target database directly and DB2 DataJoiner is not involved.

DJRA, working with DB2 DataJoiner, the Capture program, Capture triggers, and the Apply program, replicates relational data from a variety of sources to a variety of targets. The databases that DJRA supports as sources or targets are:

For DB2 source, target, or control servers, DB2 DataJoiner's distributed database connection services (DDCS) or the DB2 Connect product provides connectivity. For non-IBM sources and targets, DJRA uses DB2 DataJoiner to connect to the non-IBM servers.

DJRA provides a user interface that is divided into areas that deal with control tables, replication sources, subscription sets, and the running or editing of SQL (see Figure 20).

Using this interface, you can perform the following administration tasks:

You can also customize the logic for most of the administration tasks listed above.

Figure 20. The DJRA primary window


The DJRA primary window.

Installing DJRA

When you install DB2 UDB on a Windows system, the DB2 setup program copies the DJRA setup program (djra.exe) to the \sqllib\djra directory. DJRA also comes with DB2 DataJoiner V2; when you install DataJoiner on Windows NT, you can also optoinally install DJRA. In addition, you can download DJRA from the Web. 24 When you install DJRA, if you do not already have Object Rexx installed, DJRA will install it, otherwise DJRA will use your existing copy.

DJRA runs in the following environments:

To install DJRA:

  1. From the Windows Explorer, go to the \sqllib\djra directory, then double-click the djra.exe file. This starts the DJRA setup program.
  2. Follow the online instructions. Online help is available to help you with the remaining steps. When you complete setup, DJRA appears in the Windows Start menu.
  3. To start DJRA:
    1. Click the Start icon.
    2. Select the Programs menu.
    3. Select either the DB2 for Windows NT or DataJoiner for Windows NT menu (depending on whether you installed DJRA with DB2 or DataJoiner).
    4. Select the Replication menu.
    5. Select Replication Administration Tools. The DJRA primary window opens, as shown in Figure 20.

Setting preferences

You can specify your preferences for:

To set preferences, select File -> Preferences from the menu on the DJRA primary window. You can change the preferences at any time.

On the Connection page of the Preferences notebook, you see a list of databases that are currently cataloged on your system.

Restriction: If you are using Microsoft SQL Server in your replication environment, do not use an alias user ID. Microsoft SQL Server will reject the alias user ID.

Customizing DJRA

You can customize DJRA staging tables, indexes, predicates, and so on by selecting the appropriate Edit Logic button from the following windows:

Create Replication Control Tables
Select the Edit Tablespace Logic button to specify the table spaces for the control tables and the UOW table. Check this file to make sure that the table spaces are being defined in the location where you want them.

Define One Table as a Replication Source
Select the Edit Logic button to specify the owner and name of the CD or CCD table and the table space in which the CD or CCD table is placed. You can also customize index names for CCD tables.

Recommendation: If the source table is a non-IBM table, do not change the owner for the CCD table.

You can also select the Edit Logic button from the Define Multiple Tables as Replication Sources window. In this case, add a three-digit number to the end of the CD_TABLE (or CCD_TABLE) parameter value; DJRA automatically increments this number to ensure that each table has a unique name.

You can specify where table spaces are created by changing the default directory (C:\). Be sure to add a backslash (\) after the directory name.

Add a Member to Subscription Sets
Select the Edit Predicate Logic button to specify which rows from the source table can be replicated to the target table.

Select the Edit Create Table Logic button to specify the table space or segment in which to create target tables.

You can specify where table spaces are created by changing the default directory (C:\). Be sure to add a backslash (\) after the directory name.

You can also select the Edit Predicate Logic or Edit Create Table Logic button from the Add Multiple Members to Subscription Sets window.


Defining replication control tables

Normally, the replication control tables are created in one of the following ways:

When you create customized control tables, you must customize the CREATE TABLE statements in the DPCNTL files. There is one DPCNTL file for each operating system environment; these files are located in the sqllib\samples\repl\ directory. The file names are:

DPCNTL.UDB
Creates control tables for DB2 Universal Database (for UNIX, Windows, or OS/2).

DPCNTL.MVS
Creates control tables for DB2 for MVS/ESA and DB2 for OS/390.

DPCNTL.VM
Creates control tables for DB2 for VSE & VM.

DPCNTL.400
Creates control tables for DB2 for AS/400.

DPCNTL.SAT
Creates and drops control tables for DB2 Universal Database Satellite Edition.

If, after creating customized control tables, you need to drop them, you must customize the DROP TABLE statements in the DPNCNTL files. There is a DPNCNTL file for each operating system environment located in the sqllib\samples\repl\ directory. The files names are:

DPNCNTL.UDB
Drops control tables for DB2 Universal Database (for UNIX, Windows, or OS/2).

DPNCNTL.MVS
Drops control tables for DB2 for MVS/ESA and DB2 for OS/390.

DPNCNTL.VM
Drops control tables for DB2 for VSE & VM.

DPNCNTL.400
Drops control tables for DB2 for AS/400.

To customize the SQL for creating or dropping control tables:

  1. Open the appropriate file (sqllib\samples\repl\dpcntl.platform_name or sqllib\samples\repl\dpncntl.platform_name, where platform_name is UDB, MVS, VM, 400, or SAT.) in a text editor.
  2. Read the commented areas for each operating system and table.
  3. Edit the file for your site or application.
  4. Close the file.
  5. Connect to the database in which the control tables will be created (use the DB2 CONNECT TO database-name command).
  6. Run the file (DPCNTL or DPNCNTL) using one of the following commands from a command window:
    db2 -tf dpcntl.platform_name
     
    db2 -tf dpncntl.platform_name
    

Creating replication control tables using DJRA

You must create control tables at each DB2 (and DataJoiner) system involved in replication. 25 When you complete this step, DJRA places a register table, a pruning control table, and a register synchronization control table at the database source (and for non-IBM sources, creates nicknames for these tables in DB2 DataJoiner).

From the DJRA primary window, click the Create Replication Control Tables. The fields you complete to create a control table are:

Source, control, or target server
When you click the down arrow, DJRA checks to see what type of server it is and then lists all databases and aliases that are cataloged on the workstation from which you are running DJRA. If you select a DataJoiner server from the list, the DataJoiner non-IBM source server pull-down list becomes active. If you do not choose a DataJoiner server, you will link directly to a DB2 database.

DataJoiner non-IBM source server
If you selected a DataJoiner alias from the Source, control, or target server pull-down list and you have performed server mappings in DataJoiner, then this list displays available remote server names.

Specify (None) if you want the control tables to be created in the DataJoiner database rather than in the remote server database.

Edit Tablespace Logic
Click this push button to customize table space names for control tables or for CREATE TABLESPACE options. The default table space names for DB2 for OS/390 are: For other platforms, the default table space name is TSnnnnnn, where nnnnnn is a unique identifier.

Generate SQL
Click this push button to generate SQL after you supply all the information on this panel. While the SQL is being generated, a window is displayed showing processing messages and error messages, if any.

When the procedure completes successfully, save the file by selecting File->Save. You can now edit the generated SQL, if necessary, according to the guidelines listed in Customizing and running replication SQL files. When you are ready, run the SQL by selecting File->Run. You must save the generated SQL before you can run the SQL. You must run the SQL for generating control tables before you generate and run SQL to create replication sources or subscription sets.


Customizing and running replication SQL files

From the DB2 Control Center, you have the option to run a replication task immediately or save the generated SQL file to run at a later time. From DJRA, you can run or edit SQL files from the main window. The SQL files can be customized for large scale replication actions such as defining subscription sets, or customized for an application beyond implementations supported by either the Control Center or DJRA.

You might want to save and customize the SQL files to:

If you save the definitions of a large replication subscription set in an SQL file, you can rerun the definitions as necessary.

When editing generated SQL, be careful not to change special markers that DJRA places within the SQL. For example, :ENDOFTRIGGER: or :ENDOFPROCEDURE: is part of a comment that is necessary for DJRA to run successfully. Altering create trigger blocks can result in incorrect SQL that ends in error when run. If you add lines to the end of the file, be sure to add an extra newline (CRLF) to the end of the file.

The DJRA Run SQL push button is intended to be used for SQL generated by DJRA. SQL that you generate outside DJRA might not run successfully if you use DJRA to start it. Likewise, you might not be able to run SQL generated by DJRA at a DB2 command line.

Recommendation: Run DJRA-generated SQL from DJRA.


Setting up security for replication

Because DB2 DataPropagator is table driven, security for all replication objects depends on the database security. The database administrator who defines replication sources and subscription sets also defines security for them. Additionally, the Capture program must be authorized to access the source database and the Apply program must be authorized to access the control, source, and target databases.

Authorization requirements for administration

When you define replication sources and subscription sets, the DB2 Control Center and DJRA create many tables. Depending on the operating system, they might also create table spaces or dbspaces. Because all of these actions require a high level of database privilege, you should plan to have at least one user ID that acts as the replication administrator and has the authority to create objects, bind plans, and run generated SQL for each of the source databases.

Authorization requirements for running the Capture program

The user ID that runs the Capture program must be able to access the DB2 system catalog, be able to access and update all replication control tables, and have execute privileges on the Capture program packages. The user ID that runs the Capture program can be the same as the administrator user ID, but this is not a requirement.

For OS/390, the user ID that runs the Capture program should have either SYSADM authority or have the following authorizations:

For VM and VSE, the user ID that runs the Capture program must have DBA authority. For all other operating systems, the user ID that runs the Capture program must have either DBADM or SYSADM authority.

Authorization requirements for running the Apply program

The user ID that runs the Apply program must be a valid logon ID for the source, control, and target servers, and for the workstation where the Control Center or DJRA is installed. The user ID that runs the Apply program must be able to access the source tables, access and update all replication control tables, and update the target tables. This user ID must also have execute privileges on the Apply program packages. The user ID that runs the Apply program can be the same as the administrator user ID, but this is not a requirement. With the proper authorization, any user ID can run any Apply program instance.

An Apply program might require a password file to connect to the source or target server. For more information about authorization requirements for the Apply program, see the Capture and Apply chapter for your operating system in Operations.


Defining replication sources

To define a replication source using the DB2 Control Center:

Click the Tables folder for the source database to show all tables. Right-click on a table object to show the pop-up menu and select Define as replication source.

You can define replication sources using the Quick or Custom choices. Quick allows you to define a replication source using default values. Custom allows you to customize the defaults, such as specifying that certain columns should not be captured.

After you define the replication source, an object is created in the Replication Sources folder. The source table can now be defined in a subscription set.

To define a replication source using DJRA:

Click Define One Table as a Replication Source or Define Multiple Tables as Replication Sources, then fill in the required information, such as source server, source table names, and source columns.

For information about Capture triggers, see Capture triggers for non-IBM sources. For data restrictions when defining replication sources and subscription sets, see General restrictions for replication.

The Capture program does not recognize new DB2 replication sources until you issue either the reinit command or stop and restart the Capture program. The Capture program does not begin capturing changes for a replication source until a subscription set is created for that replication source and the subscription-set members have been fully refreshed.

Defining replication sources for update-anywhere replication

To define a replication source for update-anywhere replication using the DB2 Control Center:

Define a custom replication source and use the following selections:

  1. Select the Table will be used for update anywhere check box.
  2. Select a conflict detection level:

    None
    No conflict detection.

    Attention: Conflicting updates between the source table and the replica will not be detected. This option is not recommended for update-anywhere replication.

    Standard
    Moderate conflict detection, in which the Apply program searches rows already captured in the replica's change data tables for conflicts. Standard detection is the default value.

    When you select this option, the DB2 Control Center also selects the Define as Source and Capture before image check boxes for every column.

    Enhanced
    Conflict detection that provides the best data integrity among all replicas and the source table. The Apply program locks all replicas in the subscription set against further transactions, and begins detection after all changes prior to the locking are captured.

    Even if you specify enhanced conflict detection, when the Apply program runs in an occasionally-connected environment (started with the asnsat command, or with the COPYONCE keyword), the Apply program uses standard conflict detection.

To define a replication source for update-anywhere replication using DJRA:

Select the conflict detection level (described above) when you define a table as a replication source, and select the replica target structure when you add the member to the subscription set.

When to use update anywhere:

To reduce the risks of conflicts and costs of rejected conflicting transactions, use update-anywhere replication under the following conditions:

Fragmentation by key
Design your application so that the replication source is updated by replicas for key ranges at specific sites. For example, your New York site can update sales records only for the Eastern United States (using ZIP codes 26 less than or equal to 49999 as the key range), but can read all sales records.

Fragmentation by time
Design your application so that the table can be updated only during specific time periods at specific sites. The time periods must be sufficiently separated to allow for the replication of any pending changes to be made to the site that is now becoming the master version. Remember to allow for time changes, such as Daylight Savings Time or Summer Time, and for time-zone differences.

Detecting conflicts

For update-anywhere replication, update conflicts can occur when:

The Apply program detects update conflicts, after they occur, during the subscription cycle. The source table is considered the primary table. That is, it can receive updates from replica tables, but if there is a conflict, the source table wins and the replica tables' conflicting transactions are rejected. The Apply program detects direct row conflicts by comparing the key values in the CD tables with the source and target tables. If it finds any that match, it marks the replica transaction as rejected in the UOW table and rolls back the replica transaction.

The Apply program cannot detect read dependencies. If, for example, an application reads information that is subsequently removed (by a DELETE statement or by a rolled back transaction), the Apply program cannot detect the dependency.

DB2 DataPropagator provides three levels of conflict detection: no detection, standard detection, and enhanced detection. Each level has a numerical value which is stored in the CONFLICT_LEVEL column of the register control table. You must decide, based on your tolerance for lost or rejected transactions and performance requirements, which type of detection to use. See Defining replication sources for update-anywhere replication for more information about the levels of conflict detection and how to specify them.

Restriction: Although you set the conflict-detection level for individual replication sources, the Apply program uses the highest conflict-detection level of any subscription-set member as the level for all members of the set.

Use the rejection codes provided in the UOW table to identify the before and after row values in the CD table for each rejected transaction. Because the ASNDONE exit routine runs at the end of each subscription cycle, you can add code to the routine to handle any rejected transactions. See Using the ASNDONE exit routine for more information on the ASNDONE exit routine. Alternatively, because the change data rows and UOW control table rows for rejected transactions are exempt from normal pruning (they are, however, subject to RETENTION_LIMIT pruning), you could handle the rejected transactions as a batch by using a program that scans the UOW table.

Defining views as replication sources

You can define replication sources that are views of other tables. After defining each replication source table included in the view, you can create a view replication source. The view replication source is then available for replication to a target table.

You cannot use the DB2 Control Center to define an existing view as a replication source; use DJRA instead. You can use the DB2 Control Center to define a new view as a replication source.

To define a view using the DB2 Control Center:

  1. Define the source tables to be used in the view (or join) as replication sources.
  2. Click on the Replication Sources folder. Select the replication sources to be used in the view from the contents pane. Right-click the mouse button, then select Define join from the pop-up menu. The Define Join window opens.
  3. In the CREATE VIEW field, type the SQL statement for the view. For example:
    USERID.VIEW_NAME AS SELECT A.COL1, A.COL2, B.COL6, B.COL5
    

    Do not type the words CREATE VIEW. This part of the statement is automatically supplied during processing.

  4. In the FROM field, type table names that define the join. For example:
    TABLEA A, TABLEB B
    

    Do not type the word FROM. This part of the statement is automatically supplied during processing.

  5. If you want to use a row predicate, type the WHERE clause SQL statement in the WHERE field. For example:
    A.COL1=B.COL1
    

    Do not type word WHERE. This part of the statement is automatically supplied during processing.

  6. Select OK to save the values and close the window. After you run the SQL that defines the join view, it is available for replication.

To define a view as a replication source using DJRA:

Click Define DB2 Views as Replication Sources and fill in the required information, such as source server, source view qualifier, and source view name. You cannot define a join as a replication source using DJRA, but you can define a view for the join and use DJRA to define the view as a replication source.

Enabling replication logical-partitioning-key support

Generally, the Capture program captures an update to a source table as an UPDATE statement. However, for the following conditions, you must instruct the Capture program to capture updates as DELETE and INSERT statements (that is, you must enable logical-partitioning-key support):

You can capture updates as updates or as delete/insert pairs for both DB2 and non-DB2 sources.

By default, when you update the primary keys of either the source or target tables, the Capture program captures the changed row for the update. The Apply program then attempts to update the row in the target table with the new key value. This new key value is not found in the target table, so the Apply program converts this update to an insert. In this case, the old row with the old key value remains in the table (and is unnecessary). When you enable replication logical-partitioning-key support, the Capture program captures the change as separate DELETE and INSERT statements: delete the old row and insert the new row.

For DATALINK columns defined as ON UNLINK DELETE, the unlink is ignored because a DELETE and INSERT pair is handled within the same transaction. The external file is not deleted, but is updated.

Each captured UPDATE is converted to two rows in the CD table for all columns, non-key columns as well as key columns. You might need to adjust the space allocation for the CD table to accommodate this increase in captured data.

When you use the DB2 Control Center to define the source table, select the Changed data for partitioned key columns captured as delete and insert check box on the Define as Replication Source window to specify that the Capture program should capture updates as DELETE and INSERT statements.

When you use DJRA to define the source table, select the Updates as delete/insert pairs radio button from either the Define One Table as a Replication Source window or the Define Multiple Tables as Replication Sources window.


Defining CCD tables

Recommendation: Use DJRA to define CCD tables. The DB2 Control Center does create CCD tables, but does not allow you to define them directly.

To define a CCD table using DJRA, select CCD as the Target structure from the Add Member to a Subscription Set window, then click the Setup pushbutton. Select the type of CCD table you want from the Staging (CCD) table property selection for target server window. This window prompts you for all valid combinations of CCD tables.

For noncomplete CCD tables, you can include one or more of the UOW table columns; these columns are useful for auditing and include Apply qualifiers, authorization IDs, UOW ID, and so on.

If you are using a CCD table to stage replication (for example, in a three-tier replication environment), complete the following steps:

  1. Add the (complete and condensed) CCD table to a subscription set.

    The Apply program that owns the subscription set populates the CCD table based on the subscription-set definition.

  2. If the CCD is defined as external, define it as a replication source.

    From the DJRA Staging (CCD) table property selection for target server window, select the Register as external replication source checkbox after selecting a complete CCD table. See Defining replication sources for more information.

  3. Create a new subscription set.

    This new set is the Apply program that applies changes from the CCD table to the target tables. Usually, you use a different Apply qualifier than the one used to populate the CCD, but you can use the same one.

    See Defining replication subscription sets.

  4. Define the target tables within the subscription set.

    Select the source table depending on the type of CCD table you are using:

For more information about CCD tables, see Staging data.


Defining replication subscription sets

To define a replication subscription set using the DB2 Control Center:

  1. Click the Replication Sources folder for the source database to show all tables and views defined as replication sources. The replication sources appear in the contents pane.
  2. Select one or more tables or views that you want to define as sources for the subscription set, and right-click on one to show the pop-up menu and select Define subscription. The Define Subscription window opens.
  3. Give the subscription a name, specify the target server, and specify the Apply qualifier for the subscription. You can also change the name of the target table and specify whether the Apply program should create the target table. Target-table names cannot exceed 18 characters in length.

    If you specify that the Apply program should create the target table, and that table will contain DATALINK columns, these columns will have the default level of link control (none). If you want these columns to have a different level of link control, edit the generated SQL to modify the CREATE TABLE statement and specify a new level of link control, then run the modified SQL.

  4. Click the Advanced push button to specify the target type and to specify specific columns and rows. See Choosing a target-table type and Defining the target-table structure: columns and rows for more information about these tasks.
  5. Click the Timing push button to specify the frequency of replication and a data blocking value. See Specifying a data-blocking value for more information.
  6. Click the SQL push button to add SQL statements or stored procedures that you want to run before or after a subscription cycle. For example, you can add a DELETE statement to prune the Apply trail control table.
  7. Click the OK push button to complete the subscription definition. The Subscription Information window opens. In that window, specify the control server name.

To define a replication subscription set using DJRA:

  1. From the main window, click Create Empty Subscription Sets to open the Create Empty Subscription Sets window.
  2. In this window, specify the source server, control server, target servers, the Apply qualifier, the subscription set name, the subscription timing, and blocking factor.
  3. Add subscription-set members to the subscription set.
    1. From the main window, click Add a Member to Subscription Sets or Add Multiple Members to Subscription Sets to display either the Add a Member to Subscription Sets window or the Add Multiple Members to Subscription Sets window.
    2. In either window, specify the subscription sets to which you want to add a member, the tables and views to add to the subscription set, whether the target table should be a column or row subset of the source table (see Defining the target-table structure: columns and rows), the target table type (see Choosing a target-table type), and how the index for the target table should be created.

When you add members to a subscription set, you can specify which primary key to use for the target table. You can specify that DJRA should generate the target primary key from the source primary key and source table indexes, or you can specify the particular columns for the key, or you can specify the source primary key.

After you create subscription sets for a non-IBM source server, the Apply program connects to the DB2 DataJoiner database that is associated with the non-IBM server and accesses (through nicknames) the information in the register control table and the staging table on the non-IBM source server (see Figure 21).

Figure 21. DB2 DataJoiner in action. In a scenario where the source table is a non-IBM table (the dark arrows), DB2 DataJoiner nicknames give the Apply program access to the non-IBM source server and to changes made to the non-IBM source table (through the staging table). In a scenario where the source table is a DB2 table (the light arrows), DB2 DataJoiner nicknames give the Apply program access to the non-IBM target tables.


DB2 DataJoiner nicknames working with triggers, IBM Replication, and the Apply program.

If you defined an event to start the Apply program, you must populate the event table. See Event timing for more information about this task. To begin replicating data to the target tables, start the Capture program at the source server, then start the Apply program using the name of the control server that you specified in the Control Center Subscription Information window or the DJRA Add a Member to Subscription Sets window (or Add Multiple Members to Subscription Sets window).

Defining subscription sets for update-anywhere replication

To define a subscription set for update-anywhere replication using the DB2 Control Center, define a subscription set and use the following selections:

  1. Select the replication sources that you want to be in the subscription set. Include all sources affected by the replica tables being updated.
  2. From the Subscription Definition window, select a target table to be defined as a replica table.
  3. Click Advanced to open the Advanced Subscription notebook. The following selections are required on the Advanced Subscription notebook:
    1. From the Target Type page, click on Target table is replica.
    2. From the Target Columns page, repeat the following steps for each target table:
      1. Ensure that the Subscribe check boxes are selected for every column. Do not create new columns for the replica table.
      2. Specify a primary key for the replica table by clicking on the Primary Key check boxes next to the key column names.

        Make the primary key the same as the source-table primary key to prevent conflicts. Do not use before-image columns as primary-key columns for the target table.

        Important: For existing target tables, you must select the primary-key columns.

    3. If you want the replica to be a subset of the source table, type a row predicate in the WHERE field on the Rows page.
    4. Click OK to close the Advanced Subscription notebook.
  4. Click Timing to open the Subscription Timing notebook:
    1. On the Source to Target page, fill in the subscription set timing information for copying the source-table's changed data to the target tables.
    2. On the Replica to Source page, fill in the subscription-set timing information for copying the replica-table's changed data to the source tables.
    3. Click OK to close the notebook.
  5. If you want to define SQL or CALL procedures to run before or after the subscription set is processed, click SQL and define the processing statements.

To define a replication subscription for update-anywhere replication using DJRA, select the replica target structure when you add the member to the subscription set.

Choosing a target-table type

You can specify a target-table type if you do not want to accept the default target type of user copy.

To specify a target-table type using the DB2 Control Center:

  1. From the Define Subscription window, select a source and target table combination, and click Advanced to open the Advanced Subscription Definition notebook.
  2. From the Target Type page, select one of the following table types:
  3. If you are finished using the Advanced Subscription Definition notebook, click OK to close the notebook. Otherwise, use the other pages of the notebook to define the target table columns and rows, as needed.

To specify a target-table type using DJRA:

Click Add a Member to Subscription Sets or Add Multiple Members to Subscription Sets. Fill in the required information for the subscription-set member. You can specify the target-table type from the Table structure drop-down list. The available types include the same as those described for the DB2 Control Center, plus choices for CCD table types.

Defining the target-table structure: columns and rows

For some applications, the target table does not need all of the rows or columns that exist in the source table. You can define the target table to be a column or row subset of the source table using the Control Center or DJRA. For more information on subsetting, see Subsetting columns and rows.

Restriction: Replica target tables must contain the same columns as the source table: you cannot create subsets for them; you cannot add columns; and you cannot rename columns.

Defining the target-table columns

To define the target-table columns using the DB2 Control Center:

  1. From the Define Subscription window, select a source and target table combination and click Advanced to open the Advanced Subscription Definition notebook.
  2. From the Target Columns page, specify which columns should be the primary-key columns for the target table; you can rename columns and you can change column definitions.

    If you want to specify a column as a primary-key column for the target table, select the Primary Key check boxes next to the column names.

    Attention: For the following target-table types you must select one or more columns as part of a primary key: user copy, point-in-time, replica, and condensed staging tables. If you do not select columns for the primary key, DB2 uses the primary-key definition of the source table. However, if the source table does not have a primary-key definition, the Apply program issues an error message.

    If you want to rename a column, select the column name and type over the existing column name. A column name can have up to 17 characters and can be an ordinary or delimited identifier.

    If you want to change a column definition for the target table, click Change to open the Change Column window. From this window, you can:

    If you want to remove a column from the target table, clear the Subscribe check box next to the column name.

    If you want to create a new computed column or use aggregation for the target table:

    1. Click Create Column to open the Create Column window.
    2. Type the name of the column in the Column name field. The name can have up to 17 characters and can be an ordinary or delimited identifier.
    3. Type the SQL expression defining the new column.
    4. Click OK to close the window.
  3. If you are finished using the Advanced Subscription Definition notebook, select OK to close the notebook. Otherwise, use the Rows page to define the target table rows, as needed.

To define the target-table columns using DJRA:

Click the Selected columns radio button from the Add a Member to Subscription Sets window. Then select the columns you want replicated to the target table.

Defining the target-table rows

To define the target-table rows using the DB2 Control Center:

  1. From the Define Subscription window, select a source and target table combination and click Advanced to open the Advanced Subscription Definition notebook.
  2. From the Rows page, specify a WHERE clause that defines the row subset.

    To specify which rows are copied to the target table, type an SQL predicate in the WHERE field. The predicate can contain ordinary or delimited identifiers. See the DB2 SQL Reference for more information about WHERE clauses.

    Row Predicate Restrictions:

  3. To see examples of SQL predicates, click the Examples button.

    WHERE clause examples:

    The following examples show WHERE clauses that you can use to filter rows of the target table. These examples are very general and designed for you to use as a model.

  4. If you are finished using the Advanced Subscription Definition notebook, click OK to close the notebook.

To define the target-table rows using DJRA:

Add a WHERE clause in the Where clause field of the Add a Member to Subscription Sets window.

Defining a subscription set with a user-defined table

DB2 DataPropagator allows you to use a previously-defined DB2 table as the target table in a subscription set. That is, you can define a subscription-set member to be a target table that is defined outside of the DB2 Control Center or DJRA. This type of target table is known as a user-defined target table.

Restrictions:

To define a subscription with a user-defined target table:

  1. Refer to Table structures to determine the structure for the target-table type. For example, if you are defining a subscription for a base aggregate table, refer to the table structure definition for base aggregate tables.
  2. Alter the target table to add any required columns, such as timestamp columns.
  3. For point-in-time, user copy, replica, and condensed CCD tables, create a unique index.
  4. Define the subscription-set member to match the user-defined target table structure, including new columns, subset columns, changed column names, and renamed before-image columns.

    From the DB2 Control Center, in the Define Subscription window:

    1. Clear the Create table check boxes next to the table names for which you are providing the target tables.
    2. Type the user-defined target-table name in the Target table field.
    3. If you want to subset columns or rows, enhance data, or specify a target-table type other than user copy, click Advanced to open the Advanced Subscription Definition notebook.

      If you want to select an alternate table type, see Choosing a target-table type. If you want to modify the target-table columns to match the user-defined target table, or subselect the rows or use an aggregate expression, see Defining the target-table structure: columns and rows.

DJRA tolerates existing target tables, and checks that the columns in the target table match those defined for the subscription-set member.

DB2 DataPropagator does not check for inconsistencies between the subscription definition and a user-defined target table. You must:

Defining SQL statements or stored procedures for the subscription set

You can define SQL statements or stored procedures to be run before or after the Apply program copies the data from the source to the target table. For example, you can prune the Apply trail control table each day to remove older entries.

To specify SQL statements or stored procedures for the subscription set using the DB2 Control Center:

  1. From the Define Subscription window, click SQL to open the SQL window.

    Use the SQL window to add or remove SQL statements or stored procedures that run at the target or source server either before or after the replication subscription is processed. The statements are processed in the order that they appear in the list.

  2. Click Add to open the Add SQL window.
  3. Type the SQL statement or stored procedure name in the SQL statement or Call procedure field. The stored procedure name must begin with CALL. This field can contain ordinary or delimited identifiers.
  4. If you know that the SQL statement or stored procedure will generate SQLSTATEs that would otherwise terminate execution, specify these SQLSTATEs so that the Apply program can bypass them and treat them as successful execution. For example, a DELETE statement will generate a SQLSTATE 02000 when attempting to delete nonexistent rows, but for new tables you might not care about this error.

    Enter valid 5-byte SQLSTATE values in the SQLSTATE field and click Add. The value is added to the Acceptable SQLSTATE values box. You can add up to 10 values.

  5. Specify whether you want to run the SQL statement or stored procedure at the source or target server before the subscription set is processed, or at the target server after the subscription set is processed by clicking the appropriate radio button in the Submit SQL statement field.
  6. Click OK to add the statement to the box in the SQL window and close the Add SQL window.

To specify SQL statements or stored procedures for the subscription using DJRA:

  1. From the main DJRA window, click Add Statements or Procedures to Subscription Sets.
  2. Specify the source server and subscription sets to which you are adding SQL statements or stored procedures.
  3. Type the SQL statement in the SQL statement field or type the stored procedure name in the Stored procedure field. The stored procedure name must begin with CALL. This field can contain ordinary or delimited identifiers.
  4. If you know that the SQL statement or stored procedure will generate SQLSTATEs that would otherwise terminate execution, specify these SQLSTATEs so that the Apply program can bypass them and treat them as successful execution. For example, a DELETE statement will generate a SQLSTATE 02000 when attempting to delete nonexistent rows, but for new tables you might not care about this error.

    Select a statement number from the Statement number spin box, and enter valid 5-byte SQLSTATE values in the Acceptable SQLSTATE values field.

  5. Specify whether you want to run the SQL statement or stored procedure at the source server before the subscription set is processed, or at the target server before or after the subscription set is processed by selecting the appropriate radio button.

Data-sharing considerations

You can implement replication in an System/390 data-sharing environment. In a data-sharing environment, you run one Capture program for each source data-sharing group and one or more Apply programs for each target data-sharing group.

The Capture program can read the data-sharing logs for all supported vresions of DB2 for OS/390. That is, you can run different versions of DB2 in a data-sharing environment, for example during version-to-version migration, and have one Capture program continue to capture transaction-consistent data. However, this mixed-version environment is not recommended for long-term use, either for replication or for DB2. See the DB2 for OS/390 Administration Guide for information about data sharing with mixed versions of DB2.

Specifying a data-blocking value

To specify how many minutes worth of change data DB2 DataPropagator can replicate during a subscription cycle, use the Data Blocking page of the Subscription Timing notebook in the DB2 Control Center, or set the Blocking factor in the Create Empty Subscription Sets window in DJRA. The number of minutes that you specify determines the size of the data block. See Data blocking for large volumes of changes for more information about how to determine this value.

DB2 DataPropagator saves this value in the MAX_SYNCH_MINUTES column of the subscription set control table. To change this value, execute the following SQL statement:

UPDATE ASN.IBMSNAP_SUBS_SET
SET MAX_SYNCH_MINUTES=new_val
WHERE APPLY_QUAL=ApplyQual AND SET_NAME=name AND WHOS_ON_FIRST=val

where new_val is the new blocking factor value, ApplyQual is the current Apply qualifier, name is the current subscription-set name, and val is either F or S.

Data currency requirements

How up to date do you want target tables to be? How out of date can they be without disrupting the application programs that use them? The answers to these questions reveal your data currency requirements. You can control how often the Apply program processes subscriptions and thereby control the currency of the data. You can set an interval (or relative timing) schedule for the Apply program, or define an event trigger that the Apply program uses to start processing a subscription set.

You define subscription timing with the Subscription Timing notebook in the DB2 Control Center or from the Subscription set timing field on the Create Empty Subscription Sets window in DJRA. You can control the timing using time-based or event-based scheduling, or you can use these timing options together. For example, you can set an interval of one day, and also specify an event that triggers the subscription cycle. For update-anywhere replication, you can also specify different timing for source-to-replica and replica-to-source replication.

Recommendation: When moving from a test environment to a production environment, set a mid-range timing value (such as 2 hours) and tune your system from there (to a more frequent or less frequent interval, as appropriate).

Interval timing (relative timing)

The simplest method of controlling subscription timing is to use interval timing. You determine a specific start time, date, and interval. The interval can be specific (from one minute to one year) or continuous, but time intervals are approximate. The Apply program begins processing a subscription set as soon as it can, based on its workload and the availability of resources. If you specify continuous timing, the Apply program replicates data as frequently as it can.

Choosing a timing interval does not guarantee that the frequency of replication will be exactly at that interval. Before specifying an interval, you should determine whether it is possible to refresh all tables in the subscription set within that interval: determine the amount of data that the Apply program is likely to select for each interval and estimate the time that it will take to copy the data.

You can set and change the interval using the DB2 Control Center, DJRA, or by executing SQL statements against the subscription-set control table.

Event timing

To replicate data using event timing, specify an event name when you define the subscription set in the DB2 Control Center or DJRA. You must also populate (using an application program or the DB2 Command Center) the subscription events table with a timestamp for the event name. When the Apply program detects the event, it begins replication (either change-data capture or full refresh).

The subscription events table has three columns, as shown in Table 6.

Table 6. The subscription events table
EVENT_NAME EVENT_TIME END_OF_PERIOD
END_OF_DAY 2000-05-01-17.00.00.000000 2000-05-01-15.00.00.000000

EVENT_NAME is the name of the event that you specify while defining the subscription set. EVENT_TIME is the timestamp for when the Apply program begins processing the subscription set. END_OF_PERIOD is an optional value that indicates that updates that occur after the specified time should be deferred until a future time. Set EVENT_TIME using the clock at the control server, and set END_OF_PERIOD using the clock at the source server. This distinction is important if the two servers are in different time zones.

In Table 6, for the event named END_OF_DAY, the timestamp value (2000-05-01-17.00.00.000000) is the time when the Apply program is to begin processing the replication subscription. The END_OF_PERIOD timestamp value (2000-05-01-15.00.00.000000) is the time after which updates are not replicated and will be replicated on the next day's cycle. That is, the event replicates all outstanding updates made before three o'clock, and defers all subsequent updates.

Your application programs must post events to the subscription events table to tie your application programs to subscription activity. When you post an entry using CURRENT TIMESTAMP plus one minute for EVENT_TIME, you trigger the event named by EVENT_NAME. Any subscription set tied to this event becomes eligible to run in one minute. You can post events in advance, such as next week, next year, or every Saturday. If the Apply program is running, it starts at approximately the time that you specify. If the Apply program is stopped at the time that you specify, when it restarts, it checks the subscription events table and begins processing the subscription set for the posted event.

Any event that occurs prior to the most recent time the Apply program processed the subscription set (as specified by the value in the LASTRUN column of the subscription-set control table), is considered to be an expired event and is ignored. Therefore, if the Apply program is running, you should post events that are slightly in the future to avoid posting an expired event.

Changing subscription-set timing

You can change subscription-set timing while both the Capture program and Apply program are running by modifying values in the subscription set table. For example, to change the interval value, execute the following SQL statement:

UPDATE ASN.IBMSNAP_SUBS_SET
SET INTERVAL_MINUTES=new_val
WHERE APPLY_QUAL=ApplyQual AND SET_NAME=name AND WHOS_ON_FIRST=val

where new_val is the new interval value, ApplyQual is the current Apply qualifier, name is the current subscription-set name, and val is either F or S.

To change a subscription set to use event timing rather than interval timing, execute the following SQL statements:

UPDATE ASN.IBMSNAP_SUBS_SET
SET REFRESH_TIMING='E', EVENT_NAME='END_OF_DAY'
WHERE APPLY_QUAL=ApplyQual AND SET_NAME=name
 
INSERT INTO ASN.IBMSNAP_SUBS_EVENT
(EVENT_NAME, EVENT_TIME)
VALUES ('END_OF_DAY', 'timestamp')

where new_val is the new interval value, ApplyQual is the current Apply qualifier, name is the current subscription-set name, val is either F or S, and timestamp is the timestamp for when the Apply program should begin processing the subscription set. If you already have an event named END_OF_DAY, you do not need the INSERT statement shown above, but you might need to modify the EVENT_TIME.

See Subscription set table and Subscription events table for more information about these control tables.

Data consistency requirements

When planning and defining a subscription set, you need to be aware of the following rules and constraints:

Maintaining external CCD tables

If you maintain your own CCD table, you must update three columns in the register control table: CCD_OLD_SYNCHPOINT, SYNCHPOINT, and SYNCHTIME:

CCD_OLD_SYNCHPOINT
The synch point associated with when the CCD table was last initialized or pruned.

Before a full refresh of the CCD table, set CCD_OLD_SYNCHPOINT to NULL.

After a full refresh of the CCD table, set the CCD_OLD_SYNCHPOINT to a value greater than the previous value of SYNCHPOINT. If SYNCHPOINT has no previous value (in the case of the initial load), set the CCD_OLD_SYNCHPOINT to X'00000000000000000000'.

SYNCHPOINT
A sequence value useful for maintaining the state of CCD copies, subscription states, and for controlling pruning.

Set the SYNCHPOINT for the CCD table to MAX(IBMSNAP_COMMITSEQ) whenever you commit new changes to the CCD table. Be sure also to set SYNCHTIME accordingly.

SYNCHTIME
The timestamp-equivalent of SYNCHPOINT.

Loading target tables offline using DJRA

DJRA guides you through the process of creating an offline load of a table or database. The following procedure does not maintain the additional control information required for loading external CCD tables, so for these tables you must use the manual procedure.

To perform an offline load using DJRA:

  1. Ensure that the Capture program is running.
  2. Click Off-line load on the DJRA main window.
  3. In the Off-line load -- STEP 1 window, generate the SQL statements to disable current subscriptions for the selected subscription sets. After you load the target tables, you will re-enable these subscriptions.
  4. Unload the source tables. Then click Next Step on the Off-line load -- STEP 2 window.
  5. Load the target tables. Then click Next Step on the Off-line load -- STEP 3 window.
  6. In the Off-line load -- STEP 4 window, generate the SQL statements to re-enable current subscriptions for the selected subscription sets. Then click Finished.

Copying your replication configuration to another system

When you define tables, replication sources, or subscription sets on one system (a test system, for example), and you need to copy the replication environment to another system (a production system, for example), you can use the DJRA promote functions. These functions reverse engineer your tables, replication sources, or subscription sets, to create script files with appropriate data definition language (DDL) and data manipulation language (DML). Table 7 shows the three promote functions.

For example, use the promote functions to define subscription sets for remote DB2 Personal Edition target databases. After you define a model target system in your test environment, you can create subscription-set scripts (and modify which Apply qualifier is used and so on) for your DB2 Personal Edition systems, which are not otherwise supported from a central control point.

Table 7. Promote functions provided by DJRA
Promote function Description
Promote registration This function promotes source tables and views from a source server.
Promote table This function promotes tables, table spaces, and indexes. It does not promote constraints defined for a table.

This function is fully supported for DB2 UDB V5 and later, but for the IBM Common Server you can promote only tables, not table spaces.

Promote subscription This function promotes subscriptions: subscription sets, subscription-set members, subscription columns, subscription prune control, and subscription statements. It enables you to create a new subscription set from an existing one.

From the Promote Subscriptions window in DJRA, you can change your subscriptions (before promoting them) by setting new values for any of the following fields: Apply Qualifier, Set Name, Source server, Source alias, Target server, Target alias, Control server, and Control alias.


Setting up the Capture program

This section describes setting the Capture program generally. See the appropriate chapter for your operating system environment (in Operations) for specific information about setting up the Capture program.

Specifying tuning parameters for the Capture program

To control the performance of the Capture program, you can specify the following tuning parameters in the tuning parameters table:

Retention limit
The number of minutes to keep the CD table rows and the unit-of-work (UOW) table rows. The default value is 10 080, which is 7 days.

For AS/400, you can keep the size of tables smaller by reorganizing them using the RGZPFM command.

Lag limit
The number of minutes that the Capture program can be backlogged from the current local time before shutting itself down. The default value is 10 080, which is 7 days. If this value is exceeded, the Apply program will perform a full refresh of all target tables.

Recommendation: Set a high value for the lag limit to ensure the Capture program does not shut itself down unnecessarily.

If the database does not have or support an archive log, and the Capture program shuts itself down, you should perform a cold start of the Capture program.

Commit interval
The number of seconds that the Capture program waits before issuing a COMMIT statement. The default value is 30 seconds.

If the Apply program is not running at the same time as the Capture program, you can set the commit interval no higher than the DB2 timeout interval.

For AS/400, this value has a different meaning: it is the number of seconds between the time that an application program updates a source table and the time that the corresponding update in the CD table is written to disk. The commit interval can range from 30 to 600 seconds, and the default is 180. If the value is too small, overall system performance can be degraded.

Prune interval
The number of seconds that the Capture program waits before pruning the CD and UOW tables. The default value is ten times the commit value, or 300 seconds, whichever is larger. This parameter is ignored if you start the Capture program with the NOPRUNE option; however, you can override this option by using the prune command.

For AS/400, you can override this value by specifying a value for the wait-time subparameter of the CLNUPITV keyword of the STRDPRCAP command. If you specify *NO on the start-clean-up subparameter of the CLNUPITV keyword, the prune interval value is ignored.

For AS/400, if you start up the Capture program daily, *NO allows you to defer pruning (for example, to the weekend). During the week, you can use CLNUPITV (*DPRVSN *NO) on the STDPRCAP command. On weekends, you can use CLNUPITV (*DPRVSN *IMMED), which is the default.

Important: When you manually prune the CD table, do not delete the most recent row. Always keep at least one row in the table.

To specify the tuning parameters, do one of the following tasks:

Restrictions when running the Capture program

The following actions cause the Capture program to terminate while it is running. Stop the Capture program if you want to perform any of the following tasks:

Other Capture program restrictions include:


Setting up the Apply program

This section describes setting the Apply program generally. See the appropriate chapter in Operations for your operating system environment for specific information about setting up the Apply program.

Refreshing target tables with the ASNLOAD exit routine

The Apply program can call the ASNLOAD exit routine whenever it performs a full refresh of a target table. Specify the LOADX parameter to cause the Apply program to call this routine.

You can use the ASNLOAD routine as shipped with the Apply program, or you can modify it. As shipped, the routine uses the DB2 EXPORT utility to export data from the source table and uses the DB2 LOAD utility to fully refresh the target table. You can modify the ASNLOAD routine to call any IBM or vendor utility. See the prolog section of the sample program (ASNLOAD.SMP) in the \sqllib\samples\repl directory for information about how to modify this exit routine.

You must use the ASNLOAD routine to fully refresh tables with referential integrity constraints in order to bypass referential integrity checking.

If your source servers are password protected, you must modify the ASNLOAD routine to provide the password file. However, if the password is administered by DB2 Universal Database Satellite Edition, the ASNLOAD routine does not require a password file, and you can use the IBM-supplied routine.

If your source tables include DATALINK columns, the Apply program does not call the ASNDLCOPY exit routine. If you want external files (pointed to by the DATALINK values) to be copied during a full refresh, you must modify the ASNLOAD routine to call the ASNDLCOPY routine for these columns.

See Refreshing target tables with the ASNLOAD exit routine for AS/400 for information about using the ASNLOAD routine in an AS/400 environment.

Files generated on Windows and UNIX

When you run the ASNLOAD routine, it generates the following files:

Files generated on OS/2

When you run the ASNLOAD routine, it generates the following files:

Error handling

If an error occurs while the Apply program calls the ASNLOAD routine, or if the routine returns a nonzero return code, the Apply program issues a message, stops processing the current subscription set, and processes the next subscription set.

Restrictions

You can use the ASNLOAD routine only to refresh point-in-time and user copy tables. Target tables have the following restrictions for the ASNLOAD routine:

Using the ASNDONE exit routine

The Apply program can optionally call the ASNDONE exit routine after subscription processing completes, regardless of success or failure. You can modify this routine as necessary; for example, the routine can examine the UOW table to discover rejected transactions and initiate further actions, such as issuing a message or generating an alert. Another use for this exit routine is to deactivate a subscription set that fails (status = -1), and thus avoid retry by the Apply program until the failure is fixed.

See the prolog section of the sample program (ASNDONE.SMP) in the \sqllib\samples\repl directory for information about how to modify this exit routine. For AS/400, the following table indicates where you can find the source code for this routine:
Compiler language Library name Source file name Member name
C QDPR QCSRC ASNDONE
COBOL QDPR QCBLLESRC ASNDONE
RPG QDPR QRPGLESRC ASNDONE

See Using the ASNDONE exit routine for AS/400 for more information about using the ASNDONE exit routine in an AS/400 environment.

To use the ASNDONE exit routine:

  1. Modify the ASNDONE routine to meet your site's requirements.
  2. Compile the program and place the executable in the appropriate directory.
  3. Start the Apply program with the NOTIFY parameter to call the ASNDONE exit routine.

The parameters that the Apply program passes to the ASNDONE exit routine are:

Using the ASNDLCOPY exit routine

If a subscription set contains DATALINK columns, the Apply program calls the ASNDLCOPY exit routine during processing for a subscription-set member to copy the external file. You can modify this routine as necessary, for example, to change the file transfer protocol.

Restrictions: The Apply program does not call the ASNDLCOPY routine if the target table is a CCD table. Also, if you want external files (pointed to by DATALINK values) to be copied during a full refresh, you must modify the ASNLOAD routine to call the ASNDLCOPY routine for these columns.

See the prolog section of the sample program (ASNDLCOPY.SMP) in the \sqllib\samples\repl directory for information about how to set up and modify this exit routine. For AS/400, you can find the sample program in library QDPR, source file QCSRC, member ASNDLCOPY.

To use the ASNDLCOPY exit routine:

  1. Modify the ASNDLCOPY routine to meet your site's requirements. See ASNDLCOPY parameters and input.
  2. Configure the ASNDLUSER and ASNDLSRVMAP files. See ASNDLCOPY configuration files.
  3. Optional: Modify the ASNDLCOPYD file-copy daemon to meet your site's requirements. See Using the ASNDLCOPYD file-copy daemon.
  4. Compile the program and place the executable in the appropriate directory.

When the ASNDLCOPY routine completes, it should return a return code to the Apply program. A nonzero return code tells the Apply program that replication failed for one or more of the files; in this case, the Apply program issues a message, skips the current subscription set, and processes the next subscription set. A zero return code tells the Apply program that replication was successful.

Because the Apply program calls the ASNDONE exit routine after subscription processing completes, regardless of success or failure, you can use the routine to perform any necessary clean up if the ASNDLCOPY routine fails to replicate any external files.

The ASNDLCOPY routine creates two files: a log file and a trace file (if trace is enabled). The log file has the following name:

ASNDLApplyQualSetNameSrcSrvrTgtSrvr.LOG

where ApplyQual is the Apply qualifier, SetName is the subscription-set name, SrcSrvr is the source-server name, and TgtSrvr is the target-server name. The log file contains all messages generated by the ASNDLCOPY routine. The trace file has the following name:

ASNDLApplyQualSetNameSrcSrvrTgtSrvr.TRC

The trace file contains any trace information generated by the ASNDLCOPY routine.

ASNDLCOPY parameters and input

The parameters that the Apply program passes to the ASNDLCOPY exit routine are:

The input data file contains a list of link references captured from the source table. The format for this file is:

length source_link_reference new_link_indicator

The fields are:

length
The length of the link reference.

source_link_reference
The reference to the source link in URL format.

new_link_indicator
A one-character link indicator. The link indicator is either Y to indicate that the source file should be replicated, or N to indicate that the file should not be replicated (for example, if the file is unchanged from a previous replication).

Use the newline character to indicate the end of the input line.

Sample input file:

35 HTTP://S1.CDE.COM/data/yy/file1.avi Y
35 HTTP://S2.CDE.COM/data/qq/file2.avi N

The result file contains transformed link references that are valid for the target system. The format for this file is:

length target_link_reference

where length is the length of the target link reference, target_link_reference is the reference to the target link in URL format. If a source file cannot be replicated, the ASNDLCOPY routine should set length to 0 in the result file and set target_link_reference to blanks to ensure that no link is established in the target table.

Sample result file:

35 HTTP://T1.XYZ.COM/data/yy/file1.avi
35 HTTP://T2.XYZ.COM/data/zz/file2.avi

The trace option can be either yes or no, to specify whether you want tracing.

ASNDLCOPY configuration files

The ASNDLCOPY routine requires two configuration files: ASNDLUSER and ASNDLSRVMAP. The ASNDLUSER file contains the server address (URL format), input port number, output port number, login user ID, and password. The first port number is for the source FTP or file-copy daemon that the ASNDLCOPY routine will connect to for retrieving files and the second port number is for the target FTP or file-copy daemon for sending files. These port numbers can be the same.

Sample ASNDLUSER file:

S1.CDE.COM 21 21 userA xxyyzz
T1.XYZ.COM 21 24 userB xkxkxk

The ASNDLSRVMAP file contains the server mappings for link references and an optional directory path map. If you don't specify a directory path map, or if the path mapping cannot be found, the same path name will be used.

Sample ASNDLSRVMAP file:

HTTP://S1.CDE.COM HTTP://T1.XYZ.COM 
HTTP://S2.CDE.COM HTTP://T2.XYZ.COM /data/qq /data/zz

All fields for a given entry must appear on the same line.

Using the ASNDLCOPYD file-copy daemon

The ASNDLCOPYD file-copy daemon extracts files for the ASNDLCOPY exit routine. It is similar to a standard FTP daemon, but provides the following functions for DATALINK replication:

Recommendation: Use the ASNDLCOPYD file-copy daemon to replicate a DATALINK column that is defined with the "read permission DB" attribute. Whereas standard FTP requires superuser access, the ASNDLCOPYD daemon does not require such access.

You can configure the ASNDLCOPYD file-copy daemon to allow only certain users to log in, and for each user, you can allow access to a subset of directories. See the prolog section of the sample program (ASNDLCOPYD.SMP) in the \sqllib\samples\repl directory for information about how to set up and modify this program. For AS/400, you can find the sample program in library QDPR, source file QCSRC, member ASNDLCOPYD. If you need to add or change user logins, use the ASNDLCOPYD_CMD tool.

You pass the following parameters to the file-copy daemon:

To use the ASNDLCOPYD file-copy daemon:

  1. Compile the program and place the executable in the appropriate directory.
  2. Create two copies of the executable file (or for UNIX, create two symbolic links) named ASNDLCOPYD_CHLD and ASNDLCOPYD_CMD.
  3. Modify the configuration files to meet your site's requirements.
  4. Start the ASNDLCOPYD daemon, specifying both the port number and the configuration directory.

The ASNDLCOPYD daemon must run with root (administrator) authority.

The ASNDLCOPYD file-copy daemon creates a log file for all the messages generated by the ASNDLCOPYD program. This log file has the following name: ASNDLCOPYDYYYYMMDDHHMMSS.LOG, where YYYYMMDDHHMMSS is the time that the daemon started running.


Setting up DB2 DataJoiner

Install DB2 DataJoiner by following the steps described in the DB2 DataJoiner Planning, Installation, and Configuration Guide. The Apply program is automatically installed when you install DataJoiner. After you install DataJoiner:

For more information, see DB2 DataJoiner Planning, Installation, and Configuration Guide.


Footnotes:

23
For DataJoiner for AIX, replication from Microsoft SQL Server 6.x must use a DBLIB connection. For DataJoiner for Windows NT, replication from Microsoft SQL Server 6.x is restricted to using the ODBC protocol.

24
http://www.ibm.com/software/data/dpropr

25
For DB2 Universal Database systems, you can use the DB2 Control Center or DJRA to perform this task; for other systems, including DB2 for OS/390, DB2 for AS/400, and all non-IBM databases, you must use DJRA.

26
United States postal codes.

27
Version 4 or earlier only. This restriction does not apply to DB2 for OS/390 V5 or later.

28
If you use before-image columns or computed columns, for example, full refresh is no longer possible. You must also modify the register control table.

29
Customizing DPCNTL.400 is not necessary if you already installed DataPropagator for AS/400.


[ Top of Page | Previous Page | Next Page ]