db2 database aliases

2 Physical databases

I need 2 Physical Databases, one called tim the other called shabib.

echo "create db tim"
db2 create database tim
echo "create db shabib"
db2 create database shabib

1 Table in each Database

I need a simple table with simple data in each Db

db2 connect to tim
db2 "drop table test"
db2 "create table test(id integer, name varchar(20))"
db2 "insert into test values(1,'tim')"
db2 "select * from test"
db2 connect to shabib
db2 "drop table test"
db2 "create table test(id integer, name varchar(20))"
db2 "insert into test values(2,'shabib')"
db2 "select * from test"

Alias Time

I tried for a long time to Uncatalog and to recatalog with an Anlias - and whilst the database was re-cataloged I could not connect to it.

However - I wondered if I just treated the Datbase as a remote connection - if it would work.

Before you see the script - some specific parameters

  • IP Address
    • 192.168.1.164
  • Machine Name
    • ii9

Ok so here is the script

Data pointing to Tim

db2 uncatalog node ii9
db2 catalog tcpip node ii9 remote 192.168.1.164 server 50000 
db2 terminate
db2 list node directory
db2 uncatalog database DATA
db2 terminate
db2 catalog database TIM as DATA at node ii9
db2 terminate
db2 connect to DATA user db2inst1 using passw0rd
db2 "Select * from test"

Testing ...

source data_as_tim.sh

You see

 1    Tim

Data Pointing to Shabib

db2 uncatalog node ii9
db2 catalog tcpip node ii9 remote 192.168.1.164 server 50000 
db2 terminate
db2 list node directory
db2 uncatalog database DATA
db2 terminate
db2 catalog database SHABIB as DATA at node ii9
db2 terminate
db2 connect to DATA user db2inst1 using passw0rd
db2 "Select * from test"

Testing ...

source data_as_shabib.sh

You see

 2    Shabib

Notes:

No idea why the Alias does not work ... it may be because I am using a Non-Production version of Db2.

We do not need to drop the node in the two scripts - but it is possibly cleaner to do this.