Re: IO wait events for COPY FROM/TO PROGRAM or file - Mailing list pgsql-hackers

From Michael Paquier
Subject Re: IO wait events for COPY FROM/TO PROGRAM or file
Date
Msg-id aWBCcFgH87WnMKtA@paquier.xyz
Whole thread Raw
In response to IO wait events for COPY FROM/TO PROGRAM or file  (Nikolay Samokhvalov <nik@postgres.ai>)
Responses Re: IO wait events for COPY FROM/TO PROGRAM or file
List 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

Attachment

pgsql-hackers by date:

Previous
From: Michael Paquier
Date:
Subject: Re: pg_plan_advice
Next
From: Masahiko Sawada
Date:
Subject: Re: Optimize SnapBuildPurgeOlderTxn: use in-place compaction instead of temporary array