Thursday, September 24, 2015

Changing hostname of the DB2 server. What updates in DB2 need to be made?

Changing hostname of the DB2 server. What updates in DB2 need to be made?

In general you will get the following error if you change your hostname:
db2 => list database directory

 System Database Directory

 Number of entries in the directory = 1

Database 1 entry:

 Database alias                       = UNICADB
 Database name                        = UNICADB
 Local database directory             = /apps/db2data/unicadb
 Database release level               = 10.00
 Comment                              =
 Directory entry type                 = Indirect
 Catalog database partition number    = 0
 Alternate server hostname            =
 Alternate server port number         =

db2 => drop database UNICADB
SQL1031N  The database directory cannot be found on the indicated file system.
SQLSTATE=58031
db2 => quit
DB20000I  The QUIT command completed successfully.
[db2inst1@rhel65dbs ~]$ db2 "connect to unicadb"
SQL1031N  The database directory cannot be found on the indicated file system.
SQLSTATE=58031
[db2inst1@rhel65dbs ~]$ db2start
09/24/2015 23:36:20     0   0   SQL6048N  A communication error occurred during START or STOP DATABASE MANAGER processing.
SQL1032N  No start database manager command was issued.  SQLSTATE=57019

 Here's a good link on what to do. And another link to troubleshoot.

For me, here's what I did:

0. Login as db2inst1 and shutdown
db2stop

1. Login as root:
[root@rhel65dbs sqllib]# db2set -g DB2SYSTEM=rhel65dbs.local.com
[root@rhel65dbs sqllib]# db2set -g
DB2SYSTEM=rhel65dbs.local.com
DB2INSTDEF=db2inst1
DB2ADMINSERVER=dasusr1
[root@rhel65dbs sqllib]# uname -a
Linux rhel65dbs.local.com 2.6.32-431.el6.x86_64 #1 SMP Sun Nov 10 22:19:54 EST 2013 x86_64 x86_64 x86_64 GNU/Linux

2. Locate db2nodes.cfg in one of the following directories:
UNIX/Linux:
<db2 instance home directory>/sqllib/db2nodes.cfg
3. In the db2nodes.cfg file change <current hostname> to <new hostname>.
4. Login as db2inst1 and verify:
[root@rhel65dbs sqllib]# su - db2inst1
[db2inst1@rhel65dbs ~]$ db2set -g
DB2SYSTEM=rhel65dbs.local.com
DB2INSTDEF=db2inst1
DB2ADMINSERVER=dasusr1
5. Startup and connect:
[root@rhel65dbs sqllib]# su - db2inst1
[db2inst1@rhel65dbs ~]$ db2start
09/25/2015 00:09:06     0   0   SQL1063N  DB2START processing was successful.
SQL1063N  DB2START processing was successful.
[db2inst1@rhel65dbs ~]$ db2 "connect to unicadb"

   Database Connection Information

 Database server        = DB2/LINUXX8664 10.5.3
 SQL authorization ID   = DB2INST1
 Local database alias   = UNICADB


A useful list of IBM DB2 commands

https://wiki.base22.com/display/btg/A+useful+list+of+IBM+DB2+commands

List all databases in an instance

1. LIST DATABASE DIRECTORY

db2 => list database directory

 System Database Directory

 Number of entries in the directory = 1

Database 1 entry:

 Database alias                       = UNICADB
 Database name                        = UNICADB
 Local database directory             = /apps/db2data/unicadb
 Database release level               = 10.00
 Comment                              =
 Directory entry type                 = Indirect
 Catalog database partition number    = 0
 Alternate server hostname            =
 Alternate server port number         =


2. LIST ACTIVE DATABASES
    (An active database is available for connection and use by any application)

db2 => list active database
SQL0104N  An unexpected token "database" was found following "ACTIVE". 
Expected tokens may include:  "DATABASES".  SQLSTATE=42601
db2 => list active databases

                           Active Databases

Database name                              = UNICADB
Applications connected currently           = 1
Database path                              = /apps/db2data/unicadb/db2inst1/NODE0000/SQL00001/MEMBER0000/