ORACLE异构连接

ORACLE异构连接
一、WHERE TO DO:
测试平台
ORACLE  :  Oracle Database 11g Enterprise Edition Release 11.1.0.6.0 - Production(GBK)
target DB :SYBASE Adaptive Enterprise 15.0.2 (utf8)
		   DB2/AIX64 9.7.2
Transparent Gateway:11g R2

二、HOW TO DO:
oracle实现异构连接分为两种方式,基本原理:
1. Generic Heterogeneous Services,通用异构服务
  服务器端安装non-oracle db的client,使用其所带odbc驱动建立其数据源,然后oracle通过hs组件建立与odbc之间的dblink从而实现异构连接。
2. Transparent Gateway,透明网关
  安装透明网关,选择相应non-oracle db网关选项,建立监听连接透明网关,进而dblink实现异构连接。

三、DO:
1. Generic Heterogeneous Services,通用异构服务实现DB2异构连接
  目标:建立与target non-oracle db与odbc之间的访问,使之能和hs组件建立监听并提供dblink服务。
   此种方式须安装odbc访问db时所需的驱动,通常由client所带。
   建立异构服务如下:
   1)配置odbc源
      根据各db所带odbc驱动建立数据源,此处建立连接db2的源,测试成功进行下一步。
   2)配置在initdg4odbc.ora中的配置参数HS_FDS_CONNECT_INFO
     在ORACLE_HOME>\hs\admin下修改init<SID Name>.ora,其中sid name自定,最终这sid成为监听中的服务名。此处命名格式必须如:initDB2.ora
     主要配置参数为
     HS_FDS_CONNECT_INFO=DB2  
     (其中DB2为odbc数据源名,此处为连接DB2源)
   3)修改监听
     可以新增也可以修改现有监听。(红字部分依实际情况自行修改)
     LISTENER=
  (DESCRIPTION_LIST=
    (DESCRIPTION=
      (ADDRESS LIST=
        (ADDRESS = (PROTOCOL = TCP)(HOST = <hostname>)(PORT = 1521))
      )
    )
  )
   SID_LIST_LISTENER =
    (SID_DESC =
      (PROGRAM = dg4odbc)
     (SID_NAME = DB2)   
       (ORACLE_HOME = C:\oracle\ora)
     )
   )
备注:PROGRAM = dg4odbc,11g前版本可能为hsodbc
      SID_NAME = DB2,DB2为init<SID Name>.ora中SID Name.
      ORACLE_HOME = C:\oracle\ora, Home目录。
   4)最后建立dblink连接。
    create database link to_db2 connect to <username> identified by <password> using 
    '
    (DESCRIPTION =
     (ADDRESS_LIST =
       (ADDRESS = (PROTOCOL = TCP)(HOST =<your Oracle host machine>)(PORT = 1521))
     )
    (CONNECT_DATA =
       (SID = DB2)
     )
     (HS=OK)
   )
    '
备注:类似普通tnsname设置,但(HS=OK)此处必须。
    5)测试连接ok
    6)Done

2. Transparent Gateway,透明网关实现sybase异构连接
  目标:建立透明网关,使之建立监听并提供dblink服务。
  此种方式可无须odbc,故无须non-oracle db的client亦可,但须安装Transparent Gateway。
  建立异构服务如下:
    1)进入透明网关的home目录下tg4***,此处为tg4sybs目录
    因为安装透明时要选择异构连接db类型,并输入连接信息。此处配置oracle会自动生成。进入目录下的admin目录,默认initdg4sybs.ora配置文件,可修改为init< Gateway SID>.ora,Gateway SID可自定并将成为监听的服务。
    配置文件已经由oracle配置,可不再修改。内容如
    HS_FDS_CONNECT_INFO=[10.11.11.11]:4100/data 
    HS_FDS_TRACE_LEVEL=OFF
 	HS_FDS_RECOVERY_ACCOUNT=RECOVER
	HS_FDS_RECOVERY_PWD=RECOVER
    2)修改监听
    LISTENER=
  (DESCRIPTION_LIST=
    (DESCRIPTION=
      (ADDRESS LIST=
        (ADDRESS = (PROTOCOL = TCP)(HOST = <hostname>)(PORT = 1521))
      )
    )
  )
   SID_LIST_LISTENER =
    (SID_DESC =
      (PROGRAM = dg4sybs)
     (SID_NAME = dg4sybs)   
       (ORACLE_HOME = C:\product\11.2.0\tg_1)
     )
   )
