Re: Threading in BGWorkers (!) - Mailing list pgsql-hackers
From | Robert Haas |
---|---|
Subject | Re: Threading in BGWorkers (!) |
Date | |
Msg-id | CA+TgmoZymQGF6v6WNMRy7j=6S5hR+y3r5cz8fvjbZ5-tAsWrnA@mail.gmail.com Whole thread Raw |
In response to | Re: Threading in BGWorkers (!) (Tom Lane <tgl@sss.pgh.pa.us>) |
List | pgsql-hackers |
On Thu, Jul 30, 2020 at 2:55 PM Tom Lane <tgl@sss.pgh.pa.us> wrote: > > Why not? Our answer to threading inside functions has been, for quite a > > while, that it's kinda ok if the threads never call into postgres and > > can never escape the lifetime of a function. But that's not actually > > really safe due to the signal handler issue. > > In other words, it's *not* safe and never has been. I see no good reason > to believe that the signal handler issue is the only one. Even if it is, > not being able to call any postgres infrastructure is a pretty huge > handicap. I find this line of argument really unfair. It's true that there might be issues other than the signal handler one, but so what? That is not a principled argument against fixing the signal handler part of the problem, which is the only *known* problem with the use case Andres describes. It is also true that it would be more useful to enable additional use cases rather than just this one, but that is not a principled argument against enabling this one. My only present concern about the proposal actually in front of us -- that is to say, use pthread_sigmask() rather than sigprocmask() -- is Thomas's observation that on his system doing so breaks the world. That seems to be quite a serious problem. If we are deciding whether to use one function or another some purpose and they are equally good for the core code but one is better for people who want to play around with extensions, we may as well use the one that's better for that purpose. We need not give such experimentation our unqualified endorsement; we need only decide against obstructing it unnecessarily. But when such a substitution risks breaking things that work today, the calculus gets a lot more complicated. Unless we can find a way to avoid that risk, I don't think this is a good trade-off. But more broadly I think it is well past time that we look into making the backend more thread-friendly. The fact that "it's *not* safe and never has been" has not prevented people from doing it. We don't end up with people going "oh, well sigprocmask uh oh so I better give up now." What we end up with is people just going right ahead and doing it, probably without even thinking about sigprocmask, and ending up with low-probability failure conditions, which seems likely to hurt PostgreSQL's reputation for reliability with no compensating benefit. Or alternatively they hack core, which sucks, or they switch to some non-PG database, which also sucks. -- Robert Haas EnterpriseDB: http://www.enterprisedb.com The Enterprise PostgreSQL Company
pgsql-hackers by date: