Install and Configure DB Link to DB2 Database in Linux
This document provides step by step instructions to install IBM DB2 Driver 9.1 for ODBC and CLI for Linux 64bit
Prerequisites:
· Oracle Database Gateway for ODBC is installed
· unixODBC is installed
# rpm -q unixODBC
unixODBC-2.2.11-7.1
unixODBC-2.2.11-7.1
# rpm -q unixODBC-devel
unixODBC-devel-2.2.11-7.1
unixODBC-devel-2.2.11-7.1
Installing IBM DB2 Driver for ODBC and CLI
There is no installation program for the IBM DB2 Driver for ODBC and CLI. You must install the driver manually
1. Login as Oracle user
#su - oracle
2. Create the directory /u01/app/orcbin/db2_odbc_driver, where you will install the driver.
$ mkdir –p /u01/app/orcbin/db2_odbc_driver
$ cd /u01/app/orcbin/db2_odbc_driver
3. Locate the compressed file that contains the driver /u01/install/Linux-64_11gR1/db2_client/v9fp6a_linuxx64_db2driver_for_odbc_cli.tar
4. Copy v9fp6a_linuxx64_db2driver_for_odbc_cli.tar to the install directory, /u01/app/orcbin/db2_odbc_driver.
$ cp /u01/install/Linux-64_11gR1/db2_client/v9fp6a_linuxx64_db2driver_for_odbc_cli.tar /u01/app/orcbin/db2_odbc_driver/
5. Uncompress v9fp6a_linuxx64_db2driver_for_odbc_cli.tar:
$ tar -xvf v9fp6a_linuxx64_db2driver_for_odbc_cli.tar
Configuring IBM DB2 Driver for ODBC and CLI
1. Add the following to the beginning of the db2cli.ini. Be sure to add an extra blank line at the end of the ini file. The file is readonly, use :wq! to save it.
$ vi clidriver/cfg/db2cli.ini
[COMMON]
Trace=0
TracePathName=/u01/app/orcbin/db2_odbc_driver/clidriver/trace/
TraceComm=1
TraceFlush=1
TraceTimeStamp=1
[MYDB2]
Database=MYDB2
Hostname=mydb2.gotodba.com
Port=50000
Protocol=TCPIP
2. Configure ODBC.ini
$ su – root
# vi /etc/odbc.ini
[ODBC Data Source]
MYDB2=IBM DB2 ODBC DRIVER
[WBBURT1]
Driver=/u01/app/orcbin/db2_odbc_driver/clidriver/lib/libdb2.so
Description=MYDB2 DB2 ODBC Database
3. Test DB2 ODBC connectivity
# isql -v MYDB2 userid password
+---------------------------------------+
| Connected! |
| |
| sql-statement |
| help [tablename] |
| quit |
| |
+---------------------------------------+
SQL> quit
Configuring Oracle Database Gateway for ODBC
http://download.oracle.com/docs/cd/B28359_01/gateways.111/b31042/configodbc.htm#CIHFEGDA
1. Configure the Gateway Initialization Parameter File. For Oracle RAC database HRDCSTG, the initial parameter GLOBAL_NAMES = true, DB_Domain = mycompany.com, which enforce that database links have same name as remote database. So in the initMYDB2.ora, HS_DB_NAME and HS_DB_DOMAIN parameters have to be set.
# su – oracle
$ cd $ORACLE_HOME/hs/admin
$ cp initdg4odbc.ora initMYDB2.ora
$ vi initMYDB2.ora
# HS init parameters
#
HS_FDS_CONNECT_INFO = MYDB2
HS_FDS_TRACE_LEVEL = 0
HS_FDS_SHAREABLE_NAME = /u01/app/orcbin/db2_odbc_driver/clidriver/lib/libdb2.so
HS_DB_NAME = MYDB2
HS_DB_DOMAIN = GOTODBA.COM
#
# ODBC specific environment variables
#
set ODBCINI = /etc/odbc.ini
#
# Environment variables required for the non-Oracle system
#
#set =
2. Configure Oracle Net for the Gateway
$ cd $ORACLE_HOME/network/admin
$ vi listener.ora
# Append the following lines
SID_LIST_LISTENER_NYCDB01=
(SID_LIST=
(SID_DESC=
(SID_NAME = MYDB2)
(ORACLE_HOME = /u01/app/orcbin/oracle/product/11.1.0/db_1)
(PROGRAM = dg4odbc)
(ENVS=LD_LIBRARY_PATH=/u01/app/orcbin/db2_odbc_driver/clidriver/lib:/u01/app/orcbin/oracle/product/11.1.0/db_1/lib)
)
)
$ vi tnsname.ora
# Append the following lines
MYDB2 =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = nycdb01-vip.gotodba.com)(PORT = 1521))
(ADDRESS = (PROTOCOL = TCP)(HOST = nycdb02-vip.gotodba.com)(PORT = 1521))
)
(CONNECT_DATA =
(SERVICE_NAME = MYDB2)
)
(HS = OK)
)
3. Restart Listner
$lsnrctl reload
Create DB Link in the Oracle database
Login to the database as sys,
CREATE PUBLIC DATABASE LINK MYDB2
CONNECT TO userid
IDENTIFIED BY password
USING 'MYDB2';
Note:
Oracle RAC database ORCL, the initial parameter GLOBAL_NAMES = true, DB_Domain = gotodba.com, the above command will create db link MYDB2.gotodba.com, the db link name has to match initMYDB2.ora HS_DB_NAME. HS_DB_DOMAIN