deferred primary key and logical replication

Started by Euler Taveiraover 6 years ago9 messageshackers
Jump to latest
#1Euler Taveira
euler@eulerto.com

Hi,

While looking at an old wal2json issue, I stumbled on a scenario that a
table
with a deferred primary key is not updatable in logical replication. AFAICS
it
has been like that since the beginning of logical decoding and seems to be
an
oversight while designing logical decoding. I don't envision a problem with
a
deferred primary key in an after commit scenario. Am I missing something?

Just in case, I'm attaching a patch to fix it and also add a test to cover
this
scenario.

--
Euler Taveira http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services

Attachments:

0001-Table-with-deferred-PK-is-not-updatable-in-logical-r.patchtext/x-patch; charset=US-ASCII; name=0001-Table-with-deferred-PK-is-not-updatable-in-logical-r.patchDownload+22-7
#2Ajin Cherian
itsajin@gmail.com
In reply to: Euler Taveira (#1)
Re: deferred primary key and logical replication

The patch no longer applies, because of additions in the test source. Otherwise, I have tested the patch and confirmed that updates and deletes on tables with deferred primary keys work with logical replication.

The new status of this patch is: Waiting on Author

#3Euler Taveira
euler@eulerto.com
In reply to: Ajin Cherian (#2)
Re: deferred primary key and logical replication

On Fri, 24 Jul 2020 at 05:16, Ajin Cherian <itsajin@gmail.com> wrote:

The patch no longer applies, because of additions in the test source.
Otherwise, I have tested the patch and confirmed that updates and deletes
on tables with deferred primary keys work with logical replication.

The new status of this patch is: Waiting on Author

Thanks for testing. I attached a rebased patch.

--
Euler Taveira http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services

Attachments:

t42355_3
0001-Table-with-deferred-PK-is-not-updatable-in-logical-r.patchtext/x-patch; charset=US-ASCII; name=0001-Table-with-deferred-PK-is-not-updatable-in-logical-r.patchDownload+22-7
#4Ajin Cherian
itsajin@gmail.com
In reply to: Euler Taveira (#3)
Re: deferred primary key and logical replication

The following review has been posted through the commitfest application:
make installcheck-world: tested, passed
Implements feature: tested, passed
Spec compliant: not tested
Documentation: not tested

Patch applies cleanly. Tested that update/delete of tables with deferred primary keys now work with logical replication. Code/comments look fine.

The new status of this patch is: Ready for Committer

#5Amit Kapila
amit.kapila16@gmail.com
In reply to: Euler Taveira (#1)
Re: deferred primary key and logical replication

On Mon, May 11, 2020 at 2:41 AM Euler Taveira
<euler.taveira@2ndquadrant.com> wrote:

Hi,

While looking at an old wal2json issue, I stumbled on a scenario that a table
with a deferred primary key is not updatable in logical replication. AFAICS it
has been like that since the beginning of logical decoding and seems to be an
oversight while designing logical decoding.

I am not sure if it is an oversight because we document that the index
must be non-deferrable, see "USING INDEX records the old values of the
columns covered by the named index, which must be unique, not partial,
not deferrable, and include only columns marked NOT NULL." in docs
[1]: https://www.postgresql.org/docs/devel/sql-altertable.html

Now sure this constraint is when we use USING INDEX for REPLICA
IDENTITY but why it has to be different for PRIMARY KEY especially
when UNIQUE constraint will have similar behavior and the same is
documented?

[1]: https://www.postgresql.org/docs/devel/sql-altertable.html

--
With Regards,
Amit Kapila.

#6Euler Taveira
euler@eulerto.com
In reply to: Amit Kapila (#5)
Re: deferred primary key and logical replication

On Mon, 5 Oct 2020 at 08:34, Amit Kapila <amit.kapila16@gmail.com> wrote:

On Mon, May 11, 2020 at 2:41 AM Euler Taveira
<euler.taveira@2ndquadrant.com> wrote:

Hi,

While looking at an old wal2json issue, I stumbled on a scenario that a

table

with a deferred primary key is not updatable in logical replication.

AFAICS it

has been like that since the beginning of logical decoding and seems to

be an

oversight while designing logical decoding.

I am not sure if it is an oversight because we document that the index
must be non-deferrable, see "USING INDEX records the old values of the
columns covered by the named index, which must be unique, not partial,
not deferrable, and include only columns marked NOT NULL." in docs
[1].

Inspecting this patch again, I forgot to consider
that RelationGetIndexList()
is called by other backend modules. Since logical decoding deals with
finished
transactions, it is ok to use a deferrable primary key. However, this patch
is
probably wrong because it does not consider the other modules.

--
Euler Taveira http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services

#7Amit Kapila
amit.kapila16@gmail.com
In reply to: Euler Taveira (#6)
Re: deferred primary key and logical replication

On Sun, Oct 25, 2020 at 9:39 PM Euler Taveira
<euler.taveira@2ndquadrant.com> wrote:

On Mon, 5 Oct 2020 at 08:34, Amit Kapila <amit.kapila16@gmail.com> wrote:

On Mon, May 11, 2020 at 2:41 AM Euler Taveira
<euler.taveira@2ndquadrant.com> wrote:

Hi,

While looking at an old wal2json issue, I stumbled on a scenario that a table
with a deferred primary key is not updatable in logical replication. AFAICS it
has been like that since the beginning of logical decoding and seems to be an
oversight while designing logical decoding.

I am not sure if it is an oversight because we document that the index
must be non-deferrable, see "USING INDEX records the old values of the
columns covered by the named index, which must be unique, not partial,
not deferrable, and include only columns marked NOT NULL." in docs
[1].

Inspecting this patch again, I forgot to consider that RelationGetIndexList()
is called by other backend modules. Since logical decoding deals with finished
transactions, it is ok to use a deferrable primary key.

But starting PG-14, we do support logical decoding of in-progress
transactions as well.

--
With Regards,
Amit Kapila.

#8Anastasia Lubennikova
a.lubennikova@postgrespro.ru
In reply to: Amit Kapila (#7)
Re: deferred primary key and logical replication

On 27.10.2020 13:46, Amit Kapila wrote:

On Sun, Oct 25, 2020 at 9:39 PM Euler Taveira
<euler.taveira@2ndquadrant.com> wrote:

On Mon, 5 Oct 2020 at 08:34, Amit Kapila <amit.kapila16@gmail.com> wrote:

On Mon, May 11, 2020 at 2:41 AM Euler Taveira
<euler.taveira@2ndquadrant.com> wrote:

Hi,

While looking at an old wal2json issue, I stumbled on a scenario that a table
with a deferred primary key is not updatable in logical replication. AFAICS it
has been like that since the beginning of logical decoding and seems to be an
oversight while designing logical decoding.

I am not sure if it is an oversight because we document that the index
must be non-deferrable, see "USING INDEX records the old values of the
columns covered by the named index, which must be unique, not partial,
not deferrable, and include only columns marked NOT NULL." in docs
[1].

Inspecting this patch again, I forgot to consider that RelationGetIndexList()
is called by other backend modules. Since logical decoding deals with finished
transactions, it is ok to use a deferrable primary key.

But starting PG-14, we do support logical decoding of in-progress
transactions as well.

Commitfest entry status update.
As far as I see, this patch needs some further work, so I move it to
"Waiting on author".
Euler, are you going to continue working on it?

--
Anastasia Lubennikova
Postgres Professional: http://www.postgrespro.com
The Russian Postgres Company

#9Amit Kapila
amit.kapila16@gmail.com
In reply to: Anastasia Lubennikova (#8)
Re: deferred primary key and logical replication

On Tue, Nov 24, 2020 at 3:04 AM Anastasia Lubennikova
<a.lubennikova@postgrespro.ru> wrote:

On 27.10.2020 13:46, Amit Kapila wrote:

On Sun, Oct 25, 2020 at 9:39 PM Euler Taveira
<euler.taveira@2ndquadrant.com> wrote:

On Mon, 5 Oct 2020 at 08:34, Amit Kapila <amit.kapila16@gmail.com> wrote:

On Mon, May 11, 2020 at 2:41 AM Euler Taveira
<euler.taveira@2ndquadrant.com> wrote:

Hi,

While looking at an old wal2json issue, I stumbled on a scenario that a table
with a deferred primary key is not updatable in logical replication. AFAICS it
has been like that since the beginning of logical decoding and seems to be an
oversight while designing logical decoding.

I am not sure if it is an oversight because we document that the index
must be non-deferrable, see "USING INDEX records the old values of the
columns covered by the named index, which must be unique, not partial,
not deferrable, and include only columns marked NOT NULL." in docs
[1].

Inspecting this patch again, I forgot to consider that RelationGetIndexList()
is called by other backend modules. Since logical decoding deals with finished
transactions, it is ok to use a deferrable primary key.

But starting PG-14, we do support logical decoding of in-progress
transactions as well.

Commitfest entry status update.
As far as I see, this patch needs some further work, so I move it to
"Waiting on author".

I think this should be marked as "Returned with Feedback" as there is
no response to the feedback for a long time and also it is not very
clear if this possible.

--
With Regards,
Amit Kapila.