Skip to content

Baselining a large table with partitioned snapshots

Use slices first

Stelo recommends a parallel baseline with slices: the subscription copies its own baseline in parallel slices, with no extra subscriptions to set up and remove. Partitioned snapshots, as this page describes, still work as an alternative.

A baseline copies a table with one stream. For a very large, busy table, that can take so long that the changes captured meanwhile pile up and the incremental subscription struggles to catch up. The answer is to copy slices of the table at the same time: with a parallel baseline, or with partitioned snapshots, as this page describes.

Use it only for the few tables that need it; for most tables, a normal baseline is simpler and safe.

Parallel baselines

The subscription copies its own baseline in parallel slices, set up on its Criteria tab. See Parallel baselines with slices.

Partitioned snapshots

Split the baseline into several snapshot subscriptions, each copying one slice of the table, that run at the same time in a snapshot group. The incremental subscription then applies only the changes captured during the copy. A parallel baseline is simpler.

How it works

  1. The incremental subscription is set to Manual synchronization: its "baseline" copies no data. Running it empties the destination table and stops as Suspended, while the Capture Agent keeps staging the table's changes (see Baseline Replication Options).
  2. A snapshot group runs several snapshot subscriptions on the same source and destination tables, each with a criteria that selects one slice of the rows, for example WHERE MOD(RRN(ORDERS), 10) = 3. They append their rows to the destination table in parallel, up to the group's Maximum Subscriptions at a time (see How a group run works).
  3. Running the incremental subscription a second time completes its manual synchronization. The group then applies the changes captured since the first run, and replication continues as usual.

Before you start

  • The table must have a key that incremental replication can use, and the destination table the incremental subscription's columns; see Keys, RRN/ROWID and indexes.
  • Decide how many slices to use (x). More slices copy faster, until the source, the network or the destination becomes the bottleneck; each running slice uses its own source and destination connections.
  • Pick a slicing expression that spreads the rows evenly and is cheap for the source to evaluate (see Slicing the table).

Steps

1. Create an incremental group for the table

Create an incremental group that holds only this table (see Create an incremental group):

  • General: tick Allow disable/enable indexes, clear Allow Checkpoint/Restart, and set Maximum Subscriptions to 1.
  • Advanced: choose the Source and Destination, and clear Automatic Snapshot, so that the group doesn't start a baseline by itself while you set things up.

2. Add the incremental subscription

Insert a member for the large table. On the Destination step:

  • Baseline Replication Options: Truncate table before replication and Manual synchronization.
  • Incremental Apply Options: Strict Apply Rules.
  • Destination DDL Options:
    • if the destination table already exists: Use existing table for baseline;
    • if it doesn't (or should be re-created): Create every time subscription is Saved, save (if asked whether to run a baseline, answer No), then change the option to Use existing table for baseline and save again.

3. Create the snapshot group

Create a snapshot group (see Create a snapshot group):

  • General: clear all the Indexes/Constraints options and Allow Checkpoint/Restart, and set Maximum Subscriptions to the number of slices (x), so that all slices run at once.

The index options must be off: in a group run, each member drops and re-creates the destination table's indexes around its copy, and several members writing to the same table at once would interfere. The incremental group's Allow disable/enable indexes takes care of the indexes instead.

4. Create the first snapshot subscription

  1. Pause the incremental group.
  2. Copy Subscription the subscription with Convert to Snapshot, _SS0 as Subscription Qualifier and Subscription ticked under Apply To. The snapshot subscription appears on the source's Subscriptions tab (see Copy or convert).
  3. In its properties, set and save:
    • Destination: Use existing table, Append replicated rows to existing data and Use native-loader function, if available;
    • Criteria: the condition for slice 0, for example WHERE MOD(RRN(ORDERS), 10) = 0. Click Verify Criteria for this first slice only: it counts the rows, which can take a while on a large table.

5. Create the other slices

Select the first snapshot subscription and click Duplicate once for each remaining slice, naming each (for example ORDERS_SS1 … ORDERS_SS9). Then change each one's criteria to its own slice: = 1, = 2 and so on up to = x - 1. Every row must fall in exactly one slice.

6. Add the slices to the snapshot group

Add all the snapshot subscriptions to the snapshot group's Subscriptions tab (see Subscriptions).

7. Run

  1. Run the incremental group. With Manual synchronization, this empties the destination table and leaves the member Suspended; the Capture Agent stages the table's changes from this point on.
  2. Run the snapshot group, and wait until every snapshot subscription has completed (see Replication events). If a slice fails, fix the cause and start again from step 1: the slices append their rows, so running one again alone would copy some rows twice, while step 1 empties the destination table first.
  3. Run the incremental group a second time to complete the manual synchronization.
  4. Resume the incremental group. It applies the changes captured since step 1 and then keeps the table up to date. Once it has caught up, you can turn Automatic Snapshot back on if you want new baselines to start by themselves.

The snapshot subscriptions and group aren't needed afterwards. Keep them to reload the table the same way later, or delete them (deleting subscriptions doesn't drop the destination table).

Slicing the table

The criteria uses MOD (the remainder of a division) on a value spread evenly across the table:

WHERE MOD(<expression>, x) = y

where x is the number of slices and y the slice number, from 0 to x − 1.

These expressions have been used in the field. Adapt the table name, and test the first slice with Verify Criteria:

Source Expression (slice 0 of 10)
Db2 for i WHERE MOD(RRN(MYLIB.ORDERS), 10) = 0
Oracle WHERE MOD(DBMS_ROWID.ROWID_BLOCK_NUMBER(rowid), 10) = 0
SQL Server WHERE abs(cast(cast(cast(substring(%%lockres%%,2,12) as varchar(20)) as varbinary(40)) as bigint)) % 10 = 0

An evenly spread numeric key column (for example an order number) works as well: WHERE MOD(ORDER_ID, 10) = 0.

Put the slicing criteria on the snapshot subscriptions only, never on the incremental subscription: incremental criteria also run in the Capture Agent's Db2 for LUW staging database, which doesn't know source functions such as RRN or DBMS_ROWID, and saving it fails (for example with SQLCODE=-440; see Use constant criteria).

Snapshot criteria must start with WHERE

For snapshot subscriptions, the criteria is added to the SELECT as it is; the Data Replicator Manager adds WHERE for you when you leave the field. See Criteria.