Creating a GoldenGate Exception Handler to Trap and Log Oracle Errors

Creating a GoldenGate Exception Handler to Trap and Log Oracle Errors

 

GoldenGate does not provide a standard exceptions handler. By default, a Replicat process will abend should any operational failure occur, and will rollback the transaction to the last known checkpoint. This may not be ideal in a production environment.

 

The HANDLECOLLISIONS and NOHANDLECOLLISIONS parameters can be used to control whether or not Replicat tries to resolve duplicate-record and missing-record errors, but should these errors be ignored?

 

The way to determine what error has occurred, by which Replicat, caused by what data, create an Exceptions handler.

 

Steps

The steps below create an Exceptions handler that will trap and log the specified Oracle error(s), but allow the Replicat to continue to process data:

 

1. The first step is to create an Exceptions table, similar to the example DDL below:

 

create table ggs_admin.exceptions

( rep_name varchar2(8)

, table_name varchar2(61)

, errno number

, dberrmsg varchar2(4000)

, optype varchar2(20)

, errtype varchar2(20)

, logrba number

, logposition number

, committimestamp timestamp

);

 

ALTER TABLE ggs_admin.exceptions ADD (

  CONSTRAINT PK_CTS

 PRIMARY KEY

 (logrba, logposition, committimestamp) USING INDEX PCTFREE 0 TABLESPACE MY_INDEXES);

 

The Exceptions table must be created in the GoldenGate Admin user schema. It can log exception data for all Replicat processes.

 

2. Edit each Replicat process parameter file and add the exception handler Macro code block.

 

[oracle@linuxserver1 ggs]$ ggsci

 

GGSCI (linuxserver1) 1> edit params RTARGET1

 

-- This starts the macro

MACRO #exception_handler

BEGIN

, TARGET ggs_admin.exceptions

, COLMAP ( rep_name = "RTARGET1"

, table_name = @GETENV ("GGHEADER", "TABLENAME")

, errno = @GETENV ("LASTERR", "DBERRNUM")

, dberrmsg = @GETENV ("LASTERR", "DBERRMSG")

, optype = @GETENV ("LASTERR", "OPTYPE")

, errtype = @GETENV ("LASTERR", "ERRTYPE")

, logrba = @GETENV ("GGHEADER", "LOGRBA")

, logposition = @GETENV ("GGHEADER", "LOGPOSITION")

, committimestamp = @GETENV ("GGHEADER", "COMMITTIMESTAMP"))

, INSERTALLRECORDS

, EXCEPTIONSONLY;

END;

-- This ends the macro

 

3. Remaining within the editor (vi), edit the MAP statements to include the #exception_handler(). Also add the REPERROR parameter to reference to the Oracle error(s) you wish to trap.

 

REPERROR (DEFAULT, EXCEPTION)

REPERROR (DEFAULT2, ABEND)

REPERROR (-1, EXCEPTION)

MAP SRC.ORDERS, TARGET TGT.ORDERS;

MAP SRC.ORDERS #exception_handler()

MAP SRC.ORDER_ITEMS, TARGET TGT.ORDER_ITEMS;

MAP SRC.ORDER_ITEMS #exception_handler()

MAP SRC.PRODUCTS, TARGET TGT.PRODUCTS;

MAP SRC.PRODUCTS #exception_handler()

 

  • The REPERROR parameter controls how the Replicat process responds to errors when executing the MAP statement.
  • The DEFAULT argument sets a global response to all errors except those for which explicit REPERROR statements are specified.

 

E.g. A MAP statement to trap ORA-01403: "no data found"  error.

 

MAP SRC.ORDERS, TARGET TGT.ORDERS, REPERROR (-1403, EXCEPTION);

 

  • The DEFAULT2 argument specifies a "catch all" action for any unanticipated Oracle errors that may occur. In the example in step 3, the Replicat process will Abend.

 

4. Stop and start the Replicat process.

 

GGSCI (linuxserver1) 3> stop REPLICAT RTARGET1

 

Sending STOP request to REPLICAT RTARGET1 ...

Request processed.

 

GGSCI (linuxserver1) 4> start replicat RTARGET1

 

Sending START request to MANAGER ...

REPLICAT RTARGET1 starting

 

5. Check Replicat process is running.

 

GGSCI (linuxserver1) 5> info all

 

Program     Status Group       Lag           Time Since Chkpt

 

MANAGER     RUNNING

REPLICAT    RUNNING RTARGET1    00:00:00      00:00:22

 

6. Start your application and begin replicating data.

 

