Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Executing DB2 Commands from Command Line to Remote Server

Tags:

db2

I have two DB2 servers running Workgroup. For example, Server1 and Server2.

From Server2, at a command prompt I would like to run a SQL command against a known database on Server1.

Can someone explain to me exactly the steps I need to do in order to accomplish this. And do I simply use DB2ADMIN login for crendentials or do I need to setup some other login?

like image 686
user500741 Avatar asked Jun 20 '11 14:06

user500741


1 Answers

You need to catalog the Server1 database on Server2.

You haven't mentioned if the servers are Windows or *nix.

If the servers are *nix, you need to log in with a user that has the db2 executables loaded in it's .profile. (Check the .profile of the db2 instance owner if you are not sure).

If the servers are Windows, then you can log in as anybody that can see the IBM DB2 Program Group, and can open the DB2 Command Window or similar.

From the command line on Server2 you need to catalog Server1 as a TCPIP node. The doc is here. It will probably be something like this:

db2 catalog tcpip node server1 remote Server1 server 50000

Next you need to catalog the database on the node. The doc is here. It will probably be something like this:

db2 catalog database <dbname> at node server1

If you need to check the results of the commands, you can use LIST NODE DIRECTORY or LIST DATABASE DIRECTORY to see what db2 has cataloged.

Once you have done all that you should be able to connect to the database on Server1 from Server2 by:

db2 connect to <dbname> user <username> using <pwd>

Once the connection has been made you should be able to query the remote database.

This information will stay in the local db2 catalog unless you explicitly remove it. (You can verify that by logging out, logging back in and using LIST NODE DIRECTORY or LIST DB DIRECTORY). If you want to remove the entries, you can use the UNCATALOG DATABASE and UNCATALOG NODE commands.

like image 161
Michael Sharek Avatar answered Sep 27 '22 17:09

Michael Sharek