How to install a db2 database server and apply patches

Jephe Wu -  http://linuxtechres.blogspot.com

Objective: install IBM db2 version 8 on CentOS 4.4 server and apply patches
Environment: CentOS 4, IBM db2

 Total 5 parts

Part I - GUI Installation method


Steps:

1.  get the db2 installation file and patch file
2. extract these 2 tar file under /root/db2install directory
3.  ssh -X serverip (from a Linux machine X windows )
4. run command under /root/db2install
 ./db2setup
5. in preparing db2 tools catalog part, choose 'use a local database'
in 'set up the administration contact list', you might want to disable notification
in 'specify a contact for health monitor notification' choose 'defer this task until after installation is complete'
6. apply patches
run command './installfixpak -y' to apply patches
7. set parameters
$ db2set  (to display current settings)
$ db2set DB2AUTOSTART=YES
$ db2set DB2COMM=TCPIP
$ db2 update database manager configuration using svcename 50000
$ db2 update database manager configuration using diaglevel 4


8. Install license
login as root
cd /opt/IBM/db2/V8.1/adm
./db2licm -a 331_WSUE_LNX26_32_NLV/db2/license/db2wsue.lic


9. start up db2 database
su - db2inst1 ; db2start


Part II - CLI Installation method


Steps:
1. Install original DB2 package

# cd /usr/local/src
# cd db2srcfiles/
# cd 331_WSUE_LNX26_32_NLV/
# ./db2_install


if encounter some error regarding “libstdc++.so.5” not found, download compat-libstdc++-8-3.3.4.2.i386.rpm and install.


# db2level

2. Add groups and users and set passwords

#groupadd -g 101 dasadm1
#groupadd -g 102 db2grp1
#groupadd -g 103 db2fgrp1
# useradd -c "DB2 Admin" -d /db2/dasusr1 -g dasadm1 -m dasusr1
# useradd -c "DB2 Instance User" -d /db2/db2inst1 -g db2grp1 -m db2inst1
# useradd -c "DB2 Fenced User" -d /db2/db2fenc1 -g db2fgrp1 -m db2fenc1
# passwd db2inst1
# passwd db2fenc1
# passwd dasusr1


3. Post-install configuration
# cd /opt/IBM/db2/V8.1/instance/
# ./dascrt -u dasusr1 (create db2 administrator server)
# cd ../adm
# ./db2licm -a /usr/local/src/db2srcfiles/331_WSUE_LNX26_32_NLV/db2/license/db2wsue.lic
# cd ..
# cd instance/
# ./db2icrt -a SERVER_ENCRYPT -u db2fenc1 db2inst1 (create instance)
# su - db2inst1
# mkdir -p /db2log/db2inst1/logs
# chown db2inst1:db2grp1 -R /db2log/db2inst1/
# cd /db2log
# su – db2inst1
$ db2set
$ db2set DB2AUTOSTART=YES
$ db2set DB2COMM=TCPIP
$ db2 update database manager configuration using svcename 50000
$ db2 update database manager configuration using diaglevel 4
$ db2 terminate
$ db2start


4. create database
xterm
xhost +
export DISPLAY=:0
su – db2inst1
cd /db2/db2inst1/
mkdir –p db/db1
db2cc &
 

5. post-configuration of creating database

     * add the following to /db2/db2inst1/.bashrc
db2set DB2LINUXAIO=TRUE
db2set DB2_SCATTERED_IO=ON
db2set DB2COMM=tcpip
db2set DB2AUTOSTART=YES
db2set DB2_LGPAGE_BP=YES
(dangerous, can cause ‘shared memory cannot be allocated, referring to http://tldp.org/HOWTO/DB2-HOWTO/kernels.html for how to enable it, it requires some additional steps, not just enable it)

    *configuring database logging (right click database name, choose ‘configuring database logging’)
change circular logging to archive logging, and choose ‘manual archive log file handling’
change log patch to /db2log/db2inst1/db1/logs

    *check logretention
right click database, configure parameter, make sure logretention is set to recovery ( by default should be )

    *configuring db2inst1 cronjob to archive log every hour as follows:

0 * * * * /db2log/db2inst1/scripts/archive.sh

archive.sh

#!/bin/sh
. /db2/db2inst1/sqllib/db2profile
for DB in db1
do
db2 archive log for db $DB
done


    *right click the database in control center, configure parameters

change LOGSECOND(-1) and userexit(yes) to make the transaction log infinite
change LOGFILSIZ LOGPRIMARY APP_CTL_HEAP_SZ APPLHEAPSZ BUFFPAGE DBHEAP LOGBUFZ if necessary


Part III -   Uninstalling DB2 database


Note: steps 1 and 2 might cause to delete the whole /db2/db2inst1 directory which might not be your intention. So, be careful to do them.

   1.Remove the DAS by issuing the /opt/IBM/db2/V8.1/instance/dasdrop command as root.
   2.Remove the instance by issuing the /opt/IBM/db2/V8.1/instance/db2idrop db2inst1 command
   3. Run the db2_deinstall command as root.
   4.Remove the users that were created.
      userdel -r db2inst1
      userdel -r dasusr1
      userdel -r db2fenc1
      groupdel dasadm1
      groupdel db2grp1
      groupdel db2fgrp1
      rm –fr /var/db2
      rm –f /tmp/db2* (and other files related to DB2)
      vi /etc/inittab (remove the last line)

   5. (If you created different user names during installation, substitute as necessary.)
   6. Optionally, you can remove IBM's version of the Java 2 package that db2 installed.

rpm -e IBMJava2-SDK


Part IV - Installing db2 fix pack for live database


Su – root
Su - instancename

. $HOME/sqllib/db2profile
db2 force applications all
db2 terminate
db2stop
db2licd –end (run at each physical node)
exit
su – dasusr1
db2admin stop
exit
login as root
cd /opt/IBM/db2/V8.1/bin
./db2fmcu –d
su – dasusr1
/db2/dasusr1/das/bin/db2fm –i dasusr1 –D
su – db2inst1
/db2/db2inst1/sqllib/bin/ipclean

./installFixPack –y

login as root still
/opt/IBM/db2/V8.1/bin/instance/db2iupdt db2inst1
/opt/IBM/db2/V8.1/bin/instance/dasupdt dasusr1

su – db2inst1
db2start


Part V - Appendix

a. some commands

# list db directory
# list node directory
# catalog tcpip node db2 remote 10.0.0.1server 59000
# catalog database db1 as db1alias at node db2