Skip to content

Commit fd54927

Browse files
NikolaySNik Samokhvalov
authored andcommitted
Add IO wait events for COPY file/program operations
Add two new IO wait events: - COPY_DATA_READ: COPY FROM blocking on file or program read - COPY_DATA_WRITE: COPY TO blocking on file or program write This enables diagnosing: - Storage I/O bottlenecks during bulk loads (COPY FROM '/path/to/file') - Slow exports to files (COPY TO '/path/to/file') - Pipe buffer congestion in ETL pipelines (COPY FROM/TO PROGRAM) COPY FROM/TO STDIN/STDOUT already have coverage via Client/ClientRead and Client/ClientWrite at the protocol layer. These events are distinct from the existing COPY_FILE_READ/WRITE events, which instrument file-to-file copy operations in basebackup code.
1 parent b8ccd29 commit fd54927

File tree

3 files changed

+6
-0
lines changed

3 files changed

+6
-0
lines changed

src/backend/commands/copyfromparse.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,9 @@ CopyGetData(CopyFromState cstate, void *databuf, int minread, int maxread)
249249
switch (cstate->copy_src)
250250
{
251251
case COPY_FILE:
252+
pgstat_report_wait_start(WAIT_EVENT_COPY_DATA_READ);
252253
bytesread = fread(databuf, 1, maxread, cstate->copy_file);
254+
pgstat_report_wait_end();
253255
if (ferror(cstate->copy_file))
254256
ereport(ERROR,
255257
(errcode_for_file_access(),

src/backend/commands/copyto.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -454,6 +454,7 @@ CopySendEndOfRow(CopyToState cstate)
454454
switch (cstate->copy_dest)
455455
{
456456
case COPY_FILE:
457+
pgstat_report_wait_start(WAIT_EVENT_COPY_DATA_WRITE);
457458
if (fwrite(fe_msgbuf->data, fe_msgbuf->len, 1,
458459
cstate->copy_file) != 1 ||
459460
ferror(cstate->copy_file))
@@ -486,6 +487,7 @@ CopySendEndOfRow(CopyToState cstate)
486487
(errcode_for_file_access(),
487488
errmsg("could not write to COPY file: %m")));
488489
}
490+
pgstat_report_wait_end();
489491
break;
490492
case COPY_FRONTEND:
491493
/* Dump the accumulated row as one CopyData message */

src/backend/utils/activity/wait_event_names.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,8 @@ CONTROL_FILE_SYNC "Waiting for the <filename>pg_control</filename> file to reach
210210
CONTROL_FILE_SYNC_UPDATE "Waiting for an update to the <filename>pg_control</filename> file to reach durable storage."
211211
CONTROL_FILE_WRITE "Waiting for a write to the <filename>pg_control</filename> file."
212212
CONTROL_FILE_WRITE_UPDATE "Waiting for a write to update the <filename>pg_control</filename> file."
213+
COPY_DATA_READ "Waiting for a read from a file or program during COPY FROM."
214+
COPY_DATA_WRITE "Waiting for a write to a file or program during COPY TO."
213215
COPY_FILE_COPY "Waiting for a file copy operation."
214216
COPY_FILE_READ "Waiting for a read during a file copy operation."
215217
COPY_FILE_WRITE "Waiting for a write during a file copy operation."

0 commit comments

Comments
 (0)