public inbox for [email protected]  
help / color / mirror / Atom feed
From: Shinya Kato <[email protected]>
To: PostgreSQL-development <[email protected]>
Subject: Call EndCopyFrom() after initial table sync in logical replication
Date: Mon, 4 May 2026 16:58:12 +0900
Message-ID: <CAOzEurQKuy3RiPkd=25PEwEzaqHuGvEOf=X7vaVzhgNjaukYzA@mail.gmail.com> (raw)

Hi hackers,

While reading the logical replication initial table sync code, I
noticed that copy_table() calls BeginCopyFrom() and CopyFrom() but
never calls the matching EndCopyFrom().

EndCopyFrom() calls pgstat_progress_end_command(), which resets
st_progress_command to PROGRESS_COMMAND_INVALID. Without that call,
the backend status entry continues to report an active COPY operation
while the tablesync worker proceeds to WAL catchup. As a result,
pg_stat_progress_copy shows a stale entry for the entire WAL catchup
phase.

Attached patch adds EndCopyFrom(cstate) immediately after
CopyFrom(cstate) returns.

--
Best regards,
Shinya Kato
NTT OSS Center


Attachments:

  [application/octet-stream] v1-0001-Call-EndCopyFrom-during-initial-table-sync-in-log.patch (1.4K, 2-v1-0001-Call-EndCopyFrom-during-initial-table-sync-in-log.patch)
  download | inline diff:
From 14f523601a44f816833dd5e4e0f2326edf533278 Mon Sep 17 00:00:00 2001
From: Shinya Kato <[email protected]>
Date: Tue, 21 Apr 2026 10:29:07 +0900
Subject: [PATCH v1] Call EndCopyFrom() during initial table sync in logical
 replication

Previously, copy_table() called BeginCopyFrom() and CopyFrom() but
omitted the matching EndCopyFrom() call.  Without it, the backend
status entry continued to report an active COPY operation while the
tablesync worker proceeded to WAL catchup, causing pg_stat_progress_copy
to show a stale entry for the entire WAL catchup phase, which can be
significant for large tables.

This commit adds the missing EndCopyFrom() call, which invokes
pgstat_progress_end_command() to reset st_progress_command to
PROGRESS_COMMAND_INVALID as soon as the COPY phase completes.

Author: Shinya Kato <[email protected]>
Reviewed-by:
Discussion: https://postgr.es/m/
---
 src/backend/replication/logical/tablesync.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/src/backend/replication/logical/tablesync.c b/src/backend/replication/logical/tablesync.c
index eb718114297..a04b84ebc1d 100644
--- a/src/backend/replication/logical/tablesync.c
+++ b/src/backend/replication/logical/tablesync.c
@@ -1210,6 +1210,7 @@ copy_table(Relation rel)
 
 	/* Do the copy */
 	(void) CopyFrom(cstate);
+	EndCopyFrom(cstate);
 
 	logicalrep_rel_close(relmapentry, NoLock);
 }
-- 
2.47.3



view thread (11+ messages)  latest in thread

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: [email protected]
  Cc: [email protected]
  Subject: Re: Call EndCopyFrom() after initial table sync in logical replication
  In-Reply-To: <CAOzEurQKuy3RiPkd=25PEwEzaqHuGvEOf=X7vaVzhgNjaukYzA@mail.gmail.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox