# Postgres gem -- LoadError

**URL:** <https://www.ruby-forum.com/t/postgres-gem-loaderror/105840>\
**Category:** Rails\
**Created:** [June 3, 2007, 6:26pm UTC](https://www.ruby-forum.com/t/postgres-gem-loaderror/105840 "2007-06-03T18:26:27Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [June 3, 2007, 6:26pm UTC](https://www.ruby-forum.com/t/postgres-gem-loaderror/105840/1 "2007-06-03T18:26:27Z")

</div>

I’m at a loss to explain why the postgres gem will not work on my new  
server. I’ve gotten it working on several other servers in the past.  
The major difference between then and now is that I’m using a newer  
version of PostgreSQL. 8.x as opposed to 7.x.

=== Server setup

OS: Fedora Core 6

(Commands shown with “$” are performed as the same user that mongrel  
is running as. “#” are commands from root.)

$ /usr/local/pgsql/bin/psql --version  
psql (PostgreSQL) 8.2.4  
contains support for command-line editing

=== The error message

I’m currently running a Rails app with mongrel\_cluster on ports  
8000-8002. When I try to access a page, I get the following in my  
production.log file.

LoadError (libpq.so.5: cannot open shared object file: No such file or  
directory - /usr/lib/ruby/gems/1.8/gems/postgres-0.7.1/./postgres.so):  
/usr/lib/ruby/gems/1.8/gems/postgres-0.7.1/./postgres.so

Oddly, I can do the following.

$ irb  
irb(main):001:0\> require ‘postgres’  
=\> true

Why would that work for the mongrel user at the command line, but not  
from the mongrel\_rails process?

=== Installing the postgres gem.

First I did a “gem install postgres” and then I tried the following.

# echo $LD\_LIBRARY\_PATH

/usr/local/pgsql/lib

# pwd

/usr/lib/ruby/gems/1.8/gems/postgres-0.7.1

# make clean

# ruby extconf.rb --with-pgsql-dir=/usr/local/pgsql

checking for cygwin32\_socket() in -lwsock32… no  
checking for socket() in -lsocket… no  
checking for gethostbyname() in -linet… no  
checking for gethostbyname() in -lnsl… yes  
checking for sys/un.h… yes  
checking for socket()… yes  
checking for hsterror()… no  
checking for gethostname()… yes  
checking for PQsetdbLogin() in -lpq… yes  
checking for PQsetClientEncoding()… yes  
checking for pg\_encoding\_to\_char()… yes  
checking for PQescapeString()… yes  
creating Makefile

# make

gcc -I. -I. -I/usr/lib/ruby/1.8/i386-linux -I. -DHAVE\_SYS\_UN\_H -  
DHAVE\_SOCKET -DHAVE\_GETHOSTNAME -DHAVE\_PQSETCLIENTENCODING -  
DHAVE\_PG\_ENCODING\_TO\_CHAR -DHAVE\_PQESCAPESTRING -I/usr/local/pgsql/  
include -fPIC -c postgres.c  
gcc -shared -L"/usr/local/pgsql/lib" -L"/usr/lib" -o postgres.so  
postgres.o -lruby -lpq -lnsl -lpthread -ldl -lcrypt -lm -lc

# make install

/usr/bin/install -c -m 0755 postgres.so /usr/lib/ruby/site\_ruby/1.8/  
i386-linux

# ldd ./postgres.so

```
    linux-gate.so.1 => (0x0091b000)
    libruby.so.1.8 => /usr/lib/libruby.so.1.8 (0x00ef8000)
    libpq.so.5 => /usr/local/pgsql/lib/libpq.so.5 (0x009b7000)
    libnsl.so.1 => /lib/libnsl.so.1 (0x0085d000)
    libpthread.so.0 => /lib/libpthread.so.0 (0x00110000)
    libdl.so.2 => /lib/libdl.so.2 (0x00b1f000)
    libcrypt.so.1 => /lib/libcrypt.so.1 (0x009d3000)
    libm.so.6 => /lib/libm.so.6 (0x00127000)
    libc.so.6 => /lib/libc.so.6 (0x0023b000)
    /lib/ld-linux.so.2 (0x00531000)

```

As the mongrel user, I get the same result from ldd. I can also do  
the following:

$ cd /usr/lib/ruby/gems/1.8/gems/postgres-0.7.1/

$ ls -al  
total 164  
drwxr-xr-x 4 root root 4096 Jun 3 11:06 .  
drwxr-xr-x 17 root root 4096 Jun 3 10:50 …  
-rw-r–r-- 1 root root 5289 Jun 3 10:50 ChangeLog  
drwxr-xr-x 2 root root 4096 Jun 3 10:50 doc  
-rw-r–r-- 1 root root 1232 Jun 3 10:50 extconf.rb  
-rw-r–r-- 1 root root 3545 Jun 3 11:06 Makefile  
-rw-r–r-- 1 root root 198 Jun 3 10:50 MANIFEST  
-rw-r–r-- 1 root root 7643 Jun 3 11:06 mkmf.log  
-rw-r–r-- 1 root root 34307 Jun 3 10:50 postgres.c  
-rw-r–r-- 1 root root 32004 Jun 3 11:06 postgres.o  
-rw-r–r-- 1 root root 684 Jun 3 10:50 postgres-ruby.gemspec  
-rwxr-xr-x 1 root root 33624 Jun 3 11:06 postgres.so  
-rw-r–r-- 1 root root 2980 Jun 3 10:50 README  
-rw-r–r-- 1 root root 4347 Jun 3 10:50 README.ja  
drwxr-xr-x 2 root root 4096 Jun 3 10:50 sample

So I don’t think that it’s a permissions problem.

Is this something as simple as “PostgreSQL 8.2.4 doesn’t work with  
Ruby” or am I missing something else obvious here?

– James

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [June 5, 2007, 4:34am UTC](https://www.ruby-forum.com/t/postgres-gem-loaderror/105840/2 "2007-06-05T04:34:38Z")

</div>

On Jun 3, 11:25 am, jdl [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> is running as. “#” are commands from root.)
> 
> Why would that work for the mongrel user at the command line, but not  
> /usr/lib/ruby/gems/1.8/gems/postgres-0.7.1  
> checking for hsterror()… no  
> DHAVE\_PG\_ENCODING\_TO\_CHAR -DHAVE\_PQESCAPESTRING -I/usr/local/pgsql/  
> libruby.so.1.8 =\> /usr/lib/libruby.so.1.8 (0x00ef8000)  
> the following:  
> -rw-r–r-- 1 root root 3545 Jun 3 11:06 Makefile  
> So I don’t think that it’s a permissions problem.
> 
> Is this something as simple as “PostgreSQL 8.2.4 doesn’t work with  
> Ruby” or am I missing something else obvious here?
> 
> – James

Follow-up.  
I removed the following packages via ‘yum remove foo’.

ruby-irb  
ruby-devel  
ruby-libs  
ruby

I then removed the /usr/lib/ruby directory.

Then I compiled a new copy of ruby with the tried-and-true  
‘configure / make / make install’.

Re-ran the setup for ruby gems.

Installed the gems that I needed: postgres, rails, mongrel, etc.

Some old executables where hanging around in /usr/bin (Yay for yum not  
removing them as instructed.)  
/usr/bin/ruby  
/usr/bin  
/usr/bin/mongrel\_rails  
/usr/bin/mongrel\_cluster\_ctl

I removed those files, and made symlinks in their place.  
/usr/bin/ruby → /usr/local/bin/ruby  
etc…

The gem install postgres process still needed some hand-holding, with  
the step of going into the gem directory and running everything by  
hand (see my original post).

Everything works fine now.

Moral: package managers suck.

– James
