Re: Logical Replication of sequences

vignesh C <vignesh21@gmail.com>

From: vignesh C <vignesh21@gmail.com>
To: Amit Kapila <amit.kapila16@gmail.com>
Cc: shveta malik <shveta.malik@gmail.com>, Shlok Kyal <shlok.kyal.oss@gmail.com>, Chao Li <li.evan.chao@gmail.com>, Masahiko Sawada <sawada.mshk@gmail.com>, "Hayato Kuroda (Fujitsu)" <kuroda.hayato@fujitsu.com>, Nisha Moond <nisha.moond412@gmail.com>, Dilip Kumar <dilipbalaut@gmail.com>, Peter Smith <smithpb2250@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-10-07T11:21:48Z
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, 7 Oct 2025 at 12:09, Amit Kapila <amit.kapila16@gmail.com> wrote:
>
> On Tue, Oct 7, 2025 at 10:53 AM shveta malik <shveta.malik@gmail.com> wrote:
> >
> > 2)
> > postgres=# create publication pub1 for all sequences WITH(publish='insert');
> > ERROR:  publication parameters are not supported for publications
> > defined as FOR ALL SEQUENCES
> >
> > postgres=# alter publication pub1 add table tab1;
> > ERROR:  Tables or sequences cannot be added to or dropped from
> > publication defined FOR ALL TABLES, ALL SEQUENCES, or both
> >
> > a) First msg has 'as', while second does not. Shall we make both the
> > same? I think we can get rid of 'as'.
> > b) Shouldn't the error msg start with lower case (second one)?
> >
>
> The (b) is related to following change:
>
> +  if (tables && (pubform->puballtables || pubform->puballsequences))
> ereport(ERROR,
> -        (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
> -         errmsg("publication \"%s\" is defined as FOR ALL TABLES",
> -            NameStr(pubform->pubname)),
> -         errdetail("Tables cannot be added to or dropped from FOR ALL
> TABLES publications.")));
> +        errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
> +        errmsg("Tables or sequences cannot be added to or dropped
> from publication defined FOR ALL TABLES, ALL SEQUENCES, or both"));
> }
>
> I see a bigger problem where we made errdetail as errmsg. Here, we are
> trying to combine the message FOR ALL TABLES and FOR ALL SEQUENCES
> which caused this change/confusion. It is better to keep them separate
> to avoid confusion. The similar problem exists for following message:
> - if (schemaidlist && pubform->puballtables)
> + if (schemaidlist && (pubform->puballtables || pubform->puballsequences))
>   ereport(ERROR,
> - (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
> - errmsg("publication \"%s\" is defined as FOR ALL TABLES",
> - NameStr(pubform->pubname)),
> - errdetail("Schemas cannot be added to or dropped from FOR ALL TABLES
> publications.")));
> + errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
> + errmsg("Schemas cannot be added to or dropped from publication
> defined FOR ALL TABLES, ALL SEQUENCES, or both"));

Modified to keep it as separate error messages.

> If we fix both of these then we don't need to do anything for point (a).

Agreed

> Few other comments:
> =================
> 1. Is there a reason not to change just the footers part in
> describeOneTableDetails()?

I tried the approach to keep it as a footer and it simplifies the code
further. Update the patch accordingly.

> 2. I think we can move create_publication.sgml and
> pg_publication_sequences related changes to 0001 from doc patch.

Modified

> 3. Atop is_publishable_class(), we mention it has all the checks as
> check_publication_add_relation but the sequence check is different. Is
> it because check_publication_add_relation() is not called FOR ALL
> SEQUENCES? If so, I have modified a few comments in the attached
> related to that.

Updated

> 4.
> @@ -878,13 +885,35 @@ CreatePublication(ParseState *pstate,
> CreatePublicationStmt *stmt)
>     &publish_via_partition_root_given,
>     &publish_via_partition_root,
>     &publish_generated_columns_given,
> -   &publish_generated_columns);
> +   &publish_generated_columns,
> +   def_pub_action);
> +
> + if (stmt->for_all_sequences &&
> + (publish_given || publish_via_partition_root_given ||
> + publish_generated_columns_given))
> + {
> + /*
> + * WITH clause parameters are not applicable when creating a FOR ALL
> + * SEQUENCES publication. If the publication includes tables as well,
> + * issue a notice.
> + */
> + if (!stmt->for_all_tables)
> + ereport(ERROR,
> + errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
> + errmsg("publication parameters are not supported for publications
> defined as FOR ALL SEQUENCES"));
> +
> + ereport(NOTICE,
> + errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
> + errmsg("publication parameters are not applicable to sequence
> synchronization and will be ignored"));
> + }
>
> This change looks a bit ad hoc to me. I think it would be better to
> handle this inside parse_publication_options(). The function can take
> the third parameter as for_all_sequences and then use that to give
> error when any options are present.

Modified

Thanks for the comments, the attached patch has the changes for the same.

Regards,
Vignesh