Manual Conflict Detection and Resolution
Learn about manually configuring Conflict Detection and Resolution (CDR) using specific parameters. Conflict detection and resolution is required in active-active configurations, where Oracle GoldenGate must maintain data synchronization among multiple databases that contain the same data sets.
Overview of the Oracle GoldenGate CDR Feature
Oracle GoldenGate Conflict Detection and Resolution (CDR) provides basic conflict resolution routines that:
-
Resolve a uniqueness conflict for an
INSERT
. -
Resolve a "no data found" conflict for an
UPDATE
when the row exists, but the before image of one or more columns is different from the current value in the database. -
Resolve a "no data found" conflict for an
UPDATE
when the row does not exist. -
Resolve a "no data found" conflict for a
DELETE
when the row exists, but the before image of one or more columns is different from the current value in the database. -
Resolve a "no data found" conflict for a
DELETE
when the row does not exist.
To use conflict detection and resolution (CDR), the target database must reside on a Windows, Linux, or UNIX system. It is not supported for databases on the NonStop platform.
CDR supports scalar data types such as:
-
NUMERIC
-
DATE
-
TIMESTAMP
-
CHAR/NCHAR
-
VARCHAR/ NVARCHAR
This means that these column types can be used with the COMPARECOLS
parameter and as the resolution column in the USEMIN
and
USEMAX
options of the RESOLVECONFLICT
parameter.
Only NUMERIC
columns can be used for the USEDELTA
option of RESOLVECONFLICT
. Do not use CDR for columns that contain
LOBs, abstract data types (ADT), or user-defined types (UDT).
Conflict resolution is not performed when Replicat operates in BATCHSQL
mode. If a conflict occurs in BATCHSQL
mode, Replicat reverts to GROUPTRANSOPS
mode, and then to single-transaction mode. Conflict detection occurs in all three modes. For more information, see Parameters and Functions Reference
for Oracle GoldenGate.
Configuring the Oracle GoldenGate Parameter Files for Error Handling
Manual CDR should be used in conjunction with error handling to capture errors that were resolved and errors that CDR could not resolve.
Tools for Mapping Extra Data to the Exceptions Table
The following are some tools that you can use in the COLMAP
clause to populate extra columns:
-
If the names and definitions of the source columns are identical to those of the target columns in the exceptions table, you can use the
USEDEFAULTS
keyword instead of explicitly mapping names. Otherwise, you must map those columns in theCOLMAP
clause, for example:COLMAP (exceptions_col1 = col1, [...])
-
To map the before image of the source row to columns in the exceptions table, use the
@BEFORE
conversion function, which captures the before image of a column from the trail record. This example shows the@BEFORE
usage.COLMAP (USEDEFAULTS, exceptions_col1 = @BEFORE (source_col1), & exceptions_col2 = @BEFORE (source_col2), [...])
-
To map the current image of the target row to columns in the exceptions table, use a
SQLEXEC
query to capture the image, and then map the results of the query to the columns in the exceptions table by using the 'queryID.column
' syntax in theCOLMAP
clause, as in the following example:COLMAP (USEDEFAULTS, name_current =
queryID
.name
, phone_current =queryID
.phone
, [...]) -
To map timestamps, database errors, and other environmental information, use the appropriate Oracle GoldenGate column-conversion functions. For example, the following maps the current timestamp at time of execution.
res_date = @DATENOW ()
See Sample Exceptions Mapping with Additional Columns in the Exceptions Table, for how to combine these features in a COLMAP
clause in the
exceptions MAP
statement to populate a detailed exceptions table.
See Reference for Oracle GoldenGate for Windows and UNIX for the usage and syntax of the parameters and column-conversion functions shown in these examples.
Sample Exceptions Mapping with Source and Target Columns Only
The following is a sample parameter file that shows error handling and simple exceptions mapping for the source and target tables that are used in the CDR examples that begin. This example maps source and target columns, but no extra columns. For the following reasons, a COLMAP
clause is not needed in the exceptions MAP
statement in this example:
-
The source and target exceptions columns are identical in name and definition.
-
There are no other columns in the exceptions table.
Note:
This example intentionally leaves out other parameters that are required in a Replicat parameter file, such as process name and login credentials, as well as any optional parameters that may be required for a given database type. When using line breaks to split a parameter statement into multiple lines, use an ampersand (&) at the end of each line.
-- REPERROR error handling: DEFAULT represents all error types. DISCARD -- writes operations that could not be processed to a discard file. REPERROR (DEFAULT, DISCARD) -- Specifies a discard file. DISCARDFILE /users/ogg/discards/discards.dsc, PURGE -- The regular MAP statement with the CDR parameters MAP fin.src, TARGET fin.tgt, & COMPARECOLS (ON UPDATE ALL, ON DELETE ALL), & RESOLVECONFLICT (UPDATEROWEXISTS, (DEFAULT, USEMAX (last_mod_time)), & RESOLVECONFLICT (INSERTROWEXISTS, (DEFAULT, USEMAX (last_mod_time)), & RESOLVECONFLICT (DELETEROWEXISTS, (DEFAULT, OVERWRITE)), & RESOLVECONFLICT (UPDATEROWMISSING, (DEFAULT, OVERWRITE)), & RESOLVECONFLICT (DELETEROWMISSING, (DEFAULT, DISCARD)), & ); -- Starts the exceptions MAP statement by mapping the source table to the -- exceptions table. MAP fin.src, TARGET fin.exception, & -- directs Replicat only to map operations that caused the error specified -- in REPERROR. EXCEPTIONSONLY, & -- directs Replicat to convert all the exceptions to inserts into the -- exceptions table. This is why there cannot be a primary key constraint -- on the exceptions table. INSERTALLRECORDS ;
Sample Exceptions Mapping with Additional Columns in the Exceptions Table
The following is a sample parameter file that shows error handling and complex exceptions mapping for the source and target tables that are used in the CDR examples that begin. In this example, the exceptions table has the same rows as the source table, but it also has additional columns to capture context data.
Note:
This example intentionally leaves out other parameters that are required in a Replicat parameter file, such as process name and login credentials, as well as any optional parameters that may be required for a given database type. When using line breaks to split a parameter statement into multiple lines, use an ampersand (&) at the end of each line.
-- REPERROR error handling: DEFAULT represents all error types. DISCARD
-- writes operations that could not be processed to a discard file.
REPERROR (DEFAULT, DISCARD)
-- Specifies the discard file.
DISCARDFILE /users/ogg/discards/discards.dsc, PURGE
-- The regular MAP statement with the CDR parameters
MAP fin.src, TARGET fin.tgt, &
COMPARECOLS (ON UPDATE ALL, ON DELETE ALL), &
RESOLVECONFLICT (UPDATEROWEXISTS, (DEFAULT, USEMAX (last_mod_time)), &
RESOLVECONFLICT (INSERTROWEXISTS, (DEFAULT, USEMAX (last_mod_time)), &
RESOLVECONFLICT (DELETEROWEXISTS, (DEFAULT, OVERWRITE)), &
RESOLVECONFLICT (UPDATEROWMISSING, (DEFAULT, OVERWRITE)), &
RESOLVECONFLICT (DELETEROWMISSING, (DEFAULT, DISCARD))
);
-- Starts the exceptions MAP statement by mapping the source table to the -- exceptions table.
MAP fin.src, TARGET fin.exception, &
-- directs Replicat only to map operations that caused the error specified
-- in REPERROR.
EXCEPTIONSONLY, &
-- directs Replicat to convert all the exceptions to inserts into the
-- exceptions table. This is why there cannot be a primary key constraint
-- on the exceptions table.
INSERTALLRECORDS &
-- SQLEXEC query to select the values from the target record before the
-- Replicat statement is applied. These are mapped to the *_target
-- columns later.
SQLEXEC (id qry, query 'select name, phone, address, salary, balance, & comment, last_mod_time from fin.tgt where name = :p1', PARAMS(p1 = name )), &
-- Start of the column mapping, specifies use default column definitions.
COLMAP ( &
-- USEDEFAULTS maps the source columns to the target exceptions columns
-- that receive the after image that Replicat applied or tried to apply.
-- In this case, USEDEFAULTS can be used because the names and definitions
-- of the source and target exceptions columns are identical; otherwise
-- the columns must be mapped explicitly in the COLMAP clause.
USEDEFAULTS, &
-- captures the timestamp when the resolution was performed.
res_date = @DATENOW (), &
-- captures and maps the DML operation type.
optype = @GETENV ('LASTERR', 'OPTYPE'), &
-- captures and maps the database error number that was returned.
dberrnum = @GETENV ('LASTERR', 'DBERRNUM'), &
-- captures and maps the database error that was returned.
dberrmsge = @GETENV ('LASTERR', 'DBERRMSG'), &
-- captures and maps the name of the target table
tabname = @GETENV ('GGHEADER', 'TABLENAME'), &
-- If the names and definitions of the source columns and the target
-- exceptions columns were not identical, the columns would need to
-- be mapped in the COLMAP clause instead of using USEDEFAULTS, as
-- follows:
-- name_after = name, &
-- phone_after = phone, &
-- address_after = address, &
-- salary_after = salary, &
-- balance_after = balance, &
-- comment_after = comment, &
-- last_mod_time_after = last_mod_time &
-- maps the before image of each column from the trail to a column in the
-- exceptions table.
name_before = @BEFORE (name), &
phone_before = @BEFORE (phone), &
address_before = @BEFORE (address), &
salary_before = @BEFORE (salary), &
balance_before = @BEFORE (balance), &
comment_before = @BEFORE (comment), &
last_mod_time_before = @BEFORE (last_mod_time), &
-- maps the results of the SQLEXEC query to rows in the exceptions table
-- to show the current image of the row in the target.
name_current = qry.name, &
phone_current = qry.phone, &
address_current = qry.address, &
salary_current = qry.salary, &
balance_current = qry.balance, &
comment_current = qry.comment, &
last_mod_time_current = qry.last_mod_time)
;
Once you are confident that your routines work as expected in all situations, you can reduce the amount of data that is logged to the exceptions table to reduce the overhead of the resolution routines.
Configuring the Oracle GoldenGate Parameter Files for Conflict Resolution
The following parameters are required to support conflict detection and resolution.
- Use the
COMPARECOLS
option of theMAP
parameter in the Replicat parameter file to specify columns that are to be used with before values in the ReplicatWHERE
clause. The before values are compared with the current values in the target database to detect update and delete conflicts. (By default, Replicat only uses the primary key in theWHERE
clause; this may not be enough for conflict detection). - Use the
RESOLVECONFLICT
option of theMAP
parameter to specify conflict resolution routines for different operations and conflict types. You can useRESOLVECONFLICT
multiple times in aMAP
statement to specify different resolutions for different conflict types. However, you cannot useRESOLVECONFLICT
multiple times for the same type of conflict. Use identical conflict-resolution procedures on all databases, so that the same conflict produces the same end result. One conflict-resolution method might not work for every conflict that could occur. You might need to create several routines that can be called in a logical order of priority so that the risk of failure is minimized.
Note:
Additional consideration should be given when a table has a primary key and additional unique indexes or unique keys. The automated routines provided with the COMPARECOLS
and RESOLVECONFLICT
parameters require a consistent way to uniquely identify each row. Failure to consistently identify a row will result in an error during conflict resolution. In these situations the additional unique keys should be disabled or you can use the SQLEXEC
feature to handle the error thrown and resolve the conflict.
For detailed information about these parameters, see Parameters and Functions Reference for Oracle GoldenGate. See the examples starting on CDR Example 1: All Conflict Types with USEMAX, OVERWRITE, DISCARD, for more information on these parameters.
Making the Required Column Values Available to Extract
To use CDR, the following column values must be logged so that Extract can write them to the trail.
-
The full before image of each record. Some databases do not provide a before image in the log record, and must be configured to do so with supplemental logging. For most supported databases, you can use the
ADD TRANDATA
command for this purpose. -
Use the
LOGALLSUPCOLS
parameter to ensure that the full before and after images of the scheduling columns are written to the trail. Scheduling columns are primary key, unique index, and foreign key columns.LOGALLSUPCOLS
causes Extract to include in the trail record the before image forUPDATE
operations and the before image of all supplementally logged columns for bothUPDATE
andDELETE
operations.
For detailed information about these parameters and commands, see the Parameters and Functions Reference for Oracle GoldenGate. See the examples starting on CDR Example 1: All Conflict Types with USEMAX, OVERWRITE, DISCARD for more information on how these parameters work with CDR.
Viewing CDR Statistics
The CDR feature provides the following methods for viewing the results of conflict resolution.
Here are different techniques you can use to view CDR statistics.
Report File
Total CDR conflicts 7
CDR resolutions succeeded 6
CDR resolutions failed 1
CDR INSERTROWEXISTS conflicts 1
CDR UPDATEROWEXISTS conflicts 4
CDR UPDATEROWMISSING conflicts
CDR DELETEROWEXISTS conflicts 1
CDR DELETEROWMISSING conflicts 1
Command Line
You can view CDR statistics from the command line by using the STATS
REPLICAT
command with the REPORTCDR
option:
STATS REPLICAT group, REPORTCDR
Column-conversion Functions
-
Number of conflicts that Replicat detected
-
Number of resolutions that the Replicat resolved
-
Number of resolutions that the Replicat could not resolve
To retrieve these statistics, use the @GETENV
column-conversion
function with the STATS
or DELTASTATS
information
type. The results are based on the current Replicat session. If Replicat stops and
restarts, it resets the statistics.
@GETENV ('STATS','TABLE','SCHEMA.TABLNAME','CDR_CONFLICTS')
@GETENV ('STATS','TABLE','SCHEMA.TABLNAME','CDR_RESOLUTIONS_SUCCEEDED')
@GETENV ('STATS','TABLE','SCHEMA.TABLNAME','CDR_RESOLUTIONS_FAILED')
MAP
statements in the Replicat parameter
file:@GETENV ('STATS','CDR_CONFLICTS')
@GETENV ('STATS','CDR_RESOLUTIONS_SUCCEEDED')
@GETENV ('STATS','CDR_RESOLUTIONS_FAILED')
The 'STATS'
information type in the preceding examples can be
replaced by 'DELTASTATS'
to return the requested counts since the
last execution of 'DELTASTATS'
. For more information about
@GETENV
, see @GETENV
CDR Example 1: All Conflict Types with USEMAX, OVERWRITE, DISCARD
This example resolves all conflict types by using the USEMAX
, OVERWRITE
, and DISCARD
resolutions.
Table Used in this Example
The examples assume identical Oracle databases.
CREATE TABLE tgt( name varchar2(30) primary key, phone varchar2(10), address varchar2(100), salary number, balance number, comment varchar2(100), last_mod_time timestamp);
At the source database, all columns are supplementally logged:
ADD TRANDATA scott.src, COLS (name, phone, address, salary, balance, comment, last_mod_time);
MAP Statement with Conflict Resolution Specifications
MAP fin.src, TARGET fin.tgt, COMPARECOLS (ON UPDATE ALL, ON DELETE ALL), RESOLVECONFLICT (UPDATEROWEXISTS, (DEFAULT, USEMAX (last_mod_time)), RESOLVECONFLICT (INSERTROWEXISTS, (DEFAULT, USEMAX (last_mod_time)), RESOLVECONFLICT (DELETEROWEXISTS, (DEFAULT, OVERWRITE)), RESOLVECONFLICT (UPDATEROWMISSING, (DEFAULT, OVERWRITE)), RESOLVECONFLICT (DELETEROWMISSING, (DEFAULT, DISCARD)), );
Description of MAP Statement
The following describes the MAP
statement:
-
Per
COMPARECOLS
, use the before image of all columns in the trail record in the ReplicatWHERE
clause for updates and deletes. -
Per
DEFAULT
, use all columns as the column group for all conflict types; thus the resolution applies to all columns. -
For an
INSERTROWEXISTS
conflict, use theUSEMAX
resolution: If the row exists during an insert, use thelast_mod_time
column as the resolution column for deciding which is the greater value: the value in the trail or the one in the database. If the value in the trail is greater, apply the record but change the insert to an update. If the database value is higher, ignore the record. -
For an
UPDATEROWEXISTS
conflict, use theUSEMAX
resolution: If the row exists during an update, use thelast_mod_time
column as the resolution column: If the value in the trail is greater, apply the update. -
If you use
USEMIN
orUSEMAX
, and the values are exactly the same, thenRESOLVECONFLICT
isn't triggered and the incoming row is ignored. If you useUSEMINEQ
orUSEMAXEQ
, and the values are exactly the same, then the resolution is triggered. -
For a
DELETEROWEXISTS
conflict, use theOVERWRITE
resolution: If the row exists during a delete operation, apply the delete. -
For an
UPDATEROWMISSING
conflict, use theOVERWRITE
resolution: If the row does not exist during an update, change the update to an insert and apply it. -
For a
DELETROWMISSING
conflict use theDISCARD
resolution: If the row does not exist during a delete operation, discard the trail record.Note:
As an alternative to
USEMAX
, you can use theUSEMAXEQ
resolution to apply a>=
condition. For more information, see Parameters and Functions Reference for Oracle GoldenGate.
INSERTROWEXISTS with the USEMAX Resolution
For this example, the USEMAX
resolution is illustrated with the applicable before and after images for the record in the trail and in the database. It shows how to resolve an insert where the row exists in the source and target, but some or all row values are different.
Table 11-10 INSERTROWEXISTS Conflict with USEMAX Resolution
Image | SQL | Comments |
---|---|---|
Before image in trail |
None (row was inserted on the source). |
N/A |
After image in trail |
name='Mary' phone='1234567890' address='Oracle Pkwy' salary=100 balance=100 comment=NULL last_mod_time='9/1/10 3:00' |
|
Target database image |
name='Mary' phone='111111' address='Ralston' salary=200 balance=500 comment='aaa' last_mod_time='9/1/10 1:00' |
|
Initial |
SQL bind variables: 1)'Mary' 2)'1234567890' 3)'Oracle Pkwy' 4)100 5)100 6)NULL 7)'9/1/10 3:00' |
This SQL returns a uniqueness conflict on 'Mary'. |
|
SQL bind variables: 1)'1234567890' 2)'Oracle Pkwy' 3)100 4)100 5)NULL 6)'9/1/10 3:00' 7)'Mary' 8)'9/1/10 3:00' |
Because |
UPDATEROWEXISTS with the USEMAX Resolution
For this example, the USEMAX
resolution is illustrated with the applicable before and after images for the record in the trail and in the database. It shows how to resolve an update where the row exists in the source and target, but some or all row values are different.
Table 11-11 UPDATEROWEXISTS Conflict with USEMAX Resolution
Image | SQL | Comments |
---|---|---|
Before image in trail |
name='Mary' phone='1234567890' address='Oracle Pkwy' salary=100 balance=100 comment=NULL last_mod_time='9/1/10 3:00' |
|
After image in trail |
phone='222222' address='Holly' last_mod_time='9/1/10 5:00' |
|
Target database image |
name='Mary' phone='1234567890' address='Oracle Pkwy' salary=100 balance=600 comment='com' last_mod_time='9/1/10 6:00' |
|
Initial |
SQL bind variables: 1)'222222' 2)'Holly' 3)'9/1/10 5:00' 4)'Mary' 5)'1234567890' 6)'Oracle Pkwy' 7)100 8)100 9)NULL 10)'9/1/10 3:00' |
This SQL returns a no-data-found error because the values for the All columns are used in the |
|
SQL bind variables: 1)'Mary' 2)'222222' 3)'Holly' 4)100 5)100 6)NULL 7)'9/1/10 5:00' 8)'Mary' 9)'9/1/10 5:00' |
Because the after value of |
UPDATEROWMISSING with OVERWRITE Resolution
For this example, the OVERWRITE
resolution is illustrated with the applicable before and after images for the record in the trail and in the database. It shows how to resolve the case where the target row is missing. The logical resolution, and the one used, is to overwrite the row into the target so that both databases are in sync again.
Table 11-12 UPDATEROWMISSING Conflict with OVERWRITE Resolution
Image | SQL | Comments |
---|---|---|
Before image in trail |
name='Jane' phone='333' address='Oracle Pkwy' salary=200 balance=200 comment=NULL last_mod_time='9/1/10 7:00' |
N/A |
After image in trail |
phone='4444' address='Holly' last_mod_time='9/1/10 8:00' |
|
Target database image |
None (row for Jane is missing) |
|
Initial |
SQL bind variables: 1)'4444' 2)'Holly' 3)'9/1/10 8:00' 4)'Jane' 5)'333' 6)'Oracle Pkwy' 7)200 8)200 9)NULL 10)'9/1/10 7:00' |
This SQL returns a no-data-found error. All columns are used in the |
|
SQL bind variables: 1)'Jane' 2)'4444' 3)'Holly' 4)200 5)200 6)NULL 7)'9/1/10 8:00' |
The update is converted to an insert because |
DELETEROWEXISTS with OVERWRITE Resolution
For this example, the OVERWRITE
resolution is illustrated with the applicable before and after images for the record in the trail and in the database. It shows how to resolve the case where the source row was deleted but the target row exists. In this case, the OVERWRITE
resolution applies the delete to the target.
Table 11-13 DELETEROWEXISTS Conflict with OVERWRITE Resolution
Image | SQL | Comments |
---|---|---|
Before image in trail |
name='Mary' phone='222222' address='Holly' salary=100 balance=100 comment=NULL last_mod_time='9/1/10 5:00' |
N/A |
After image in trail |
None |
N/A |
Target database image |
name='Mary' phone='1234567890' address='Oracle Pkwy' salary=100 balance=600 comment=com last_mod_time='9/1/10 7:00' |
The row exists on the target, but the |
Initial |
SQL bind variables: 1)'Mary' 2)'222222' 3)'Holly' 4)100 5)100d 6)NULL 7)'9/1/10 5:00' |
All columns are used in the A no-data-found error occurs because of the difference between the before and current values. |
|
SQL bind variables: 1)'Mary' |
Because |
DELETEROWMISSING with DISCARD Resolution
For this example, the DISCARD
resolution is illustrated with the applicable before and after images for the record in the trail and in the database. It shows how to resolve the case where the target row is missing. In the case of a delete on the source, it is acceptable for the target row not to exist (it would need to be deleted anyway), so the resolution is to discard the DELETE
operation that is in the trail.
Table 11-14 DELETEROWMSING Conflict with DISCARD Resolution
Image | SQL | Comments |
---|---|---|
Before image in trail |
name='Jane' phone='4444' address='Holly' salary=200 balance=200 comment=NULL last_mod_time='9/1/10 8:00' |
N/A |
After image in trail |
None |
N/A |
Target database image |
None (row missing) |
N/A |
Initial |
SQL bind variables: 1)'Jane' 2)'4444' 3)'Holly' 4)200 5)200 6)NULL 7)'9/1/10 8:00' |
This SQL returns a no-data-found error. All columns are used in the |
SQL applied by Replicat to resolve the conflict |
None |
Because |
CDR Example 2: UPDATEROWEXISTS with USEDELTA and USEMAX
This example resolves the condition where a target row exists on UPDATE
but non-key columns are different, and it uses two different resolution types to handle this condition based on the affected column.
Table Used in this Example
The examples assume identical Oracle databases.
CREATE TABLE tgt( name varchar2(30) primary key, phone varchar2(10), address varchar2(100), salary number, balance number, comment varchar2(100), last_mod_time timestamp);
At the source database, all columns are supplementally logged:
ADD TRANDATA scott.src, COLS (name, phone, address, salary, balance, comment, last_mod_time);
MAP Statement
MAP fin.src, TARGET fin.tgt, COMPARECOLS (ON UPDATE KEYINCLUDING (address, phone, salary, last_mod_time), ON DELETE KEYINCLUDING (address, phone, salary, last_mod_time)), RESOLVECONFLICT ( UPDATEROWEXISTS, (delta_res_method, USEDELTA, COLS (salary)), (DEFAULT, USEMAX (last_mod_time)));
Description of MAP Statement
For an UPDATEROWEXISTS
conflict, where a target row exists on UPDATE
but non-key columns are different, use two different resolutions depending on the column:
-
Per the
delta_res_method
resolution, use theUSEDELTA
resolution logic for thesalary
column so that the change in value will be added to the current value of the column. -
Per
DEFAULT
, use theUSEMAX
resolution logic for all other columns in the table (the default column group), using thelast_mod_time
column as the resolution column. This column is updated with the current time whenever the row is modified; the value of this column in the trail is compared to the value in the target. If the value oflast_mod_time
in the trail record is greater than the current value oflast_mod_time
in the target database, the changes toname
,phone
,address
,balance
,comment
andlast_mod_time
are applied to the target.
Per COMPARECOLS
, use the primary key (name
column) plus the address
, phone
, salary
, and last_mod_time
columns as the comparison columns for conflict detection for UPDATE
and DELETE
operations. (The balance
and comment
columns are not compared.)
Note:
As an alternative to USEMAX
, you can use the USEMAXEQ
resolution to apply a >=
condition. For more information, see Parameters and Functions Reference
for Oracle GoldenGate.
Error Handling
For an example of error handling to an exceptions table, see Configuring the Oracle GoldenGate Parameter Files for Error Handling.
Table 11-15 UPDATEROWEXISTS with USEDELTA and USEMAX
Image | SQL | Comments |
---|---|---|
Before image in trail |
|
|
After image in trail |
|
|
Target database image |
|
|
Initial |
SQL bind variables:
|
This SQL returns a no-data-found error because the values for the |
|
SQL bind variables:
|
Per
|
|
SQL bind variables:
|
Per Note that the |
CDR Example 3: UPDATEROWEXISTS with USEDELTA, USEMAX, and IGNORE
This example resolves the conflict where a target row exists on UPDATE
but non-key columns are different, and it uses three different resolution types to handle this condition based on the affected column.
Table Used in this Example
The examples assume identical Oracle databases.
CREATE TABLE tgt( name varchar2(30) primary key, phone varchar2(10), address varchar2(100), salary number, balance number, comment varchar2(100), last_mod_time timestamp);
At the source database, all columns are supplementally logged:
ADD TRANDATA scott.src, COLS (name, phone, address, salary, balance, comment, last_mod_time);
MAP Statement
MAP fin.src, TARGET fin.tgt, COMPARECOLS (ON UPDATE ALLEXCLUDING (comment)), RESOLVECONFLICT ( UPDATEROWEXISTS, (delta_res_method, USEDELTA, COLS (salary, balance)), (max_res_method, USEMAX (last_mod_time), COLS (address, last_mod_time)), (DEFAULT, IGNORE));
Description of MAP Statement
-
For an
UPDATEROWEXISTS
conflict, where a target row exists onUPDATE
but non-key columns are different, use two different resolutions depending on the column:-
Per the
delta_res_method
resolution, use theUSEDELTA
resolution logic for thesalary
andbalance
columns so that the change in each value will be added to the current value of each column. -
Per the
max_res_method
resolution, use theUSEMAX
resolution logic for theaddress
andlast_mod_time
columns. Thelast_mod_time
column is the resolution column. This column is updated with the current time whenever the row is modified; the value of this column in the trail is compared to the value in the target. If the value oflast_mod_time
in the trail record is greater than the current value oflast_mod_time
in the target database, the changes toaddress
andlast_mod_time
are applied to the target; otherwise, they are ignored in favor of the target values. -
Per
DEFAULT
, use theIGNORE
resolution logic for the remaining columns (phone
andcomment
) in the table (the default column group). Changes to these columns will always be ignored by Replicat.
-
-
Per
COMPARECOLS
, use all columns except thecomment
column as the comparison columns for conflict detection forUPDATE
operations. Comment will not be used in theWHERE
clause for updates, but all other columns that have a before image in the trail record will be used.Note:
As an alternative to
USEMAX
, you can use theUSEMAXEQ
resolution to apply a>=
condition. For more information, see Parameters and Functions Reference for Oracle GoldenGate.
Error Handling
For an example of error handling to an exceptions table, see Configuring the Oracle GoldenGate Parameter Files for Error Handling.
Table 11-16 UPDATEROWEXISTS with USEDELTA, USEMAX, and IGNORE
Image | SQL | Comments |
---|---|---|
Before image in trail |
|
|
After image in trail |
|
|
Target database image |
|
|
Initial |
SQL bind variables:
|
This SQL returns a no-data-found error because the values for the |
|
SQL bind variables:
|
For |
|
SQL bind variables:
|
Because the after value of Note that the |
|
SQL bind variables:
|
|