Rails, Postgres: dyld: lazy symbol binding failed: Symbol not found: _PQresultMemorySize
Asked Answered
B

8

9

creating a new rails-app (6.0.2) with postgres, on mac, could not get it to run.

Getting this error on app start:

dyld: Symbol not found: _PQresultMemorySize
  Referenced from: /Users/dev/.rvm/gems/ruby-2.5.7/gems/pg-1.2.2/lib/pg_ext.bundle
  Expected in: /usr/lib/libpq.5.dylib

enter image description here

This seems to be similar to dyld: lazy symbol binding failed: Symbol not found: _PQresultMemorySize - Rails,

but what is to do?

My previous rails apps, on rails v6.0.1, also with the same postgres gem 'pg', '>= 0.18', '< 2.0' are running just fine

Bannerman answered 21/1, 2020 at 17:7 Comment(1)
Found out very easy way to solve the issue. Just need to uninstall pg gem and then re-install it. 1. gem uninstall pg 2. bundle install or gem install pg And lastly don't forget to stop if any spring process is running in your machine.Pulverulent
G
2

I found the following workaround. It hardcodes the path to the shared library in the pg_ext.bundle:

install_name_tool -change libpq.5.dylib /Library/PostgreSQL/12/lib/libpq.5.12.dylib pg_ext.bundle
Gaye answered 28/3, 2020 at 13:0 Comment(2)
Thanks, Roman, worked for me! (cd to gem-path and your command) - now i can work with pg 1.2.3. Hope, that the postgres-people fix this annoying errorBannerman
I got an error. error: /Library/Developer/CommandLineTools/usr/bin/install_name_tool: can't open file: pg_ext.bundle (No such file or directory)Snakebird
P
28

What solved my issue was to run a gem uninstall pg and after that do the bundle install

Pericles answered 17/9, 2020 at 0:45 Comment(0)
P
6

PQresultMemorySize was introduced in postgres 12, since 1.2.0 pg gem checks if it is available during extension build and uses if it is (previously it did not). Since it was available at build, and you probably have not downgraded postgres or libpq right away - it suggests some version conflict.

When installing from homebrew location would be /usr/local/lib/libpq.5.dylib, but you have /usr/lib/libpq.5.dylib Looks like you have libpq from/and postgres >= 12 installed together with some older version.

You need to find which different postgresses/libpq you have installed and remove one of these to get rid of the conflict.

As a temporary solution - you can set pg version requirement to be exactly the same as your already working one (look into Gemfile.lock of the other app), so that already installed gem will be used (and have more correct extension or just be a version that does not try to access this new feature yet).

Parallelogram answered 21/1, 2020 at 17:32 Comment(1)
Thanks Vasfed! since then it ran, i cannot say why, but since today i have the same issue. yesterday it worked, today not. i think you're right. i wanted to ln -s /Library/PostgreSQL/12/lib/libpq.5.12.dylib /usr/lib/libpq.5.dylib but now i have this problem: #60395802. for now i made gem 'pg', '~> 1.1.4' in my Gemfile and it works for now ...Bannerman
C
5

Okay, team — here’s what I did.

First, I ran into this issue upgrading from postgresql 12 to 13 via homebrew ... because I am an idiot and didn’t pin 12.

After fixing a bunch of issues, all seemed to be functioning (I could boot my server, I could reinstall the pg gem — all seemed to be good). I had gotten the /usr/lib/libpq.5.dylib error reinstalling pg early on ... but then it magically went away and I thought I was golden. I wasn’t. When I ran my Rails console, I ran a query and ... got the /usr/lib/libpq.5.dylib error.

What did work was:

  1. brew services stop postgresql
  2. brew install libpq
  3. brew link --overwrite libpq --force
  4. brew services start postgresql

For those of you running spring, don’t forget to spring stop (I’m not sure the order really matters, and it’s also possible stopping/restarting postgresql wasn’t necessary, but better safe than sorry).

Cirone answered 12/3, 2021 at 16:18 Comment(1)
This worked for me, Rails 6.1.3Mainstay
X
3

Rebuilding the gem worked for me:

gem pristine pg
Xylo answered 30/10, 2020 at 1:30 Comment(2)
This is one of the easier solution.Lello
Great. This did the job.Postfix
B
2

next attempt for solution:

$ gem install pg -- --with-pg-config=/Library/PostgreSQL/12/bin/pg_config according to github-pg

Fetching: pg-1.2.2.gem (100%)
Building native extensions with: '--with-pg-config=/Library/PostgreSQL/12/bin/pg_config'
This could take a while...
Successfully installed pg-1.2.2
Parsing documentation for pg-1.2.2
Installing ri documentation for pg-1.2.2
Done installing documentation for pg after 0 seconds
1 gem installed

Gemfile: gem 'pg', '~> 1.2.2'

same result

pg searches for /usr/lib/libpq.5.dylib, and there is a symlink, but it seems to point to the older version of postgres.

for me, it seems, that it should look for /Library/PostgreSQL/12/lib/libpq.5.dylib

how to teach the gem for looking to that dylib?

Bannerman answered 3/3, 2020 at 18:31 Comment(0)
G
2

I found the following workaround. It hardcodes the path to the shared library in the pg_ext.bundle:

install_name_tool -change libpq.5.dylib /Library/PostgreSQL/12/lib/libpq.5.12.dylib pg_ext.bundle
Gaye answered 28/3, 2020 at 13:0 Comment(2)
Thanks, Roman, worked for me! (cd to gem-path and your command) - now i can work with pg 1.2.3. Hope, that the postgres-people fix this annoying errorBannerman
I got an error. error: /Library/Developer/CommandLineTools/usr/bin/install_name_tool: can't open file: pg_ext.bundle (No such file or directory)Snakebird
N
1

I had the same issue and the steps I did to solve this issue was:

  1. gem uninstall pg - you might receive a message saying:
pg is not installed in GEM_HOME, try:
    gem uninstall -i /Users/user_name/.rvm/rubies/ruby-2.7.1/lib/ruby/gems/2.7.0 pg

If that happens, execute the suggested path with sudo:

sudo gem uninstall -i /Users/user_name/.rvm/rubies/ruby-2.7.1/lib/ruby/gems/2.7.0 pg
  1. if you run bundle install might result in an error saying "An error occurred while installing pg (1.2.3), and Bundler cannot continue.". Install postgres:
brew install postgresql

or

gem install pg -v '1.2.3' --source 'https://rubygems.org/
  1. Proceed with rails command as in my case:
rails db:setup
Numidia answered 18/9, 2020 at 5:15 Comment(0)
J
0

You may need to find where pg_config file is located for the version of postgres you'd like to connect to. Try sudo find / -name "*pg_config". You should find an entry like /usr/local/Cellar/postgresql@14/14.13/bin/pg_config (I installed postgres using brew).

Remove pg if it's already installed for your app. Make sure to remove the pg folder in the vendor gems as well.

Run the following commands

> bundle config build.pg --with-pg-config=<config-path-your-found>
> bundle install

Credit: https://mcmap.net/q/129465/-gem-install-pg-with-pg-config-works-bundle-fails

Janitor answered 6/9 at 4:3 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.