From 202802ac9cef08c67bd258fb95c3013580bcb73f Mon Sep 17 00:00:00 2001 From: "Chao Li (Evan)" Date: Fri, 26 Jun 2026 16:51:18 +0800 Subject: [PATCH v1] Clear base backup progress reporting during sink cleanup bbsink_progress_new() starts command progress reporting for pg_stat_progress_basebackup, but the matching pgstat_progress_end_command() was only reached from the success path in perform_base_backup(). If BASE_BACKUP failed after progress reporting started, the walsender could keep a stale progress entry until the connection ended or another progress command replaced it. Move the progress cleanup into the progress sink's cleanup callback, so it is run through the existing PG_FINALLY cleanup path on both success and error. Remove the now-unused basebackup_progress_done() wrapper. Author: Chao Li Reviewed-by: Discussion: https://postgr.es/m/ --- src/backend/backup/basebackup.c | 2 -- src/backend/backup/basebackup_progress.c | 22 ++++++++++++---------- src/include/backup/basebackup_sink.h | 1 - 3 files changed, 12 insertions(+), 13 deletions(-) diff --git a/src/backend/backup/basebackup.c b/src/backend/backup/basebackup.c index 9c79dadaacc..5214e7b99c7 100644 --- a/src/backend/backup/basebackup.c +++ b/src/backend/backup/basebackup.c @@ -676,8 +676,6 @@ perform_base_backup(basebackup_options *opt, bbsink *sink, /* clean up the resource owner we created */ ReleaseAuxProcessResources(true); - - basebackup_progress_done(); } /* diff --git a/src/backend/backup/basebackup_progress.c b/src/backend/backup/basebackup_progress.c index fb9e57f04df..93310b95c08 100644 --- a/src/backend/backup/basebackup_progress.c +++ b/src/backend/backup/basebackup_progress.c @@ -38,6 +38,7 @@ static void bbsink_progress_begin_backup(bbsink *sink); static void bbsink_progress_archive_contents(bbsink *sink, size_t len); static void bbsink_progress_end_archive(bbsink *sink); +static void bbsink_progress_cleanup(bbsink *sink); static const bbsink_ops bbsink_progress_ops = { .begin_backup = bbsink_progress_begin_backup, @@ -48,7 +49,7 @@ static const bbsink_ops bbsink_progress_ops = { .manifest_contents = bbsink_forward_manifest_contents, .end_manifest = bbsink_forward_end_manifest, .end_backup = bbsink_forward_end_backup, - .cleanup = bbsink_forward_cleanup + .cleanup = bbsink_progress_cleanup }; /* @@ -82,6 +83,16 @@ bbsink_progress_new(bbsink *next, bool estimate_backup_size, bool incremental) return sink; } +/* + * Clean up progress reporting. + */ +static void +bbsink_progress_cleanup(bbsink *sink) +{ + pgstat_progress_end_command(); + bbsink_forward_cleanup(sink); +} + /* * Progress reporting at start of backup. */ @@ -236,12 +247,3 @@ basebackup_progress_transfer_wal(void) pgstat_progress_update_param(PROGRESS_BASEBACKUP_PHASE, PROGRESS_BASEBACKUP_PHASE_TRANSFER_WAL); } - -/* - * Advertise that we are no longer performing a backup. - */ -void -basebackup_progress_done(void) -{ - pgstat_progress_end_command(); -} diff --git a/src/include/backup/basebackup_sink.h b/src/include/backup/basebackup_sink.h index bbf4de0cbdc..96fa2c4eaba 100644 --- a/src/include/backup/basebackup_sink.h +++ b/src/include/backup/basebackup_sink.h @@ -297,6 +297,5 @@ extern void basebackup_progress_wait_checkpoint(void); extern void basebackup_progress_estimate_backup_size(void); extern void basebackup_progress_wait_wal_archive(bbsink_state *); extern void basebackup_progress_transfer_wal(void); -extern void basebackup_progress_done(void); #endif -- 2.50.1 (Apple Git-155)