Re: BUG #17756: Invalid replica indentity set order in a dump

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Robert Haas <robertmhaas(at)gmail(dot)com>, Michael Paquier <michael(at)paquier(dot)xyz>
Cc: Sergey Belyashov <sergey(dot)belyashov(at)gmail(dot)com>, pgsql-bugs(at)lists(dot)postgresql(dot)org, Alvaro Herrera <alvherre(at)alvh(dot)no-ip(dot)org>
Subject: Re: BUG #17756: Invalid replica indentity set order in a dump
Date: 2023-01-20 19:54:25
Message-ID: 615621.1674244465@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

I wrote:
> I wonder why it is that the backend rejects this sequence.
> I see that you can do this:
> regression=# create table tbl (id integer not null primary key) partition by list (id);
> CREATE TABLE
> regression=# alter table tbl replica identity using index tbl_pkey;
> ALTER TABLE
> and it doesn't seem like the partitioned index is notably more
> valid in this state than in the one that pg_dump has created.
> So I think it might be better to fix the backend to allow this
> sequence of operations.

I looked into this, and I think we basically could just drop the
restriction in ATExecReplicaIdentity that rejects marking an invalid
index as replica identity. If it is invalid, then the relcache won't
treat it as being the live replica identity (cf RelationGetIndexList),
so nothing will happen until it becomes valid; but there's no reason
why we can't mark it as identity in advance of that. We support
not-yet-valid primary keys, so why not replica identity?

In checking this, I found a comment in index.c claiming

* ALTER TABLE assumes that indisreplident cannot be set for
* invalid indexes.

which was added by Michael's 9511fb37a. The back story for that
indicates that Michael was worried about multiple indexes of a
relation becoming marked with indisreplident. However, as far
as I can see the only actual issue there is that
relation_mark_replica_identity is too trusting, and that looks
like either sloppy coding or premature optimization. I think
we could just rip out its early-exit path and fix it to positively
guarantee that no more than one index is marked indisreplident.

In short, I propose the attached. This'd need to be back-patched,
which 9511fb37a wasn't, so maybe we should also back-patch 9511fb37a?
I don't think it's really necessary though.

regards, tom lane

Attachment Content-Type Size
allow-invalid-replica-identity-index-1.patch text/x-diff 4.7 KB

In response to

Browse pgsql-bugs by date

  From Date Subject
Next Message PG Bug reporting form 2023-01-20 22:48:09 BUG #17757: Not honoring huge_pages setting during initdb causes DB crash in Kubernetes
Previous Message Tom Lane 2023-01-20 18:14:01 Re: BUG #17756: Invalid replica indentity set order in a dump