[ruby-dbi-users] DBI 0.4.0 & DBD::Pg gem installation issues

Michael Glaesemann grzm at seespotcode.net
Mon Sep 29 15:31:55 EDT 2008

I've installed ruby via yum on RHEL5, and am having issues with  
getting DBD::Pg to work.

Here's a test script I've been using for debugging:

[grzm at db05 ~]$ cat test_dbd_pg.rb
#!/usr/bin/ruby -w

require 'rubygems'
require 'dbi'

db_host = 'localhost'
db_port = '5432'
db_name = 'production'
db_user = 'postgres'

query = 'SELECT version()';
dbh = DBI.connect(%(dbi:Pg:#{db_name}:#{db_host}:#{db_port}), db_user)  
do |dbh|
   sth = dbh.execute(query)
   sth.each do |row|
      puts %Q(#{row['version']})
[grzm at db05 ~]$ ruby test_dbd_pg.rb
`load_driver': Unable to load driver 'Pg' (DBI::InterfaceError)
	from /usr/lib/ruby/1.8/monitor.rb:238:in `synchronize'
	from /usr/lib64/ruby/gems/1.8/gems/dbi-0.4.0/lib/dbi.rb:236:in  
	from /usr/lib64/ruby/gems/1.8/gems/dbi-0.4.0/lib/dbi.rb:154:in  
	from /usr/lib64/ruby/gems/1.8/gems/dbi-0.4.0/lib/dbi.rb:139:in  
	from test_dbd_pg.rb:12

Just confirming that the connection parameters should work (if the  
script got to that point).

[grzm at db05 ~]$ /usr/local/pgsql/bin/psql -h localhost -p 5432 -U  
postgres production
Welcome to psql 8.3.3, the PostgreSQL interactive terminal.

Type:  \copyright for distribution terms
        \h for help with SQL commands
        \? for help with psql commands
        \g or terminate with semicolon to execute query
        \q to quit

production=# \q

And a quick test in irb showing an error when just requiring pg:

[grzm at db05 ~]$ irb
irb(main):001:0> require 'rubygems'
=> true
irb(main):002:0> require 'dbi'
=> true
irb(main):003:0> gem 'pg'
=> true
irb(main):005:0> require 'pg'
LoadError: libpq.so.5: cannot open shared object file: No such file or  
directory - /usr/lib64/ruby/gems/1.8/gems/pg-
	from /usr/lib64/ruby/gems/1.8/gems/pg-
	from /usr/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in  
	from (irb):5
[grzm at db05 ~]$ ls -la /usr/lib64/ruby/gems/1.8/gems/ 
-rwxr-xr-x 1 root root 131132 Sep 19 12:19 /usr/lib64/ruby/gems/1.8/ 

Any help or further debugging pointers would be much appreciated.

Michael Glaesemann
grzm seespotcode net

More information about the ruby-dbi-users mailing list