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.

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.

相关实践学习
日志服务之使用Nginx模式采集日志
本文介绍如何通过日志服务控制台创建Nginx模式的Logtail配置快速采集Nginx日志并进行多维度分析。
目录
相关文章
|
6月前
|
SQL Oracle 关系型数据库
问题出在Debezium Oracle Connector的日志解析器上
问题出在Debezium Oracle Connector的日志解析器上
56 2
|
6天前
|
运维 Oracle 关系型数据库
Oracle日志文件:数据王国的“记事本”
【4月更文挑战第19天】Oracle日志文件是数据库稳定运行的关键,记录数据变更历史,用于恢复和故障处理。它们协调并发操作,确保数据一致性和完整性。日志文件实时写入操作信息并定期刷新到磁盘,便于数据恢复。然而,日志文件需备份和归档以保证安全性,防止数据丢失。日志文件,数据王国的“记事本”,默默守护数据安全。
|
7月前
|
Oracle 关系型数据库 MySQL
Oracle 19C 静默安装 GoldenGate
十年以上 MySQL Oracle DBA从业者,MySQL 5.7 OCP, 个人公众号:jinjusk
105 0
|
10月前
|
Oracle 关系型数据库 数据库
查询listener的日志排除不能登录的错误使用Oracle官方提供的ova文件建立Oracle 19c学习环境
Oracle官方提供了安装好的Oracle 19c虚拟机,打包成ova文件。可以使用这个文件建立一个oracle 19c的学习环境。
121 0
|
11月前
|
Oracle 关系型数据库 数据库
一个Oracle数据库,一天归档日志3T多
Oracle数据库一体机,Oracle linux7,看看归档日志大小
|
11月前
|
Oracle 关系型数据库 数据库
Oracle 的联机日志文件
Oracle 的联机日志文件
117 0
|
11月前
|
SQL Oracle 关系型数据库
Oracle 的归档日志文件
Oracle 的归档日志文件
201 0
|
11月前
|
消息中间件 JSON Oracle
「事件驱动架构」使用GoldenGate创建从Oracle到Kafka的CDC事件流(下)
「事件驱动架构」使用GoldenGate创建从Oracle到Kafka的CDC事件流
|
11月前
|
消息中间件 SQL 存储
「事件驱动架构」使用GoldenGate创建从Oracle到Kafka的CDC事件流(上)
「事件驱动架构」使用GoldenGate创建从Oracle到Kafka的CDC事件流
|
Oracle 关系型数据库 Linux
【ogg二】Oracle GoldenGate(ogg)安装经验大汇总,采坑总结,绝对干货!
【ogg二】Oracle GoldenGate(ogg)安装经验大汇总,采坑总结,绝对干货!
133 0

热门文章

最新文章

推荐镜像

更多