IBM DB2 on the Mac with Ruby, Rails and Radiant

Posted on 13 January 2009 by Johannes Fahrenkrug. Tags: db2 programming tutorials ruby rails
Last year ended with an amazing announcement: IBM DB2 for the Mac! I have worked with DB2 for years and it's a truly great database. Who would have thought that Big Brother would bring one of it's flagship products to the Mac? And not (directly) to make money, but only for us developers?
Ok, so how do you set this thing up? Well, I won't walk you through it step by step, but I'll give you the big steps you'll have to take:
  1. Download DB2 for Mac.
  2. Follow this PDF guide.
  3. Follow the instructions in this blog post to install the IBM DB2 Ruby Gem.
Those are the big steps. But I ran into a few minor problems on my machine. So in case you run into them as well, here's how to solve them.
Problem #1 - Error SQL1205N when running db2sampl
When I tried to create the SAMPLE database with the db2sampl command, I got this error:
Attempt to create the database “SAMPLE” failed. SQL1205N The code page “1208″ and/or territory code “0″ that has been specified is not valid.
Obviously this had to do with my code page. Adding these two lines to my .profile file solved the problem:
export LC_ALL=en_EN.UTF-8 export LANG=en_EN.UTF-8
Don't forget to source your .profile file and you'll be good to go.
I got this error when I tried to run the sample Ruby app from the blog post that tries to connect to the SAMPLE database via the ibm_db Ruby Gem. This is what it spat out:
Connection error: [IBM][CLI Driver] SQL30082N Security processing failed with reason "42" ("ROOT CAPABILITY REQUIRED"). SQLSTATE=08001 SQLCODE=-30082
The solution: Stop the DB2 server with the db2stop command and restart it with 
sudo db2start
Since DB2 uses OS authentication and the DB2 server is started without superuser privileges right after the installation, it can't authenticate other users. So you'll have to run it as a superuser.
So now we can get to what I actually wanted to try: Running the Radiant CMS on a DB2 database. These are the steps:
  1. sudo gem install radiant    (it's version 0.6.9 as of this writing)
  2. Create a new radiant app:
    radiant mygreatapp
  3. Edit config/database.yml We'll only edit the development section. Make it look like this:
    adapter:     ibm_db
    username:    your_username
    password:    your_password
    database:    db2_dev
  4. Create the database (note: it's name cannot be longer than 8 chars!)
    db2 create database db2_dev
  5. Freeze Radiant to the vendor dir (we'll have to edit it):
    rake radiant:freeze:gems
  6. OK, when the ibm_db gem can't rename columns. So we'll have to use this really ugly hack: Delete all the 21 migrations in the vendor/radiant/db/migrate directory and place this single migration file in there:
  7. Now run rake db:bootstrap
  8. Start the app with ruby script/server
  9. Go to http://localhost:3000/admin and login with admin/radiant
  10. You should be able to use your Radiant CMS now, running on DB2!
This is still pretty raw and I'll post this to the Radiant mailing list, so we can get better DB2 support built right in.


Johannes Fahrenkrug said...

Your .profile is directly in your home directory. If not, you can simply create it.

December 23, 2009 11:48 AM

Anonymous said...

where is my .profile???

December 22, 2009 06:16 AM

Johannes Fahrenkrug said...

Thank you for that, Ian, that was very thoughtful.

January 15, 2009 06:34 AM

Ian Bjorhovde said...


I added the comment so that (hopefully) other RoR developers (who aren't familiar with DB2) don't start trying to run their DB2 instances as root...


January 15, 2009 01:35 AM

Johannes Fahrenkrug said...

Hi Ian,

Thank you for the tip! In my special setup I'm not concerned about security: It's just my development laptop and I just wanted to get DB2 up and running with Ruby, Rails und Radiant as a proof that it works. This post is by no means meant to be a description of a production setup.

- Johannes

January 14, 2009 06:36 AM

Ian Bjorhovde said...


Good post, but you don't want to start db2 using 'sudo db2start'. Running your entire DB2 instance as root is not a great idea for security reasons.

There are a few SUID root binaries in a typical DB2 instance that handle specific tasks like authentication.

To avoid the authentication errors, you have two options:

1) Install DB2 as root (sudo db2setup)
2) Use the 'db2rfe' tool to enable the instance; however, please note that with the current beta db2rfe does not work.

Good luck

January 13, 2009 09:41 PM


Please keep it clean, everybody. Comments with profanity will be deleted.

blog comments powered by Disqus