future2012lg

博客园 首页 新随笔 联系 订阅 管理

  为客户部署的Oracle GoldenGate在测试阶段出现如下的错误:

2012-04-24 10:45:20  ERROR   OGG-01168  Oracle GoldenGate Delivery for Oracle, rep1.prm:  Encountered an update for target table CCENSE.ST_CARDOPERATORSTATTMP, which has no unique key defined.  KEYCOLS can be used to define a key.  Use ALLOWNOOPUPDATES to process the update without applying it to the target database.  Use APPLYNOOPUPDATES to force the update to be applied using all columns in both the SET and WHERE clause.
        
        数据同步出问题的表没有主键,客户执行insert的时候没有问题,在执行update的时候报了上面的错误。以上的报错涉及三个参数,KEYCOLS,ALLOWNOOPUPDATES,APPLYNOOPUPDATES。下面我们分别讨论这3个参数:


        1)KEYCOLS
        KEYCOLS关键字用于对没有主键的表,指定能够唯一标识数据的字段,这样Oracle GoldenGate同样可以完成数据的同步(同步UPDATE操作)。
        将目标数据库的replicat配置修改为:
MAP CCENSE.ST_CARDOPERATORSTATTMP, TARGET CCENSE.ST_CARDOPERATORSTATTMP, KEYCOLS(cardsfid)
        重启目标数据库的replicat进程即可完成数据的同步,但需要注意的是,使用这种方式必须把所有的表列出来,不能指定为<username>.*。

        2)ALLOWNOOPUPDATES
        
        官方文档解释如下:

ALLOWNOOPUPDATES | NOALLOWNOOPUPDATES
Valid for Replicat
Use ALLOWNOOPUPDATES and NOALLOWNOOPUPDATES to control how Replicat responds to a “noop”
operation. A no-op operation is one in which there is no effect on the target table. The
following are some examples of how this can occur.
● The source table has a column that does not exist in the target table, or has a column
that was excluded from replication (with a COLSEXCEPT clause). In either case, if that
source column is updated, there will be no target column name to use in the SET clause
within the Replicat SQL statement.
● An update is made that sets a column to the same value as the current one. The
database does not log the new value, because it did not really change. However, Oracle
GoldenGate extracts the operation as a change record because the primary key was
logged — but there is no column value for the SET clause in the Replicat SQL statement.
By default (NOALLOWNOOPUPDATES), Replicat abends with an error because these types of
operations do not update the database. With ALLOWNOOPUPDATES, Replicat ignores the
operation instead of abending. The statistics reported by Replicat will show that an update
was made, but the database will not be updated.
You can use the internal parameter APPLYNOOPUPDATES to force the update to be applied.
APPLYNOOPUPDATES overrides ALLOWNOOPUPDATES. If both are specified then updates with
only key columns will be applied. By default, Oracle GoldenGate will abend with the
following message if it only has source key columns but there is no key defined for the target table.

2011-01-25 02:28:42 GGS ERROR 160 Encountered an update for target
table TELLER, which has no unique key defined. KEYCOLS can be used to
define a key. Use ALLOWNOOPUPDATES to process the update without applying
it to the target database. Use APPLYNOOPUPDATES to force the update to
be applied using all columns in both the SET and WHERE clause.

Exceptions when error-handling is in place
If ALLOWNOOPUPDATES is specified when the HANDLECOLLISIONS or INSERTMISSINGUPDATES
parameters are being used, and if Oracle GoldenGate has all of the target key values, then
Oracle GoldenGate will not ignore the update, but instead will apply it using all key
columns in the SET clause and the WHERE clause (invoking APPLYNOOPUPDATES behavior). This
is necessary so Oracle GoldenGate can detect if the row being updated is missing. If it is,
then Oracle GoldenGate turns the update into an insert.
Default NOALLOWNOOPUPDATES (only applies if the table does not have a key)
Syntax ALLOWNOOPUPDATES | NOALLOWNOOPUPDATES 

        该参数的含义就是在同步到目标数据库的时候忽略出现的NO-OP操作,NO-OP操作包括目标数据库没有主数据库的字段(两边数据库字段不同),还有一种情况是执行UPDATE语句修改的数据和原有数据一样,没有发生变化。以上两种情况叫做NO-OP操作,遭遇NO-OP操作gg会被终止。

         3)APPLYNOOPUPDATES 
        该参数的含义就是不忽略出现的NO-OP操作,而是在目标数据库强制执行UPDATE修改操作,且只更新键值数据(主键或KEYCOLS指定的键值),如果表没有主键,也没有使用KEYCOLS关键字指定字段,那么将更新表数据的所有字段,如果没有相应记录,将INSERT新插入一条。
        官方文档解释如下:

APPLYNOOPUPDATES | NOAPPLYNOOPUPDATES
Valid for Replicat
Use APPLYNOOPUPDATES to force a “no-op” update to be applied using all columns in both the
SET and WHERE clauses. See ALLOWNOOPUPDATES | NOALLOWNOOPUPDATES for a description of
“no-op.”
APPLYNOOPUPDATES uses whatever data is in the trail. If there is a primary key update
record, it uses the before columns from the source. If there is a regular (non-key) update,
it assumes that the after value is the same as the before value (otherwise it would be a
primary key update). The preceding assumes source and target keys are identical. If they
are not, you must use a KEYCOLS clause in the TABLE statement on the source.
Default NOAPPLYNOOPUPDATES
Syntax APPLYNOPUPDATES | NOAPPLYNOPUPDATES

        请注意,我们在讨论NO-OP操作的时候,NO-OP操作并不包含UPDATE没有主键的表,所以我们遇到的这个问题和ALLOWNOOPUPDATES和APPLYNOOPUPDATES这两个参数没有关系。通过实践证明,在replicat配置文件中加入这两个参数(或只加入ALLOWNOOPUPDATE参数),在更新没有主键,也没有指定KEYCOLS字段的表的时候同样会报错。对没有主键,但加上了KEYCOLS字段后的表执行UPDATE操作成功同步了数据。

        如果没有在源数据库启用记录表的supplement log,同样会收到以上的报错,原因是在于没有记录没有主键表的supplement log数据,并将其传递到目标数据库,执行以下操作可以启用记录表的supplement log:
cd $GGHOME
./ggsci
dblogin userid <username>,password <password>
add trandata <username>.<tablename>
         完成以上操作之后,可以解决由此问题导致的update不能同步。

结论
        在处理没有主键的表,且对表有UPDATE操作的时候,应该为这些表在replicat配置文件的MAP设置中加上KEYCOLS关键字,后面的跟上能够唯一标识数据的一个字段或多个字段,甚至可以把表的所有字段加在KEYCOLS关键字后面。 
http://blog.itpub.net/23135684/viewspace-722194/
posted on 2015-06-03 16:07  future2012lg  阅读(720)  评论(0编辑  收藏  举报