备注:PROGRAM = dg4sybs,可能为其他,如安装其他异构db的透明网关,具体参看dg4***目录
      SID_NAME = dg4sybs,dg4sybs为init<Gateway SID>.ora中Gateway SID.
      ORACLE_HOME = C:\product\11.2.0\tg_1,透明网关home目录。
      尤其注意如果透明网关的监听配置应该配置在透明网关home目录下的NETWORK中
   3)建立dblink
	create database link to_sybase connect to <username> identified by <password> using 
    '
    (DESCRIPTION =
     (ADDRESS_LIST =
       (ADDRESS = (PROTOCOL = TCP)(HOST =<your Oracle host machine>)(PORT = 1521))
     )
    (CONNECT_DATA =
       (SID = dg4sybs)
     )
     (HS=OK)
   )
备注:类似普通tnsname设置,但(HS=OK)此处必须。sid为init<Gateway SID>.ora所指定sid
   4)测试连接ok
   5)Done

四、SUMMARY
   两种异构连接实现方式各有特点:
   通用异构服务本身不需安装但需odbc源往往需要安装异构数据库的客户端从来利用其odbc驱动,而透明网关自带连接组件,但其本身需安装。
	配置上来说两种均不复杂,但透明网关更简单。
    两种差别在于,透明网关支持更强的异构连接,如一些特殊字段类型的支持会更多更强。而通用异构服务所基于odbc,处理时难免不周。
    sybase有时使用区分大小的字符集时,所有字符最好加上" ",防止oracle自动转换为大写而产生一些错误。

五、TROUBLESHOOTING
   1.ORA-28528:多机种服务数据类型转换出现错误
     [oracle][odbc sybase wire protocol driver]string data,right truncated.error in column 3.{01004}
    ora-02063:紧接着2Line(起自to_sybase)
   ORA-28528:
Heterogeneous Services datatype conversion error Cause: Either an Oracle datatype could not be converted to a non-Oracle datatype, or a non-Oracle datatype could not be converted to an Oracle datatype. The following are possible reasons for for the conversion failure: -- overflow problems (in the case of numbers) -- length limitations (in the case of character strings) -- invalid values passed into the conversion routines
Action: Contact customer support of the agent vendor. If the problem is due to size discrepancies between Oracle and the non-Oracle system, it may not be possible to convert the value

2.ora-28511: 丢失与使用sid=……的多机种远程代理程序的rpc连接
ORA-28511:
lost RPC connection to heterogeneous remote agent using SID=string Cause: A fatal error occurred in one of the following places: -- the connection between the ORACLE server and the agent -- the heterogeneous services remote agent itself -- the connection to the non-Oracle system This error occurred after communication had been established successfully.
Action: Check for network problems and remote host crashes. The problem is probably in the agent software. If so, contact a customer support representative of the agent vendor.
sybase通用异构服务连接odbc查询远程db不同字符集时报错,可以使用odbc日志调试分析,连接可以建立,但查询失败。使用透明网关解决。

3.ora-28500:连接oracle到非oracle系统时返回此信息:[MICROSOFT][ODBC驱动程序管理器]未发现数据源名并且未指定默认驱动程序
   原因:根据错误提示,sid未配置正确。重新配置解决。

4.ora-28500:连接oracle到非oracle系统时返回此信息:[IBM][CLI DRIEVER] SQL30082N尝试建立连接失败,安全性原因为“24”("username and/or password invalid").sqlstate=08001
原因:用户名、密码不匹配。ora-28500错误根据错误提示应该就可解决。

5.ora-02050:事务处理4.7.2886已回退,某些远程数据库可能有问题
ORA-02050:
transaction string rolled back, some remote DBs may be in-doubt Cause: network or remote failure in 2PC.
Action: Notify operations; remote DBs will automatically re-sync when the failure is repaired.
解决:须dba手工提交或回滚事务,自行保证一致性。
      dbms_transaction.purge_lost_db_entry('4.7.2886');commit;
具体解决方式需视情况而定。
phase       local_state    remote_state       action
prepare     collecting           /            本地DBMS_TRANSACTION.PURGE_LOST_DB_ENTRY
             prepared             /        	本地rollback force后PURGE_LOST_DB_ENTRY
commit      prepared        commited      本地commit force后本地和远程均PURGE
             commited        commited       本地和远程均PURGE_LOST_DB_ENTRY
forget      commited            /         	本地PURGE_LOST_DB_ENTRY

你可能感兴趣的:(ORACLE异构连接)