Re: BUG #15114: logical decoding Segmentation fault

From: Michael Paquier <michael(at)paquier(dot)xyz>
To: Petr Jelinek <petr(dot)jelinek(at)2ndquadrant(dot)com>
Cc: Петър Славов <pet(dot)slavov(at)gmail(dot)com>, Alvaro Herrera <alvherre(at)alvh(dot)no-ip(dot)org>, Andres Freund <andres(at)anarazel(dot)de>, Petr Jelinek <petr(at)2ndquadrant(dot)com>, pgsql-bugs(at)lists(dot)postgresql(dot)org, Peter Eisentraut <peter(dot)eisentraut(at)2ndquadrant(dot)com>
Subject: Re: BUG #15114: logical decoding Segmentation fault
Date: 2018-10-30 06:28:28
Message-ID: 20181030062828.GB23393@paquier.xyz
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

On Mon, Oct 29, 2018 at 04:03:31PM +0100, Petr Jelinek wrote:
> The reason why it breaks for OP is that his IMMUTABLE function is not
> actually IMMUTABLE, that's also why we don't see it reported much.

Thanks, Petr. I have missed that part. Now I can see the failure
easily. Please note that on the receiver side you have the same
problem, RelationGetIndexAttrBitmap() is still being used in
logicalrep_rel_open() so that crashes the receiver:
#18 0x0000563cc278baa4 in RelationGetIndexPredicate
(relation=0x7f9764cdc050) at relcache.c:4720
#19 0x0000563cc22ccdd6 in BuildIndexInfo (index=0x7f9764cdc050) at
index.c:1789
#20 0x0000563cc278be4f in RelationGetIndexAttrBitmap
(relation=0x7f9764de52e8, attrKind=INDEX_ATTR_BITMAP_IDENTITY_KEY) at
relcache.c:4921
#21 0x0000563cc25a6b0c in logicalrep_rel_open (remoteid=16388,
lockmode=3) at relation.c:313

> Given this I am not sure if we want to add test for this as it's
> something one should not do because it has unpredictable side effects,
> but if you think it will be useful anyway I can whip something out.

Hmm. People should not do that but they can do it, so this thread is
telling is to be careful. Adding new objects in the schema of the
publisher and the receiver would be also cheap. A test like that is not
something we would see but I would suggest to stress the new routine on
both sides. In the patch, something which makes me uncomfortable is
that get_rel_idattr() is a duplicate of the code paths taken by
RelationGetIndexAttrBitmap() when INDEX_ATTR_BITMAP_IDENTITY_KEY gets
used to fill in the relation cache. In this case, wouldn't we want to
just fetch the replica index instead of the full index list? What is
proposed here needs more thoughts I think. Something that we could
consider on HEAD is to remove INDEX_ATTR_BITMAP_IDENTITY_KEY as it is
visibly unsafe. rd_idattr is also an unsafe concept.

Putting a safeguard in RelationGetIndexAttrBitmap() so as it generates
an ERROR if called in an output plugin, or just assert would be nice,
however such a check would need to use MyReplicationSlot (I don't recall
something else), and the limitations could just be documented as well.
--
Michael

In response to

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message PG Bug reporting form 2018-10-30 06:35:50 BUG #15470: Docker image dpage/pgadmin4:3.4 (and latest) fail with non-root user
Previous Message Michael Paquier 2018-10-30 04:11:19 Re: BUG #15437: Segfault during insert into declarative partitioned table with a trigger creating partition