DB2 installation

From OpenVZ Virtuozzo Containers Wiki
Revision as of 14:45, 6 September 2007 by Elronxenu (talk | contribs) (Fixed grant command)
Jump to: navigation, search

DB2 has been certified by IBM for use inside Virtuozzo. It works in OpenVZ too!

IBM provides a free download of DB2 Express-C which is what I installed.

Here is a rough guide to installing DB2 into a freshly-created VE.

Create a new VE

I created a new VE for the Debian distribution using debootstrap.

Set VE resource limits appropriately

DB2 installation can fail and it will not be possible to operate the database if your resource limits are too low. I used these limits for a small database:

  • kmemsize to 10,000,000
  • privvmpages to 300,000
  • shmpages to 80,000
  • numproc to 150
  • tcpsndbuf to 700,000
  • tcprcvbuf to 700,000
  • diskspace to 6,000,000

Install additional packages

  • libstdc++5 (required for installation)
  • pdksh (required for operation?)
  • ssh (may be required for operation)
  • xbase-clients (for xauth)
  • firefox (for post-installation)
  • strace and telnet (for debugging)
  • libdbi-perl gcc libc6-dev make (for building CPAN DBD::DB2 package)

Download the DB2 Express-C package

DB2 Express-C version 9 is available from this page: [[1]]

You will need to register with IBM before you can download.

  • Untar the received file as root
  • Run exp/disk1/db2setup
  • Follow the prompts:
    • Setup user 'dasusr1'
    • Setup user 'db2inst1' and database instance 'db2inst1'

Post-install actions

This is where it gets yukky. DB2 wants to run a browser inside the VPS. It wants to run Java applets inside the browser. I installed Iceweasel, but the post-install script does not recognise it. I was eventually able to hack the script to recognise and use the browser but it crashed on one of the Java applets. I think you can get by without running the post-install.

Here's what to do instead:

First, su to the instance owner:

  • su - db2inst1

Try starting and stopping the database:

  • db2start
  • db2stop

If these don't work it means your environment variables are not set properly. IBM set these for me:

CLASSPATH=/home/db2inst1/sqllib/java/db2java.zip:/home/db2inst1/sqllib/java/db2jcc.jar:/home/db2inst1/sqllib/java/sqlj.zip:/home/db2inst1/sqllib/function:/home/db2inst1/sqllib/java/db2jcc_license_cu.jar:.
DB2INSTANCE=db2inst1
PATH=/usr/local/bin:/usr/bin:/bin:/usr/games:/home/db2inst1/sqllib/bin:/home/db2inst1/sqllib/adm:/home/db2inst1/sqllib/misc

Try creating IBM's sample database:

  • db2sampl

Setup a development environment

I develop in perl so I was most interested in access to the database though the DBI library. I did this:

  • Use CPAN to download and install DBD::DB2

If you don't use CPAN you can also do this (as root):

Setup DB2 for autostart

It seems that DB2 can be auto-started at VE boot time, but not auto-stopped. I used this script:

#!/bin/sh
#
# Script to start DB2 instances on bootup.
#

set -e

. /lib/lsb/init-functions

case "$1" in
start)
        echo Starting DB2
        /opt/ibm/db2/V9.1/instance/db2istrt
        ;;
stop)
        ;;
restart|reload)
        ;;
esac

exit 0

And I used this command to create the symlink to make it start at VE "boot" time:

update-rc.d db2 start 95 2 .

Testing your installation

From the db2inst1 user, do:

  • db2

Inside the db2 client, try:

connect to sample
grant dbadm on database to user fred
connect reset

Enjoy!

Please provide feedback in the discussion (Talk) page about improvements to this HOWTO.