Error when running rails db:prepare after upgrading Postgresql 14.5 to 14.5.1 with homebrew

rails aborted! LoadError: dlopen(/Users/my-user/.asdf/installs/ruby/3.1.2/lib/ruby/gems/3.1.0/gems/pg-1.4.3/lib/pg_ext.bundle, 0x0009): Library not loaded: /opt/homebrew/opt/postgresql/lib/libpq.5.dylib

It looks like the pg gem is looking for the libpq.5.dylib in the wrong directory after the upgrade 🤷‍♂️


  1. Rebuild the pg gem gem pristine pg
  2. run bundle install in your repo
  3. run rails db:prepare
  4. 🎉🎉🎉