Skip to content

Key log

The key log is a table in the control database, ir_keylog, with one row for each change an incremental group applied: the row's keys, what SQDR did with the change, how many destination rows it affected, and any error. Use it when a member is flagged for unexpected errors or row counts on INSERT, UPDATE or DELETE and you need to find the changes involved, or when Stelo Support asks for it.

Tracing a group records the same details in the verbose log (shortened for long runs), without writing to the control database. Prefer tracing for one or a few runs, and the key log when you need the records in a table over a longer time.

How it works

The key log is written by change data logging: with a group's Logging Level set, the Replicator Service passes each change to the stored procedure SQLOGGER in the control database, which inserts it into ir_keylog. It covers every member of the group; it can't be turned on for one member only (to log a few members, see Log only some members).

  • The rows stay until deleted: the history limits don't prune ir_keylog. A member's rows are deleted by Delete Statistics on the member, or when you move it to another group or remove it from the group.
  • Key logging turned on for one subscription (the Enable-KeyLog cmdlet or the EnableKeyLog.vbs script) isn't supported.

Turn the key log on

  1. Open the incremental group's Properties, Advanced tab, and under Change Data Logging choose the Logging Level:

    Logging Level What each row records Use it when
    Errors-Only Only changes that failed to apply, with the error. You're looking for the changes behind errors. The key log stays small.
    Keys-Always Every change, with its keys. You need to follow every change, such as for row count differences.
    Data-Always Every change, with its keys and data. You also need the row data. The key log grows fastest.
  2. Leave Stored Procedure empty (SQLOGGER) and keep Control DBMS.

  3. Save the group, and resume it if it's paused. The changes applied from then on are recorded.

Keep the group on the Batch apply method; see Change data processing.

Read the key log

  1. In Service Settings, Query tab, choose IR_keylog.sql.
  2. In Where, narrow it down, for example subscription_name = 'ORDERS' AND result_error IS NOT NULL, and click Go. Sort by keylog_sort to see the changes in the order they were recorded; Export saves them as JSON for Stelo Support. See Query.
Column What it holds
group_name, subscription_name The group and member.
transaction_id, change_row_counter, change_row_sequence The position of the change in the Capture Agent's staged changes (transaction, and order within it).
change_row_timestamp, change_row_nanosecond When the change was logged on the source.
change_row_type The kind of change (see below).
change_row_log_detail, change_row_member Journal details (job, user, journal code, RRN) and the member name, for Db2 for i sources when the Capture Agent provides them.
action_taken What SQDR did with the change (see below).
result_row_count The number of destination rows the statement affected. Anything other than 1 for a row change is unexpected.
result_error The error the destination returned, if any.
flagged_count How many changes of the member had unexpected results since its last baseline.
before_key, after_key (and _edited) The key values used to find the destination row: before the change for updates and deletes, after it for some updates.
after_image The destination table and, with Data-Always, the row data.
keylog_sort, keylog_ts, insert_ts The order in which rows were recorded, and when.
Code change_row_type action_taken
I Insert a row The row was inserted; also an update applied as an insert because the row wasn't found, when the apply options allow it
U Update a row The row was updated by an upsert: an insert that found the row already there, when the apply options allow it
M The row was updated
D Delete a row The row was deleted
B Delete a row (horizontal partitioning)
T Truncate the table The table was truncated
S Baseline required A baseline was requested
R Table reorganized
A Source table altered
X Source table dropped
C End of the synchronization window after a baseline The window was closed
# A close-window signal that didn't match the current baseline (stale)
? The change type wasn't recognized
empty The change was ignored, or it only changed the member's state

Values in the key and data columns

  • before_key, after_key and after_image hold text in the group's Encoding (JSON by default, or XML), as described in What your procedure receives. before_key_edited and after_key_edited are kept for compatibility; don't rely on them.
  • change_row_log_detail, for a Db2 for i source, holds the journal entry's details: the journal receiver, user, job, journal code and entry type, sequence number, RRN and program, for example:

    <detail> <receiver>MYLIB QSQJRN0014</receiver> <user>SQDRUSER</user> <job>QZRCSRVS QUSER 511037</job>
    <type>U 70</type> <sequence>00000000000019012714</sequence> <rrn>0</rrn> <program>RJRNLAPI</program> </detail>
    
  • change_row_member is set when a Db2 for i table's member other than the first (*FIRST) is replicated.

Log only some members

Change data logging is set per group. To log only one member, or a few, without logging the whole group, move them for a while to a group of their own:

  1. Create an incremental group with the same source and destination, for example DEBUG, and set its Logging Level as in Turn the key log on. Leave it paused.
  2. Pause the members' group, and move the members to DEBUG with Move Subscription (see Move). They keep their position and don't need a new baseline.
  3. Resume both groups. DEBUG applies the members' changes and logs them.
  4. When you have what you need, read and export the key log rows: moving a member to another group deletes its key log rows.
  5. Pause both groups, move the members back, resume their group, and delete DEBUG.

Keep a key log over a long time

The key log isn't pruned, so a key log left on for weeks needs housekeeping. A scheduled snapshot subscription on the control database can copy the older rows to an archive table in another database and then delete them from the key log. The archive also keeps a complete record of the changes, for example to drive downstream processing.

  1. Create a source for the control database, if there isn't one (see Create a source).
  2. Optionally, to have the group and member names in the archive, create a view in the control database. SQL Server (control tables in dbo):

    CREATE VIEW dbo.IR_KEYLOGV AS
    SELECT g.group_name, s.subscription_name, k.*
      FROM dbo.ir_keylog k
      JOIN dbo.groups g ON g.id = k.group_id
      JOIN dbo.subscription s ON s.id = k.subscription_id;
    

    On a Db2 control database, the tables are in the schema SQDR.

  3. Create a snapshot subscription for the view (or ir_keylog) to the archive database, with Create if does not exist, else use existing and Append replicated rows to existing data (see Destination).

  4. Enter the Criteria and the source processing to run after the run, which copy and then delete the rows older than a day:

    Control database Criteria Source processing after the run
    SQL Server WHERE CAST(insert_ts AS date) < DATEADD(day, -1, GETDATE()) DELETE FROM dbo.ir_keylog WHERE CAST(insert_ts AS date) < DATEADD(day, -1, GETDATE())
    Db2 for LUW WHERE DATE(insert_ts) < CURRENT DATE - 1 DAY DELETE FROM SQDR.IR_KEYLOG WHERE DATE(insert_ts) < CURRENT DATE - 1 DAY
  5. Schedule it, for example daily (see Scheduling).

If a run fails after some rows were written, the next run copies them again: keylog_sort identifies the duplicates in the archive. To copy only the rows added since the last run, without deleting them from the key log, use the technique in Replicate new rows without a Capture Agent with keylog_sort, which increases with every row, as the row-version column.

Turn the key log off

  1. On the group's Advanced tab, set Logging Level to *Disabled and save the group.
  2. Delete the rows you no longer need: Delete Statistics on each member's Replication Events tab deletes its key log rows along with its history (see Delete Statistics).

Because ir_keylog isn't pruned, a key log left on keeps growing; see Size and growth.