diff --git a/src/bin/pg_upgrade/t/002_pg_upgrade.pl b/src/bin/pg_upgrade/t/002_pg_upgrade.pl
index 4cbc75644c..755b26b605 100644
--- a/src/bin/pg_upgrade/t/002_pg_upgrade.pl
+++ b/src/bin/pg_upgrade/t/002_pg_upgrade.pl
@@ -148,6 +148,7 @@ if (defined($ENV{oldinstall}))
 # Initialize a new node for the upgrade.
 my $newnode = PostgreSQL::Test::Cluster->new('new_node');
 $newnode->init(extra => [ '--wal-segsize', '1', '--allow-group-access' ]);
+$newnode->append_conf('autovacuum' => 'off');
 my $newbindir = $newnode->config_data('--bindir');
 my $oldbindir = $oldnode->config_data('--bindir');
 
@@ -302,6 +303,11 @@ if (-d $log_path)
 	}
 }
 
+# Record the horizons from the upgraded cluster, then enable autovacuum.
+my $horizon2 = $newnode->safe_psql('regression', $horizon_query);
+$newnode->safe_psql('regression', "ALTER SYSTEM SET autovacuum = 'on'");
+$newnode->safe_psql('regression', "SELECT pg_reload_conf();");
+
 # Second dump from the upgraded instance.
 $newnode->command_ok(
 	[
@@ -311,9 +317,6 @@ $newnode->command_ok(
 	],
 	'dump after running pg_upgrade');
 
-# And record the horizons from the upgraded cluster as well.
-my $horizon2 = $newnode->safe_psql('regression', $horizon_query);
-
 # Compare the two dumps, there should be no differences.
 my $compare_res = compare("$tempdir/dump1.sql", "$tempdir/dump2.sql");
 is($compare_res, 0, 'old and new dumps match after pg_upgrade');
