Skip to content

Conversation

@NikolayS
Copy link
Owner

@NikolayS NikolayS commented Jan 7, 2026

Summary

COPY operations previously showed wait_event = NULL when blocking on file/program I/O, making it impossible to diagnose performance issues during data loading, ETL operations, or pg_dump/pg_restore.

This patch adds two new IO wait events:

  • COPY_DATA_READ: When COPY FROM blocks reading from file or program
  • COPY_DATA_WRITE: When COPY TO blocks writing to file or program

Coverage

COPY Variant Wait Event
COPY FROM file COPY_DATA_READ
COPY TO file COPY_DATA_WRITE
COPY FROM PROGRAM COPY_DATA_READ
COPY TO PROGRAM COPY_DATA_WRITE
COPY FROM/TO STDIN/STDOUT CLIENT_READ/WRITE (existing)

Note: STDIN/STDOUT already have coverage via Client/ClientRead and Client/ClientWrite events at the protocol layer.

Use Cases

  • Diagnose slow pg_dump/pg_restore operations
  • Identify storage I/O bottlenecks during bulk loads
  • Analyze pipe buffer congestion in ETL pipelines
  • ASH (Active Session History) analysis of COPY operations

Changes

  • src/backend/commands/copyfromparse.c: Wrap fread() with wait events
  • src/backend/commands/copyto.c: Wrap fwrite() with wait events
  • src/backend/utils/activity/wait_event_names.txt: Add event definitions

@NikolayS NikolayS changed the base branch from master to claude/review-postgres-discussions-n0hWB January 7, 2026 23:28
@NikolayS NikolayS force-pushed the claude/review-postgres-discussions-n0hWB branch from fe60593 to e0fe9e6 Compare January 8, 2026 21:16
@NikolayS NikolayS force-pushed the claude/copy-wait-events-n0hWB branch 3 times, most recently from 416f8ea to fd54927 Compare January 8, 2026 21:51
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.

Example usage:

  -- Session 1:
  COPY large_table TO '/slow/nfs/mount/out.csv';

  -- Session 2:
  SELECT wait_event, wait_event_type
  FROM pg_stat_activity
  WHERE pid = <session1_pid>;
  -- Shows: COPY_DATA_WRITE / IO
@NikolayS NikolayS force-pushed the claude/copy-wait-events-n0hWB branch from fd54927 to 54a3b83 Compare January 8, 2026 21:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants