diff --git a/doc/src/sgml/ref/pgupgrade.sgml b/doc/src/sgml/ref/pgupgrade.sgml
index 07bb46f89c..bef107295c 100644
--- a/doc/src/sgml/ref/pgupgrade.sgml
+++ b/doc/src/sgml/ref/pgupgrade.sgml
@@ -694,7 +694,7 @@ rsync --archive --delete --hard-links --size-only --no-inc-recursive /vol1/pg_tb
Configure the servers for log shipping. (You do not need to run
pg_backup_start() and pg_backup_stop()
or take a file system backup as the standbys are still synchronized
- with the primary.) Replication slots on old standby are not copied.
+ with the primary.) Replication slots on the old standby are not copied.
Only logical slots on the primary are migrated to the new standby,
and other slots must be recreated.
diff --git a/src/bin/pg_upgrade/check.c b/src/bin/pg_upgrade/check.c
index a013366280..ea0fe88876 100644
--- a/src/bin/pg_upgrade/check.c
+++ b/src/bin/pg_upgrade/check.c
@@ -1507,9 +1507,12 @@ check_old_cluster_for_valid_slots(bool live_check)
conn = connectToServer(&old_cluster, active_db->db_name);
- prep_status("Checking for logical replication slots");
+ prep_status("Checking for valid logical replication slots");
- /* Check there are no logical replication slots with a 'lost' state. */
+ /*
+ * We don't allow to upgrade in the presence of lost slots as we can't
+ * migrate those.
+ */
res = executeQueryOrDie(conn,
"SELECT slot_name FROM pg_catalog.pg_replication_slots "
"WHERE wal_status = 'lost' AND "
@@ -1529,10 +1532,11 @@ check_old_cluster_for_valid_slots(bool live_check)
pg_fatal("One or more logical replication slots with a state of 'lost' were detected.");
/*
- * Do additional checks if a live check is not required. This requires
- * that confirmed_flush_lsn of all the slots is the same as the latest
- * checkpoint location, but it would be satisfied only when the server has
- * been shut down.
+ * Do additional checks to ensure that confirmed_flush LSN of all the slots
+ * is the same as the latest checkpoint location.
+ *
+ * Note: This can be satisfied only when the old cluster has been shut
+ * down, so we skip this live checks.
*/
if (!live_check)
{
diff --git a/src/bin/pg_upgrade/controldata.c b/src/bin/pg_upgrade/controldata.c
index 808156ec09..11881db84c 100644
--- a/src/bin/pg_upgrade/controldata.c
+++ b/src/bin/pg_upgrade/controldata.c
@@ -175,7 +175,8 @@ get_control_data(ClusterInfo *cluster, bool live_check)
/*
* Read the latest checkpoint location if the cluster is PG17
* or later. This is used for upgrading logical replication
- * slots.
+ * slots. Currently, we need it only for the old cluster but
+ * didn't add additional check for the similicity.
*/
if (GET_MAJOR_VERSION(cluster->major_version) >= 1700)
{
diff --git a/src/bin/pg_upgrade/function.c b/src/bin/pg_upgrade/function.c
index 5b4b414a91..71e3ec7a51 100644
--- a/src/bin/pg_upgrade/function.c
+++ b/src/bin/pg_upgrade/function.c
@@ -47,11 +47,8 @@ library_name_compare(const void *p1, const void *p2)
/*
* get_loadable_libraries()
*
- * Fetch the names of all old libraries:
- * 1. Name of library files containing C-language functions (for non-built-in
- * functions), and
- * 2. Shared object (library) names containing the logical replication output
- * plugins
+ * Fetch the names of all old libraries containing either C-language functions
+ * or are corresponding to logical replication output plugins.
*
* We will later check that they all exist in the new installation.
*/
@@ -66,7 +63,7 @@ get_loadable_libraries(void)
ress = (PGresult **) pg_malloc(old_cluster.dbarr.ndbs * sizeof(PGresult *));
totaltups = 0;
- /* Construct a query string for fetching non-built-in C functions */
+ /* distinct libraries for non-built-in C functions */
appendPQExpBuffer(query, "SELECT DISTINCT probin "
"FROM pg_catalog.pg_proc "
"WHERE prolang = %u AND "
@@ -75,10 +72,7 @@ get_loadable_libraries(void)
ClanguageId,
FirstNormalObjectId);
- /*
- * If old_cluster is PG 17 or later, logical decoding output plugins must
- * also be included.
- */
+ /* upgrade of logical slots are supported since PG 17 */
if (GET_MAJOR_VERSION(old_cluster.major_version) >= 1700)
appendPQExpBufferStr(query, " UNION "
"SELECT DISTINCT plugin "
diff --git a/src/bin/pg_upgrade/info.c b/src/bin/pg_upgrade/info.c
index c905e02d45..e7e92f17ec 100644
--- a/src/bin/pg_upgrade/info.c
+++ b/src/bin/pg_upgrade/info.c
@@ -661,8 +661,10 @@ get_old_cluster_logical_slot_infos_per_db(DbInfo *dbinfo)
* Higher level routine to generate LogicalSlotInfoArr for all databases.
*
* Note: This function will not do anything if the old cluster is pre-PG17.
- * The logical slots are not saved at shutdown, and the confirmed_flush_lsn is
- * always behind the SHUTDOWN_CHECKPOINT record. Subsequent checks done in
+ * This is because before that the logical slots are not saved at shutdown, so
+ * there is no guarantee that the latest confirmed_flush_lsn is saved to disk
+ * which can lead to data loss. It is still not guaranteed for manually created
+ * slots in PG17, so subsequent checks done in
* check_old_cluster_for_valid_slots() would raise a FATAL error if such slots
* are included.
*/
@@ -697,8 +699,8 @@ get_old_cluster_logical_slot_infos(void)
* Sum up and return the number of logical replication slots for all databases.
*
* Note: this function always returns 0 if the old_cluster is PG16 and prior
- * because old_cluster.dbarr.dbs[dbnum].slot_arr is set only for PG17 and
- * later.
+ * because we gather slot information only for cluster versions greater than or
+ * equal to PG17. See get_old_cluster_logical_slot_infos().
*/
int
count_old_cluster_logical_slots(void)
diff --git a/src/bin/pg_upgrade/pg_upgrade.c b/src/bin/pg_upgrade/pg_upgrade.c
index c4bf12fd6b..b267b484b1 100644
--- a/src/bin/pg_upgrade/pg_upgrade.c
+++ b/src/bin/pg_upgrade/pg_upgrade.c
@@ -190,9 +190,6 @@ main(int argc, char **argv)
check_ok();
/*
- * Logical replication slot upgrade only supported for old_cluster >=
- * PG17.
- *
* Note: This must be done after doing the pg_resetwal command because
* pg_resetwal would remove required WALs.
*/