Skip to content

Schema changes

How to prepare for changes to the structure of the tables you replicate: which ALTERs the groups replicate by themselves, and what to do for the changes they can't.

Decide how ALTERs are handled before they happen

Do:

  • For sources that support ALTER processing, set DDL Replication on the groups (or the service default) to Automatic, with ADD and MODIFY set to Perform, so added columns are replicated and widened columns widened at the destination. ADD can be Copy, which also fills in the added columns for existing rows. Keep DROP at Ignore (the column and its data stay) unless the destination must lose the column.
  • Use On Demand instead when every change should be reviewed first: after the member shows Altered, check it with Merge With Source on the Columns tab, then run the group.
  • For sources without ALTER processing, and for members that use an existing table, keep Automatic Snapshot on or plan the baseline that an altered table needs. For a very large table, see Avoid a new baseline when ALTER processing can't apply for a manual procedure.

Why: the service defaults are On Demand with ADD, MODIFY and DROP all at Ignore. With MODIFY at Ignore, a widened source column stays narrow at the destination, and longer values fail with truncation errors and flag the member. Changes to key columns always need a new baseline. See ALTER processing.

Not when: destination tables are read by applications that can't cope with changed columns: keep On Demand, and coordinate each change with them.

Pause replication before you restructure a table

Do: for changes that ALTER processing doesn't handle (dropping and re-creating a table, reloading it, changing its key), pause the group, make the change, then update the subscription (Merge With Source or Rebuild Column List) and run a new baseline. For large reloads of a Db2 for i table, take the subscription offline in the SQDR Control Center first (see Take subscriptions offline and online).

Why: a reload or restore is captured like any other change: the Capture Agent stages every row, and the group applies them one by one, which takes far longer than a baseline.

Avoid a new baseline when ALTER processing can't apply

When a source table is altered (for example a column added or dropped), the Capture Agent tells SQDR, and the subscription stops until its definition is updated with Merge With Source or Rebuild Column List. Where ALTER processing doesn't apply (sources without it, or members that use an existing table), that means re-creating the destination table and a new baseline. For a very large table, the baseline can mean hours of downtime. This procedure keeps the destination table and its data instead. Plan it before you alter the source table.

First check whether saving the subscription offers Alter Destination on Next Run (see Saving an incremental subscription); if it does, that's simpler.

1. Prepare the group. Pause the incremental group that holds the subscription. In its properties, note whether Automatic Snapshot is on, and clear it, so that the group doesn't start a baseline by itself (see Scheduling).

2. Alter the source table. No updates may reach the table while you change it:

  1. Stop all updates to the source table, for example with an exclusive lock or by restricting access.
  2. Alter the table, for example add a column, with a default value if you want one.
  3. Make the table available for updates again. The changes are captured and applied after step 6.

3. Find the new column types. The subscription shows as stopped and flagged; its latest replication event says that the source table was altered. Open the subscription, click Merge With Source (or Rebuild Column List) on the Columns tab, and note the destination type proposed for each new or changed column.

4. Alter the destination table to match the new source definition with SQL at the destination (for example ALTER TABLE ... ADD ...), using the types you noted.

5. Update the subscription.

  1. On the Destination tab, choose Use existing table for baseline, Append replicated rows to existing data and Manual synchronization (see Destination).
  2. On the Columns tab, check that the column list matches the source with Merge With Source or Rebuild Column List.
  3. Save. When asked, accept that a new baseline is required (Require Baseline). If the subscription can't be validated, save it anyway.

6. Resume and run the group.

  1. Resume the group, then Run it. With Manual synchronization, the run copies no data and leaves the destination table as it is: the subscription stops as Suspended.
  2. Run the group again, to complete the manual synchronization. The group and its subscriptions become active, and the changes made since step 2 are applied.
  3. Turn Automatic Snapshot back on if it was on in step 1.

Keep in mind: once a subscription uses Manual synchronization, changing that setting later needs a new baseline.

Why: with Use existing table for baseline, Append and Manual synchronization, the "baseline" neither re-creates nor empties the destination table and copies no data, so the existing rows stay in place, and the captured changes keep them current.