How to connect with a remote DB2 Server from anoth

2019-07-18 05:30发布

问题:

I have two instances on two separate AIX servers. Both DB2 databases are up with their sample databases. I want to connect with one DB2 instance from the other instance.

I am new on DB2 and want to know how can I do that.

I have executed following commands:

This path is client instance:

#.  /home/db2inst2/sqllib/db2profile
db2 catalog tcpip node db2serverinst remote lpar1 server 50005 remote_instance ctginst1
db2 => terminate
DB20000I  The TERMINATE command completed successfully.
# db2 connect to db2serverinst user ctginst1
Enter current password for ctginst1: SQL1031N  The database directory cannot be found on the indicated file system.
SQLSTATE=58031

回答1:

You have only cataloged DB2 instance. You need to catalog the database at the remote server:

db2 catalog database XXXX at node db2serverinst

Obviously, you'll need to replace the XXXX with the actual name of the remote database. Once you've cataloged the database, you can then connect:

db2 connect to XXXX user ctginst1

Note, this only defines the connection. You won't be able to access objects within this remote database from other databases within the local instance without configuring federation.



回答2:

The term "Connect to an instance" is not correct. The correct one is to attach:

Machine A
 db2inst1
  db-1
  db-2
  sample

Machine B
 db2inst2
  db-3
  db-4
  sample
 db2inst3
  sample

If you want to execute commands from Machine A into Machine B, you have to catalog db2inst2 AND/OR db2inst3 in db2inst1 (catalog tcpip node). Remember that you have to give different names to each cataloged object.

Once you have cataloged a remote instance, you could also issue database commands, but you have to catalog remote databases. You can have a remote sample, and a local sample, but alias should be different.

If you cataloged db2inst2 instance as db2inst2 node in local node from Machine A. And you cataloged sample database as sample-2 alias in local node from Machine A. You could execute in Machine A.

 db2 attach to db2inst2
 db2 connect to sample-2

Attach is for 'administrative' things, like list applciations, create db, etc. Connect is to use the database.



标签: db2