datori

Database administration for fun and profit

Automatic startup and shutdown of DB2 instances on Linux

The default approach to enabling automatic startup of DB2 instances on Linux operating systems relies on the DB2 Fault Monitor. During the installation a line like this:

fmc:2345:respawn:/opt/IBM/db2/V8.1/bin/db2fmcd #DB2 Fault Monitor Coordinator

is added to the /etc/inittab file. The fault monitor then takes care of starting and restarting the instances which were enabled for autostart by db2iauto on.

There seem to be several problems with that approach. Firstly, the use of /etc/inittab to start programs is deprecated in the modern Linux versions. Secondly, one may want to have a more flexible tool to manage the lifecycle of DB2 instances on the system, such as that provided by the System V init scripts.

I’ve created a couple of scripts — one for the Red Hat Linux, another for SuSE — that can be used in place of the default startup control. They can be downloaded from GitHub.

The installation is easy: drop the appropriate for your server version of the script into /etc/init.d, naming it “db2”. Change the file permissions to allow execution. Run chkconfig --add db2 to enable it.

At this point the scripts respond to three commands: start, stop, and status.

The start command causes the script to check all instances listed in the DB2 global registry file and start those for which the startatboot flag is set to “1”.

The stop command, on the other hand, will stop all running DB2 instances, regardless of their startatboot flag value.

To modify the flag you can use the command:

db2greg -updinstrec instancename=db2inst1!startatboot=0

Obvisously, you’ll need to replace “db2inst1” with your instance name. Set the flag to “1” to enable autostart; set it to “0” to disable it.

For more information on the global registry file and the db2greg utility check the manual, as always. Running db2greg -h also provides much useful information.

2 Responses to Automatic startup and shutdown of DB2 instances on Linux

  1. BT Humble says:

    Thanks for this, it’s been very helpful. I’ve managed to make it work on Debian as well, which required the following minor changes:

    1. Copy the db2_rhel script to db2_deb
    2. Edit db2_deb, comment out line #51 (# . /etc/init.d/functions)
    3. Install the service
    su root
    cp ./db2_deb /etc/init.d/db2
    chmod 755 /etc/init.d/db2
    update-rc.d db2 defaults
    4. Run the service functions as described above
    service db2 start
    service db2 status
    service db2 stop

  2. John Croson says:

    I found that db2_rhel needed to be modified where it checks for database instances:

    Changed Line 55 from:
    $DB2_INSTALL_PATH/bin/db2greg -dump | grep -E ‘^I,DB2’ | \

    To:
    $DB2_INSTALL_PATH/bin/db2greg -dump | grep -a –text ‘^I,DB2’ | \

    Evidently it was actually returning “Binary file (standard input) matches” and not the text version.

Leave a Reply

Your email address will not be published. Required fields are marked *