My last contact with IBM Db2 was more than 10 years ago, and that only on the SQL/application level. I’ve never done an installation of Db2 as most of our customers either don’t use it, or we don’t know about it, or these databases are managed by other teams than those we work with. And now we have a request for supporting someone with performance issues on Db2, and requests are showing up from people who want to migrate to PostgreSQL. First thing to do? Install the product so you have something to play with and this is the topic of this post.
There is a free version of Db2 with some restrictions you can download here. The database size restriction of 100MB seems a bit too low, but as I am planning to use this as a playground I don’t care right now. The requirements for the installation are documented here. I had expected a list of packages to install on the operating system but this listed on another page, which is here. I’ll be doing this with SLES 15 just because I like to switch between distributions from time to time. You can also use Red Hat, CentOS or Ubuntu as listed in the documentation linked above. When you want to install Db2 you have the choice between “root” and “non-root” installations and I’ll go for the “non-root” version here.
My SLES 15 is a minimal installation and for SLES that really means minimal, you don’ event have sudo or vi. In addition, because I’ll use the graphical installer, you need an X environment, and of course an operating system user and group:
sles15db2:~ $ zypper in xorg-x11-xauth sudo vi sles15db2:~ $ groupadd db2 sles15db2:~ $ useradd -g db2 -m db2 sles15db2:~ $ passwd db2 sles15db2:~ $ cat /etc/sudoers | grep db2 db2 ALL=(ALL) NOPASSWD: ALL
Once that is ready create a new SSH connection with X11 forwarding enabled, extract the downloaded file:
[email protected]:~$ ssh -X [email protected] ([email protected]) Password: /usr/bin/xauth: file /home/db2/.Xauthority does not exist [email protected]:~> tar axf v11.5.6_linuxx64_server_dec.tar.gz [email protected]:~> ls -l total 2034628 drwxr-xr-x 2 db2 db2 6 Mar 3 2021 bin drwxr-xr-x 3 db2 db2 206 Jun 11 2021 server_dec -rw-r--r-- 1 db2 db2 2083458415 Jan 14 10:05 v11.5.6_linuxx64_server_dec.tar.gz [email protected]:~/server_dec> ls -l total 84 drwxr-xr-x 6 db2 db2 134 Jun 11 2021 db2 -r--r--r-- 1 db2 db2 4987 Jun 11 2021 db2checkCOL_readme.txt -r--r--r-- 1 db2 db2 16808 Jun 11 2021 db2checkCOL.tar.gz -r-xr-xr-x 1 db2 db2 5254 Jun 11 2021 db2ckupgrade -r-xr-xr-x 1 db2 db2 5207 Jun 11 2021 db2_deinstall -r-xr-xr-x 1 db2 db2 5077 Jun 11 2021 db2_install -r-xr-xr-x 1 db2 db2 5041 Jun 11 2021 db2ls -r-xr-xr-x 1 db2 db2 5059 Jun 11 2021 db2prereqcheck -r-xr-xr-x 1 db2 db2 5059 Jun 11 2021 db2setup -r-xr-xr-x 1 db2 db2 5095 Jun 11 2021 installFixPack
Without installing any additional packages let’s try to start the installation:
[email protected]:~/server_dec> ./db2setup ERROR: The 'strings' utility that is used to detect prerequisite libraries is not present on this system. Please use your package or software manager to install the GNU Binary Utilities Requirement not matched for DB2 database "Server" . Version: "188.8.131.52". Summary of prerequisites that are not met on the current system: DBT3514W The db2prereqcheck utility failed to find the following 32-bit library file: "/lib/libpam.so*". DBT3609E The db2prereqcheck utility could not find the library file libnuma.so.1. Aborting the current installation ... Run installation with the option "-f sysreq" parameter to force the installation.
Obviously a few packages are missing:
[email protected]:~/server_dec> sudo zypper in binutils libnuma1
[email protected]:~/server_dec> ./db2setup Requirement not matched for DB2 database "Server" . Version: "184.108.40.206". Summary of prerequisites that are not met on the current system: DBT3514W The db2prereqcheck utility failed to find the following 32-bit library file: "/lib/libpam.so*". DBT3609E The db2prereqcheck utility could not find the library file libnuma.so.1. DBT3514W The db2prereqcheck utility failed to find the following 32-bit library file: "libstdc++.so.6". Aborting the current installation ... Run installation with the option "-f sysreq" parameter to force the installation.
Two more packages to install:
[email protected]:~/server_dec> sudo zypper in libstdc++6-32bit pam-32bit
And finally the installer is starting up:
[email protected]:~/server_dec> ./db2setup DBI1190I db2setup is preparing the DB2 Setup wizard which will guide you through the program setup process. Please wait. DBI1160I Non-root install is being performed.
In the following screen there is some important information you should write down somewhere, such as the port and profiles which will give you the correct environment:
Finally the installer wants to open a browser for displaying the “Db2 first steps”:
You either skip this or install a browser and then continue:
That’s it for the installation. All in all, quite easy to do and for re-doing this you can use the response file which was generated by the installer.
The installer already started the instance and you can see that in the process list:
[email protected]:~/server_dec> ps -ef | grep db2 root 9829 1032 0 09:57 ? 00:00:00 sshd: db2 [priv] db2 9834 1 0 09:57 ? 00:00:00 /usr/lib/systemd/systemd --user db2 9835 9834 0 09:57 ? 00:00:00 (sd-pam) db2 9842 9829 0 09:57 ? 00:00:08 sshd: [email protected]/0 db2 9843 9842 0 09:57 pts/0 00:00:00 -bash db2 26473 1 0 12:02 pts/0 00:00:00 db2wdog 0 [db2] db2 26475 26473 0 12:02 pts/0 00:00:00 db2sysc 0 db2 26480 26473 0 12:02 pts/0 00:00:00 db2ckpwd 0 db2 26481 26473 0 12:02 pts/0 00:00:00 db2ckpwd 0 db2 26482 26473 0 12:02 pts/0 00:00:00 db2ckpwd 0 db2 26484 26473 0 12:02 pts/0 00:00:00 db2vend (PD Vendor Process - 1) 0 db2 26488 26473 0 12:02 pts/0 00:00:00 db2acd ,0,0,0,1,0,0,00000000,0,0,0000000000000000,0000000000000000,00000000,00000000,00000000,00000000,00000000,00000000,0000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,000000002d85b000,0000000000000000,0000000000000000,1,0,0,,,,,a89e68,14,1e014,2,0,1,0000000000041fc0,0x240000000,0x240000000,1600000,7,2,10 db2 29070 9834 0 12:06 ? 00:00:00 /usr/bin/dbus-daemon --session --address=systemd: --nofork --nopidfile --systemd-activation --syslog-only db2 29072 9834 0 12:06 ? 00:00:00 /usr/lib/gvfs/gvfsd db2 29077 9834 0 12:06 ? 00:00:00 /usr/lib/gvfs/gvfsd-fuse /run/user/1000/gvfs -f db2 29106 9834 0 12:06 ? 00:00:00 /usr/lib/at-spi2/at-spi-bus-launcher db2 29356 9843 99 12:07 pts/0 00:00:00 ps -ef db2 29357 9843 0 12:07 pts/0 00:00:00 grep --color=auto db2
For connecting to the instance you need to source the profile and then start the “db2” utility:
[email protected]:~> . sqllib/db2profile [email protected]:~> db2 (c) Copyright IBM Corporation 1993,2007 Command Line Processor for DB2 Client 220.127.116.11 You can issue database manager commands and SQL statements from the command prompt. For example: db2 => connect to sample db2 => bind sample.bnd For general help, type: ?. For command help, type: ? command, where command can be the first few keywords of a database manager command. For example: ? CATALOG DATABASE for help on the CATALOG DATABASE command ? CATALOG for help on all of the CATALOG commands. To exit db2 interactive mode, type QUIT at the command prompt. Outside interactive mode, all commands must be prefixed with 'db2'. To list the current command option settings, type LIST COMMAND OPTIONS. For more detailed help, refer to the Online Reference Manual. db2 =>
Create a database, connect to it, and create a dummy table:
db2 => create database db1 DB20000I The CREATE DATABASE command completed successfully. b2 => connect to db1 Database Connection Information Database server = DB2/LINUXX8664 18.104.22.168 SQL authorization ID = DB2 Local database alias = DB1 db2 => create table t1 ( a int ) DB20000I The SQL command completed successfully. db2 => select * from t1 A ----------- 0 record(s) selected.
Ready to start playing. Last, but not least: If you reboot the machine, the instance will not come up automatically. To start it:
[email protected]:~> . sqllib/db2profile [email protected]:~> db2start 01/14/2022 12:29:12 0 0 SQL1063N DB2START processing was successful. SQL1063N DB2START processing was successful.