Re: Logical Replication of sequences - Mailing list pgsql-hackers

From vignesh C
Subject Re: Logical Replication of sequences
Date
Msg-id CALDaNm3bukJq_Z730aZb3TUar0oLBv-0ZjtgM-+V6GugcX0QAQ@mail.gmail.com
Whole thread Raw
In response to Re: Logical Replication of sequences  (shveta malik <shveta.malik@gmail.com>)
List pgsql-hackers
On Tue, 15 Jul 2025 at 11:27, shveta malik <shveta.malik@gmail.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

pgsql-hackers by date:

Previous
From: Bertrand Drouvot
Date:
Subject: Re: Improve LWLock tranche name visibility across backends
Next
From: "Joel Jacobson"
Date:
Subject: Re: Optimize LISTEN/NOTIFY