Skip to content

Commit 416f8ea

Browse files
NikolaySNik Samokhvalov
authored andcommitted
Add wait events for COPY file/program operations
Add two new IO wait events for COPY operations: - COPY_DATA_READ: When COPY FROM blocks reading from file or program - COPY_DATA_WRITE: When COPY TO blocks writing to file or program These events cover: - COPY FROM/TO file (including slow storage I/O) - COPY FROM/TO PROGRAM (pipe buffer congestion in ETL pipelines) Note: COPY FROM/TO STDIN/STDOUT already have wait event coverage via existing Client/ClientRead and Client/ClientWrite events emitted at the protocol layer, so no additional instrumentation is needed there. This enables DBAs to: - Diagnose slow pg_dump/pg_restore operations - Identify storage I/O bottlenecks during bulk loads - Analyze pipe buffer congestion in ETL pipelines - Perform ASH analysis of COPY operations
1 parent b8ccd29 commit 416f8ea

3 files changed

Lines changed: 7 additions & 0 deletions

File tree

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: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -454,10 +454,12 @@ 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))
460461
{
462+
pgstat_report_wait_end();
461463
if (cstate->is_program)
462464
{
463465
if (errno == EPIPE)
@@ -486,6 +488,7 @@ CopySendEndOfRow(CopyToState cstate)
486488
(errcode_for_file_access(),
487489
errmsg("could not write to COPY file: %m")));
488490
}
491+
pgstat_report_wait_end();
489492
break;
490493
case COPY_FRONTEND:
491494
/* 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 to read data from file or program during COPY FROM."
214+
COPY_DATA_WRITE "Waiting to write data to 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)