As pre-announced in my two previous posts, DB2 for Mac OS X Leopard is finally available for download. It’s now official, DB2 on Mac is here.
Reflections on DB2 on Mac
Several people, including myself, would happily ditch their virtual machines and start introducing DB2 into their native Mac development stacks. But this milestone represents much more than the immediate implications would have us believe. A few years ago, the idea of giving away DB2 for free would have been met with rejection. Yet, DB2 Express-C came along, and unlike the other “express” databases, it’s a true production-ready DB2 version that can be used free of charge.
Likewise, the idea of having a DB2 version for Mac was unthinkable up to a few years ago. Yet today we finally have a copy of DB2 Express-C for Mac OS X that’s available for download. Aside from this being an acknowledgment of the growing importance of Mac as a development and business platform, I feel it underlines IBM’s ability to change. The desire that a few of us mac addicts had, coupled with reasonable pressure from the community, was sufficient enough to make DB2 on Mac a reality. This matters and appeals to both the developer and the technical evangelist in me.
In the list of downloads, you’ll notice that the Mac download is only 138 MB, versus the 412 MB of Linux’s 64-bit. The reason for this difference is that DB2 Express-C for Mac currently ships in English only, and at this stage it doesn’t include either DB2 Text Search or the Java based tools like the DB2 Control Center. This lighter package is, in my opinion, a welcome side effect of this brand new beta release.
Getting started with DB2 and Rails on Mac OS X
Since the first download went live on Friday, a newer release that includes a guide for installing DB2 on Mac OS X was published and it incorporates a few changes that will make the lives of developers easier, as they approach building and using drivers (e.g. the ibm_db Ruby gem). If you downloaded this beta version over the weekend, do not worry: just grab – and execute – this shell script (e.g. sudo fixlib.sh
). If you are downloading DB2 on Mac now, you won’t need this script of course.
Once you’ve downloaded DB2 for Mac OS X Leopard, please proceed to read this PDF guide, which will tell you everything you need to know (and more) about installing DB2 on your Mac, as well as providing extra details. It’s best not to skip over reading this document, as the installation on Mac OS X requires a few more steps than simply running the setup wizard.
With DB2 installed and started (sudo db2start
), and the SAMPLE database created (db2sampl
), you’re ready to start playing with this power horse. For details about SAMPLE’s structure you can read this article in the InfoCenter.
To run the DB2 console (known as the Command Line Processor or CLP for short), run:
$ db2
To connect to the SAMPLE database, from within the CLP run:
db2 => connect to sample
Unless you get an error, you should now be ready to query the database. For example, run the following query:
db2 => select count(*) from staff
Then to exit from the CLP, simply run:
db2 => quit
If this sanity test worked well you can proceed with installing the ibm_db gem (which includes the Ruby driver and the Rails adapter for DB2). To do so, run the following, adjusting the path to your own username of course:
$ sudo -s $ export IBM_DB_INCLUDE=/Users/acangiano/sqllib/include $ export IBM_DB_LIB=/Users/acangiano/sqllib/lib32 $ export ARCHFLAGS="-arch i386" $ gem update --system $ gem install ibm_db $ exit
The ibm_db gem will be installed on your system and is ready to be used. To verify that this is the case, run a small Ruby program with the following code:
require 'rubygems' require 'ibm_db.bundle' conn = IBM_DB.connect("sample","my_username", "my_password") if conn stmt = IBM_DB.exec(conn, "select count(*) from staff") count = IBM_DB.fetch_array(stmt)[0] puts "The staff table contains #{count} records." else puts "Connection error: #{IBM_DB.conn_errormsg}" end
If everything is fine and dandy, you should see the message “The staff table contains 35 records.”.
Now that Ruby can talk with DB2, we can move on to Rails. Assuming you have Rails 2.2.x installed, run the following to create a sample bookshelf application:
$ rails books -d ibm_db
This generates a Rails application (as usual) with a config/database.yml file customized for DB2. You’ll notice that unlike with MySQL, the database names are not books_development, books_production and books_test. The names are truncated by default due to the fact that DB2 currently only allows for database names that are up to 8 characters long. Feel free to change the development database in database.yml simply to ‘books’.
As a Rails developer you may also be accustomed to running rake db:create
to automatically create the development database, yet this feature is not available for DB2 at this point, so instead you can create the database using the db2
command, as follows:
db2 create database books
DB2 allows you to specify all kinds of options for the creation of databases, but in its simplest form, the line above will work just fine.
Once the development database has been created, you should be able to use Rails with DB2 as you normally would with other database management systems. For example, you could scaffold a resource as follows:
$ ruby script/generate scaffold Book title:string author:string isbn:string description:text loaned:boolean
Start the webserver with:
$ ruby script/server
And then visit https://localhost:3000/books to perform CRUD operations on book records.
At this stage, the only caveats are that you’ll have to use the db2
command, rather than ruby script/dbconsole
, and that you won’t be able to use the rename_column
method in your migrations. On the plus side, you’ll have the XML datatype (t.xml
in your sexy migrations) at your disposal, to natively store XML documents and retrieve them through XQuery and SQL/XML.
I really hope that you’ll enjoy DB2 on Mac! Don’t be afraid to ask for help, if you need it, in the DB2 Express-C forum. Oh and we are trying to get the word out there. Your help is highly appreciated. You can promote this story on Twitter, Hacker News, Reddit, DZone, StumbleUpon and Digg.
Disclaimer: The opinions expressed in this post are mine and mine alone, and do not necessarily represents the opinions of my employer, IBM.
Get more stuff like this
Subscribe to my mailing list to receive similar updates about programming.
Thank you for subscribing. Please check your email to confirm your subscription.
Something went wrong.
This is good news! Just a quick question. Do I have the ability to manually start it? I’d like to install it, but I don’t want to leave it running all the time.
Yes, DB2 Express-C for Mac OS X has the db2start and db2stop commands to manually start and stop DB2. You’ll find this in the sqllib/bin directory of your DB2 instance.
You could also probably set up a cron job to start/stop it at specific times, but I haven’t tried that yet.
This is great news. However, I couldn’t work out whether this port includes a DB2 client for Mac – you suggest that the db2CC isn’t there, but is there an alternative?
What I really need is a means to manage DB2 databases on other servers from my Mac (I currently use the java DB2CC via X-windows but this is very very slow), does it give me that?
Hi Stuart, this DB2 for Mac OS X port doesn’t include the DB2 Administration Server or the Control Center + java based graphical administration tools (Config Assistant, Health Center, etc). All the core command line based client function is available, so you can use that to do admin tasks on your DB2 servers on Unix/Linux/Windows/Mac.
I know that some people want DB2 graphical admin tooling, and there are other alternatives. Right now I’m testing the DB2 Technology Explorer fka db2mc (http://sourceforge.net/projects/db2mc/) on my Mac with the latest DB2 for Mac OS X beta, this is a lightweight web based PHP tool. Once I finish my testing and finish writing up the how-to guide, I’ll make that available. This should help meet your needs for DB2 graphical admin tooling. And did I mention it’s also free ?
Who deploys on OS X? I suppose it’s nice for client side development, but really, just not that big of a deal in the corporate world.
Daniel, this release is meant for developers. We don’t expect anyone to use it in production nor for it to excite the corporate world.
Hi Antonio!
I’ve been waiting for this for a long time now and will be installing DB2 on my iMac. When it comes to graphical tools I stumbled over something called RazorSQL that is not for free, but can be run on a Mac and it supports DB2. Did you ever try that tool? If so, what do you think about it?
/Len…
Len, thank you very much for the pointer. I wasn’t aware of RazorSQL, but I will definitely check it out as soon as I get a new Mac.
Hi. I’ve seen quite a few announcements on DB2 lately. Could anyone point out what the key advantages of DB2 are? Compared to, for example, PostgreSQL.
I maintain a rails frontend app that runs on PostgreSQL which imports data periodically from a DB2 database. I am wondering if changing to DB2 would yield any benefits.
Dear all,
I’ve successfully installed DB2 V9.5 Express-C on my 10.5.6 Mac OS X system. Creation of the SAMPLE database (db2sampl) worked just fine and first tests (SQL queries, ODBC connects) indicate that the DBMS works as it should.
When I follow Antonio’s recipe (thanks!) to install the ibm_db gem, however, everythings appears to work OK first.
I then stumble quickly, though:
Has anyone seen similar behavior/problems? I’d appreciate any hint or insight!
Thanks and best wishes for 2009,
–Torsten
Hi Torsten,
The bus error might be because the DB2 client is not able to find a required library or might be the ipc resources available on the system is less. Could you check if there is a file named libicclib.dylib present in the directory /sqllib/lib32/icc/icclib. If you are seeing a libicclib.so instead of libicclib.dylib please rename the file to libicclib.dylib. With this you should be able to get going with the ibm_db gem without any problems.
If the files specified above are as required, then you would need to check the ipc resources on your system.
Thanks
Praveen
Hi Praveen,
many thanks for your reply. You’re pointing at libicclib.dylib and, indeed, I can find this file only in the sqllib/lib64/icc/icclib directory (note: lib64, not lib32). In fact, there is *no* icc subdirectory below sqllib/lib32…
This coincides with my observation that I can compile/link/run 64-bit CLI applications just fine, but receive ‘Bus Errors’ once I try do the same with a 32-bit application. (Here’s the corresponding posting in the DB2 Express-C forum:
http://www.ibm.com/developerworks/forums/thread.jspa?threadID=238971&tstart=0
I dug deep into the db2exc_952beta_MAC_x86_64.tar.gz and db2exc_client_952beta_MAC_x86_64.tar.gz files (and the contained tar archives) and can only find the sqllib/lib64/icc directory and its contents. No sqllib/lib32/icc directory at all.
Hmm…
Many thanks again,
–Torsten
Dear all,
the IBM DB2 on Mac OS X team prepared new download packages. For me, these new packages now work right out of the box — just as advertised by Antonio above.
I’d like to thank the team for their responsiveness and help in resolving this — as it turned out — 32-bit vs. 64-bit library issue.
Best wishes,
–Torsten
Hi!
This is incredible news. I’ve been working with DB2 for years and it’s a great DB. Wonderful to see it on a great OS now 😉
I have an issue though. When I run the db2sampl command, I get this:
Creating database “SAMPLE”…
Attempt to create the database “SAMPLE” failed.
SQL1205N The code page “1208” and/or territory code “0” that has been
specified is not valid.
‘db2sampl’ processing complete.
Any suggestions?
– Johannes
Ok, answered my own question:
Add these two lines to your .profile
and then source it. That’s it.
– Johannes
Thanks. I was facing the same issue. It worked.
I’ve put together my experience installing DB2 for Mac and getting the Radiant CMS up and running on it in this blog post:
http://blog.springenwerk.com/2009/01/ibm-db2-on-mac-with-ruby-rails-and.html
Enjoy!
I just installed DB2 Express-C 9.7 and I am having the same error (see below) but in Windows XP. Do you know how can I resolve it?
thanks in advanced.
=======================
Creating database “SAMPLE”…
Attempt to create the database “SAMPLE” failed.
SQL1205N The code page “1208? and/or territory code “0? that has been
specified is not valid.
‘db2sampl’ processing complete.
Any suggestions?
– Johannes
Johannes Fahrenkrug on January 13th, 2009 5:29 am Ok, answered my own question:
Add these two lines to your .profile
export LC_ALL=en_EN.UTF-8
export LANG=en_EN.UTF-8
and then source it. That’s it.
– Johannes