Table of Contents

Search

  1. Preface
  2. Data Replication Overview
  3. Understanding Data Replication
  4. Sources - Preparation and Replication Considerations
  5. Targets - Preparation and Replication Considerations
  6. Starting the Server Manager
  7. Getting Started with the Data Replication Console
  8. Defining and Managing Server Manager Main Servers and Subservers
  9. Creating and Managing User Accounts
  10. Creating and Managing Connections
  11. Creating Replication Configurations
  12. Materializing Targets with InitialSync
  13. Scheduling and Running Replication Tasks
  14. Implementing Advanced Replication Topologies
  15. Monitoring Data Replication
  16. Managing Replication Configurations
  17. Handling Replication Environment Changes and Failures
  18. Troubleshooting
  19. Data Replication Files and Subdirectories
  20. Data Replication Runtime Parameters
  21. Command Line Parameters for Data Replication Components
  22. Updating Configurations in the Replication Configuration CLI
  23. DDL Statements for Manually Creating Recovery Tables
  24. Sample Scripts for Enabling or Disabling SQL Server Change Data Capture
  25. Glossary

Post-Apply Processing

Post-Apply Processing

If you use Merge Apply or Audit Apply, you can configure the Applier to run a set of SQL statements or stored procedure calls on the following targets at the end of each apply cycle:
  • Amazon Redshift
  • Greenplum
  • Netezza
  • Oracle
  • Teradata
  • Vertica
Applier thread 1 runs the set of SQL statements on the target database at the end of each apply cycle after all Applier threads complete applying change data to the target. If the post-apply SQL statements complete successfully, the main Applier thread performs a commit on each Applier thread. If an error occurs, the main Applier thread rolls back the change data that was applied during the current apply cycle.
You can define post-apply SQL statements or stored procedure calls for the targets in the
DataReplication_installation
/uiconf/afterapply.xsl file. In the target database section of this file, create the [AFTER_APPLY] section and define an XSL script that transforms the AFTER_APPLY XML data structure into a set of SQL statements. Also, ensure that the
apply.post_apply_script_enabled
advanced runtime parameter is set to 1.
The Applier uses Apache XALAN XSL processor V 1.10 to process XSL scripts in the afterapply.xsl file and generate post-apply SQL statements for the target database. The XSL scripts transform the in-memory AFTER_APPLY XML data structure that Data Replication produces at the end of each apply cycle for the targets if the replication configuration includes Merge Apply or Audit Apply mappings.

Examples

The following XSL script runs the test_proc stored procedure on the tgt_db1 Teradata target database and passes the apply cycle ID as an argument to this procedure:
[TERADATA] [AFTER_APPLY] <?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> <xsl:output method="text"/> <xsl:template match="/"> call tgt_db1.test_proc(<xsl:value-of select="//Cycle/@cycle_id"/>) </xsl:template> </xsl:stylesheet> [END_OF_XSL] [END_OF_DEST]
To run multiple post-apply SQL statements on an Amazon Redshift, Greenplum, Netezza, Teradata
, or Vertica
target, use a semicolon (;) to separate the SQL statements.
For Teradata targets, you can run only one stored procedure.
The following XSL script runs three INSERT statements:
[TERADATA] [AFTER_APPLY] <?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> <xsl:output method="text"/> <xsl:template match="/"> INSERT INTO tgt_db1.stat1(total_inserts) VALUES (<xsl:value-of select="sum(//Mapping/@inserts)"/>); INSERT INTO tgt_db1.stat2(total_updates) VALUES (<xsl:value-of select="sum(//Mapping/@updates)"/>); INSERT INTO tgt_db1.stat3(total_deletes) VALUES (<xsl:value-of select="sum(//Mapping/@deletes)"/>); </xsl:template> </xsl:stylesheet> [END_OF_XSL] [END_OF_DEST]
To run multiple post-apply SQL statements on an Oracle target, use an anonymous block. The following XSL script runs two INSERT statements:
[ORACLE] [AFTER_APPLY] <?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> <xsl:output method="text"/> <xsl:template match="/"> BEGIN INSERT INTO tgt_db1.STAT1 VALUES (sysdate,<xsl:value-of select="count(//Mapping)"/>); INSERT INTO tgt_db1.STAT2 VALUES (<xsl:value-of select="sum(//Mapping/@inserts)"/>, <xsl:value-of select="sum(//Mapping/@updates)"/>, <xsl:value-of select="sum(//Mapping/@deletes)"/>); END; </xsl:template> </xsl:stylesheet> [END_OF_XSL] [END_OF_DEST]
The first INSERT statement inserts the date and time of an apply cycle and the number of tables that are processed during the apply cycle into the STAT1 table. The second INSERT statement inserts the total number of Inserts, Updates, and Deletes that are processed during an apply cycle into the STAT2 table.

0 COMMENTS

We’d like to hear from you!