diff --git a/src/test/subscription/t/029_on_error.pl b/src/test/subscription/t/029_on_error.pl
index 5c29e5cc32..16603aa9a7 100644
--- a/src/test/subscription/t/029_on_error.pl
+++ b/src/test/subscription/t/029_on_error.pl
@@ -45,9 +45,8 @@ sub test_skip_lsn
 		"SELECT subskiplsn = '0/0' FROM pg_subscription WHERE subname = 'sub'"
 	);
 
-	# Check the log to ensure that the transaction is skipped, and advance the
-	# offset of the log file for the next test.
-	$offset = $node_subscriber->wait_for_log(
+	# Check the log to ensure that the transaction is skipped
+	$node_subscriber->wait_for_log(
 		qr/LOG: ( [A-Z0-9]+:)? logical replication completed skipping transaction at LSN $lsn/,
 		$offset);
 
@@ -61,6 +60,11 @@ sub test_skip_lsn
 	my $res =
 	  $node_subscriber->safe_psql('postgres', "SELECT count(*) FROM tbl");
 	is($res, $expected, $msg);
+
+	# Advance the offset of the log file for the next test. The line must be
+	# after the non-conflict transaction because it may output additional log
+	# messages if some debug logs are enabled.
+	$offset = -s $node_subscriber->logfile;
 }
 
 # Create publisher node. Set a low value of logical_decoding_work_mem to test
