You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Segfault while connecting from multiple processes with Postgres 12 #311
I'm running Postgres 12.1, Ruby 2.6.5 and pg 1.1.4 on MacOS Catalina. This also happens on Ruby 2.5.1 and 2.5.7 as well as MacOS Mojave. It does not happen with Postgres 10 or 11.
Running the following small script will cause a segfault.
Confirming the same issue. Ran into it while testing on my MacOS an app, after upgrading to Postgres 12 from Postgres 11 ( via brew) . Works for a Single connection, but crashes for multiple, i.e. crashes a Rails app, when trying to load models.
gem 'pg' => PG::VERSION = "1.1.4"
rails 6.0.1
ruby 2.6.5 (also tried 2.5.3 with the same result)
psql (PostgreSQL) 12.1
MacOS Catalina
The only thing that changed - upgraded Postrgres to 12.1 from 11
It looks like in Rails 5, this can be fixed by adding gssencmode: disable as a connection parameter in database.yml
Unfortunately Rails 4 doesn't pass gssencmode along to pg (because VALID_CONN_PARAMSis hardcoded until Rails 5). We were able to fix this by setting a PGGSSENCMODE="disable" environment variable.
Reacted by aldrin-fc, prangarang, Miguel Peniche, Alexey Smirnov, Thiago Belem, Akshay Khole, Carlos Feliciano Barba, Rafael Santos, Adriano Rob, Garrett Bjerkhoel and 31 more
Reacted by Brad West
Reacted by Miguel Peniche, Akshay Khole, Carlos Feliciano Barba, Adriano Rob, Thibaut Barrère, Bibek Sharma Chapagain, Mariusz Błaszczak, Kate Efimova, Will Butler, Rafael Simoes and 2 more
Reacted by Bibek Sharma Chapagain, Mariusz Błaszczak, Mauricio Lima, Raphael Monteiro, David Marchante, Pavel Zhukov, Kevin Maze and Rikki
Reacted by Bibek Sharma Chapagain, Mariusz Błaszczak, Kate Efimova, Raphael Monteiro, Kevin Maze and Rikki
Reacted by Bibek Sharma Chapagain and Kate Efimova
I'm a bit confused - based on my understanding of the problem, I would expect that closing the connection before the fork would resolve it but it does not.
It's not about shared handles or anything. It seems that macOS libraries are generally not safe to use after fork() (due to libdispatch.) It's a known issue over at Homebrew.
If you're in Rails, you can just do the same thing with the host params.
# 1: This will crashdevelopment:
adapter: postgresqldatabase: my_databasehost: localhost# 2: This won't crash and will still connect to localhost just finedevelopment:
adapter: postgresqldatabase: my_databasehost:
So far I noticed that I only need this workaround if the host is localhost or 127.0.0.1.
Reacted by Adriano Rob, JD Wolk, brianinator, Dan Dobrick, Aleksandr Borovkov, Michael Seneadza, spinlister-team, vihuynh, Tim Messick, Dimitris and 13 more
Reacted by brianinator, Dan Dobrick, Arpsara, Aishwarya Sankar Raman, Amisha Shukla, Kyrylo Machukhin, Luan Santos, heeitoor, Leonardo Fernandes Zappani, Tectract and 1 more
Reacted by Mezbah Alam, heeitoor and Leonardo Fernandes Zappani
@alienxp03 Yes, this also skips GSS encryption by connecting over Unix socket (which is only available when client and server are on the same machine.) Depending on how the server is configured, Unix socket may involve different authentication than TCP socket.
I got the same issue on Macbook pro latest Tahoe (26.2) and setting gssencmode: disable to false fixed it. Before this mac update it used to come up occasionally but now it's became all the time. It was also strange because it would happen when starting it from rails 8.1's new bin/ci command, but running rails test in my normal shell worked fine.
I'm still version-locked on Rails 5 and PostgresQL 13 from old debian repo backports because of this issue. I tried all the suggestions above, setting gssencode: disable didn't fix the solution on my servers.
Rails just segfaults on any modern installation of PG. It appears Rails and PostgresQL have parted ways, as of like years ago. Surely I can't be the only one experiencing this.
Here from the future, @harsh183 did you ever figure out why this seems like it regressed recently? Was it specific to 26.2 or did my own behavior change and now just only noticing it. I'm also aggressively using bin/ci now, or i guess, a lot more forking workers in general. When i first saw this ignored it because of the year, but this is forsure the issue. I'm also able to "fix" with PARALLEL_WORKERS=1 which is another dead give away.
best one I've found but it stayed broken across several mac os versions. My projects have quite a few tests and my MacBook has 12 cores so I want to use all of them to crunch so I just disable it.
At least I've only configured this hack to be local dev and ci. Ownership of fixing this seems so diffused, I'm not sure if someone will handle it.
I've only seen it on minitest, and I've also run into a lot because of all the bin/ci I use recently
Activity
konung commentedon Dec 3, 2019
Confirming the same issue. Ran into it while testing on my MacOS an app, after upgrading to Postgres 12 from Postgres 11 ( via brew) . Works for a Single connection, but crashes for multiple, i.e. crashes a Rails app, when trying to load models.
The only thing that changed - upgraded Postrgres to 12.1 from 11
cbandy commentedon Dec 3, 2019
@jessebs I expect
gssencmode: "disable"will avoid the crash. Can you please verify?jessebs commentedon Dec 3, 2019
Yes, that did avoid the issue.
cbandy commentedon Dec 3, 2019
I've reported this upstream: https://postgr.es/m/93f7379b-2e2f-db0c-980e-07ebd5de92ff%40crunchydata.com
trevorcreech commentedon Dec 5, 2019
It looks like in Rails 5, this can be fixed by adding
gssencmode: disableas a connection parameter indatabase.ymlUnfortunately Rails 4 doesn't pass
gssencmodealong topg(becauseVALID_CONN_PARAMSis hardcoded until Rails 5). We were able to fix this by setting aPGGSSENCMODE="disable"environment variable.miguelpeniche commentedon Dec 6, 2019
Thanks a lot @trevorcreech, ENV variable PGGSSENCMODE="disable" worked for me.
jessebs commentedon Dec 6, 2019
I'm a bit confused - based on my understanding of the problem, I would expect that closing the connection before the fork would resolve it but it does not.
Any understanding of why that's the case?
cbandy commentedon Dec 6, 2019
It's not about shared handles or anything. It seems that macOS libraries are generally not safe to use after fork() (due to libdispatch.) It's a known issue over at Homebrew.
alienxp03 commentedon Dec 11, 2019
Another workaround that I found is by not setting any value to the host, or just omit the
hostparams.If you're in Rails, you can just do the same thing with the
hostparams.So far I noticed that I only need this workaround if the host is
localhostor127.0.0.1.cbandy commentedon Dec 11, 2019
@alienxp03 Yes, this also skips GSS encryption by connecting over Unix socket (which is only available when client and server are on the same machine.) Depending on how the server is configured, Unix socket may involve different authentication than TCP socket.
TiuTalk commentedon Dec 11, 2019
Just letting you guys know that this also happens on Ruby 2.3.1, using
pg0.19.0, withpostgresqlstable 12.1 from Homebrew.Adding
gssencmode: disableto the database.yaml fixed the segfaults, thanks @trevorcreechankane commentedon Jan 21, 2020
If you installed PostgreSQL through Homebrew, reinstalling should fix it, thanks to this PR: Homebrew/homebrew-core#47494
brew uninstall postgresql # then kill all postgresql processes or restart machine brew install postgresqlconfig: fix spring randomly crashing in the pg gem
22 remaining items
Enable using Spring to speed up RSpec startup
Enable using Spring to speed up RSpec startup
Enable using Spring to speed up RSpec startup
Enable using Spring to speed up RSpec startup
Enable using Spring to speed up RSpec startup
Enable using Spring to speed up RSpec startup
Enable using Spring to speed up RSpec startup
Enable using Spring to speed up RSpec startup
VickTor61 commentedon Oct 18, 2025
I have been experiencing this issue for little over a week now and no solution so far has worked for me.
Ruby:
ruby 3.1.4p223 (2023-03-30 revision 957bb7cb81) [arm64-darwin25]Pg:
1.4.5Rails:
6.1.7.2Postgresql:
psql (PostgreSQL) 16.10 (Homebrew)Machine:
Mbp m4 pro 2024 running macos Tahoe (latest version)I have tried adding some suggestions above to my database.yml file yet i still get the segmentation fault error.
Any and every help is highly appreciated as this has been a major blocker for me. For context below is a snapshot of the error stack trace
error.txt
VickTor61 commentedon Oct 18, 2025
@Meekohi @docwhat @stevenharman @konung @trevorcreech
harsh183 commentedon Jan 30, 2026
I got the same issue on Macbook pro latest Tahoe (26.2) and setting
gssencmode: disableto false fixed it. Before this mac update it used to come up occasionally but now it's became all the time. It was also strange because it would happen when starting it from rails 8.1's newbin/cicommand, but runningrails testin my normal shell worked fine.https://notes.max.engineer/ruby-pg-gem-segfault - reading this was also a help. We should reopen this issue
Tectract commentedon Jan 31, 2026
I'm still version-locked on Rails 5 and PostgresQL 13 from old debian repo backports because of this issue. I tried all the suggestions above, setting gssencode: disable didn't fix the solution on my servers.
Rails just segfaults on any modern installation of PG. It appears Rails and PostgresQL have parted ways, as of like years ago. Surely I can't be the only one experiencing this.
rromanchuk commentedon Sep 6, 2026
Here from the future, @harsh183 did you ever figure out why this seems like it regressed recently? Was it specific to 26.2 or did my own behavior change and now just only noticing it. I'm also aggressively using bin/ci now, or i guess, a lot more forking workers in general. When i first saw this ignored it because of the year, but this is forsure the issue. I'm also able to "fix" with PARALLEL_WORKERS=1 which is another dead give away.
harsh183 commentedon Sep 6, 2026
https://notes.max.engineer/ruby-pg-gem-segfault
best one I've found but it stayed broken across several mac os versions. My projects have quite a few tests and my MacBook has 12 cores so I want to use all of them to crunch so I just disable it.
At least I've only configured this hack to be local dev and ci. Ownership of fixing this seems so diffused, I'm not sure if someone will handle it.
I've only seen it on minitest, and I've also run into a lot because of all the bin/ci I use recently
rromanchuk commentedon Sep 7, 2026
same, all of the the above