25

I have app that is running Ruby 1.9.2, Rails 3, and postgreSQL 8.3. It was originally setup and working with postgreSQL 9.1, but I uninstalled 9.1 and installed and changed to 8.3 insure compatibility on a Heroku shared database setup. It was running ok, but it's not now

Now, when working on this app, when I run a database upgrade I get this error:

dlopen(/Users/michaeljmccoy/.rvm/gems/ruby-1.9.2-p290/gems/pg-0.12.2/lib/pg_ext.bundle, 9): Library not loaded: libpq.5.dylib
  Referenced from: /Users/michaeljmccoy/.rvm/gems/ruby-1.9.2-p290/gems/pg-0.12.2/lib/pg_ext.bundle
  Reason: no suitable image found.  Did find:
    /usr/lib/libpq.5.dylib: no matching architecture in universal wrapper - /Users/michaeljmccoy/.rvm/gems/ruby-1.9.2-p290/gems/pg-0.12.2/lib/pg_ext.bundle

And when I try to run the server I get this error message:

/Users/michaeljmccoy/.rvm/gems/ruby-1.9.2-p290/gems/pg-0.12.2/lib/pg.rb:4:in `require': dlopen(/Users/michaeljmccoy/.rvm/gems/ruby-1.9.2-p290/gems/pg-0.12.2/lib/pg_ext.bundle, 9): Library not loaded: libpq.5.dylib (LoadError)
  Referenced from: /Users/michaeljmccoy/.rvm/gems/ruby-1.9.2-p290/gems/pg-0.12.2/lib/pg_ext.bundle
  Reason: no suitable image found.  Did find:
    /usr/lib/libpq.5.dylib: no matching architecture in universal wrapper - /Users/michaeljmccoy/.rvm/gems/ruby-1.9.2-p290/gems/pg-0.12.2/lib/pg_ext.bundle
    from /Users/michaeljmccoy/.rvm/gems/ruby-1.9.2-p290/gems/pg-0.12.2/lib/pg.rb:4:in `<top (required)>'
    from /Users/michaeljmccoy/.rvm/gems/ruby-1.9.2-p290@global/gems/bundler-1.0.21/lib/bundler/runtime.rb:68:in `require'
    from /Users/michaeljmccoy/.rvm/gems/ruby-1.9.2-p290@global/gems/bundler-1.0.21/lib/bundler/runtime.rb:68:in `block (2 levels) in require'
    from /Users/michaeljmccoy/.rvm/gems/ruby-1.9.2-p290@global/gems/bundler-1.0.21/lib/bundler/runtime.rb:66:in `each'
    from /Users/michaeljmccoy/.rvm/gems/ruby-1.9.2-p290@global/gems/bundler-1.0.21/lib/bundler/runtime.rb:66:in `block in require'
    from /Users/michaeljmccoy/.rvm/gems/ruby-1.9.2-p290@global/gems/bundler-1.0.21/lib/bundler/runtime.rb:55:in `each'
    from /Users/michaeljmccoy/.rvm/gems/ruby-1.9.2-p290@global/gems/bundler-1.0.21/lib/bundler/runtime.rb:55:in `require'
    from /Users/michaeljmccoy/.rvm/gems/ruby-1.9.2-p290@global/gems/bundler-1.0.21/lib/bundler.rb:122:in `require'
    from /Users/michaeljmccoy/www/mikemccoy/config/application.rb:7:in `<top (required)>'
    from /Users/michaeljmccoy/.rvm/gems/ruby-1.9.2-p290/gems/railties-3.2.0.rc2/lib/rails/commands.rb:53:in `require'
    from /Users/michaeljmccoy/.rvm/gems/ruby-1.9.2-p290/gems/railties-3.2.0.rc2/lib/rails/commands.rb:53:in `block in <top (required)>'
    from /Users/michaeljmccoy/.rvm/gems/ruby-1.9.2-p290/gems/railties-3.2.0.rc2/lib/rails/commands.rb:50:in `tap'
    from /Users/michaeljmccoy/.rvm/gems/ruby-1.9.2-p290/gems/railties-3.2.0.rc2/lib/rails/commands.rb:50:in `<top (required)>'
    from script/rails:6:in `require'
    from script/rails:6:in `<main>'

I know they are very similar errors and probably has to do with a missing path. However, when I add the path to my .profile file and restart the terminal window, I get the same errors.

BryanH
  • 5,826
  • 3
  • 34
  • 47
Mike McCoy
  • 797
  • 2
  • 10
  • 19
  • Your `PATH` controls where the shell looks for executables. Your `LD_LIBRARY_PATH` controls where the shell looks for libraries. That said, this looks to me like your pg gem was compiled against a different PostgreSQL library version than the one you have now. You probably just need to reinstall pg. – Daniel Lyons Feb 07 '12 at 19:52
  • I removed the current pg gem and am trying to reinstall, however I am getting what seems to be a pretty common error regarding missing postgres libraries. Here is what I am seeing: 'checking for pg_config... yes Using config values from /Library/PostgreSQL/8.3/bin/pg_config checking for libpq-fe.h... yes checking for libpq/libpq-fs.h... yes checking for pg_config_manual.h... yes checking for PQconnectdb() in -lpq... no checking for PQconnectdb() in -llibpq... no checking for PQconnectdb() in -lms/libpq... no Can't find the PostgreSQL client library (libpq) *** extconf.rb failed *** – Mike McCoy Feb 10 '12 at 20:28
  • 1
    I remember having to solve this at some point in the past, and it amounted to having to manually supply flags to the gem builder to tell it where to look for headers and libraries, but I don't have the info on-hand right now. – Daniel Lyons Feb 10 '12 at 22:20
  • hmmm. ok, i will look at doing that. if you do happen to come across what you did and would be willing to share that would be great. Thanks again for pointing me in the right direction. Much appreciated. – Mike McCoy Feb 11 '12 at 15:44
  • 3
    To anyone who's found this question because you're experiencing this dylib issue on Mac OS X Mavericks and you're using PostgresApp: please see my answer to the related question here: http://stackoverflow.com/a/19547385/1493505. Basically I needed to go as far back as version 9.2.2.0 of the Postgres App in order to get this working. Thanks @jhiro009 for pointing me in the right direction - version 9.2.4.3 simply didn't work for me on Mavericks. – schmielson Oct 23 '13 at 18:03

2 Answers2

54

You may need to remove and re-install the pg gem, so it's compiled against the correct version of Postgres.

Ariejan
  • 10,910
  • 6
  • 43
  • 40
4

For anyone seeing this error and running PostgresApp, this is a known problem that was fixed in version 9.2.4.3:

Discussion: https://github.com/PostgresApp/PostgresApp/issues/109

Installer: https://github.com/PostgresApp/PostgresApp/releases/tag/9.2.4.3

Of course, you could just grab the latest version (http://postgresapp.com/). Both versions got me back up and running with Rails 3.2.14 and Ruby 2.0.0. However, note that when I installed 9.2.4.3 my databases were still listed in psql, but when I installed 9.3.0 (the current version at the moment), my databases were no longer listed.

jhiro009
  • 576
  • 4
  • 13