Setup a DB2 Database

acangiano edited this page Mar 24, 2011 · 4 revisions
Clone this wiki locally

Setting up Radiant CMS with DB2 is straightforward. Simply follow the few steps below.

Prerequisites

Before continuing with the setup procedure described below, ensure that you have DB2 installed. You can obtain a free, production ready copy at the DB2 Express-C site. During the DB2 setup on Linux, you need to select a custom installation in order to include the Application Development Development files and libraries. These are needed to compile the DB2 Ruby driver provided and supported by IBM.

Install the DB2 Ruby driver and Rails adapter

On *nix based systems, you can install both the Ruby driver and Rails adapter for DB2 with the following commands:

$ sudo -s
$ export IBM_DB_INCLUDE=/home/db2inst1/sqllib/include
$ export IBM_DB_LIB=/home/db2inst1/sqllib/lib
$ source /home/db2inst1/sqllib/db2profile
$ gem install ibm_db

On Windows, you'll only need the last line, given that the gem for Windows ships with precompiled binaries.

Create databases

You can create development, test, and production databases as follows:

$ su - db2inst1 -c 'db2 create db BLOG_DEV'
$ su - db2inst1 -c 'db2 create db BLOG_TST'
$ su - db2inst1 -c 'db2 create db BLOG'

The database names must be limited to 8 characters. For performance reasons, it is advised to enable the Statement Concentrator feature in production if you are running DB2 9.7 or greater:

$ su - db2inst1 -c 'db2 update db config for BLOG using stmt_conc literals'

Configure database.yml

The config/database.yml file should be along the lines of the following configuration:

development:
  adapter:     ibm_db
  username:    <username e.g., db2inst1>
  password:    <password>
  database:    blog_dev
  schema:      <schema e.g., db2inst1>
  host:        <hostname or IP, e.g., localhost>
  port:        <port e.g., 50000>

test:
  adapter:     ibm_db
  username:    <username e.g., db2inst1>
  password:    <password>
  database:    blog_tst
  schema:      <schema e.g., db2inst1>
  host:        <hostname or IP, e.g., localhost>
  port:        <port e.g., 50000>

production:
  adapter:     ibm_db
  username:    <username e.g., db2inst1>
  password:    <password>
  database:    blog
  schema:      <schema e.g., db2inst1>      
  host:        <hostname or IP, e.g., localhost>
  port:        <port e.g., 50000>

Schema, host, and port are optional values. Schema defaults to the given username, and a missing hostname and port combo indicates to the adapter that a local connection to DB2 should be established.