Re: IO wait events for COPY FROM/TO PROGRAM or file

From: Michael Paquier <michael(at)paquier(dot)xyz>
To: Nikolay Samokhvalov <nik(at)postgres(dot)ai>
Cc: pgsql-hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: IO wait events for COPY FROM/TO PROGRAM or file
Date: 2026-01-08 23:49:04
Message-ID: aWBCcFgH87WnMKtA@paquier.xyz
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Thu, Jan 08, 2026 at 01:53:17PM -0800, Nikolay Samokhvalov wrote:
> Following up on the discussion about wait event coverage for COPY
> operations [1], here's a tiny patch that adds two new IO wait events:
> - COPY_DATA_READ: COPY FROM blocking on file/program read
> - COPY_DATA_WRITE: COPY TO blocking on file/program write

case COPY_FILE:
+ pgstat_report_wait_start(WAIT_EVENT_COPY_DATA_WRITE);
if (fwrite(fe_msgbuf->data, fe_msgbuf->len, 1,
cstate->copy_file) != 1 ||
ferror(cstate->copy_file))
@@ -486,6 +487,7 @@ CopySendEndOfRow(CopyToState cstate)
(errcode_for_file_access(),
errmsg("could not write to COPY file: %m")));
}
+ pgstat_report_wait_end();

Hmm. Makes sense to me (perhaps you have played with an LLM to find
out fread() and fwrite() patterns that would need an event?), but I
don't think that the part about COPY TO is done right. The wait event
should be set during the fwrite() call only, similarly to the COPY
FROM case, by saving the result returned by fwrite() in a separate
variable.
--
Michael

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Masahiko Sawada 2026-01-08 23:58:55 Re: Optimize SnapBuildPurgeOlderTxn: use in-place compaction instead of temporary array
Previous Message Michael Paquier 2026-01-08 23:29:38 Re: pg_plan_advice