Updates for the Ruby PostgreSQL native driver

12 Dec 2007

UPDATE: Jeff Davis has released a new PostgreSQL native driver gem, so just doing a gem install postgres should work fine again; no need for the hackery that I had suggested in this post. Thanks to Jeff for getting a new gem out there so quickly!

Josh Berkus let me and some other folks know that the gem that you get with "gem install postgres" won't work with PostgreSQL 8.3. That gem (postgres-0.7.1 gem) has been languishing for a while and is finally, well, gone. So if you do a "gem install postgres" you'll see this:

$ gem install postgres
ERROR:  While executing gem ... (Gem::GemNotFoundException)
    Could not find postgres (> 0) in the repository

OK, so, now what? Well, Jeff Davis (who originally noticed the breakage) has been maintaining the driver in a different RubyForge project, ruby-pg. So to use his Postgres library, go to the ruby-pg files page, download the latest, untar it, and do a ruby extconf.rb && make && sudo make install. Huzzah!

I noticed that when I built and installed the library, I ran it with Rails and got the error MissingSourceFile: no such file to load -- postgres. I had to tweak ActiveRecord to pick up the new library, specifically, I edited line 7 of activerecord-some_version_number_like_1.14.4/lib/active_record/connection_adapters/postgresql_adapter.rb to read require_library_or_gem 'pg' unless self.class.const_defined?(:PGconn). There's probably a better way to do this, please feel free to chime in with a comment or just email me or whatever... thanks!

As a last resort, the "postgres-pr" gem is still available. That's the pure Ruby driver, so it's very slow. I haven't tried it with PostgreSQL 8.3 either, so, who knows. And as a last last resort, I stuck a gzip'd copy of postgres-0.7.1.gem here, so you can always just grab that too.

Thanks to Jeff for keeping this driver going, and thanks to Josh for the prodding!