Sie sind auf Seite 1von 5

How to setup federation between two DB2 LUW databases

Guest Blogger Bella Kogan works on the DB2 LUW Technical support team and has over 10 years experience with
Databases.

The following example shows how to setup federation between two DB2 LUW databases.

I have two AIX servers:

Server 1 - Remote Data Source (server where the actual table resides)
--------

hostname: warehouse
db2level: v9.5
svcename: 21267
instance: db2inst1
password: ibmlab
db name : sample
tab name: test1
db2inst1@warehouse /home/db2inst1 > hostname
warehouse
db2inst1@warehouse /home/db2inst1 > db2level
DB21085I Instance "db2inst1" uses "64" bits and DB2 code release "SQL09052" with
level identifier "03030107".
Informational tokens are "DB2 v9.5.0.2", "s080911", "U820796", and Fix Pack
"2a".
Product is installed at "/home/db2inst1/sqllib".

db2inst1@warehouse /home/db2inst1 > db2 get dbm cfg | grep -i svcename


TCP/IP Service name (SVCENAME) = 21267

db2inst1@warehouse /home/db2inst1 > db2 create db sample


DB20000I The CREATE DATABASE command completed successfully.

db2inst1@warehouse /home/db2inst1 > db2 connect to sample


Database Connection Information
Database server = DB2/AIX64 9.5.2
SQL authorization ID = DB2INST1
Local database alias = SAMPLE
db2inst1@warehouse /home/db2inst1 > db2 "create table test1 (c1 int, c2 int)"
DB20000I The SQL command completed successfully.
db2inst1@warehouse /home/db2inst1 > db2 "insert into test1 values (13,32)"
DB20000I The SQL command completed successfully.

db2inst1@warehouse /home/db2inst1 > db2 "select * from test1"


C1 C2
----------- -----------
13 32
1 record(s) selected.

Server 2 - Federated database


--------
hostname: dss
db2level: v9.1
db2inst1@dss /home/db2inst1 > hostname
dss
db2inst1@dss /home/db2inst1 > db2level
DB21085I Instance "db2inst1" uses "64" bits and DB2 code release "SQL09015" with
level identifier "01060107".
Informational tokens are "DB2 v9.1.0.5", "s080512", "U815922", and Fix Pack
"5".
Product is installed at "/home/db2inst1/sqllib".
- federated dbm cfg has to be set to yes:
db2inst1@dss /home/db2inst1 > db2 update dbm cfg using federated yes
DB20000I The UPDATE DATABASE MANAGER CONFIGURATION command completed
successfully.
SQL1362W One or more of the parameters submitted for immediate modification
were not changed dynamically. Client changes will not be effective until the
next time the application is started or the TERMINATE command has been issued.
Server changes will not be effective until the next DB2START command.
db2inst1@dss /home/db2inst1 > db2stop
SQL1064N DB2STOP processing was successful.
db2inst1@dss /home/db2inst1 > db2start
SQL1063N DB2START processing was successful.

db2inst1@dss /home/db2inst1 > db2 get dbm cfg | grep -i federated


Federated Database System Support (FEDERATED) = YES
During setup, I'll perform the following:

- create db sample (federated db)


- catalog node tcpfed and remote db stsamp in order to connect to db sample on Server 1
- create drda wrapper
- create server sample_db
- create user mapping
- create nickname ntest1
At the end of setup, I'll have:

local db: sample


remote db: stsamp
node: tcpfed
wrapper: drda
server: sample_db
nickname: ntest1
Script
------
db2inst1@dss /home/db2inst1 > more fed_script
create db sample;
connect to sample;
catalog tcpip node tcpfed remote warehouse server 21267;
catalog db sample as stsamp at node tcpfed;
create wrapper drda;
create server sample_db type db2/udb version 9.5 wrapper drda authorization "db2inst1"
password "ibmlab" options (DBNAME 'stsamp');
create user mapping for db2inst1 server sample_db options (remote_authid 'db2inst1',
remote_password 'ibmlab');
create nickname ntest1 for sample_db.db2inst1.test1;
db2inst1@dss /home/db2inst1 > db2 -tvf fed_script
create db sample
DB20000I The CREATE DATABASE command completed successfully.
connect to sample
Database Connection Information
Database server = DB2/AIX64 9.1.5
SQL authorization ID = DB2INST1
Local database alias = SAMPLE

catalog tcpip node tcpfed remote warehouse server 21267


DB20000I The CATALOG TCPIP NODE command completed successfully.
DB21056W Directory changes may not be effective until the directory cache is
refreshed.
catalog db sample as stsamp at node tcpfed
DB20000I The CATALOG DATABASE command completed successfully.
DB21056W Directory changes may not be effective until the directory cache is
refreshed.
create wrapper drda
DB20000I The SQL command completed successfully.
create server sample_db type db2/udb version 9.5 wrapper drda authorization "db2inst1"
password "ibmlab" options (DBNAME 'stsamp')
DB20000I The SQL command completed successfully.
create user mapping for db2inst1 server sample_db options (remote_authid 'db2inst1',
remote_password 'ibmlab')
DB20000I The SQL command completed successfully.
create nickname ntest1 for sample_db.db2inst1.test1
DB20000I The SQL command completed successfully.
We're done here.

To verify setup:

db2inst1@dss /home/db2inst1 > db2 connect to sample


