DataStage 三、配置ODBC
1.学习关于DataStage配置ODBC的基础知识;2.学习DataStage配置ODBC的方法;3.介绍和学习两种配置Oracle ODBC的方法;4.学习MySql ODBC的配置方法。
h1, h2, h3, h4 { color: rgba(17, 17, 17, 1); font-weight: 400 }
h1, h2, h3, h4, h5, p { margin-bottom: 16px; padding: 0 }
h1 { font-size: 28px }
h2 { font-size: 22px; margin: 20px 0 6px }
h3 { font-size: 21px }
h4 { font-size: 18px }
h5 { font-size: 16px }
a { color: rgba(0, 153, 255, 1); margin: 0; padding: 0; vertical-align: baseline }
a:link, a:visited { text-decoration: none }
a:hover { text-decoration: underline }
ul, ol { padding: 0; margin: 0 }
li { line-height: 24px; margin-left: 30px }
li ul, li ul { margin-left: 24px }
ul, ol { font-size: 14px; line-height: 20px; max-width: 98% }
p { font-size: 14px; line-height: 20px; max-width: 98%; margin-top: 3px }
pre { padding: 0 4px; max-width: 98%; white-space: pre-wrap; font-family: Consolas, Monaco, Andale Mono, monospace; line-height: 1.5; font-size: 13px; border: 1px solid rgba(221, 221, 221, 1); background-color: rgba(247, 247, 247, 1); border-radius: 3px }
code { font-family: Consolas, Monaco, Andale Mono, monospace; line-height: 1.5; font-size: 13px; border: 1px solid rgba(221, 221, 221, 1); background-color: rgba(247, 247, 247, 1); border-radius: 3px }
pre code { border: 0 }
aside { display: block; float: right; width: 390px }
blockquote { border-left: 0.5em solid rgba(64, 170, 83, 1); padding: 0 2em; margin-left: 0; max-width: 98% }
blockquote cite { font-size: 14px; line-height: 20px; color: rgba(191, 191, 191, 1) }
blockquote cite:before { content: “— ” }
blockquote p { color: rgba(102, 102, 102, 1); max-width: 98% }
hr { height: 1px; border-top: 1px dashed rgba(0, 102, 204, 1); border-right: none; border-bottom: none; border-left: none }
button, input, select, textarea { font-size: 100%; margin: 0; vertical-align: baseline; *vertical-align: middle }
button, input { line-height: normal; *overflow: visible }
{ border: 0; padding: 0 }
button, input[type=”button”], input[type=”reset”], input[type=”submit”] { cursor: pointer; -webkit-appearance: button }
input[type=”checkbox”], input[type=”radio”] { cursor: pointer }
input:not([type=”image”]), textarea { -webkit-box-sizing: content-box; -moz-box-sizing: content-box; box-sizing: content-box }
input[type=”search”] { -webkit-appearance: textfield; -webkit-box-sizing: content-box; -moz-box-sizing: content-box; box-sizing: content-box }
{ -webkit-appearance: none }
label, input, select, textarea { font-family: “Helvetica Neue”, Helvetica, Arial, sans-serif; font-size: 13px; font-weight: normal; line-height: normal; margin-bottom: 18px }
input[type=”checkbox”], input[type=”radio”] { cursor: pointer; margin-bottom: 0 }
input[type=”text”], input[type=”password”], textarea, select { display: inline-block; width: 210px; padding: 4px; font-size: 13px; font-weight: normal; line-height: 18px; height: 18px; color: rgba(128, 128, 128, 1); border: 1px solid rgba(204, 204, 204, 1); -webkit-border-radius: 3px; -moz-border-radius: 3px; border-radius: 3px }
select, input[type=”file”] { height: 27px; line-height: 27px }
textarea { height: auto }
{ color: rgba(191, 191, 191, 1) }
{ color: rgba(191, 191, 191, 1) }
input[type=”text”], input[type=”password”], select, textarea { -webkit-transition: border linear 0.2s, box-shadow linear 0.2s; -moz-transition: border linear 0.2s, box-shadow linear 0.2s; transition: border 0.2s linear, box-shadow 0.2s linear; -webkit-box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.1); -moz-box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.1); box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.1) }
input[type=”text”]:focus, input[type=”password”]:focus, textarea:focus { outline: none; border-color: rgba(82, 168, 236, 0.8); -webkit-box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.1), 0 0 8px rgba(82, 168, 236, 0.6); -moz-box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.1), 0 0 8px rgba(82, 168, 236, 0.6); box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.1), 0 0 8px rgba(82, 168, 236, 0.6) }
button { display: inline-block; padding: 4px 14px; font-family: “Helvetica Neue”, Helvetica, Arial, sans-serif; font-size: 13px; line-height: 18px; -webkit-border-radius: 4px; -moz-border-radius: 4px; border-radius: 4px; -webkit-box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.2), 0 1px 2px rgba(0, 0, 0, 0.05); -moz-box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.2), 0 1px 2px rgba(0, 0, 0, 0.05); box-shadow: inset 0 1px rgba(255, 255, 255, 0.2), 0 1px 2px rgba(0, 0, 0, 0.05); background-color: rgba(0, 100, 205, 1); background-repeat: repeat-x; background-image: linear-gradient(0deg, rgba(4, 156, 219, 1), rgba(0, 100, 205, 1)); color: rgba(255, 255, 255, 1); text-shadow: 0 -1px rgba(0, 0, 0, 0.25); border-top: 1px solid rgba(0, 0, 0, 0.1); border-right: 1px solid rgba(0, 0, 0, 0.1); border-bottom: 1px solid rgba(0, 0, 0, 0.25); border-left: 1px solid rgba(0, 0, 0, 0.1); -webkit-transition: 0.1s linear all; -moz-transition: 0.1s linear all; transition: all 0.1s linear }
button:hover { color: rgba(255, 255, 255, 1); background-position: 0 -15px; text-decoration: none }
button:active { -webkit-box-shadow: inset 0 3px 7px rgba(0, 0, 0, 0.15), 0 1px 2px rgba(0, 0, 0, 0.05); -moz-box-shadow: inset 0 3px 7px rgba(0, 0, 0, 0.15), 0 1px 2px rgba(0, 0, 0, 0.05); box-shadow: inset 0 3px 7px rgba(0, 0, 0, 0.15), 0 1px 2px rgba(0, 0, 0, 0.05) }
{ padding: 0; border: 0 }
table { border-spacing: 0; border: 1px solid rgba(204, 204, 204, 1) }
td, th { border: 1px solid rgba(204, 204, 204, 1); padding: 5px }
pre .literal, pre .comment, pre .template_comment, pre .diff .header, pre .javadoc { color: rgba(0, 128, 0, 1) }
pre .keyword, pre .css .rule .keyword, pre .winutils, pre .javascript .title, pre .nginx .title, pre .subst, pre .request, pre .status { color: rgba(0, 0, 255, 1); font-weight: bold }
pre .number, pre .hexcolor, pre .python .decorator, pre .ruby .constant { color: rgba(0, 0, 255, 1) }
pre .string, pre .tag .value, pre .phpdoc, pre .tex .formula { color: rgba(221, 17, 68, 1) }
pre .title, pre .id { color: rgba(153, 0, 0, 1); font-weight: bold }
pre .javascript .title, pre .lisp .title, pre .clojure .title, pre .subst { font-weight: normal }
pre .class .title, pre .haskell .type, pre .vhdl .literal, pre .tex .command { color: rgba(68, 85, 136, 1); font-weight: bold }
pre .tag, pre .tag .title, pre .rules .property, pre .django .tag .keyword { color: rgba(0, 0, 128, 1); font-weight: normal }
pre .attribute, pre .variable, pre .lisp .body { color: rgba(0, 128, 128, 1) }
pre .regexp { color: rgba(0, 153, 38, 1) }
pre .class { color: rgba(68, 85, 136, 1); font-weight: bold }
pre .symbol, pre .ruby .symbol .string, pre .lisp .keyword, pre .tex .special, pre .prompt { color: rgba(153, 0, 115, 1) }
pre .built_in, pre .lisp .title, pre .clojure .built_in { color: rgba(0, 134, 179, 1) }
pre .preprocessor, pre .pi, pre .doctype, pre .shebang, pre .cdata { color: rgba(153, 153, 153, 1); font-weight: bold }
pre .deletion { background: rgba(255, 221, 221, 1) }
pre .addition { background: rgba(221, 255, 221, 1) }
pre .diff .change { background: rgba(0, 134, 179, 1) }
pre .chunk { color: rgba(170, 170, 170, 1) }
pre .markdown .header { color: rgba(136, 0, 0, 1); font-weight: bold }
pre .markdown .blockquote { color: rgba(136, 136, 136, 1) }
pre .markdown .link_label { color: rgba(136, 136, 255, 1) }
pre .markdown .strong { font-weight: bold }
pre .markdown .emphasis { font-style: italic }
DataStage序列文章
DataStage 一、安装
DataStage 二、InfoSphere Information Server进程的启动和停止
1 配置ODBC需要了解的基础知识
配置ODBC的步骤:
- 在.odbc.ini 文件里配置ODBC数据源信息
- 在uvodbc.config文件里配置数据源名称信息(DSN)
- 测试数据源
路径和文档信息:
名称 | 说明 |
---|---|
DataStage默认安装驱动的路径 | /opt/IBM/InformationServer/Server/branded_odbc |
关于ODBC配置的文档 | /opt/IBM/InformationServer/Server/branded_odbc/docs |
哪里配置ODBC信息 | $DSHOME/.odbc.ini |
哪里配置ODBC data Source name(DSN) | $DSHOME/uvodbc.config和每个DataStage项目下的uvodbc.config |
1.1 说明
在$DSHOME/.odbc.ini内配置ODBC数据源信息,这里配置的信息包括驱动、服务器、用户、端口等信息,这个文件的名称和路径不是绝对的,可以在$DSHOME/dsenv 文件内的ODBCINI变量配置:
ODBCINI=$DSHOME/.odbc.ini
export ODBCINI
dsenv 是非常重要的配置文件,修改该文件必须重启Enginer生效,里面的变量信息对所有项目有效,并且可以在开发项目时引用。
在uvodbc.config文件里配置ODBC数据源名称(DSN),这里配置的信息和上面的.odbc.ini不一样,.odbc.ini文件是详细的数据源配置信息,而这里是配置DSN,可以理解为.odbc.ini里配置了数据源详细信息,而uvodbc.config文件是给项目提供的引用接口定义。
<Oracle_30>
DBMSTYPE = ODBC
Oracle_30表示数据源名称,名称必须和.odbc.ini里面配置的一样。
DBMSTYPE指定该数据源的类型。
2 Oracle 数据源配置
Oracle 数据源配置方式有两种:
- 基于DWire Protocol Driver配置ODBC:这种方式不需要Oracle客户端软件,也不需要配置Oracle环境变量
- 基于TNS配置ODBC:这种方式需要配置Oracle环境变量并且必须有$ORACLE_HOME/network/admin/tnsnames.ora TNS配置文件
2.1 基于DWire Protocol Driver配置ODBC
2.1.1 配置.odbc.ini
在$DSHOME/.odbc.ini文件中找到官方提供的预配置ODBC数据源[Oracle Wire Protocol],复制该段内容,修改ODBC配置信息.
[Oracle_30]
Driver=/opt/IBM/InformationServer/Server/branded_odbc/lib/VMora24.so
Description=DWire Protocol Driver for server 30
ApplicationUsingThreads=1
ArraySize=60000
CachedCursorLimit=32
CachedDescLimit=0
CatalogIncludesSynonyms=1
CatalogOptions=0
DefaultLongDataBuffLen=1024
DescribeAtPrepare=0
EnableDescribeParam=0
EnableNcharSupport=0
EnableScrollableCursors=1
EnableStaticCursorsForLongData=0
EnableTimestampWithTimeZone=0
HostName=127.0.0.1
LocalTimeZoneOffset=
LockTimeOut=-1
LogonID=
Password=
PortNumber=1521
ProcedureRetResults=0
SID=testdb
UseCurrentSchema=1
这里Oracle_30表示数据源名称,HostName表示数据库所在的主机名,PortNumber表示数据库端口,SID表示数据库实例ID;将内容保存到.odbc.ini文件中。
2.1.2 配置uvodbc.config
编辑$DSHOME/uvodbc.config文件,增加上面在.odbc.ini文件中配置的ODBC数据源信息。
[ODBC DATA SOURCES]
<localuv>
DBMSTYPE = UNIVERSE
network = TCP/IP
service = uvserver
host = 127.0.0.1
<Oracle_30>
DBMSTYPE = ODBC
DNS名称Oracle_30必须和.odbc.init中的一致。**注意:该文件在两个地方存在,一个在$DSHOME目录下,一个在项目的目录下,当创建新项目时,DataStage拷贝该文件到新项目目录下;DS项目运行时首先查找项目下的uvodbc.config文件,如果未找到则查找$DSHOME/uvodbc.config文件,所以编辑完成后要将该文件拷贝到项目目录下;当然这种方式只在多个项目需要访问相同的ODBC的情况下介意这么做,如果每个项目所使用的ODBC不同,那么最好的方式就是编辑项目目录下的uvodbc.config文件了。
2.1.3 测试ODBC数据源
进入DSHOME目录使用dssh工具测试数据源。
$ cd $DSHOME
$ ./dsenv
$ ./dssh
DataStage Command Language 8.5 Licensed Materials - Property of IBM
(c) Copyright IBM Corp. 1997, 2009 All Rights Reserved.
DSEngine logged on: Friday, September 25, 2015 09:07
键入LOGTO 项目名称进入项目,注意项目名称区分大小写。
>LOGTO dstest
键入DS_CONNECT命令查看该项目所有的ODBC源配置,这里你可以看到项目使用的uvodbc.config文件和刚才配置的Oracle_30数据源了。
>DS_CONNECT
Data Source information from /opt/IBM/dsprojects/dstest/uvodbc.config:
Data Source: localuv
DBMS Type: UNIVERSE
Network Type: TCP/IP
Host System: loopback 127.0.0.1
Service Name: uvserver
Data Source: Oracle_30
DBMS Type: ODBC
键入DS_CONNECT Oracle_30测试数据源,注意数据源名称区分大小写。根据提示输入数据库用户名和密码。
>DS_CONNECT Oracle_30
Enter username for connecting to \'Oracle_30\' DBMS [dsadm]: dsource
Enter password for dsource:
如果没有任何的报错,那说明数据源测试成功了,并且>提示变为了数据源名称>(Oracle_30>);你可以键入sql验证数据源。
Oracle_30> select * from tab;
TNAME TABTYPE CLUSTERID
---------- ---------- ----------
DOBJ01 TABLE NULL
1 row selected
2.2 基于TNS配置ODBC
2.2.1 什么时候使用TNS配置ODBC
- 当GoldenGate服务器上存在Oracle服务端或客户端软件时
- 当数据库地址端口经常发生变化时
- 当多个应用程序和GoldenGate需要同时访问一个数据源时
- 当GoldenGate所在的服务器不能直接连接数据库需要通过TNS代理连接时
这种方式需要配置Oracle环境变量,也必须有$ORACLE_HOME/network/admin/tnsnames.ora TNS配置文件,并且GoldenGate具有读取该文件的权限。
2.2.2 在dsenv文件中配置Oracle环境
$ cd $DSHOME
$ vi dsenv
export ORACLE_HOME=/opt/oracle/product/11.2.0
export LIBPATH=$LIBPATH:$ORACLE_HOME/lib:$ORACLE_HOME/rdbms/lib
export PATH=$PATH:$ORACLE_HOME/bin
export NLS_LANG=AMERICAN_AMERICA.AL32UTF8
export ORACLE_SID=testdb
export TNS_ADMIN=/opt/oracle/product/11.2.0/network/admin
配置完成后必须重启Engine使配置文件生效。
$ uv -admin -stop
$ uv -admin -start
注意:在重启Engine后,你要确认上面的变量是否在你当前会话环境中生效,否则会影响后面的测试,如果未生效可能是你的配置错误或者之前的配置与之冲突导致变量失效,请尝试重新登录会话确定。
2.2.3 在TNS文件中配置ServerName和其它信息
$ vi /opt/oracle/product/11.2.0/network/admin/tnsnames.ora
xmeta_111 =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = testhost)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = xmeta)
)
)
2.2.4 在.odbc.ini文件中配置数据源信息
[Ora_remote_111]
Driver=/software/IBM/InformationServer/Server/branded_odbc/lib/VMora24.so
Description=DataDirect Oracle for remote server
ApplicationUsingThreads=1
ArraySize=60000
CachedCursorLimit=32
CachedDescLimit=0
CatalogIncludesSynonyms=1
CatalogOptions=0
DefaultLongDataBuffLen=1024
DescribeAtPrepare=0
EnableDescribeParam=0
EnableNcharSupport=0
EnableScrollableCursors=1
EnableStaticCursorsForLongData=0
EnableTimestampWithTimeZone=0
LocalTimeZoneOffset=
LockTimeOut=-1
LogonID=
Password=
ProcedureRetResults=0
ServerName=xmeta_111
UseCurrentSchema=1
这里不需要配置主机、端口信息,只需要配置ServerName为TNS文件中的serverName。
2.2.5 在uvodbc.config文件中配置数据源DSN
<Ora_remote_111>
DBMSTYPE = ODBC
这样就可以了,再通过2.1.3 中的那样测试ODBC数据源吧。
2.2.6 可能遇到的错误
>ds_connect Ora_remote_111
Enter username for connecting to \'Ora_remote_111\' DBMS [dsadm]: scott
Enter password for scott:
SQLConnect error: Status = -1 SQLState = 08001 Natcode = -1
[ODBC] [IBM(DataDirect OEM)][ODBC Oracle Wire Protocol driver][Oracle]TNS-12505: TNS:listener could not resolve SID given in connect descriptor
Network connection to Data Source \'Ora_remote_111\' failed
服务端不能识辨sid,这类错误有两种原因:
- TNS文件中的SID或者Service_name配置错误,请尝试在sqlplus下测试该配置的可连接性,或者使用Easy connect name method方式测试连接
- .odbc.init中的数据源信息配置错误,请检查ServerName的值是否配置正确
>ds_connect Ora_remote_111
Enter username for connecting to \'Ora_remote_111\' DBMS [dsadm]: scott
Enter password for scott:
SQLConnect error: Status = -1 SQLState = S1000 Natcode = 0
[ODBC] [IBM(DataDirect OEM)][ODBC Oracle Wire Protocol driver]Cannot open TNS Names file.
这个错误请检查Oracle环境变量配置和文件权限分配,通常文件具有读的权限即可。
3 MySql 数据源配置
配置的方式都是差不多的,理解了工作原理,然后根据官方提供的预配置信息配置。
配置.odbc.ini
[mysql_99]
Driver=/opt/IBM/InformationServer/Server/branded_odbc/lib/VMmysql24.so
Description=DataDirect 6.0 MySQL Wire Protocol
AlternateServers=
ApplicationUsingThreads=1
ConnectionReset=0
ConnectionRetryCount=0
ConnectionRetryDelay=3
DefaultLongDataBuffLen=1024
EnableDescribeParam=0
EncryptionMethod=0
FailoverGranularity=0
FailoverMode=0
FailoverPreconnect=0
HostName=mySqlHost
Database=mysql
PortNumber=3306
HostNameInCertificate=
InteractiveClient=0
KeyPassword=
KeyStore=
KeyStorePassword=
LoadBalanceTimeout=0
LoadBalancing=0
LoginTimeout=15
LogonID=
Password=
MaxPoolSize=100
MinPoolSize=0
Pooling=0
QueryTimeout=0
ReportCodepageConversionErrors=0
TreatBinaryAsChar=0
TrustStore=
TrustStorePassword=
ValidateServerCertificate=1
这里HostName配置主机,Database mysql数据库,PortNumber 数据库端口。
配置uvodbc.config
<mysql_99>
DBMSTYPE = ODBC
测试数据源 注意8.5版本的DataStage驱动不支持MySQL Community Servers版本,如果测试的版本是MySQL Community Servers,则会得到下面的错误信息。
>ds_connect mysql_99
Enter username for connecting to \'mysql_99\' DBMS [dsadm]: root
Enter password for root:
SQLConnect error: Status = -1 SQLState = S1000 Natcode = 0
[ODBC] [IBM(DataDirect OEM)][ODBC MySQL Wire Protocol driver]Connections to MySQL Community Servers are not supported. Please contact MySQL to obtain a MySQL Enterprise or Commercial version.
4 数据源的使用
当在服务器端配置好ODBC数据源后,便可以任何连接到该服务端的客户端中使用,这有利于管理,因为不需要在客户端中做任何的操作,并且服务端的更改对于客户端来说是透明的。
在Data source中输入服务端配置的ODBC数据源名称;
在Username和Password中输入数据库用户名和密码;
单击“测试”按钮测试数据源连接,然后再进行其它开发。
5 总结
在本文中介绍了DataStage ODBC的安装路径、官方帮助文档、需要配置的文件以及配置方法和注意事项;.odbc.ini是数据源的核心文件,改文件的路径可以在dsenv配置文件中的ODBCINI变量中配置,该文件配置数据源连接的详细信息,如主机、数据库名、端口等信息。uvodbc.config文件配置数据源DSN信息,里面配置的DSN name必须和.odbc.ini的名称相同,该文件存在于项目目录下和$DSHOME目录下,默认项目首先查找和使用项目目录下的uvodbc.config文件,如果未找到则使用$DSHOME目录下uvodbc.config文件,所以使用时注意理解它们的作用和使用范围。通常配置完后建议在服务端中进行测试,然后再在客户端中开发使用,这样可以减少一些未知的错误问题。
–The end(2015-09-28)