]> git.ipfire.org Git - thirdparty/postgresql.git/commitdiff
Add two IO wait events for COPY FROM/TO on a pipe/file/program
authorMichael Paquier <michael@paquier.xyz>
Tue, 3 Feb 2026 03:20:41 +0000 (12:20 +0900)
committerMichael Paquier <michael@paquier.xyz>
Tue, 3 Feb 2026 03:20:41 +0000 (12:20 +0900)
Two wait events are added to the COPY FROM/TO code:
* COPY_FROM_READ: reading data from a copy_file.
* COPY_TO_WRITE: writing data to a copy_file.

In the COPY code, copy_file can be set when processing a command through
the pipe mode (for the non-DestRemote case), the program mode or the
file mode, when processing fread() or fwrite() on it.

Author: Nikolay Samokhvalov <nik@postgres.ai>
Reviewed-by: Dilip Kumar <dilipbalaut@gmail.com>
Reviewed-by: Sami Imseih <samimseih@gmail.com>
Discussion: https://postgr.es/m/CAM527d_iDzz0Kqyi7HOfqa-Xzuq29jkR6AGXqfXLqA5PR5qsng@mail.gmail.com

src/backend/commands/copyfromparse.c
src/backend/commands/copyto.c
src/backend/utils/activity/wait_event_names.txt

index 5868a7fa11f6314efff9ac7aafa7a60aed173b4d..94d6f415a069dc7ad935ebc98f32d609754abbed 100644 (file)
@@ -249,7 +249,9 @@ CopyGetData(CopyFromState cstate, void *databuf, int minread, int maxread)
        switch (cstate->copy_src)
        {
                case COPY_FILE:
+                       pgstat_report_wait_start(WAIT_EVENT_COPY_FROM_READ);
                        bytesread = fread(databuf, 1, maxread, cstate->copy_file);
+                       pgstat_report_wait_end();
                        if (ferror(cstate->copy_file))
                                ereport(ERROR,
                                                (errcode_for_file_access(),
index 4ab4a3893d5fd51e4ed9455b60c9f3b0efb4248c..9ceeff6d99e0bece85fa223267b9d1c78d620f0b 100644 (file)
@@ -454,6 +454,7 @@ CopySendEndOfRow(CopyToState cstate)
        switch (cstate->copy_dest)
        {
                case COPY_FILE:
+                       pgstat_report_wait_start(WAIT_EVENT_COPY_TO_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();
                        break;
                case COPY_FRONTEND:
                        /* Dump the accumulated row as one CopyData message */
index efde48e76b721829362271f4377258f14b996253..4aa864fe3c3cf5c600812cf2853d6f4dab048d5b 100644 (file)
@@ -213,6 +213,8 @@ CONTROL_FILE_WRITE_UPDATE   "Waiting for a write to update the <filename>pg_contro
 COPY_FILE_COPY "Waiting for a file copy operation."
 COPY_FILE_READ "Waiting for a read during a file copy operation."
 COPY_FILE_WRITE        "Waiting for a write during a file copy operation."
+COPY_FROM_READ "Waiting to read data from a pipe, a file or a program during COPY FROM."
+COPY_TO_WRITE  "Waiting to write data to a pipe, a file or a program during COPY TO."
 DATA_FILE_EXTEND       "Waiting for a relation data file to be extended."
 DATA_FILE_FLUSH        "Waiting for a relation data file to reach durable storage."
 DATA_FILE_IMMEDIATE_SYNC       "Waiting for an immediate synchronization of a relation data file to durable storage."