Last Update: 14 May 2010
Product: StarQuest Data Replicator
Version: SQDR 3.6 or later
Article ID: SQV00DR021
SQDR provides a key logging feature that captures the incremental primary key data replicated to the destination database. This data may be helpful to dictate work flow operations. This document describes how to use SQDR to replicate the newly added records in the key logging table to another SQL Server database and present the data in a user-friendly format.
The ir_keylog table is a log of the communication between the host system (running SQDR Plus) and the client system (running SQDR) as it relates to the application of changes to the destination table. For a given subscription, the ir_keylog table will contain the details of the row to be inserted, deleted, or updated. The before and after key fields illustrate the source ODBC type, the local program data type and destination ODBC types used to effect the transfer, in addition to the string representation of the value(s) used to identify the row. Refer to the SQDR Documentation Addendum for more information on the ir_keylog table fields.
The ir_keylog table is intended to be a "read-only " resource and its data is regularly pruned as the SQDR service processes incremental replication subscriptions. The pruning rate is determined by the SQDR service History Logging settings. Using the technique described in this document, SQDR can replicate the new ir_keylog records to an "archive" table which allows the user to maintain a complete record of key data changes.
This document is intended for users who are familiar with the techniques of creating tables, views and indices, and altering tables on a SQL Server database. All of the SQL Server SQL statements included in the instructions below can be executed in the Query Analyzer (SQL Server 2000) or the Management Studio New Query window (SQL Server 2005/2008).
Following are the general steps that you need to perform. Each step is described in more detail in the Detailed Procedures section.
These procedures assume the name of the SQDR control database is ControlDB with schema dbo.
Follow the instructions in the StarQuest technical document How to Enable SQDR Logging for an Incremental Replication Subscription to enable key logging for the group or subscription. The logging data will be stored in the SQDR control database table ir_keylog.
Create a view of the ir_keylog table that contains only the columns with pertinent data and that joins other control database tables to include the group name, subscription name, source table schema, and source table name in the result set. This ir_keylogv view, instead of the ir_keylog table, will be replicated by SQDR. Execute the following command against the SQDR control database to create the view.
CREATE VIEW ir_keylogv
AS
SELECT g.group_name, s.subscription_name, s.source_owner, s.source_table,
i.resync_state, i.change_row_counter, i.change_row_sequence, i.change_row_timestamp, i.change_row_nanosecond, i.change_row_type, i.action_taken, i.result_row_count, i.result_error,
i.flagged_count, i.before_key, i.before_key_edited, i.after_key,
i.after_key_edited, i.keylog_sort, i.keylog_ts, i.insert_ts
FROM dbo.ir_keylog i JOIN dbo.subscription s
ON i.subscription_id = s.id JOIN dbo.group_subscriptions gs
ON s.id = gs.subscription_id JOIN dbo.groups g
ON gs.group_id = g.id
CREATE TABLE subtrack
(subname VARCHAR (128) NOT NULL,
curmax binary(8) DEFAULT 0,
lastmax binary(8) DEFAULT 0,
PRIMARY KEY (subname))
The subname column will store the name of the SQDR subscription. The curmax column will store the maximum timestamp of the rows in the source table to be replicated to the destination host at the start of the replication. The lastmax column will hold the timestamp value of the last row successfully replicated to the destination host.
CREATE UNIQUE INDEX subtrackix ON subtrack (subname)
INSERT INTO subtrack (subname) VALUES ('KEYLOG')
UPDATE [destination_database].[schema].subtrack
SET curmax = (select convert (binary(8), max(insert_ts))
FROM [control_database].dbo.ir_keylogv) WHERE subname = 'KEYLOG'
UPDATE [destination_database].[schema].subtrack SET lastmax=curmax WHERE subname='KEYLOG'
WHERE (insert_ts > (
SELECT lastmax FROM [destination_database].[schema].subtrack where subname = 'KEYLOG'))
and (insert_ts <= (
SELECT curmax FROM [destination_database].[schema].subtrack where subname = 'KEYLOG'))
The information in technical documents comes without any warranty or applicability for a specific purpose. The author(s) or distributor(s) will not accept responsibility for any damage incurred directly or indirectly through use of the information contained in these documents. The instructions may need to be modified to be appropriate for the hardware and software that has been installed and configured within a particular organization. The information in technical documents should be considered only as an example and may include information from various sources, including IBM, Microsoft, and other organizations.