IBM Books

DB2 Replication Guide and Reference


The Apply Program

The Apply program is the replication tool that replicates changes of the source table data to the target table.

The Apply program reads the changed data previously captured and stored in a CD table and applies the changes to target tables. The Apply program also reads data directly from source tables when copying the entire source table to the target table (called a full refresh copy).

The Apply program generally runs at the target server, but it can run at any server in your network that can connect to the source, control, and target servers. Several Apply program instances can run on the same or different servers. Each Apply program can run using the same authorization, different authorization, or as part of a group of Apply programs where each Apply program in the group runs using the same authorization (user ID).

The Apply program runs independently of the Control Center, but uses control information that the Control Center creates. The control information that the Apply program uses is stored in tables at the control server.

Tasks that you can perform with the Apply program include:

See the Capture and Apply chapter in this book for your Apply program platform for instructions about performing these tasks.

How the Apply Program Replicates Data

When the Apply program reads the changed data stored in CD tables, it applies it to target tables at either local or remote servers. It can also perform column functions, such as SUM and AVG, on the data from the source table or CD table and append the result to the target tables. The Apply program can run at any server that can connect through the SQL CONNECT statement to each database server where source and target tables reside. Figure 5 shows the Apply program's relationship with the source server control tables, the subscription definition control tables, and the target table.

Figure 5. The Apply Program. The Apply program reads the source server tables, manages the subscription control tables, and updates the target tables.
The Apply program

The Apply Processing Cycle

In the more common "pull" mode, the Apply program runs at the target server and connects to the source and control server to pick up changed data and to read the control tables. Table 1 describes how the Apply program completes a replication cycle from the target server.

Table 1. The Apply Program Cycle: A high-level overview of how a replication subscription is processed.
Step Server
1. Look for work; check the subscription control tables. Control server
2. Pick up recent change data to be applied to the target table. Source server
3. Write the answer set into a local "spill" file (possibly an in-memory file). Target server
4. Apply the change data in the spill file to the target table. Target server
5. Update subscription status. Control server
6. Report subscription progress in the pruning control table. Source server

How the Apply Program Selects a Source Table

When the Apply program refreshes or updates a target, it chooses from a list of potential source tables in the following order:

  1. The CCD table associated with the defined replication source table
  2. The CD table associated with the replication source table
  3. The replication source table associated with the replication subscription

In some cases, the source table considered first might not be the one that the Apply program reads from. For example, if the target table is a point-in-time table but has not yet been initialized, the Apply program must use a source table that is complete. If the CCD table is not complete (that is, CCD_COMPLETE=N in the register control table), the replication source table is selected as the refresh source. (The complete attributes are set when the CCD table is created.)

The Apply Qualifier

When the Apply program is started, it is supplied with a job qualifier, called an Apply qualifier, independent from a logon user ID. The Apply qualifier (APPLY_QUAL) is associated with individual replication subscriptions and is responsible for replicating only those replication subscriptions. You specify a value for the Apply qualifier when you define a subscription with the Control Center.

The Apply qualifier allows a user ID to run more than one instance of the Apply program, using different Apply qualifiers.

The Control Server

The control server is the logical server that contains the subscription control tables. Each Apply program is associated with a control server, which you specify when you invoke the Apply program. Multiple Apply programs can share a control server.

The control server can be located at the source server, the target server, or any database server that the Apply program can connect to. For better performance, the control server should be located at the server where the Apply program runs because the Apply program frequently reads the tables in the control server. However, locating the control server at the source server, if it is a server in a secure environment, can provide improved security.

Each control server is associated with one or more Apply qualifiers. The qualifier associates a control server with an Apply program and a replication subscription. This association allows a replication subscription to be serviced by one Apply program and identifies where the control tables for that subscription are located. You cannot easily change the Apply qualifier, so it is important to plan carefully.

Control Tables Used by the Apply Program

The Apply program relies on the following control tables to control the replication of source table changes to the target tables:

Source server control tables
The control tables used by the Capture program are: the register table, the unit-of-work table, the pruning control table, the critical section table, and the change data tables.

Control server control tables

Apply trail
Records statistics about full refresh and differential refresh (update) copies that are performed during each subscription set cycle.

Subscription set
Defines the characteristics of each subscription set, such as the subscription set name, the Apply qualifier that is associated with the subscription set, and the timing of the subscription set.

Subscription statements
Contains the SQL statements or names of stored procedures to be run before or after the subscription member (or subscription set) is processed.

Subscription events
Contains the timing information for copying the subscription set based on event triggering. This table is maintained by a user application or by other subscription sets. This table itself can be replicated if you want to distribute event notifications.

Subscription targets member
Contains information for an individual subscription set that maps a specific source table to a specific target table. Subscription sets of DB2 views usually have many subscription members for the same target table.

Subscription columns
Contains supplemental information about each copied column, such as renamed columns or computed columns.

These tables are described in more detail in Chapter 19. Table Structures.

Full Refresh and Differential Refresh Replication

The Apply program copies data from the source to the target either by full refresh or by differential refresh. For full refresh copying, the Apply program copies the entire source table and copies it to the target table. The Capture program does not capture changes, and there are no CD or CCD tables involved. You can specify full refresh copying when you define the replication source table. If you have large tables, you might want to use a fastload program to simulate an initial full refresh copy. See the Capture and Apply chapter for your platform in this book for more information about fastload programs such as ASNLOAD.

For differential refresh, the Apply program copies only the changed data from the CD table to the target table. The first time the Apply program copies data to the target table or after a cold start of the Capture program, the Apply program uses full refresh copying to populate the target table. (See the Capture and Apply chapter for your platform in this book for more information about cold start.) After the target table is populated, differential refresh is used. This type of copying is the default and is used unless you specify otherwise when you define the replication source.


[ Top of Page | Previous Page | Next Page | Table of Contents | Index ]

[ DB2 List of Books | Search the DB2 Books ]