Viewing Exceptions

Below is an example of the data collected following an ORA-00001: "unique constraint violated"

 

 

SQL> select * from ggs_admin.exceptions where rownum <= 1;

 

REP_NAME TABLE_NAME ERRNO DBERRMSG

-------- ---------- ----- --------

RTARGET1 SRC.ORDERS     1 OCI Error ORA-00001: unique constraint (TGT.PK_ORD) violated (status = 1), SQL

                          <INSERT INTO "TGT"."ORDERS" ("ORDER_ID","CUST_ID","PRODUCT_ID" ..

 

OPTYPE ERRTYPE LOGRBA LOGPOSITION COMMITTIMESTAMP

------ ------- ------ ----------- -------------------------

INSERT DB         988   171211460 02-APR-10 12.41.42.999468

 

 

Tip: The DBERRMSG column will store the error, the error description and the complete SQL up to 4000 bytes.

 

The exception handler can be modified to also include the before and after images of an UPDATE operation. This information is valuable for conflict resolution.

时间: 2024-10-02 21:14:38

Creating a GoldenGate Exception Handler to Trap and Log Oracle Errors的相关文章

VxWorks操作系统shell命令与调试方法总结

VxWorks下的调试手段 主要介绍在Tornado集成开发环境下的调试方法和利用支撑定位问题的步骤.思路. 1         Tornado的调试工具 嵌入式实时操作系统VxWorks和集成开发环境Tornado的组成结构如下图1.分为主机和目标机系统. 图1 集成开发环境结构图 在Tornado下调试相关操作在Debug菜单下包括 图2 Debug菜单 简单解释各菜单项的功能 1.1        WindShell 1.1.1         简介 Vxworks的Shell分为两种ho

Flow control and exception Handling

2) Flow control and exception Handling Objective 1)Write code using if and switch statements and identify legal argument types for these statements. ·    Unreachable statements produce a compile-time error. while (false) { x = 3; } // won't compilefo

Exception Handling in C#

Exception Handling in C# Level Author Intermediate Anonymous What 抯 Wrong with Return Codes? Most programmers have probably written code that looked like this:bool success =CallFunction();if (!success){//process the error}This works okay, but every r

Enterprise Library深入解析与灵活应用(4):创建一个自定义Exception Handl

Enterprise Library深入解析与灵活应用(4):创建一个自定义Exception Handler改变ELAB的异常处理机制 1.背景与动机 微软Enterprise Library ELAB(Exception Handling Application Block)提供了一种基于策略(Policy)的异常 处理方式,在不同的环境中,比如多层架构中不同的层次中,我们可以定义不同的异常处理策略.对于ELAB来说,Exception Handling Policy = Exception

Oracle GoldenGate 11g的单向DDL配置实战

在认真学习了GoldenGate企业级运维实战后,重点是对OGG几个进程的理解,结合对原理的理解,在整整实验了近两天,反复配置了四次之后,终于配置成功.本文经过多次配置成功实践整理而成,还有很多的细节需要完善. 目录 ================================ 一.环境准备并安装GoldenGate 1. 数据库准备情况 2. 下载OGG软件并解压安装 3. 准备OGG环境变量 4. 配置日志模式 5. 创建GoldenGate用户帐号 6. 安装GoldenGate软件

【黑马Android】(05)短信/查询和添加/内容观察者使用/子线程网络图片查看器和Handler消息处理器/html查看器/使用HttpURLConnection采用Post方式请求数据/开源项目

备份短信和添加短信 操作系统短信的uri: content://sms/ <?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.itheima28.backupsms" android:versionCode="1

Microsoft Visual C++ and Win32 structured exception handling

Introduction In an earlier article [1] I described some performance measurements when using exceptions in various languages on Windows. A couple of people since then have asked me questions about how the windows exception model actually works and how

Java中异常Exception的实现的一些分析

文章地址:http://blog.csdn.net/hengyunabc/article/details/14108617 前言: 最近发现一个很有用的Eclipse插件:http://andrei.gmxhome.de/bytecode/,可以在Eclipse直接查看,调试Java的字节码. 顺带研究了下Java里异常的实现机制,还有JDK7里的mutil catch的实现原理. athrow指令: 在JVM里实现异常的指令是athrow,指令的参考在这里:http://docs.oracle

How a C++ compiler implements exception handling

Introduction One of the revolutionary features of C++ over traditional languages is its support for exception handling. It provides a very good alternative to traditional techniques of error handling which are often inadequate and error-prone. The cl