This appendix describes the necessary steps to stop and start a DB2 instance. There are many ways to stop and start a DB2 instance, but the following steps will guide you to stop a DB2 instance to ensure that any defunct DB2 processes, interprocess communications, and defunct DARI processes have been removed successfully.
Current configuration:
Instance: | db2inst1 |
Database: | sample |
Server: | phantom |
Stop the DB2 instance.
Check existing applications that are currently connected to the database by logging on to phantom server as DB2 instance owner db2inst1:
$ db2 list applications Auth Id Appl. Name Appl.. Handle Appl. Id DB Name # of Agents ------- ---------- ------------- ---------------------------- ------- ----------- DB2INST1 db2bp 207 *LOCAL.db2inst1.010824003917 SAMPLE 1 DB2INST1 java 276 CCF21FFC.E5D8.010829004049 SAMPLE 1 DB2INST1 java 51 CCF21FFC.E5D9.010829004051 SAMPLE 1
If there is any application connected to the database, you can tell who is currently connected and from which location they are connected. In this case, there is one local connection from db2inst1 user ID, and there are two remote connections from IP address: 204.242.31.252 converted from hex to decimal: CCF21FFC.
For remote connections, after you get the IP address, you can get the hostname by issuing the nslookup command:
$ /usr/sbin/nslookup 204.242.31.252 Server: charter.phantom.com Address: 204.242.31.83 Name: phantom.phantom.com Address: 204.242.31.252
If there are any applications connected to the database, verify that they are not currently executing:
$ db2 list applications show detail | egrep ?i "executing|pending"
If there are applications executing or pending, you can now force them off. Then verify to make sure there is no application connected to the database. If you see the following message, you're ready to stop the DB2 instance:
$ db2 force application all DB20000I The FORCE APPLICATION command completed successfully. DB21024I This command is asynchronous and may not be effective immediately. $ db2 list applications SQL1611W No data was returned by Database System Monitor. SQLSTATE=00000
Now you can stop the DB2 instance. When you get the message "SQL1064N DB2STOP processing was successful" you're ready to do the next step. If you get the message below, you must start this step again:
$ db2stop SQL1025N The database manager was not stopped because databases are still active.
LAST RESORT. If for some reason you cannot stop the DB2 instance or DB2 commands are hung, you must run this utility to remove the DB2 engine and client's IPC resources for that instance. This is your lifesaver:
$ ipclean ipclean: Removing DB2 engine and client's IPC resources for db2inst1.
Stop the DB2 Administration Server instance.
Skip this step if DB2 Admin instance is not running; otherwise, execute this command:
$ db2admin stop
Remove defunct DARI processes, DB2 background processes, or other defunct threads.
List all DB2 processes for this instance:
$ ps ?ef | grep db2 db2as 23797 23796 0 Aug 28 ? 0:00 db2sysc db2as 23800 23798 0 Aug 28 ? 0:00 db2sysc db2inst1 22229 1 0 13:08:01 pts/5 0:00 /db2/dbhome/db2inst1/sqllib/bin/db2bp 20580 5 db2as 23802 23797 0 Aug 28 ? 0:00 db2sysc db2as 23801 23797 0 Aug 28 ? 0:00 db2sysc db2as 23799 23797 0 Aug 28 ? 0:00 db2sysc
From the list above, we notice that there are processes belonging to the DB2 Admin services instance, so you must leave them alone. There is only one process that belongs to db2inst1, and that is a DB2 background process that did not get cleaned up after executing ipclean. Get the PID number and kill that process:
$ kill ?9 22229
Most of the time, you will see many defunct processes, and to save time, you should execute the following command instead of executing the kill -9 ${PID} command many times:
$ ps ?ef | grep db2inst1 | awk '{print "kill ?9 "$2}' > /tmp/kpid $ chmod +x /tmp/kpid $ /tmp/kpid
Verify that no defunct processes are left. Repeat this step if necessary:
$ ps ?ef | grep db2inst1
Remove defunct interprocess communication segments.
List all memory segments:
$ ipcs ?am | grep db2inst1 IPC status from <running system> as of Thu Aug 30 13:16:55 2001 T ID KEY MODE OWNER GROUP Shared Memory: m 9910 0x74006380 --rw-rw-rw- db2inst1 db2grp m 59714 0x61006380 --rw------- db2inst1 db2grp
From the list above, you notice that there are two memory segments that were not removed when executing ipclean. You must remove them manually:
$ ipcrm ?m 9910 $ ipcrm ?m 59714
List all semaphore segments:
$ ipcs ?as | grep db2inst1 IPC status from <running system> as of Thu Aug 30 13:16:55 2001 T ID KEY MODE OWNER GROUP Shared Memory: s 1900549 0x74006380 --ra-ra-ra- db2inst1 db2grp 1 s 1310727 00000000 --ra-ra---- db2inst1 db2grp 1 s 2031624 0x73006380 --ra-ra-ra- db2inst1 db2grp 1
From the list above, notice that there are three semaphore segments that were not removed after executing ipclean. You must remove them manually:
$ ipcrm ?s 1900549 $ ipcrm ?s 1310727 $ ipcrm ?s 2031624
List all message queue segments:
$ ipcs ?aq | grep db2inst1 IPC status from <running system> as of Thu Aug 30 13:16:55 2001 T ID KEY MODE OWNER GROUP Shared Memory: q 1572868 0x01dadd16 -Rrw------- db2inst1 db2grp 65535 q 901125 0x01eba5ed --rw------- db2inst1 db2grp 65535 q 1609739 00000000 --rw------- db2inst1 db2grp 65535 q 659468 00000000 -Rrw------- db2inst1 db2grp 65535
From the list above, notice that there are four message queue segments that were not removed after executing ipclean. You must remove them manually:
$ ipcrm ?q 1572868 $ ipcrm ?q 901125 $ ipcrm ?q 1609739 $ ipcrm ?q 659468
Verify that there are no defunct interprocess communications left. Repeat this step if necessary:
$ ipcs ?a | grep db2inst1
Before you start the DB2 instance, it is best practice to back up the previous db2diag.log, any event logs, notification log, and the associated trap files, and start with a fresh copy.
Move the current db2diag.log to the backup directory:
$ mkdir ?p /db2/backup/db2inst1/diaglogSep12 $ cd /db2/dbhome/db2inst1/sqllib/db2dump $ mv db2diag.log /db2/backup/db2inst1/diaglogSep12/ $ mv db2eventlog* /db2/backup/db2inst1/diaglogSep12/ $ mv db2inst1.nfy /db2/backup/db2inst1/diaglogSep12/ $ touch db2diag.log db2inst1.nfy db2eventlog.nnn where nnn is the database partition number $ chmod 666 db2diag.log db2inst1.nfy db2eventlog.*
If there are any trap files, group them together:
$ cd /db2/dbhome/db2inst1/sqllib/db2dump $ tar ?cvf /db2/backup/db2inst1/diaglog/trapAug292001.tar t* c* l* [0-9]*
Or execute this keepDiagLog.sh script:
#!/bin/ksh # # Clean up db2diag.log, trap files, dump files, etc # # Usage: keepDiagLog.sh # # Execute as DB2 instance owner # LOGTIME=`date '+%y%m%d%H%M%S'` DIAGDIR=${HOME}/sqllib/db2dump typeset instname=${1-db2inst1} typeset ROOTDIR=${2-/dbbackup} typeset dbname=${3-sample} typeset OLDDIR=${4-${ROOTDIR}/${instname}/${dbname}/db2diag${LOGTIME}} mkdir ?p ${OLDDIR} cd ${DIAGDIR} cp ?r * ${OLDDIR}/ for j in `ls` do if [ -d "${j}" ]; then rm ?r ${j} else rm ${j} fi done touch db2diag.log ${instname}.nfy chmod 666 db2diag.log ${instname}.nfy exit 0 # You need to add the steps for the event log files based on the # number of database partitions defined on your server.
Now you're ready to start the DB2 instance.
Start the DB2 instance:
$ db2start SQL1063N DB2START processing was successful.
And you're ready to start the DB2 Admin instance.
Start the DB2 Admin instance:
$ db2admin start
Verify the database connection.
Connect to the sample database:
$ db2 connect to sample Database Connection Information Database server = DB2/SUN 8.1.0 SQL authorization ID = DB2INST1 Local database alias = SAMPLE
Disconnect from the sample database:
$ db2 terminate
Reactivate the database to improve performance.
Activate the sample database:
$ db2 activate database sample DB20000I The ACTIVATE DATABASE command completed successfully.