Database Connection Information
Database server = DB2/AIX64 9.1.5
SQL authorization ID = DB2INST1
Local database alias = SAMPLE

db2inst1@dss /home/db2inst1 > db2 "select * from ntest1"


C1 C2
----------- -----------
13 32
1 record(s) selected.
Here is what we have:

db2inst1@dss /home/db2inst1 > more fed_cat


list node directory;
list db directory;
list tables;
select substr(WRAPNAME,1,20) as WRAPNAME, WRAPTYPE, WRAPVERSION, substr(LIBRARY,1,20)
as LIBRARY from syscat.wrappers;
select substr(WRAPNAME,1,20) as WRAPNAME, substr(SERVERNAME,1,20) as SERVERNAME,
substr(SERVERTYPE,1,10) as SERVERTYPE, substr(SERVERVERSION,1,5) as SERVERVERSION from
syscat.servers;
select substr(WRAPNAME,1,20) as WRAPNAME, substr(SERVERNAME,1,20) as SERVERNAME,
CREATE_TIME, substr(OPTION,1,20) as OPTION, substr(SETTING,1,15) as SETTING,
SERVEROPTIONKEY from syscat.serveroptions;
select substr(AUTHID,1,20) as AUTHID, substr(SERVERNAME,1,20) as SERVERNAME,
substr(OPTION,1,20) as OPTION, substr(SETTING,1,15) as SETTING from
syscat.useroptions;
select substr(TABSCHEMA,1,15) as TABSCHEMA, substr(TABNAME,1,15) as TABNAME,
substr(OPTION,1,20) as OPTION, substr(SETTING,1,10) as SETTING from syscat.taboptions;
db2inst1@dss /home/db2inst1 > db2 -tvf fed_cat
list node directory
Node Directory
Number of entries in the directory = 1
Node 1 entry:
Node name = TCPFED
Comment =
Directory entry type = LOCAL
Protocol = TCPIP
Hostname = warehouse
Service name = 21267

list db directory
System Database Directory
Number of entries in the directory = 2
Database 1 entry:
Database alias = STSAMP
Database name = SAMPLE
Node name = TCPFED
Database release level = b.00
Comment =
Directory entry type = Remote
Catalog database partition number = -1
Alternate server hostname =
Alternate server port number =
Database 2 entry:
Database alias = SAMPLE
Database name = SAMPLE
Local database directory = /home/db2inst1
Database release level = b.00
Comment =
Directory entry type = Indirect
Catalog database partition number = 0
Alternate server hostname =
Alternate server port number =

list tables
Table/View Schema Type Creation time
------------------------------- --------------- ----- --------------------------
NTEST1 DB2INST1 N 2009-08-07-21.16.01.592070
1 record(s) selected.

select substr(WRAPNAME,1,20) as WRAPNAME, WRAPTYPE, WRAPVERSION, substr(LIBRARY,1,20)


as LIBRARY from syscat.wrappers
WRAPNAME WRAPTYPE WRAPVERSION LIBRARY
-------------------- -------- ----------- --------------------
DRDA R 0 libdb2drda.a
1 record(s) selected.

select substr(WRAPNAME,1,20) as WRAPNAME, substr(SERVERNAME,1,20) as SERVERNAME,


substr(SERVERTYPE,1,10) as SERVERTYPE, substr(SERVERVERSION,1,5) as SERVERVERSION from
syscat.servers
WRAPNAME SERVERNAME SERVERTYPE SERVERVERSION
-------------------- -------------------- ---------- -------------
DRDA SAMPLE_DB DB2/UDB 9.5
1 record(s) selected.
select substr(WRAPNAME,1,20) as WRAPNAME, substr(SERVERNAME,1,20) as SERVERNAME,
CREATE_TIME, substr(OPTION,1,20) as OPTION, substr(SETTING,1,15) as SETTING,
SERVEROPTIONKEY from syscat.serveroptions
WRAPNAME SERVERNAME CREATE_TIME OPTION
SETTING SERVEROPTIONKEY
-------------------- -------------------- -------------------------- -----------------
--- --------------- ------------------
- SAMPLE_DB 2009-08-07-21.16.01.518298
DBNAME stsamp SQL090807211601518
1 record(s) selected.

select substr(AUTHID,1,20) as AUTHID, substr(SERVERNAME,1,20) as SERVERNAME,


substr(OPTION,1,20) as OPTION, substr(SETTING,1,15) as SETTING from syscat.useroptions
AUTHID SERVERNAME OPTION SETTING
-------------------- -------------------- -------------------- ---------------
DB2INST1 SAMPLE_DB REMOTE_AUTHID db2inst1
DB2INST1 SAMPLE_DB REMOTE_PASSWORD ********
2 record(s) selected.

select substr(TABSCHEMA,1,15) as TABSCHEMA, substr(TABNAME,1,15) as TABNAME,


substr(OPTION,1,20) as OPTION, substr(SETTING,1,10) as SETTING from syscat.taboptions
TABSCHEMA TABNAME OPTION SETTING
--------------- --------------- -------------------- ----------
DB2INST1 NTEST1 SERVER SAMPLE_DB
DB2INST1 NTEST1 REMOTE_SCHEMA DB2INST1
DB2INST1 NTEST1 REMOTE_TABLE TEST1
3 record(s) selected.

Das könnte Ihnen auch gefallen