Library not loaded: /usr/local/lib/libpq.5.4.dylib Library not loaded: /usr/local/lib/libpq.5.4.dylib postgresql postgresql

Library not loaded: /usr/local/lib/libpq.5.4.dylib


if you have upgraded

  • PostgreSQL with homebrew (brew update && brew upgrade),
  • macOS (eg. from Catalina to BigSur)

then simply uninstall the pg gem:

gem uninstall pgbundle install

and the path will be corrected for you. No need to uninstall the whole PostgreSQL cluster.


I was running into this issue after switching over to the PostgresApp and removing the existing PostgreSQL version via

brew remove postgres

I ultimately solved the problem by re-installing PostgreSQL via

brew install postgres

I was able to retain the use of the PostgresApp by adding the following to my .bash_profile

export PATH="/Applications/Postgres.app/Contents/MacOS/bin:/usr/local/bin:$PATH"

You can also try running:

brew doctor

As it alerted me to this as well as some additional errors.

This error was also affecting my ability to use the Paperclip gem as it was causing ImageMagick to fail with the same error.

(Using OS X 10.8.2)


Some time after I posted this question, I found that libpq.5.4.dylib resides in /Library/PostgreSQL/9.1/lib/.
So, I created the following link:
lrwxr-xr-x 1 sathishvc admin 43 Jan 28 23:40 /usr/local/lib/libpq.5.4.dylib -> /Library/PostgreSQL/9.1/lib/libpq.5.4.dylib.

This solved the problem then.