pg.ddx.io  pgsql-committers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: pgsql-committers@lists.postgresql.org
Subject: pgsql: Allow REPLICA IDENTITY to be set on an index that's not (yet) va
Date: Sat, 21 Jan 2023 18:10:48 +0000
Message-ID: <E1pJIKG-004oqz-Le@gemulon.postgresql.org> (raw)

Allow REPLICA IDENTITY to be set on an index that's not (yet) valid.

The motivation for this change is that when pg_dump dumps a
partitioned index that's marked REPLICA IDENTITY, it generates a
command sequence that applies REPLICA IDENTITY before the partitioned
index has been marked valid, causing restore to fail.  We could
perhaps change pg_dump to not do it like that, but that would be
difficult and would not fix existing dump files with the problem.
There seems to be very little reason for the backend to disallow
this anyway --- the code ignores indisreplident when the index
isn't valid --- so instead let's fix it by allowing the case.

Commit 9511fb37a previously expressed a concern that allowing
indisreplident to be set on invalid indexes might allow us to
wind up in a situation where a table could have indisreplident
set on multiple indexes.  I'm not sure I follow that concern
exactly, but in any case the only way that could happen is because
relation_mark_replica_identity is too trusting about the existing set
of markings being valid.  Let's just rip out its early-exit code path
(which sure looks like premature optimization anyway; what are we
doing expending code to make redundant ALTER TABLE ... REPLICA
IDENTITY commands marginally faster and not-redundant ones marginally
slower?) and fix it to positively guarantee that no more than one
index is marked indisreplident.

The pg_dump failure can be demonstrated in all supported branches,
so back-patch all the way.  I chose to back-patch 9511fb37a as well,
just to keep indisreplident handling the same in all branches.

Per bug #17756 from Sergey Belyashov.

Discussion: https://postgr.es/m/17756-dd50e8e0c8dd4a40@postgresql.org

Branch
------
REL_11_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/6c122eddecc1c2e702aa05d2868a3e6a0d75bda1

Modified Files
--------------
src/backend/catalog/index.c                    |  6 ++-
src/backend/commands/tablecmds.c               | 64 +++++++++-----------------
src/test/regress/expected/replica_identity.out | 37 +++++++++++++++
src/test/regress/sql/replica_identity.sql      | 20 ++++++++
4 files changed, 84 insertions(+), 43 deletions(-)



view thread (6+ messages)

Message-ID: <E1pJIKG-004oqz-Le@gemulon.postgresql.org>
Permalink:  ../E1pJIKG-004oqz-Le@gemulon.postgresql.org/
Also on:    postgresql.org/message-id/E1pJIKG-004oqz-Le@gemulon.postgresql.org

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-committers@postgresql.org
  Cc: tgl@sss.pgh.pa.us
  Subject: Re: pgsql: Allow REPLICA IDENTITY to be set on an index that's not (yet) va
  In-Reply-To: <E1pJIKG-004oqz-Le@gemulon.postgresql.org>
  References: <E1pJIKG-004oqz-Le@gemulon.postgresql.org>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox