Re: Segmentation fault when calling BlessTupleDesc in a C function in parallel on PostgreSQL-(12.6, 12.7, 13.2, 13.3)

Поиск
Список
Период
Сортировка
От Eric Thinnes
Тема Re: Segmentation fault when calling BlessTupleDesc in a C function in parallel on PostgreSQL-(12.6, 12.7, 13.2, 13.3)
Дата
Msg-id 636195a3-32d0-f45c-6e06-4df99ece5760@gmx.de
обсуждение исходный текст
Ответ на Re: Segmentation fault when calling BlessTupleDesc in a C function in parallel on PostgreSQL-(12.6, 12.7, 13.2, 13.3)  (Tom Lane <tgl@sss.pgh.pa.us>)
Ответы Re: Segmentation fault when calling BlessTupleDesc in a C function in parallel on PostgreSQL-(12.6, 12.7, 13.2, 13.3)  (Thomas Munro <thomas.munro@gmail.com>)
Список pgsql-bugs
Because of the parallelism it is difficult to debug the error.
I have less experience with that.

But I have now rewritten the function setof_kpos a little and
no longer use the user-specific result type. The c-function
was of course adjusted accordingly and the result type was not
more dynamically determined via the corresponding functions.

CREATE OR REPLACE FUNCTION setof_kpos(
     kontopositionen text
   , OUT Pos         smallint
   , OUT Count       smallint
   , OUT Konto       integer
   , OUT Sign        smallint
   , OUT BTyp        smallint
   , OUT Betrag      bigint
   )
   RETURNS SETOF RECORD
   AS '/var/lib/postgresql/lib/13/test', 'set_of_kpos'
   LANGUAGE C IMMUTABLE STRICT
   PARALLEL SAFE
;

That seems to solve the problem.

 > BlessTupleDesc certainly has side effects; that's pretty much the
 > whole point of it.  If you're marking this thing as parallel safe,
 > I imagine that the problem boils down to "parallel worker locally
 > registers a blessed tupdesc, but the leader has never heard of it,
 > so fails to interpret the returned tuple".

I noticed that as well. Whenever it was the leader's turn the crash came.
That explains a lot and I now understand why the changes brought success.


But it doesn't matter, it does and I am richer by one experience.

Thank you very much for the good and quick help.

Eric Thinnes


Am 14.05.21 um 17:20 schrieb Tom Lane:
> Eric Thinnes <e.thinnes@gmx.de> writes:
>> The function always delivers the same result with the same call
>> parameters except for the determination of the result types and the
>> generation of the TupleDesc, the function has no side effects.
>
> BlessTupleDesc certainly has side effects; that's pretty much the
> whole point of it.  If you're marking this thing as parallel safe,
> I imagine that the problem boils down to "parallel worker locally
> registers a blessed tupdesc, but the leader has never heard of it,
> so fails to interpret the returned tuple".
>
> Perhaps a workaround is possible by using a named composite type
> instead of generating a rowtype on the fly?  But that won't work
> if you want this to be polymorphic.
>
> Also, I recall that there are provisions in typcache.c in recent
> versions to support a shared pool of registered (i.e. blessed)
> tuple descriptors.  That would likely solve your problem, but
> I've never looked into how to use that code.  I doubt just
> calling BlessTupleDesc is enough.  In particular, I imagine
> you need to make sure the leader process creates the tupdesc
> first, so it's available to all workers.
>
>             regards, tom lane
>



В списке pgsql-bugs по дате отправления:

Предыдущее
От: Peter Geoghegan
Дата:
Сообщение: Re: BUG #16833: postgresql 13.1 process crash every hour
Следующее
От: PG Bug reporting form
Дата:
Сообщение: BUG #17013: All RH6 repos are missing repomod.xml.asc files.