summaryrefslogtreecommitdiff
path: root/src/bin/pg_upgrade/server.c
diff options
context:
space:
mode:
authorAmit Kapila <akapila@postgresql.org>2023-10-26 06:54:16 +0530
committerAmit Kapila <akapila@postgresql.org>2023-10-26 07:06:55 +0530
commit29d0a77fa6606f9c01ba17311fc452dabd3f793d (patch)
treec1d63845bf43db3ab71cb16a43ee53867b6119dc /src/bin/pg_upgrade/server.c
parentbddc2f7480374023218427a0185145a127207c28 (diff)
Migrate logical slots to the new node during an upgrade.
While reading information from the old cluster, a list of logical slots is fetched. At the later part of upgrading, pg_upgrade revisits the list and restores slots by executing pg_create_logical_replication_slot() on the new cluster. Migration of logical replication slots is only supported when the old cluster is version 17.0 or later. If the old node has invalid slots or slots with unconsumed WAL records, the pg_upgrade fails. These checks are needed to prevent data loss. The significant advantage of this commit is that it makes it easy to continue logical replication even after upgrading the publisher node. Previously, pg_upgrade allowed copying publications to a new node. With this patch, adjusting the connection string to the new publisher will cause the apply worker on the subscriber to connect to the new publisher automatically. This enables seamless continuation of logical replication, even after an upgrade. Author: Hayato Kuroda, Hou Zhijie Reviewed-by: Peter Smith, Bharath Rupireddy, Dilip Kumar, Vignesh C, Shlok Kyal Discussion: http://postgr.es/m/TYAPR01MB58664C81887B3AF2EB6B16E3F5939@TYAPR01MB5866.jpnprd01.prod.outlook.com Discussion: http://postgr.es/m/CAA4eK1+t7xYcfa0rEQw839=b2MzsfvYDPz3xbD+ZqOdP3zpKYg@mail.gmail.com
Diffstat (limited to 'src/bin/pg_upgrade/server.c')
-rw-r--r--src/bin/pg_upgrade/server.c25
1 files changed, 22 insertions, 3 deletions
diff --git a/src/bin/pg_upgrade/server.c b/src/bin/pg_upgrade/server.c
index 0bc3d2806b8..d7f6c268ef4 100644
--- a/src/bin/pg_upgrade/server.c
+++ b/src/bin/pg_upgrade/server.c
@@ -201,6 +201,7 @@ start_postmaster(ClusterInfo *cluster, bool report_and_exit_on_error)
PGconn *conn;
bool pg_ctl_return = false;
char socket_string[MAXPGPATH + 200];
+ PQExpBufferData pgoptions;
static bool exit_hook_registered = false;
@@ -227,23 +228,41 @@ start_postmaster(ClusterInfo *cluster, bool report_and_exit_on_error)
cluster->sockdir);
#endif
+ initPQExpBuffer(&pgoptions);
+
/*
- * Use -b to disable autovacuum.
+ * Construct a parameter string which is passed to the server process.
*
* Turn off durability requirements to improve object creation speed, and
* we only modify the new cluster, so only use it there. If there is a
* crash, the new cluster has to be recreated anyway. fsync=off is a big
* win on ext4.
*/
+ if (cluster == &new_cluster)
+ appendPQExpBufferStr(&pgoptions, " -c synchronous_commit=off -c fsync=off -c full_page_writes=off");
+
+ /*
+ * Use max_slot_wal_keep_size as -1 to prevent the WAL removal by the
+ * checkpointer process. If WALs required by logical replication slots
+ * are removed, the slots are unusable. This setting prevents the
+ * invalidation of slots during the upgrade. We set this option when
+ * cluster is PG17 or later because logical replication slots can only be
+ * migrated since then. Besides, max_slot_wal_keep_size is added in PG13.
+ */
+ if (GET_MAJOR_VERSION(cluster->major_version) >= 1700)
+ appendPQExpBufferStr(&pgoptions, " -c max_slot_wal_keep_size=-1");
+
+ /* Use -b to disable autovacuum. */
snprintf(cmd, sizeof(cmd),
"\"%s/pg_ctl\" -w -l \"%s/%s\" -D \"%s\" -o \"-p %d -b%s %s%s\" start",
cluster->bindir,
log_opts.logdir,
SERVER_LOG_FILE, cluster->pgconfig, cluster->port,
- (cluster == &new_cluster) ?
- " -c synchronous_commit=off -c fsync=off -c full_page_writes=off" : "",
+ pgoptions.data,
cluster->pgopts ? cluster->pgopts : "", socket_string);
+ termPQExpBuffer(&pgoptions);
+
/*
* Don't throw an error right away, let connecting throw the error because
* it might supply a reason for the failure.