Re: `pg_ctl init` crashes when run concurrently; semget(2) suspected
Tom Lane <tgl@sss.pgh.pa.us>
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Gavin Panella <gavinpanella@gmail.com>
Cc: pgsql-hackers@postgresql.org
Date: 2025-08-11T23:41:07Z
Lists: pgsql-hackers
Gavin Panella <gavinpanella@gmail.com> writes: > With that fix applied to REL_17_5 things are working well. Limiting the > search sounds like an improvement too. Cool. I'll push the fix after our release freeze lifts. > Then I thought: I'm only seeing the log from one of those instances, yet > they're all going through the same search for free semaphore sets. That's a > few system calls going to waste. Maybe not important in the big picture, > but it gave me an idea to left shift nextSemaKey in PGReserveSemaphores, > i.e. `nextSemaKey = statbuf.st_ino << 4`, to give each pg_ctl process a few > guaranteed uncontested keys (at least, uncontested between themselves). In > a small test this eliminated contention for semaphore sets due to > concurrency. It is more of an optimisation though, rather than a bug fix. Meh ... if we thought this was worth worrying about, I'd be more inclined to run the st_ino through a hash function to spread out the possible values a little more. But I think in nearly all scenarios it'd be a waste of effort. If collisions were probable we'd have found this issue years ago. regards, tom lane
Commits
-
Don't treat EINVAL from semget() as a hard failure.
- 21fddb3d7690 19 (unreleased) landed
- f4c0883448d8 15.15 landed
- e67d5f7baa7d 16.11 landed
- e3b3fa863810 13.23 landed
- b3d6e8b63bc1 14.20 landed
- ab92f0e7f7d7 17.7 landed
- 787cd2b7d5cd 18.0 landed
-
Give up on running with NetBSD/OpenBSD's default semaphore settings.
- 810a8b1c8051 18.0 cited