Académique Documents
Professionnel Documents
Culture Documents
We can use the REPERROR parameter in the Replicat parameter file to control the way that the
replication process responds to or handles any errors encountered in any of the DML statements which
it is trying to process.
We can use the keyword DEFAULT to set a global response for all errors except those for which explicit
REPERROR statements have been specified.
In the example we will see how we are handling the ORA-00001: unique constraint violated error using
an exception handler specified via the REPERROR (-1, EXCEPTION) clause of the Replicat parameter file.
By default, if the replicat process encounters any error condition it will abend.
The example shows how by using an exception handler, replicat process does not abend, but handles
the exceptions appropriately and continues processing.
If we have a primary key defined on both the source and target tables and if a unique key violation does
happen, then neither the Extract or Replicat process gets affected and processing is not halted on either
end of the Goldengate environment.
But if we have a case where say there are duplicate key values on the source table, but on the target
table there is a primary or unique constraint in place. When these duplicate rows get propagated to the
target server via the extract trail and when the Replicat process does encounter these row violations of
the primary key constraint in place on the target table, the replicat process will abend.
However, we can use the REPERROR parameter to specify how we will handle this specific error (or any
other error or all errors).
In our example, we have created an ‘exception’ table and the exception handler is to write information
about any such rows which are violating the unique constraint to this exception table AND continue
processing without abending the replicat process.
Without the exception handler in place, we will first see that the Replicat process terminates or abends.
SQL> /
Enter value for 1: 4001
Enter value for 2: KERRY
old 3: (&1,'&2')
new 3: (4001,'KERRY')
insert into emp
*
ERROR at line 1:
ORA-00001: unique constraint (IDIT_PRD.PK_EMP) violated
GGSCI (indb02) 5> info replicat myrep
Using the VIEW REPORT command, we can see why the process has abended.
2011-04-15 12:22:27 WARNING OGG-01004 Aborted grouped transaction on 'IDIT_PRD.EMP', Database
error 1 (ORA-00001: unique constraint (IDIT_PRD.PK_EMP) violated).
2011-04-15 12:22:27 WARNING OGG-01154 SQL error 1 mapping IDIT_PRD.EMP to IDIT_PRD.EMP OCI
Error ORA-00001: unique constraint (IDIT_PRD.PK_EMP) violated (status = 1), SQL .
Now let us put in an exception handler into our replicat parameter file.
REPLICAT myrep
ASSUMETARGETDEFS
USERID idit_prd,PASSWORD idit_prd
REPERROR (-1, EXCEPTION)
MAP idit_prd.emp, TARGET idit_prd.emp;
INSERTALLRECORDS
MAP idit_prd.emp, TARGET idit_prd.emp_exception,
EXCEPTIONSONLY,
COLMAP (USEDEFAULTS,
optype = @GETENV ("lasterr", "optype"),
dberr = @GETENV ("lasterr", "dberrnum"),
dberrmsg = @GETENV ("lasterr", "dberrmsg"));
So the REPERROR (-1, EXCEPTION) means that when we encounter the ORA-00001 error, the exception
handler will kick in.
The EXCEPTIONSONLY clause defines that such exceptions will be logged in the EMP_EXCEPTIONS table,
which has all the columns of the EMP table, plus additional columns which will log information about
row violations in the OPTYPE, DBERR and DBERRMSG columns.
So now we go and insert some duplicate rows on the source table.
SQL> commit;
Commit complete.
We see that on the target, this time the replicat process has not abended and continues to do the
processing.
GGSCI (indb02) 26> info replicat myrep
-----------------------------------