Reputation: 1102
I have
Ruby 3.0.4
Rails 6.1.7
pg 1.4.5
postgresql 14.6
Here is my database.yml file
development:
adapter: postgresql
encoding: utf8
database: olio_development
username: postgres
password: password
pool: 5
host: 127.0.0.1
port: 5432
gssencmode: disable
When I run rake db:create I am getting the following segmentatin fault
/home/usr/.rvm/gems/ruby-3.0.4/gems/pg-1.4.5/lib/pg/connection.rb:626: [BUG] Segmentation fault at 0x00007fd79729a140
ruby 3.0.4p208 (2022-04-12 revision 3fa771dded) [x86_64-linux]
-- Control frame information -----------------------------------------------
c:0050 p:---- s:0275 e:000274 CFUNC :connect_poll
c:0049 p:0543 s:0271 e:000270 METHOD /home/suganya/.rvm/gems/ruby-3.0.4/gems/pg-1.4.5/lib/pg/connection.rb:626
The connection fails.
I have verified postgres is running and is on host 127.0.0.1 and post 5432.
Please help me how to resolve this segmentation fault?
Upvotes: 14
Views: 7133
Reputation: 7532
EDIT: the segfault described in the original question was caused by the PG client libraries, not the pg gem, so this answer doesn’t help with it. See the above answer instead. However, pinning older versions of a gem is always a reasonable troubleshooting step when you start to suddenly see failures you can’t otherwise debug in a process known as [bisecting](https://en.m.wikipedia.org/wiki/Bisection_(software_engineering).
I'm seeing a GitHub issue for the pg gem (https://github.com/ged/ruby-pg/issues/493) that matches your problem, so it might be a bug with pg v1.4.5. I would try pinning it to an older version:
gem 'pg', '1.4.4'
And work your way backwards if that still has issues. You can also add your information to the GitHub issue linked above to help the maintainers resolve the issue.
Upvotes: 5
Reputation: 1521
I came across this question while searching for a solution to a similar issue. So will post the fix which worked for me, maybe it will help someone else.
My environment:
Ruby 3.2.2
Rails 7.0.4.3
pg 1.4.5
postgresql 14.9
Adding the following line to .zshrc
(and restarting the terminal) fixed the problem for me:
export PGGSSENCMODE="disable"
This Github Issue comment provides more background about the root cause and why you're seeing it. It includes a few possible resolutions, including the one above:
- Disable GSSAPI via the
PGGSSENCMODE=disable
environment variable or passgssencmode=disable
in the connection string.- Initiate the database connection by preloading the app before forking so the macOS system calls are invoked in the parent process. In Puma, the
preload_app!
config option does this.- Use a PostgreSQL server that does not have
--with-gssapi
enabled. By default I believe the Homebrew version has this, but asdf does not install PostgreSQL with this. You can check by usingotool -L
.
Upvotes: 38