From 2b609524df2dd827dadd7eef30d76dc47d16c585 Mon Sep 17 00:00:00 2001
From: Sai Pranav <rajasaipranav0@gmail.com>
Date: Fri, 20 Nov 2026 17:06:38 +0000
Subject: [PATCH v1] Report COPY FROM command and type before opening the
 source

COPY FROM published the command and type in pg_stat_progress_copy only
after it had opened its file or started its program.  Opening a FIFO
blocks until a writer appears, so during that time the view showed the
relation but NULL command and type.  Report them just before the open,
as the type is already known there.

Discussion: https://postgr.es/m/19879-79f1b50f5f75a9e9@postgresql.org
---
 src/backend/commands/copyfrom.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/src/backend/commands/copyfrom.c b/src/backend/commands/copyfrom.c
index 89f48c8951..2018aeccf7 100644
--- a/src/backend/commands/copyfrom.c
+++ b/src/backend/commands/copyfrom.c
@@ -1884,6 +1884,8 @@ BeginCopyFrom(ParseState *pstate,
 		if (cstate->is_program)
 		{
 			progress_vals[1] = PROGRESS_COPY_TYPE_PROGRAM;
+			/* Report these before starting the program, which may block */
+			pgstat_progress_update_multi_param(2, progress_cols, progress_vals);
 			cstate->copy_file = OpenPipeStream(cstate->filename, PG_BINARY_R);
 			if (cstate->copy_file == NULL)
 				ereport(ERROR,
@@ -1896,6 +1898,8 @@ BeginCopyFrom(ParseState *pstate,
 			struct stat st;
 
 			progress_vals[1] = PROGRESS_COPY_TYPE_FILE;
+			/* Report these before opening, which blocks for a FIFO */
+			pgstat_progress_update_multi_param(2, progress_cols, progress_vals);
 			cstate->copy_file = AllocateFile(cstate->filename, PG_BINARY_R);
 			if (cstate->copy_file == NULL)
 			{
-- 
2.50.1 (Apple Git-155)

