Re: Logical Replication of sequences

vignesh C <vignesh21@gmail.com>

From: vignesh C <vignesh21@gmail.com>
To: shveta malik <shveta.malik@gmail.com>
Cc: Nisha Moond <nisha.moond412@gmail.com>, Amit Kapila <amit.kapila16@gmail.com>, Peter Smith <smithpb2250@gmail.com>, "Hayato Kuroda (Fujitsu)" <kuroda.hayato@fujitsu.com>, Masahiko Sawada <sawada.mshk@gmail.com>, Shlok Kyal <shlok.kyal.oss@gmail.com>, Peter Eisentraut <peter@eisentraut.org>, PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>, Euler Taveira <euler@eulerto.com>, Michael Paquier <michael@paquier.xyz>, "Zhijie Hou (Fujitsu)" <houzj.fnst@fujitsu.com>, "Jonathan S. Katz" <jkatz@postgresql.org>
Date: 2025-07-16T06:51:08Z
Lists: pgsql-hackers

Commits

Same data as JSON: GET /api/v1/messages/:b64id/commits the thread's linked commits as JSON, with link sources. API reference →
  1. Doc: Add documentation for sequence synchronization.

  2. Remove unused assignment in CREATE PUBLICATION grammar.

  3. Add seq_sync_error_count to subscription statistics.

  4. Fix few issues in commit 5509055d69.

  5. Add sequence synchronization for logical replication.

  6. Add worker type argument to logical replication worker functions.

  7. Introduce "REFRESH SEQUENCES" for subscriptions.

  8. Refactor logical worker synchronization code into a separate file.

  9. Standardize use of REFRESH PUBLICATION in code and messages.

  10. Add "ALL SEQUENCES" support to publications.

  11. Expose sequence page LSN via pg_get_sequence_data.

  12. Resume conflict-relevant data retention automatically.

  13. Post-commit review fixes for 228c370868.

  14. Generate GUC tables from .dat file

Attachments

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