From 30d2d0aa75fa1d519ee9d1f8cff15b79148f36f3 Mon Sep 17 00:00:00 2001 From: Rui Zhao Date: Fri, 14 Aug 2026 15:50:46 +0800 Subject: [PATCH] Cover the origin that was advanced to exactly 0/0 need_advance is fed from !PG_ARGISNULL(2) rather than from remote_lsn because a missing pg_replication_origin_status row and a row at 0/0 both reach the new cluster as InvalidXLogRecPtr. The suite has an origin that was never advanced and origins with a non-zero remote_lsn, but not one advanced to 0/0 -- so deriving need_advance from remote_lsn instead leaves 004_subscription.pl green while silently dropping such an origin's tracking state across the upgrade. --- src/bin/pg_upgrade/t/004_subscription.pl | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/bin/pg_upgrade/t/004_subscription.pl b/src/bin/pg_upgrade/t/004_subscription.pl index 3460d02d7d..f2f6d7b6f7 100644 --- a/src/bin/pg_upgrade/t/004_subscription.pl +++ b/src/bin/pg_upgrade/t/004_subscription.pl @@ -340,6 +340,16 @@ $pre_upgrade_roident{$user_origin_name} = $old_sub->safe_psql('postgres', "SELECT roident FROM pg_replication_origin WHERE roname = '$user_origin_name'" ); +# An origin advanced to exactly 0/0 is tracked on the old cluster and must stay +# tracked. This is the case that the NULL-ness of the remote_lsn argument +# exists to catch: a missing status row and a status row at 0/0 both reach the +# new cluster as InvalidXLogRecPtr. +my $zero_origin_name = 'regress_zero_origin'; +$old_sub->safe_psql('postgres', + "SELECT pg_replication_origin_create('$zero_origin_name')"); +$old_sub->safe_psql('postgres', + "SELECT pg_replication_origin_advance('$zero_origin_name', '0/0')"); + # Have the subscription in disabled state before upgrade $old_sub->safe_psql('postgres', "ALTER SUBSCRIPTION regress_sub5 DISABLE"); @@ -463,6 +473,17 @@ is($result, qq(0), "never-advanced origin '$user_origin_name' is still untracked after upgrade" ); +# The origin advanced to 0/0 is still present in pg_replication_origin_status +# on the new cluster. +$result = $new_sub->safe_psql( + 'postgres', qq[ + SELECT count(*) FROM pg_replication_origin_status s + JOIN pg_replication_origin o ON o.roident = s.local_id + WHERE o.roname = '$zero_origin_name']); +is($result, qq(1), + "origin '$zero_origin_name' advanced to 0/0 is still tracked after upgrade" +); + # Subscription relations should be preserved $result = $new_sub->safe_psql('postgres', "SELECT srrelid, srsubstate FROM pg_subscription_rel ORDER BY srrelid"); -- 2.43.7