From: | shveta malik <shveta(dot)malik(at)gmail(dot)com> |
---|---|
To: | vignesh C <vignesh21(at)gmail(dot)com> |
Cc: | Shlok Kyal <shlok(dot)kyal(dot)oss(at)gmail(dot)com>, Chao Li <li(dot)evan(dot)chao(at)gmail(dot)com>, Masahiko Sawada <sawada(dot)mshk(at)gmail(dot)com>, "Hayato Kuroda (Fujitsu)" <kuroda(dot)hayato(at)fujitsu(dot)com>, Nisha Moond <nisha(dot)moond412(at)gmail(dot)com>, Dilip Kumar <dilipbalaut(at)gmail(dot)com>, Amit Kapila <amit(dot)kapila16(at)gmail(dot)com>, Peter Smith <smithpb2250(at)gmail(dot)com>, Peter Eisentraut <peter(at)eisentraut(dot)org>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>, Euler Taveira <euler(at)eulerto(dot)com>, Michael Paquier <michael(at)paquier(dot)xyz>, "Zhijie Hou (Fujitsu)" <houzj(dot)fnst(at)fujitsu(dot)com>, "Jonathan S(dot) Katz" <jkatz(at)postgresql(dot)org>, shveta malik <shveta(dot)malik(at)gmail(dot)com> |
Subject: | Re: Logical Replication of sequences |
Date: | 2025-09-29 04:28:49 |
Message-ID: | CAJpy0uDNUcLHKLMk2kH2EL2_YpZcavawtUizQ62WX34XkWspnQ@mail.gmail.com |
Views: | Whole Thread | Raw Message | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-hackers |
On Fri, Sep 26, 2025 at 12:55 PM vignesh C <vignesh21(at)gmail(dot)com> wrote:
>
> On Thu, 25 Sept 2025 at 12:23, shveta malik <shveta(dot)malik(at)gmail(dot)com> wrote:
> >
> > sequencesync_list_invalidate_cb():
> > 5)
> >
> > + /* invalidate all entries */
> > + hash_seq_init(&status, sequences_to_copy);
> > + while ((entry = (LogicalRepSequenceInfo *) hash_seq_search(&status)) != NULL)
> > + entry->entry_valid = false;
> >
> > Can you please elaborate when this case can be hit? I see such logic
> > in all such invalidation functions registered with
> > CacheRegisterRelcacheCallback(), but could not find any relevant
> > comment.
>
> I noticed this could happen in cases like:
> create publication for all tables;
> alter publication on many relations;
>
> but there might be more apart from this
>
Okay. I will review more here.
> Rest of the comments were addressed.
> The attached patch has the changes for the same.
>
Thanks.
I found a race condition between the apply worker and the sequence
sync worker, where a sequence might be deleted from
pg_subscription_rel and fail to be re-added when it should be.
Steps:
1)
The publisher and subscriber both have two sequences: seq1 and seq2.
2)
A REFRESH PUBLICATION SEQUENCES command is executed on the subscriber.
Before the sequencesync worker on the subscriber can locate the
corresponding sequence on the publisher, the sequence gets dropped on
the publisher. In other words, the sequence is removed from the
publisher before walrcv_exec() is called in copy_sequences().
3)
Before the sequencesync worker on the subscriber can drop the sequence
locally, it is recreated on the publisher. Then, a second REFRESH
PUBLICATION SEQUENCES command is executed on the subscriber. (i.e.,
before RemoveSubscriptionRel() is reached in copy_sequences(), the
sequence is already recreated on the publisher and a new refresh
command is issued on the subscriber.)
4)
During this second REFRESH PUBLICATION SEQUENCES, the sequence is
found to already exist in pg_subscription_rel, so it is not re-added.
However, concurrently, the sequencesync worker from the first refresh
proceeds and drops the sequence from the subscriber.
As a result, the sequence ends up being removed from
pg_subscription_rel, even though it should have remained after both
REFRESH PUBLICATION SEQUENCES commands.
thanks
Shveta
From | Date | Subject | |
---|---|---|---|
Next Message | shveta malik | 2025-09-29 06:11:15 | Re: Clear logical slot's 'synced' flag on promotion of standby |
Previous Message | Chao Li | 2025-09-29 04:18:21 | Re: bug, ALTER TABLE call ATPostAlterTypeCleanup twice for the same relation |