BUG #19879: Blocked COPY FROM reports NULL command and type in pg_stat_progress_copy

Started by PG Bug reporting form17 days ago3 messagesbugs

Thread notes

1 note#bug#not-a-bug
hackorum-bot#bug#not-a-bug
hackorum-bot
2 days ago

@global #bug #not-a-bug

#bug#not-a-bug
Jump to latest
#1PG Bug reporting form
noreply@postgresql.org

The following bug has been logged on the website:

Bug reference: 19879
Logged by: Noah
Email address: imchifan8@gmail.com
PostgreSQL version: 18.6
Operating system: Linux/amd64
Description:

A server-side COPY FROM that blocks while opening a FIFO appears in
pg_stat_progress_copy with the correct relation OID but NULL command and
type. The view should identify the running command as COPY FROM and its I/O
type as FILE, as documented for pg_stat_progress_copy.

How to repeat:

Save this as run.sh:

#!/usr/bin/env bash
set -euo pipefail

: "${PG_BINDIR:?set PG_BINDIR to the target PostgreSQL bin directory}"
base="$PWD/work"
data="$base/data"
sock="$base/socket"
fifo="$base/input.fifo"
mkdir -p "$base" "$sock"
"$PG_BINDIR/initdb" -D "$data" --no-locale --encoding=UTF8 >/dev/null
"$PG_BINDIR/pg_ctl" -D "$data" -o "-k $sock -c listen_addresses=''" -w start

/dev/null

