Re: Logical Replication of sequences

From: vignesh C <vignesh21(at)gmail(dot)com>
To: shveta malik <shveta(dot)malik(at)gmail(dot)com>
Cc: "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>, Masahiko Sawada <sawada(dot)mshk(at)gmail(dot)com>, Shlok Kyal <shlok(dot)kyal(dot)oss(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>
Subject: Re: Logical Replication of sequences
Date: 2025-08-01 04:33:03
Message-ID: CALDaNm1y3TxA1KdA0VdJ8NeiNzfqEn4Qgf1zc2XxOv__Ezq1qQ@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Wed, 30 Jul 2025 at 11:16, shveta malik <shveta(dot)malik(at)gmail(dot)com> wrote:
>
> On Mon, Jul 28, 2025 at 3:37 PM vignesh C <vignesh21(at)gmail(dot)com> wrote:
>
> > Thanks for the comments, the attached v20250728 version patch has the
> > changes for the same.
> >
> Thanks for the patches, please find a few comments:
>
> 1)
> WARNING: WITH clause parameters do not affect sequence synchronization
>
> a)
> How about:
> WITH clause parameters are not applicable to sequence synchronization
> or
> WITH clause parameters are not applicable to sequence synchronization
> and will be ignored.

Modified

> b)
> Should it be NOTICE OR WARNING? I feel NOTICE Is more appropriate as
> it is more of an information than a warning since it has no negative
> consequences.

Modified

> 2)
> AlterSubscription_refresh(Subscription *sub, bool copy_data,
> - List *validate_publications)
> + List *validate_publications, bool refresh_tables,
> + bool refresh_sequences, bool resync_all_sequences)
> {
>
> Do we need 3 new arguments? If we notice, 'refresh_sequences' is
> always true in all cases. I feel only the last one should suffice.
> IIUC, this is the state:
>
> When resync_all_sequences is true:
> it indicates it is 'REFRESH PUBLICATION SEQUENCES', that means we have
> to refresh new sequences and resync all sequences.
>
> When resync_all_sequences is false:
> That means it is 'REFRESH PUBLICATION', we have to refresh new tables
> and new sequences alone.
>
> So if the caller pass only 'resync_all_sequences', we should be able
> to drive the rest of the values internally.

Modified

> 3)
> ALTER SUBSCRIPTION regress_testsub REFRESH PUBLICATION;
> -ERROR: ALTER SUBSCRIPTION ... REFRESH cannot run inside a transaction block
> +ERROR: ALTER SUBSCRIPTION ... REFRESH PUBLICATION cannot run inside
> a transaction block
>
> In the same script, we can test REFRESH PUBLICATION SEQUENCES also in
> trancsation block.

Added it

> 4)
> Commit message of patch004 says:
>
> This patch introduce a new command to synchronize the sequences of
> a subscription:
> ALTER SUBSCRIPTION ... REFRESH PUBLICATION SEQUENCES
>
> a)
> introduce --> introduces
>
> b)
> We should also add:
>
> This patch also changes the scope of
> ALTER SUBSCRIPTION ... REFRESH PUBLICATION
> This command now also considers sequences (newly added or dropped ones).

Modified the commit message now to add this information

> 5)
> + * Reset the last_start_time of the sequencesync worker in the subscription's
> + * apply worker.
>
> last_start_time-->last_seqsync_start_time

Modified

> 6)
> alter_subscription.sgml has this:
> <term><literal>refresh</literal> (<type>boolean</type>)</term>
> <listitem>
> <para>
> When false, the command will not try to refresh table information.
> <literal>REFRESH PUBLICATION</literal> should then be
> executed separately.
> The default is <literal>true</literal>.
> </para>
> </listitem>
> </varlistentry>
>
> Shouldn't we mention sequence too here:
> When false, the command will not try to refresh table and sequence information.

Modified

Also, the comment from [1] has been addressed — the lock is now
released from the caller function itself. Previously, the lock was
required to fetch the number of sync workers running, but this has
been refactored to retrieve the count within the caller function
instead.

Thanks for the comments, the attached patch has the changes for the same.
[1] - https://www.postgresql.org/message-id/CAJpy0uBCOmoyc44J46PpHbip0Sovqm99cL%3DAJoAErXG0EN2Duw%40mail.gmail.com

Regards,
Vignesh

Attachment Content-Type Size
v20250801-0001-Enhance-pg_get_sequence_data-function.patch application/octet-stream 7.2 KB
v20250801-0005-New-worker-for-sequence-synchronization-du.patch application/octet-stream 83.6 KB
v20250801-0004-Introduce-REFRESH-PUBLICATION-SEQUENCES-fo.patch application/octet-stream 43.3 KB
v20250801-0003-Reorganize-tablesync-Code-and-Introduce-sy.patch application/octet-stream 24.6 KB
v20250801-0002-Introduce-ALL-SEQUENCES-support-for-Postgr.patch application/octet-stream 110.0 KB
v20250801-0006-Documentation-for-sequence-synchronization.patch application/octet-stream 34.3 KB

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Tom Lane 2025-08-01 05:07:33 Re: Convert varatt.h macros to static inline functions
Previous Message Tom Lane 2025-08-01 04:07:03 Re: Should --enable-debug set CFLAGS to -O0 instead of -O2?