Re: Logical Replication of sequences

From: vignesh C <vignesh21(at)gmail(dot)com>
To: shveta malik <shveta(dot)malik(at)gmail(dot)com>
Cc: Nisha Moond <nisha(dot)moond412(at)gmail(dot)com>, Amit Kapila <amit(dot)kapila16(at)gmail(dot)com>, Peter Smith <smithpb2250(at)gmail(dot)com>, "Hayato Kuroda (Fujitsu)" <kuroda(dot)hayato(at)fujitsu(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-07-16 06:51:08
Message-ID: CALDaNm3bukJq_Z730aZb3TUar0oLBv-0ZjtgM-+V6GugcX0QAQ@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Tue, 15 Jul 2025 at 11:27, shveta malik <shveta(dot)malik(at)gmail(dot)com> wrote:
>
> Thank You. Few comments:
>
> 1)
> patch 005 has trailing whitespaces issue.

Fixed them

> 2)
> In LogicalRepSyncSequences(), do we really need this:
>
> + seq_count = list_length(subsequences);;
>
> seq_count is only used at the end to figure out if we really had some
> sequences. We can simply check subsequences against NIL for that
> purpose. If we really want to use list_length as a check, then we
> shall move it at the end where we use it.

Modified

> 3)
> LogicalRepSyncSequences():
> + MemoryContext oldctx;
>
> we can move this to a for-loop where it is being used.

Modified

> 4)
> The only usage of sequence_states_not_ready is this now:
>
> + /* No sequences to sync, so nothing to do */
> + if (list_length(sequence_states_not_ready) == 0)
> + return;
>
> Now, do we need to have it as a List?

Removed this list variable and used a output function argument in
FetchRelationStates

> 5)
> + <sect2 id="missing-sequences">
> + <title>Missing Sequences</title>
> + <para>
> + During sequence synchronization, if a sequence is dropped on the
> + publisher. An ERROR is logged listing the missing sequences before the
> + process exits. The apply worker detects this failure and repeatedly
> + respawns the sequence synchronization worker to continue the
> + synchronization process until the sequences are created in the publisher.
> + See also <link
> linkend="guc-wal-retrieve-retry-interval"><varname>wal_retrieve_retry_interval</varname></link>.
> + </para>
> + <para>
> + To resolve this, either use
> + <link linkend="sql-createsequence"><command>CREATE
> SEQUENCE</command></link>
> + to recreate the missing sequence on the publisher, or, if the sequence are
> + no longer required, execute <link
> linkend="sql-altersubscription-params-refresh-publication">
> + <command>ALTER SUBSCRIPTION ... REFRESH PUBLICATION</command></link>
> + to remove the stale sequence entries from synchronization in the
> subscriber.
> + </para>
> + </sect2>
> +
>
> Please see if this looks appropriate, I have added drop-sequence
> option as well and corrected few trivial things:
>
> During sequence synchronization, if a sequence is dropped on the
> publisher, an ERROR is logged listing the missing sequences before the
> process exits. The apply worker detects this failure and repeatedly
> respawns the sequence synchronization worker to continue the
> synchronization process until the sequences are either recreated on
> the publisher, dropped on the subscriber, or removed from the
> synchronization list.
>
> To resolve this issue, either recreate the missing sequence on the
> publisher using CREATE SEQUENCE, drop the sequences on the subscriber
> if they are no longer needed using DROP SEQUENCE, or run ALTER
> SUBSCRIPTION ... REFRESH PUBLICATION to remove these sequences from
> synchronization on the subscriber.

Modified

The attached v20250716 version patch has the changes for the same.

Regards,
Vignesh

Attachment Content-Type Size
v20250716-0001-Introduce-pg_sequence_state-function-for-e.patch application/octet-stream 7.3 KB
v20250716-0004-Introduce-REFRESH-PUBLICATION-SEQUENCES-fo.patch application/octet-stream 43.1 KB
v20250716-0003-Reorganize-tablesync-Code-and-Introduce-sy.patch application/octet-stream 23.0 KB
v20250716-0002-Introduce-ALL-SEQUENCES-support-for-Postgr.patch application/octet-stream 104.8 KB
v20250716-0005-New-worker-for-sequence-synchronization-du.patch application/octet-stream 73.4 KB
v20250716-0006-Documentation-for-sequence-synchronization.patch application/octet-stream 33.4 KB

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Joel Jacobson 2025-07-16 07:00:05 Re: Optimize LISTEN/NOTIFY
Previous Message Bertrand Drouvot 2025-07-16 06:31:36 Re: Improve LWLock tranche name visibility across backends