您的位置:首页 > 数据库

[DB2]联邦数据库访问远程DB2

2009-08-12 11:03 323 查看
联邦数据库访问远程DB2
假定两个环境host1和host2

host1,本机
IP: 192.168.1.192
DB2 instance: db2inst1
DB2 db: local_db

host2,远程被访问机器
IP: 192.168.1.195
DB2 instance: db2inst1(port=50000,pwd=db2inst1)
DB2 db: remote_db
table: t_usertable

现在需要在host1的local_db数据库中访问远程host2上的表t_usertable

首先需要在host1上把host2节点和remote_db库编目进来
db2 catalog tcpip node node_195 remote 192.168.1.195 server 50000
db2 catalog db remote_db as remote_db_195 at node node_195
db2 TERMINATE (必须使用该命令否则可能导致catalog更新不能生效)

然后在host1上测试到host2的连通性
db2 connect to remote_db_195 user db2inst1 using db2inst1
db2 connect reset

修改host1和host2的实例配置参数,需要重起实例
db2 update dbm cfg using FED_NOAUTH yes
db2stop
db2start

然后连接到host1机器上的local_db数据库中
db2 connect to local_db

(本地为unix环境)create wrapper DRDA;
(本地为windows环境) create wrapper "DRDA" LIBRARY 'db2drda.dll' OPTIONS( ADD DB2_FENCED 'N');

create server remoteserver_195 TYPE DB2/UDB VERSION '8.2' WRAPPER DRDA AUTHORIZATION "db2inst1" PASSWORD "db2inst1" OPTIONS( DBNAME 'remote_db_195', PASSWORD 'Y');
CREATE USER MAPPING FOR "db2inst1" SERVER remoteserver_195 OPTIONS ( ADD REMOTE_AUTHID 'db2inst1', ADD REMOTE_PASSWORD 'db2inst1');
CREATE NICKNAME remote_t_usertable FOR remoteserver_195.db2inst1.t_usertable;
(其中,wrapper使用DB2数据源的缺省名称DRDA server名称是remoteserver_195,t_usertable表在local_db数据库中的nickname是remote_t_usertable)

在缺省的db2inst1模式下 然后可以在host1机器上,登陆进local_db,对remote_t_usertable表进行查询等操作了
db2 'select * from db2inst1.remote_t_usertable'
db2 connect reset
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: