我们所熟知oracle的字符集一旦创建完毕后最好不要修改,关于oracle goldengate的字符集问题还是需要注意的,因为如果目标端和源端字符集不一致,而有些字符无法在目标端表示ogg可能无法保证数据一致性。
源库字符集:
SQL> select value from v$nls_parameters where parameter='NLS_CHARACTERSET';
VALUE
----------------------------------------------------------------
AL32UTF8
如果这里小鱼在源端设置SETENV(NLS_LANG=“AMERICAN_AMERICA.ZHS16GBK”)去指定源端客户端的字符集
GGSCI (dg01) 21> view params exiaoyu
extract exiaoyu
SETENV (NLS_LANG="AMERICAN_AMERICA.ZHS16GBK")
SETENV (ORACLE_SID="xiaoyu")
userid ogg,password ogg
dynamicresolution
gettruncates
report at 2:00
reportrollover at 3:00
warnlongtrans 3h,checkinterval 10m
exttrail ./dirdat/dd
table xiaoyu.*;
table xiaoyugg.*;
来看看对应的extract进程的报告,发现此时ogg发觉源端客户端的NLS_LANG变量和源端数据库字符集不一致,从而选择源端数据库字符集,并没有根据extract进程参数中的SETENV指定。
GGSCI (dg01) 52> view report exiaoyu
** Running with the following parameters **
***********************************************************************
2013-06-04 04:50:27 INFO OGG-03035 Operating system character set identified as UTF-8. Locale: en_US, LC_ALL:.
extract exiaoyu
SETENV (NLS_LANG="AMERICAN_AMERICA.ZHS16GBK")
Set environment variable (NLS_LANG=AMERICAN_AMERICA.ZHS16GBK)
SETENV (ORACLE_SID="xiaoyu")
Set environment variable (ORACLE_SID=xiaoyu)
userid ogg,password ***
2013-06-04 04:50:28 INFO OGG-03500 WARNING: NLS_LANG environment variable does not match database character set, or not set. Using database character set value of AL32UTF8.
[oracle@ogg 11.2]$ oggerr 3500
03500, 00000, "WARNING: NLS_LANG environment variable does not match database character set, or not set. Using database character set value of {0}"
// *{0}: nls_charset (String)
// *Cause: The NLS_LANG environment variable is not set to the same as the
// database character set. Oracle GoldenGate is using the database
// character set.
// *Action: None
看来源端设置NLS_LANG跟oracle database的字符集不一致时,ogg还是会选择oracle database的字符集,而忽略掉extract的进程参数SETEVN NLS_LANG
接下来测试目标端:
这里也指定SETENV(NLS_LANG=”AMERICAN_AMERICA.ZHS16GBK”)
GGSCI (ogg.single) 15> view params rxiaoyu
replicat rxiaoyu
SETENV (NLS_LANG="AMERICAN_AMERICA.ZHS16GBK")
SETENV (ORACLE_SID="xiaoyu")
userid ogg,password ogg
assumetargetdefs
gettruncates
report at 2:00
reportrollover at 3:00
discardfile ./dirrpt/discard_rxiaoyu.dsc,append,megabytes 100
map xiaoyu.xiaoyu10,target xiaoyu.xiaoyu10,filter(@getenv("transaction","csn")>1074454806);
map xiaoyu.*,target xiaoyu.*;
map xiaoyugg.*,target ogg.*;
观察目标端的replicat进程,发现ogg选择了进程参数中SETENV(NLS_LANG=“AMERICAN_AMERICA.ZHS16GBK”)
GGSCI (ogg.single) 17> view report rxiaoyu
。。。
2013-06-05 03:14:14 WARNING OGG-03504 NLS_LANG character set ZHS16GBK on the target is different from the source database character set AL32UTF8. Replication may not be valid if the source data has an incompatible character for the target NLS_LANG character set
此时ogg给出的提示需要在replicat进程中正确设置SETENV NLS_LANG变量,这里源端传递的是AL32UTF8字符集,目标端通过replicat进程参数SETENV NLS_LANG指定的是ZHS16GBK,而ogg也采用了replicat进程的参数,并没有选择源端的字符集。
[oracle@ogg 11.2]$ oggerr 3504
03504, 00000, "NLS_LANG character set {0} on the target is different from the source database character set {1}. Replication may not be valid if the source data has an incompatible character for the target NLS_LANG character set."
// *{0}: nls_lang_charset (String)
// *{1}: src_db_charset (String)
// *Cause: The NLS_LANG environment variable on the target is set to a
// different character set than the character set of the source
// database.
// *Action: Set the NLS_LANG environment variable on the target to the
// character set of the source database that is shown in the message.
// You can use the SETENV parameter in the Replicat parameter file to
// set it for the Replicat session.
而ogg报出的3504警告是为了提醒目标端字符集和源端不一致,可能会引起replicat进程异常,这里ogg也推荐在replicat进程中设置NLS_LANG使目标端和源端一致。
那么对于字符集对ogg的影响就是源端和目标端,如果源端和目标端database字符集一直,这里在进程中直接采用一致的SETENV NLS_LANG都等于缺省的数据库字符集即可,而对于源端和目标端字符集不一致的,则需要在目标端手动指定replicat进程参数SETENV NLS_LANG等于源端字符集,当然对于最后在数据库中数据行小鱼认为还是需要再次转化成目标端oracle database的字符集。(ogg也是一个同步复制产品,其技术原理依然不能脱离oracle database)
原链接地址:http://www.dbaxiaoyu.com/archives/1066