Just Install?

So, I figured I would write a new post specifically for installing the latest DB2 Express-C on OpenSuSE as I had a bit of difficulty.

Ultimately, the path to success includes just following along the normal install (e.g. what I have automated below, changing yum and RH package names to zypper and SuSE package names) with 1 exception:

  • db2prereqcheck

db2prereqcheck

Running db2prereqcheck will always crash. Attempting to debug expc/db2/linuxadm64/bin/db2prereqcheck_exe shows that it is trying to compare a minimum version for SuSE, passing “42.2 “ into atoi and then crashing in ____strtoll_l_internal.

After tring to get it work by chaning values in /etc/os-release and /etc/SuSE-release, I just gave up and commented out the call to db2prereqcheck_exe in expc/db2/linuxadm64/bin/db2prereqcheck.

And, that’s it! Enjoy DB2, and make sure to follow my db2profile and zsh post if you use zsh!

Comment and share

Fotolia_70774541_XS.jpg

Yea yea, I’m on a DB2 blog kick tonight. I’ve been a fan of DB2 for a long time and it’s about time I posted some of this!

What’s the goal?

Simple:

  • install DB2 (rootless)
  • configure it
  • configure fault monitors
  • setup autostart

That’s it!

What do I need?

This particular script assumes CentOS 7. To test it out, you can create a quick CentOS 7 VM, or spin up a droplet on DigitalOcean if you wish.

Note: make sure you have your host properly defined in /etc/hosts

Oh, and you should probably download DB2 Express-C while you’re at it.

Just get on with it!

Fine!

Ok, so a few points:

  • The script is a combination of @angoca‘s work on getting DB2 into Docker (https://github.com/angoca/db2-docker), and some of my own additions (like enabling the fault monitor).
  • The script must be run as root (which it will validate in lines 3-7)
  • The script will validate that you defined your hostname in /etc/hosts (lines 9-14)
  • This will be a rootless install, and the instance owner will be db2inst1
  • For testing, I like to make myself an instance owner (probably not best practice, but in the context of a development environment I’m fine with it) (line 23)
  • Lines 25-40 ensure needed packages are installed
  • Line 46 actually installs DB2
  • Lines 49-52 make some tweaks to the configuration (e.g. port, OS authentication, etc.)
  • Line 57 configures DB2 with our tweaks, and also enables TCP communication to the database
  • Lines 60-84 configure auto-start and the fault monitors
  • Lines 88-94 do some cleanup, then prompt to reboot

What do I do next?

With DB2 installed, all of my database user setup, database creation, table creation, etc. are all automated. Maybe in another post I’ll explain that.

Oh, and if you are using zsh, see my post on getting db2profile to work with zsh at http://www.craigstjean.com/2016/03/db2profile-and-zsh/

Are you a DBA and did I do something wrong? Let me know! I’ll get it fixed so I don’t direct someone the wrong way

Comment and share

db2profile and zsh

in DB2
Fotolia_52415534_XS.jpg

What?

To leverage DB2 commands from a *nix environment, you typically append the following to your shell profile script:

1
. /path/to/db2/sqllib/db2profile

But, if you try that in zsh, you get the lovely errors:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
zsh: awk: command not found...
AddRemoveString:12: command not found: awk
zsh: sed: command not found...
AddRemoveString:14: command not found: sed
zsh: sed: command not found...
AddRemoveString:18: command not found: sed
zsh: awk: command not found...
AddRemoveString:12: command not found: awk
zsh: sed: command not found...
AddRemoveString:14: command not found: sed
zsh: sed: command not found...
AddRemoveString:18: command not found: sed
zsh: awk: command not found...
AddRemoveString:12: command not found: awk
zsh: sed: command not found...
AddRemoveString:14: command not found: sed
zsh: sed: command not found...
AddRemoveString:18: command not found: sed
zsh: awk: command not found...
AddRemoveString:12: command not found: awk
zsh: sed: command not found...
AddRemoveString:14: command not found: sed

And worse, you completely lost everything in $PATH. Due to differences between the Bourne shell and the Z shell, the AddRemoveString function in db2profile splits your path variables in a way it can’t recombine.

So how can I fix it?

Luckily, there’s an easy fix I’ve come up with. First, I copy db2profile to db2profile.zsh, then towards the bottom of AddRemoveString I add a line that replaces the newlines in the path variable with the correct delimiter:

In the end, it looks like this:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
AddRemoveString()
{
if [ $# -ne 3 ]; then
return 0
fi
var=$1 #The enviornment variable to be processed
addrm_str=$2 #The new path to be used
action=$3 #Action: a -> add, r -> remove
if [ "X${action?}" != "Xa" -a "X${action?}" != "Xr" ]; then
return 0 # return without doing anything
fi
awkval='$1 != "'${addrm_str?}'"{print $0}'
newval=`eval echo \\${$var:-""} | awk '{for (i=1; i<= NF; ++i) \
if( $i != VAR && length($i) > 0 ) print $i":"}' FS=":" VAR=${addrm_str?}`
newval=`echo ${newval?} | sed 's/\: /\:/g'`
if [ "X${action?}" = "Xa" ]; then
newval=${newval?}"${addrm_str?}"
else
newval=`echo ${newval?} | sed 's/:$//'`
fi
+ newval=`echo ${newval?} | tr '\n' ':'`
eval $var=\"${newval?}\"
unset var addrm_str awkval newval
}

That line marked with a + is the line added (make sure to remove the + if you copy/paste).

Then, just update your .zshrc with:

1
. /path/to/db2/sqllib/db2profile.zsh

That’s it!

Comment and share

  • page 1 of 1

Craig St. Jean

Father, programmer, constant learner, @pluralsight author


Software Architect