]> git.ipfire.org Git - thirdparty/postgresql.git/commitdiff
Reject sequence synchronization against pre-PostgreSQL 19 publishers.
authorAmit Kapila <akapila@postgresql.org>
Thu, 23 Jul 2026 05:16:42 +0000 (10:46 +0530)
committerAmit Kapila <akapila@postgresql.org>
Thu, 23 Jul 2026 05:16:42 +0000 (10:46 +0530)
Sequence synchronization requires the page_lsn field returned by
pg_get_sequence_data(), which was added in PostgreSQL 19. Previously,
requesting sequence synchronization against an older publisher (via
ALTER SUBSCRIPTION ... REFRESH SEQUENCES or by running
ALTER SUBSCRIPTION ... CONNECTION on a disabled subscription with
sequences in the INIT state and subsequently enabling the subscription)
would cause the sequence synchronization worker to repeatedly fail with a
confusing "invalid query response" error.

Check the publisher's server version up front in both
AlterSubscription_refresh_seq() and copy_sequences(), and error out
immediately when it predates PostgreSQL 19.

Also document the PostgreSQL 19 publisher requirement for sequence
replication in the logical replication documentation and in
ALTER SUBSCRIPTION ... REFRESH SEQUENCES.

Reported-by: Noah Misch <noah@leadboat.com>
Author: vignesh C <vignesh21@gmail.com>
Reviewed-by: Shveta Malik <shveta.malik@gmail.com>
Reviewed-by: Hayato Kuroda <kuroda.hayato@fujitsu.com>
Reviewed-by: Amit Kapila <amit.kapila16@gmail.com>
Backpatch-through: 19
Discussion: https://postgr.es/m/20260710045217.f0.noahmisch@microsoft.com

doc/src/sgml/logical-replication.sgml
doc/src/sgml/ref/alter_subscription.sgml
src/backend/commands/subscriptioncmds.c
src/backend/replication/logical/sequencesync.c

index 690598bff98e59924f2f1a3e9d9bd060ac5140f5..36298cacb759a28ed2355bf12644eea5b32cbb69 100644 (file)
@@ -1818,6 +1818,13 @@ Included in publications:
    configuration.
   </para>
 
+  <note>
+   <para>
+    Sequence synchronization requires the publisher to be running
+    <productname>PostgreSQL</productname> 19 or later.
+   </para>
+  </note>
+
   <sect2 id="sequence-definition-mismatches">
    <title>Sequence Definition Mismatches</title>
    <para>
@@ -2368,7 +2375,16 @@ CONTEXT:  processing remote data for replication origin "pg_16395" during "INSER
      <command>ALTER SUBSCRIPTION ... REFRESH SEQUENCES</command></link>
      or by copying the current data from the publisher (perhaps using
      <command>pg_dump</command>) or by determining a sufficiently high value
-     from the tables themselves.
+     from the tables themselves.  Note that
+     <link linkend="sql-altersubscription-params-refresh-sequences">
+     <command>ALTER SUBSCRIPTION ... REFRESH SEQUENCES</command></link> only
+     re-synchronizes sequences that are already known to the subscription
+     (see <xref linkend="logical-replication-sequences"/>); in particular, it
+     requires the publisher to be running <productname>PostgreSQL</productname>
+     19 or later. Before relying on it to prepare for a switchover or
+     failover, confirm that the publisher's version supports sequence
+     replication and that the sequences of interest are already known to the
+     subscription.
     </para>
    </listitem>
 
index 8d64744375a5043303672c3e51785d70148469e9..6fc3e07a2d5028a72fd1067295d92a4b2196bc95 100644 (file)
@@ -245,6 +245,12 @@ ALTER SUBSCRIPTION <replaceable class="parameter">name</replaceable> RENAME TO <
       sequences are subscribed. Run <literal>REFRESH PUBLICATION</literal>
       first if the publication's set of sequences has changed.
      </para>
+     <note>
+      <para>
+       Sequence replication requires the publisher to be running
+       <productname>PostgreSQL</productname> 19 or later.
+      </para>
+     </note>
      <para>
       See <xref linkend="sequence-definition-mismatches"/> for
       recommendations on how to handle any warnings about sequence definition
index 63d288a46302a3de30d020a3bd393b146cdccbf4..7f946c5b454578adcaa5249a1a20bb20768af08f 100644 (file)
@@ -1381,6 +1381,16 @@ AlterSubscription_refresh_seq(Subscription *sub)
        /* The publisher connection is only needed for the origin check. */
        PG_TRY();
        {
+               /*
+                * Sequence synchronization depends on publisher-side functionality
+                * introduced in PostgreSQL 19, so it cannot work against an older
+                * publisher.
+                */
+               if (walrcv_server_version(wrconn) < 190000)
+                       ereport(ERROR,
+                                       errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
+                                       errmsg("cannot synchronize sequences if the publisher is running a version earlier than PostgreSQL 19"));
+
                check_publications_origin_sequences(wrconn, sub->publications, true,
                                                                                        sub->origin, NULL, 0, sub->name);
        }
index 63ad46d7fd7b2a9f76eb294f48988afba47a9c53..28d4d011a84e04b8901871ad0f90b11952867870 100644 (file)
@@ -444,6 +444,16 @@ copy_sequences(WalReceiverConn *conn)
        StringInfoData cmd;
        MemoryContext oldctx;
 
+       /*
+        * Sequence synchronization depends on publisher-side functionality
+        * introduced in PostgreSQL 19, so it cannot work against an older
+        * publisher.
+        */
+       if (walrcv_server_version(conn) < 190000)
+               ereport(ERROR,
+                               errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
+                               errmsg("cannot synchronize sequences if the publisher is running a version earlier than PostgreSQL 19"));
+
        initStringInfo(&seqstr);
        initStringInfo(&cmd);