Thursday, February 13, 2014

Catalog a DB2 database

Aim : Need to access a remote database as local database on the server that i currently reside on. For this we need to catalog the database

Works on : Machine having db2 server or client sotware installed on it

Its a two step process First catalog node then catalog database.

Catalog Node   - This puts an entry into node directory.
Catalog Database - This puts an entry into local database directory.

Syntax

db2 catalog tcpip node <NODENAME> remote <REMOTE> server <PORT>

use can use any name for <nodename>, this is just for indetification purpose.
use the ip address or hostname of the target machine for <remote> parameter.
use port number on which the db2 server is listening to <PORT> for allowing incoming connections.

To get the ip address of machine, use command - ifconfig -a
To get the hostname or machine name, use command - hostname
To get the port number to which db2 server is listening to, use command - db2 get dbm cfg | grep SVCE 
SVCENAME is the service name of db2, which we need to match this services files in /etc/services to get the respective port number for the service name(SVCENAME) 


this is example of matching SVCENAME to respective portnumber in /etc/services file

db2inst1@test-machine:~$ db2 get dbm cfg | grep SVCE
 TCP/IP Service name                          (SVCENAME) = db2c_db2inst1
 SSL service name                         (SSL_SVCENAME) = 
db2inst1@test-machine:~$ 
db2inst1@test-machine:~$ cat /etc/services | grep db2c_db2inst1
db2c_db2inst1 50001/tcp

db2 catalog database <dbname> as <aliasname> at node <nodename>

use database name for <dbname> you can also put an alias name for that database using <aliasname> if you dont want any such just ignore it.
user node name that is defined in the first command <nodename>

Always make sure to check the connectivity to the database, that how its shown below.

db2inst1@test-machine:~$ db2 connect to test1 user murali using murali

   Database Connection Information

 Database server        = DB2/LINUXX8664 9.7.6
 SQL authorization ID   = MURALI
 Local database alias   = TEST1

No comments:

Post a Comment