Skip to content

DB2 - Server Installation

This chapter guides you through modern methods for installing and setting up an IBM Db2 server. While traditional on-premises installation is still an option, we will focus on containerization with Docker, which is the recommended approach for development, testing, and many production environments due to its speed, consistency, and isolation.

Section titled “Option 1: Development Setup with Docker (Recommended)”

Using Docker is the fastest and most popular way to get a Db2 instance running on any machine. It encapsulates the database in a lightweight, portable container.

  • Docker Desktop (for Windows/Mac) or Docker Engine (for Linux) installed and running.
  • A basic understanding of the command line.

Step 1: Pull the Official Db2 Docker Image

Section titled “Step 1: Pull the Official Db2 Docker Image”

Open your terminal and pull the latest Db2 Community Edition image from IBM’s official repository on Docker Hub.

docker pull ibmcom/db2

Execute the following command to start a new Db2 container. This command will also create a database named ‘testdb’.

docker run -itd --name mydb2 --privileged=true -p 50000:50000 -e LICENSE=accept -e DB2INST1_PASSWORD=your_password -e DBNAME=testdb -v /my/db2/data:/database ibmcom/db2

Let’s break down the command:

  • docker run -itd: Runs the container in interactive, detached mode.
  • --name mydb2: Assigns a memorable name to your container.
  • --privileged=true: Required for Db2 to have the necessary kernel-level permissions.
  • -p 50000:50000: Maps port 50000 on your local machine to port 50000 inside the container, allowing you to connect to the database from your host.
  • -e LICENSE=accept: You must accept the license terms to run the container.
  • -e DB2INST1_PASSWORD=your_password: Sets the password for the default instance owner db2inst1. Choose a strong password.
  • -e DBNAME=testdb: Automatically creates a database named ‘testdb’ on startup.
  • -v /my/db2/data:/database: (Optional but Recommended) Mounts a local directory on your host into the container. This ensures your database data persists even if you remove the container.

Step 3: Accessing the Container’s Command Line

Section titled “Step 3: Accessing the Container’s Command Line”

To run Db2 commands, you need to get a shell inside the running container as the instance user db2inst1.

docker exec -tiu db2inst1 mydb2 bash -c "db2start"

After a moment, you can connect to your database:

docker exec -tiu db2inst1 mydb2 bash -c "db2 connect to testdb"

Option 2: Traditional Installation on Linux

Section titled “Option 2: Traditional Installation on Linux”

This method is suitable for system administrators setting up dedicated Db2 servers on-premises or on virtual machines.

  • Processor: Modern multi-core 64-bit CPU (e.g., x86-64, POWER).
  • RAM: 4 GB minimum, 8GB+ recommended.
  • Hard Disk: 50 GB minimum free space.
  • Operating System: A supported Linux distribution (e.g., RHEL, SLES, Ubuntu).
  • Software: Required libraries such as libstdc++, 32-bit compatibility libraries, etc. Always consult the official IBM documentation for the exact prerequisites for your specific Db2 version and OS.

Before installing, use the db2prereqcheck utility included with the installer to verify your system meets all requirements.

./db2prereqcheck -v 11.5.8.0
  1. Download the Db2 server edition from the IBM website and extract the archive.
  2. Run the non-interactive installer script: ./db2_install.
  3. Create the Db2 instance owner, fenced user, and administration users.
  4. Create the Db2 instance using the db2icrt command: /opt/ibm/db2/V11.5/instance/db2icrt -u db2fenc1 db2inst1.
  5. Log in as the instance owner (su - db2inst1) and start the Db2 instance (db2start).

Once installed, you can verify the version and license information.

This command displays the current version and service level of the installed Db2 product.

# For Docker:
docker exec -iu db2inst1 mydb2 bash -c "db2level"
# For Traditional Install:
su - db2inst1
db2level

Output (example):

DB21085I This instance or install (instance name, where applicable: "db2inst1") uses "64" bits and DB2 code release "SQL11058" with level identifier "0609010F".
Informational tokens are "DB2 v11.5.8.0", "s2305101200", "DYN2305101200AMD64", and Fix Pack "0".
Product is installed at "/opt/ibm/db2/V11.5".

This command shows license-related information.

# Run as root or with sudo on a traditional install
db2licm -l
# For Docker, run as root inside the container
docker exec -itu root mydb2 bash -c "/opt/ibm/db2/V11.5/adm/db2licm -l"

The CLP is the primary tool for interacting with Db2. It can be used in three modes:

  • Command Mode: Each command is prefixed with db2. Useful for single commands or scripting. Example: db2 connect to testdb.
  • Interactive Mode: Start by typing db2. The prompt changes to db2 =>, and you can enter SQL statements and commands without the prefix. Exit with quit.
  • Batch Mode: Place your commands in a file (e.g., myscript.sql) and execute it with db2 -tvf myscript.sql. The -t flag uses semicolon as a statement terminator, and -v echoes the command being run.