diff --git a/src/test/modules/commit_ts/t/005_switchover.pl b/src/test/modules/commit_ts/t/005_switchover.pl
new file mode 100644
index 0000000000..f414f632c5
--- /dev/null
+++ b/src/test/modules/commit_ts/t/005_switchover.pl
@@ -0,0 +1,85 @@
+# Test master/standby switchover scenario where the track_commit_timestamp
+# GUC is originally off, then enabled on the new primary after a switchover.
+use strict;
+use warnings;
+
+use TestLib;
+use Test::More tests => 2;
+use PostgresNode;
+
+my $bkplabel = 'backup';
+my $master   = get_new_node('master');
+$master->init(allows_streaming => 1);
+$master->append_conf(
+	'postgresql.conf', qq{
+	track_commit_timestamp = off
+	max_wal_senders = 5
+	max_worker_processes = 8
+	});
+$master->start;
+$master->backup($bkplabel);
+
+my $standby = get_new_node('standby');
+$standby->init_from_backup($master, $bkplabel, has_streaming => 1);
+$standby->start;
+
+for my $i (1 .. 10)
+{
+	$master->safe_psql('postgres', "create table t$i()");
+}
+my $master_lsn =
+  $master->safe_psql('postgres', 'select pg_current_wal_lsn()');
+$standby->poll_query_until('postgres',
+	qq{SELECT '$master_lsn'::pg_lsn <= pg_last_wal_replay_lsn()})
+  or die "standby never caught up";
+
+$standby->safe_psql('postgres', 'checkpoint');
+$standby->restart;
+
+# Begin the switchover, stop the primary.  Note that attempting to
+# start this cluster with a value of max_worker_processes lower than
+# the original causes its startup to fail.
+$master->append_conf('postgresql.conf', 'max_worker_processes = 4');
+$master->stop;
+
+# Promote the standby with larger max_worker_processes, and enable
+# track_commit_timestamp while on it.
+$standby->append_conf('postgresql.conf', 'track_commit_timestamp = on');
+$standby->promote;
+$standby->restart;
+
+# Enable streaming on the previous primary, and attempt to start it.
+# This fails as max_worker_processes is lower than on the root
+# cluster.
+$master->enable_streaming($standby);
+command_fails(
+    [ 'pg_ctl', '-D', $master->data_dir, '-l', $master->logfile, 'start' ],
+    'start fails because of max_worker_processes lower on standby');
+
+# Consume some transactions on the standby without the primary knowing
+# about it yet.
+for my $i (1 .. 100)
+{
+	$standby->safe_psql('postgres', "select txid_current();");
+}
+$standby->safe_psql('postgres', "create table t11()");
+
+# Add now a proper setting for max_worker_processes to allow startup
+# to go through.  This new standby will replay all information
+# received from the transactions of the standby previously done.
+$master->append_conf('postgresql.conf', 'max_worker_processes = 8');
+$master->start;
+
+# Check that old master is correctly streaming as a new standby.
+my $standby_lsn =
+  $standby->safe_psql('postgres', 'select pg_current_wal_lsn()');
+$master->poll_query_until('postgres',
+    qq{SELECT '$standby_lsn'::pg_lsn <= pg_last_wal_replay_lsn()});
+
+# And finally check that commit timestamps are generated on the
+# new primary.
+my $standby_ts = $standby->safe_psql('postgres',
+	qq{SELECT ts.* FROM pg_class, pg_xact_commit_timestamp(xmin) AS ts WHERE relname = 't11'}
+);
+isnt($standby_ts, '',
+	"standby gives valid value ($standby_ts) after promotion");
