Changing the DB2 hostname

SQL6031N  Error in the db2nodes.cfg file at line number "1".  Reason code "10".

DB2 caches your machine’s hostname in several places. If your machine is changing its hostname, or if you are somehow moving an existing installation to a machine with a different hostname, you will need to adjust the hostname stored by DB2. Hostname change is common in virtual and cloud environments, so even better than adjusting it would be writing a script that adjusts it for you.

Here’s my rudimentary stab at a such a script:

#!/bin/sh
echo -n "Discovering the new hostname "
UNAME_CACHE=$(uname -n)

echo -n "Adjusting hostname list for unconfigured database partitioning feature "
# this may need to be changed if DPF preconfigured
if [ -e /home/db2inst1/sqllib/db2nodes.cfg ]; then
    chmod 666 /home/db2inst1/sqllib/db2nodes.cfg
    su - db2inst1 -c "cp /home/db2inst1/sqllib/db2nodes.cfg /home/db2inst1/sqllib/db2nodes.cfg.old"
    su - db2inst1 -c "echo 0 $UNAME_CACHE 0 > /home/db2inst1/sqllib/db2nodes.cfg"
fi

echo -n "Making registry writable "
chmod 666 /var/db2/*

echo -n "Adjusting the DB2 hostname "
UNAME_CACHE=$(uname -n)
/opt/ibm/db2/V9.7/adm/db2set -g db2system=$UNAME_CACHE

echo -n "Updating DAS configuration "
# todo
# db2 uncatalog node 
db2 catalog admin tcpip node $UNAME_CACHE remote $UNAME_CACHE system $UNAME_CACHE
db2 update admin cfg using DB2SYSTEM $UNAME_CACHE
db2 update admin cfg using SMTP_SERVER $UNAME_CACHE

This doesn’t cover all cases. For example, if you use extended operating system security, you may also need to set the db2accountname and db2instowner parameters. A quick check with db2set -all should tell you if this applies in your case — if there is something that looks like a hostname in those parameters already, you need to change them.

I may also have missed other necessary changes. Please let me know if I did.:-)

References

3 thoughts on “Changing the DB2 hostname

  1. In 9.7, I am seeing a profile.env under /var/db2/global.reg. It has a DB2SYSTEM parameter — hopefully the same one that is changed by db2set. The actual file is binary rather than text, so I’d hesitate to munge it directly.

    Like

  2. Hi Leon, Thanks for posting this. I am new to DB2 but inherited this
    vCenter Server/DB2 9.5 EE appliance where we need to change the host
    name.

    I first run db2set -all to verify everything looks okay and my vCenter Server is still working with DB2.

    “db2set -all” returns the following:
    DB2ACCOUNTNAME=db2admin
    DB2INSTOWNER=

    After
    changing host name in db2node,cfg file, DB2 longer works. When I run
    db2set -all , it return no output. It just goes back to the command
    line. And I cannot reverse out and start DB2 again. My db2node.cfg looks
    like this:

    0 0

    Where else do I need to make changes besides db2node.cfg.

    Thanks for any help you can suggest.

    Like

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.