diff --git a/doc/src/sgml/logical-replication.sgml b/doc/src/sgml/logical-replication.sgml
index 2edf65af66e..efbed7b3bcb 100644
--- a/doc/src/sgml/logical-replication.sgml
+++ b/doc/src/sgml/logical-replication.sgml
@@ -1803,6 +1803,13 @@ Included in publications:
configuration.
+
+
+ Sequence synchronization requires the publisher to be running
+ PostgreSQL 19 or later.
+
+
+
Sequence Definition Mismatches
@@ -2353,7 +2360,16 @@ CONTEXT: processing remote data for replication origin "pg_16395" during "INSER
ALTER SUBSCRIPTION ... REFRESH SEQUENCES
or by copying the current data from the publisher (perhaps using
pg_dump) or by determining a sufficiently high value
- from the tables themselves.
+ from the tables themselves. Note that
+
+ ALTER SUBSCRIPTION ... REFRESH SEQUENCES only
+ re-synchronizes sequences that are already known to the subscription
+ (see ); in particular, it
+ requires the publisher to be running PostgreSQL
+ 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.
diff --git a/doc/src/sgml/ref/alter_subscription.sgml b/doc/src/sgml/ref/alter_subscription.sgml
index 51081ef369e..ec6d5f1dcf6 100644
--- a/doc/src/sgml/ref/alter_subscription.sgml
+++ b/doc/src/sgml/ref/alter_subscription.sgml
@@ -245,6 +245,12 @@ ALTER SUBSCRIPTION name RENAME TO <
sequences are subscribed. Run REFRESH PUBLICATION
first if the publication's set of sequences has changed.
+
+
+ Sequence replication requires the publisher to be running
+ PostgreSQL 19 or later.
+
+
See for
recommendations on how to handle any warnings about sequence definition
diff --git a/src/backend/commands/subscriptioncmds.c b/src/backend/commands/subscriptioncmds.c
index a2c079fcb5a..de62ec49514 100644
--- a/src/backend/commands/subscriptioncmds.c
+++ b/src/backend/commands/subscriptioncmds.c
@@ -1322,6 +1322,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);
}
diff --git a/src/backend/replication/logical/sequencesync.c b/src/backend/replication/logical/sequencesync.c
index 82f503f1c00..06946afe683 100644
--- a/src/backend/replication/logical/sequencesync.c
+++ b/src/backend/replication/logical/sequencesync.c
@@ -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);