cleanup() {
"$PG_BINDIR/pg_ctl" -D "$data" -m immediate -w stop >/dev/null 2>&1 ||
true
}
trap cleanup EXIT
"$PG_BINDIR/psql" -X -h "$sock" -d postgres -v ON_ERROR_STOP=1 -c 'CREATE
TABLE copy_progress_target(i int)'
mkfifo "$fifo"
"$PG_BINDIR/psql" -X -h "$sock" -d postgres -v ON_ERROR_STOP=1 \
-c "COPY copy_progress_target FROM '$fifo'" >"$base/copy.out"
2>"$base/copy.err" &
copy_pid=$!
for _ in $(seq 1 100); do
row=$("$PG_BINDIR/psql" -XAt -h "$sock" -d postgres -c \
"SELECT coalesce(command,'<NULL>') || '|' || coalesce(type,'<NULL>')
FROM pg_stat_progress_copy WHERE relid='copy_progress_target'::regclass")
test -n "$row" && break
sleep 0.05
done
printf 'observed=%s\n' "$row"
printf '1\n' >"$fifo"
wait "$copy_pid"
test "$row" = 'COPY FROM|FILE'

Run it as a non-root operating-system user from an otherwise empty writable
directory:

chmod +x run.sh
PG_BINDIR=/path/to/postgresql/bin ./run.sh

On the affected build, it prints:

observed=<NULL>|<NULL>

The final test then exits nonzero. The progress row exists and has the
relation OID for copy_progress_target, but its command and type are missing.
Writing to the FIFO allows COPY to finish; the metadata is then populated or
the progress row disappears.

The issue was reproduced on PostgreSQL 18.6 (Debian 18.6-1.pgdg13+2) on
Linux/amd64. COPY execution and table data are unaffected. This occurs when
an authorized server-side COPY FROM opens a filesystem object whose open
blocks while another session monitors pg_stat_progress_copy.

#2Raja Sai pranav
rajasaipranav0@gmail.com
In reply to: PG Bug reporting form (#1)
Re: BUG #19879: Blocked COPY FROM reports NULL command and type in pg_stat_progress_copy

Hi,

I reproduced this on master (4a26e36f87) with your script and attached a
patch.

BeginCopyFrom() starts the progress entry with the relation, but sets the
command and type only after AllocateFile() (or OpenPipeStream() for
PROGRAM) returns. Opening a FIFO waits for a writer, so until then the view
shows the relation with NULL command and type. The type is already known
before the open, so the patch reports command and type just before it.

With the patch your script prints "observed=COPY FROM|FILE"; without it,
"observed=|". The core regression tests pass. I didn't add a test, because
it needs a FIFO and a timing loop, which doesn't fit the regression suite
and wouldn't run on Windows.

COPY TO starts its progress entry only after opening the file, so a blocked
COPY TO doesn't show up in the view at all instead of showing a half-filled
row. I left that alone.

Regards,
Sai Pranav

On Fri, Nov 20, 2026 10:36 PM, PG Bug reporting form <noreply@postgresql.org>
wrote:

Show quoted text

The following bug has been logged on the website:

Bug reference: 19879
Logged by: Noah
Email address: imchifan8@gmail.com
PostgreSQL version: 18.6
Operating system: Linux/amd64
Description:

A server-side COPY FROM that blocks while opening a FIFO appears in
pg_stat_progress_copy with the correct relation OID but NULL command and
type. The view should identify the running command as COPY FROM and its I/O
type as FILE, as documented for pg_stat_progress_copy.

How to repeat:

Save this as run.sh:

#!/usr/bin/env bash
set -euo pipefail

: "${PG_BINDIR:?set PG_BINDIR to the target PostgreSQL bin directory}"
base="$PWD/work"
data="$base/data"
sock="$base/socket"
fifo="$base/input.fifo"
mkdir -p "$base" "$sock"
"$PG_BINDIR/initdb" -D "$data" --no-locale --encoding=UTF8 >/dev/null
"$PG_BINDIR/pg_ctl" -D "$data" -o "-k $sock -c listen_addresses=''" -w
start

/dev/null

cleanup() {
"$PG_BINDIR/pg_ctl" -D "$data" -m immediate -w stop >/dev/null 2>&1 ||
true
}
trap cleanup EXIT
"$PG_BINDIR/psql" -X -h "$sock" -d postgres -v ON_ERROR_STOP=1 -c 'CREATE
TABLE copy_progress_target(i int)'
mkfifo "$fifo"
"$PG_BINDIR/psql" -X -h "$sock" -d postgres -v ON_ERROR_STOP=1 \
-c "COPY copy_progress_target FROM '$fifo'" >"$base/copy.out"
2>"$base/copy.err" &
copy_pid=$!
for _ in $(seq 1 100); do
row=$("$PG_BINDIR/psql" -XAt -h "$sock" -d postgres -c \
"SELECT coalesce(command,'<NULL>') || '|' || coalesce(type,'<NULL>')
FROM pg_stat_progress_copy WHERE relid='copy_progress_target'::regclass")
test -n "$row" && break
sleep 0.05
done
printf 'observed=%s\n' "$row"
printf '1\n' >"$fifo"
wait "$copy_pid"
test "$row" = 'COPY FROM|FILE'

Run it as a non-root operating-system user from an otherwise empty writable
directory:

chmod +x run.sh
PG_BINDIR=/path/to/postgresql/bin ./run.sh

On the affected build, it prints:

observed=<NULL>|<NULL>

The final test then exits nonzero. The progress row exists and has the
relation OID for copy_progress_target, but its command and type are
missing.
Writing to the FIFO allows COPY to finish; the metadata is then populated
or
the progress row disappears.

The issue was reproduced on PostgreSQL 18.6 (Debian 18.6-1.pgdg13+2) on
Linux/amd64. COPY execution and table data are unaffected. This occurs when
an authorized server-side COPY FROM opens a filesystem object whose open
blocks while another session monitors pg_stat_progress_copy.

Attachments:

t258498_2
v1-0001-Report-COPY-FROM-command-and-type-before-opening-.patchtext/x-patch; charset=UTF-8; name=v1-0001-Report-COPY-FROM-command-and-type-before-opening-.patchDownload+4-1
#3Masahiko Sawada
sawada.mshk@gmail.com
In reply to: PG Bug reporting form (#1)
Re: BUG #19879: Blocked COPY FROM reports NULL command and type in pg_stat_progress_copy

On Wed, Nov 11, 2026 at 6:00 AM PG Bug reporting form
<noreply@postgresql.org> wrote:

The following bug has been logged on the website:

Bug reference: 19879
Logged by: Noah
Email address: imchifan8@gmail.com
PostgreSQL version: 18.6
Operating system: Linux/amd64
Description:

A server-side COPY FROM that blocks while opening a FIFO appears in
pg_stat_progress_copy with the correct relation OID but NULL command and
type. The view should identify the running command as COPY FROM and its I/O
type as FILE, as documented for pg_stat_progress_copy.

How to repeat:

Save this as run.sh:

#!/usr/bin/env bash
set -euo pipefail

: "${PG_BINDIR:?set PG_BINDIR to the target PostgreSQL bin directory}"
base="$PWD/work"
data="$base/data"
sock="$base/socket"
fifo="$base/input.fifo"
mkdir -p "$base" "$sock"
"$PG_BINDIR/initdb" -D "$data" --no-locale --encoding=UTF8 >/dev/null
"$PG_BINDIR/pg_ctl" -D "$data" -o "-k $sock -c listen_addresses=''" -w start

/dev/null

cleanup() {
"$PG_BINDIR/pg_ctl" -D "$data" -m immediate -w stop >/dev/null 2>&1 ||
true
}
trap cleanup EXIT
"$PG_BINDIR/psql" -X -h "$sock" -d postgres -v ON_ERROR_STOP=1 -c 'CREATE
TABLE copy_progress_target(i int)'
mkfifo "$fifo"
"$PG_BINDIR/psql" -X -h "$sock" -d postgres -v ON_ERROR_STOP=1 \
-c "COPY copy_progress_target FROM '$fifo'" >"$base/copy.out"
2>"$base/copy.err" &
copy_pid=$!
for _ in $(seq 1 100); do
row=$("$PG_BINDIR/psql" -XAt -h "$sock" -d postgres -c \
"SELECT coalesce(command,'<NULL>') || '|' || coalesce(type,'<NULL>')
FROM pg_stat_progress_copy WHERE relid='copy_progress_target'::regclass")
test -n "$row" && break
sleep 0.05
done
printf 'observed=%s\n' "$row"
printf '1\n' >"$fifo"
wait "$copy_pid"
test "$row" = 'COPY FROM|FILE'

Thank you for the report and the patch.

Since the progress information is updated incrementally as the command
proceeds, I think it's expected that the view doesn't show complete
information at some point. Even while the command and type columns are
NULL, the COPY already appears in pg_stat_progress_copy with its pid
and relid, so users can find which command the backend is stuck on. So
I don't think it's worth fixing. BTW how did you find this problem?

Regards,

--
Masahiko Sawada
Amazon Web Services: https://aws.amazon.com