21

I have to make DB2 connection in java using port number. Is there any command in DB2 or any way that can get the DB2 port number?

I have not used the default port 50000 while making DB2 connection as this port can be changed during DB2 installation. Please suggest any DB2 command or any other alternative.

AngocA
  • 7,655
  • 6
  • 39
  • 55
user628083
  • 353
  • 1
  • 5
  • 15

5 Answers5

33

On the Windows DB2 server, open a DB2 Command Window and execute the command

db2 get database manager configuration | findstr /i svce

This should provide some output like:

 TCP/IP Service name                          (SVCENAME) = db2c_DB2
 SSL service name                         (SSL_SVCENAME) =

SVCENAME is the port that DB2 is listening on. To resolve this name to an actual port number, you need to refer to the services file, which is located at %SystemRoot%\system32\drivers\etc\services.

Ian Bjorhovde
  • 10,916
  • 1
  • 28
  • 25
  • 3
    This only works for the current instance. It is necessary to attach to each instance in the server in order to know all ports for DB2 instances defined in the "services" file. – AngocA Feb 28 '12 at 00:34
  • @DurgadasKamath Care to elaborate? – Ian Bjorhovde Jan 21 '13 at 21:49
  • In the DB2 command editor that command gave me an error, but "get database manager configuration" (without leading "db" and without the piped command) worked. In there I could manually search for svcename. – MetalSnake Jul 04 '16 at 08:34
17

Go to DB2 command prompt.

Issue the command to get the db2 instance

Command : db2 get instance

Issue the command to find the TCP/IP service name

Command : db2 get dbm cfg | grep SVCE

Example

db2 get dbm cfg | grep SVCE

TCP/IP Service name (SVCENAME) = db2c_db2inst9 The TCP/IP service name is "db2c_db2inst9"

Use the TCP/IP service name to find the port number in the /etc/services file

Command : grep TCP/IPservicename /etc/services

Change TCP/IPservicename with the current service name.

Example

grep db2c_db2inst9 /etc/services

db2c_db2inst9 50090/tcp

The DB2 instance is running on the port number 50090

  • This worked for me just using: db2 get dbm cfg. Then reading down a little I saw my port, it was 50000. – Adam Jul 05 '16 at 14:16
9

On the Linux/Unix DB2 server, open a shell terminal and logon with the instance owner. Execute the below command:

        db2 "get dbm cfg"|grep -i svce

Like the answer of Ian Bjorhvde you show the TCP/IP Service name, SVCENAME you can view in the file /etc/service .

Dhanish Jose
  • 739
  • 1
  • 8
  • 19
  • This only works for the current instance. If is necessary to change to each instance in order to get the service name, and match it in the services file. – AngocA Feb 28 '12 at 00:35
3

Probably you have different instances in your server, that means, DB2 is listening in different ports. First, you have to list the instances in the server

db2ilist

You will get a set of instance names. For each one you have to get the port name

Windows

set DB2INSTANCE=instname
db2 get dbm cfg

Linux

export DB2INSTANCE=instname
db2 get dbm cfg

If you do not change the instance, you will only get the service name of the current instance. Another way to get that information from the client is via the Configuration Assistant (db2ca). With advanced view, you right click on an instance, and then you will get the details of the instance: port number, service name, etc.

AngocA
  • 7,655
  • 6
  • 39
  • 55
0

This will give the ports of all the db2 instance installed on the machine (for Linux or AIX systems)

netstat -aan | grep -i db2
Dhanish Jose
  • 739
  • 1
  • 8
  • 19