RE: Logical Replication of sequences

From: "Zhijie Hou (Fujitsu)" <houzj(dot)fnst(at)fujitsu(dot)com>
To: Amit Kapila <amit(dot)kapila16(at)gmail(dot)com>
Cc: "Hayato Kuroda (Fujitsu)" <kuroda(dot)hayato(at)fujitsu(dot)com>, vignesh C <vignesh21(at)gmail(dot)com>, Peter Smith <smithpb2250(at)gmail(dot)com>, shveta malik <shveta(dot)malik(at)gmail(dot)com>, Dilip Kumar <dilipbalaut(at)gmail(dot)com>, 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>, Nisha Moond <nisha(dot)moond412(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>, "Jonathan S(dot) Katz" <jkatz(at)postgresql(dot)org>
Subject: RE: Logical Replication of sequences
Date: 2025-10-16 11:24:30
Message-ID: OS9PR01MB169132A589A50884EDBBBCD3294E9A@OS9PR01MB16913.jpnprd01.prod.outlook.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Tuesday, October 14, 2025 6:07 PM Amit Kapila <amit(dot)kapila16(at)gmail(dot)com> wrote:
>
> On Tue, Oct 14, 2025 at 3:33 PM Zhijie Hou (Fujitsu)
> <houzj(dot)fnst(at)fujitsu(dot)com> wrote:
> >
> > 0003~0005:
> > Unchanged.
> >
> > TODO:
> > * The latest comment from Shveta[5].
> > * The comment from Amit[6] to avoid creating slot/origin for sequence only
> subscription.
> >
>
> Few comments on 0003 and 0004 based on previous version of the patch.
> As those are not changed, so I assume they apply for the new version
> as well.

Thanks for the comments.

>
> 2.
> - /* Process any tables that are being synchronized in parallel. */
> + /*
> + * Process any tables that are being synchronized in parallel and any
> + * newly added relations.
> + */
> ProcessSyncingRelations(commit_data.end_lsn);
>
> pgstat_report_activity(STATE_IDLE, NULL);
> @@ -1364,7 +1372,10 @@ apply_handle_prepare(StringInfo s)
>
> in_remote_transaction = false;
>
> - /* Process any tables that are being synchronized in parallel. */
> + /*
> + * Process any tables that are being synchronized in parallel and any
> + * newly added relations.
> + */
> ProcessSyncingRelations(prepare_data.end_lsn);
>
> In the first line of comment, it is mentioned as tables and in the
> second line, the relations are mentioned. I think as part of this it
> can process sequences as well if any are added. I wonder whether this
> (while applying prepare/commit) is the right time to invoke it for
> sequences. The apply worker do need to invoke sequencesync worker if
> required but not sure if this is the right place.

I agree that we can start sequence sync worker at any point regardless of the
transaction boundary, because we do not support incremental seq sync, so another
approach could be to call ProcessSyncingSequencesForApply() in the main loop of
LogicalRepApplyLoop(), similar to maybe_advance_nonremovable_xid().

OTOH, I think the current implementation also works, because we have one
ProcessSyncingRelations() call in the main loop as well.

What do you think ?

>
> 4.
> @@ -3284,7 +3307,7 @@ FindDeletedTupleInLocalRel(Relation localrel,
> Oid localidxoid,
> */
> LWLockAcquire(LogicalRepWorkerLock, LW_SHARED);
> leader = logicalrep_worker_find(MyLogicalRepWorker->subid,
> - InvalidOid, false);
> + InvalidOid, false, false);
>
> …
> extern LogicalRepWorker *logicalrep_worker_find(Oid subid, Oid relid,
> + LogicalRepWorkerType wtype,
> bool only_running);
>
> The third parameter is LogicalRepWorkerType and passing it false in
> the above usage doesn't make sense. Also, we should update comments
> atop logicalrep_worker_find as to why worker_type is required. I want
> to know why subid+relid combination is not sufficient to identify the
> workers uniquely.

I think it's because sequencesync worker also do not have a valid relid, similar
to the apply worker, so we would need the worker type to distinguish them. I
added some general comments atop of the function in the latest version.

Best Regards,
Hou zj

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Christoph Berg 2025-10-16 11:38:35 failed NUMA pages inquiry status: Operation not permitted
Previous Message Zhijie Hou (Fujitsu) 2025-10-16 11:23:39 RE: Logical Replication of sequences