What Are Wait Events?
PostgreSQL wait events provide insight into what a backend process is doing at any given moment. When a process is actively waiting on a resource (I/O, lock, network), PostgreSQL records the specific wait event. This allows monitoring tools to show where time is being spent.
Official Documentation: pg_stat_activity — PostgreSQL Documentation
The "Green CPU" Problem
Many monitoring tools (AWS RDS Performance Insights, PASH Viewer, etc.) visualize wait_event IS NULL as green "CPU" time:
┌────────────────────────────────┐
│ Active Sessions (sampled/s) │
│ │
│ ████████████ <- CPU (green) │
│ ▓▓▓▓▓▓ <- I/O (blue) │
│ ░░░░ <- Lock (orange) │
│ │
│ Green = NULL wait_event │
└────────────────────────────────┘
But NULL doesn't always mean "CPU working" — it can also mean "not instrumented yet."
The Real Problem
When a backend is stuck waiting on network I/O, external authentication, or other blocking operations without wait event coverage, monitoring tools incorrectly show it as green "CPU" activity.
The issue: NULL doesn't always mean "CPU working" — some wait events are uninstrumented.
When a backend is stuck waiting on network I/O, external authentication, or other blocking operations without wait event coverage, monitoring tools incorrectly show it as CPU activity.
Best practice: Tools should visualize NULL as "CPU or unknown wait event" — PostgresAI monitoring follows this convention.
This leads to misdiagnosis during incidents. A connection storm caused by slow LDAP authentication appears as "high CPU load" when it's actually network/auth waits that lack instrumentation.
Gap Categories
Source audit: 2026-11-18. PostgreSQL REL_19_STABLE at 882f6b32f4ae (the REL_19_0 tag plus 3 commits that touch no cited file). PostgreSQL 19 is not GA yet: the latest announcement is 19 RC 2, and the release is planned for 2026-11-19. These are source-level findings, not measured latency claims. See the audit and counting method.
10 need validation
5 rejected DNS claims
5 removed RADIUS rows
7 retained + relation creation
The 32 historical authentication rows reconcile to 12 potentially blocking uninstrumented operations, 10 requiring library or platform validation, 5 rejected DNS claims, and 5 removed RADIUS rows. This is not an exhaustive current gap count. Numeric address conversions, library initialization and option access must not be counted as confirmed network waits.
Authentication: open gaps and corrected claims
- LDAP: DNS SRV lookup, synchronous TLS, binds and search remain candidates for instrumentation. Initialization and option calls are not automatically network waits.
- Ident: blocking connect/send/receive remain uninstrumented. The address conversions use numeric-only flags, not DNS.
- PAM: external authentication and account-management calls remain uninstrumented; hostname lookup is conditional on
pam_use_hostname. RADIUS: 5 historical candidatesREMOVED in PostgreSQL 19, not instrumented: a1643d40b.- GSSAPI/Kerberos: external-library work remains uninstrumented; do not assume every call contacts a KDC.
- DNS: connection hostname logging can block when
log_hostname=on, but runs before shared PGPROC setup; it must not be described as an ordinary active CPU row inpg_stat_activity. Numeric-only auth error-message conversions are not DNS gaps.
I/O operations: 8 identified source locations
COPY FROM/TO pipe/file/program read/write:FIXED in PostgreSQL 19 by e05a24c. This covers the two original read/write sites, not every subprocess lifecycle operation.- Relation-file removal (details): three
unlink()sites remain uninstrumented: md.c:406, 465, 1966. - Recovery signal files: two
pg_fsync()sites remain uninstrumented: 1027, 1041. - Dynamic shared memory: two
fstat()sites remain uninstrumented: 279, 850. - NEW: relation-file creation (details): mdcreate() at md.c:249 calls
PathNameOpenFile(... O_CREAT | O_EXCL); the underlying open() has no wait-event wrapper.
Relation files: creation, removal and truncation
Every new relation gets a file on disk, and DROP removes it. PostgreSQL 19 reports no wait event for these filesystem calls.
- Creation:
mdcreate()md.c:249 callsPathNameOpenFile(... O_CREAT | O_EXCL). The chain goes through fd.c 1568, 1579 and 1611 toBasicOpenFilePerm()fd.c:1115. Itsopen()at 1121/1123 has no wait event. - Removal:
mdunlinkfork()callsunlink()at md.c:406 for the first segment and md.c:465 for extra segments. Temp relations are unlinked here immediately. Permanent main forks go through the deferred path:mdunlinkfiletag()md.c:1966, called from sync.c:231. Neither callee nor caller has a wait event. - Truncation (not counted in the 8): for permanent relations,
mdunlinkfork()first callsdo_truncate()(md.c 393, 420, 455). That callspg_truncate()fd.c:724, a baretruncate()with no wait event. UnlikeFileTruncate()(DATA_FILE_TRUNCATE), it is not instrumented. Temp relations skip this step.
Why temporary tables matter: repeated CREATE TEMP TABLE/DROP TABLE exercises relation-file creation and immediate removal. These filesystem operations can block without a dedicated wait event. This is not a claim that all temporary-table work lacks instrumentation or that all elapsed time is I/O: catalog work, invalidation and real CPU execution are separate.
PostgreSQL hacking opportunity: measure these filesystem paths and propose narrowly scoped creation/removal I/O wait events, including common wrappers and platform-specific behavior. Do not wrap an entire DDL command in an I/O event or treat CPU work as waiting.
Evidence: audit, temporary tables section.
□ Compression ✗ NOT APPLICABLE
Base backup compression (gzip, LZ4, Zstandard) was considered for wait event coverage.
Community consensus: CPU-bound operations should NOT be covered by wait events. Per pgsql-hackers discussion: "I vehemently oppose turning wait events into a poor emulation of a CPU profiler."
Status: Rejected — wait events are for waiting, not CPU work.
□ Cryptography ✗ NOT APPLICABLE
SCRAM-SHA-256 (PBKDF2), SQL hash functions, HMAC operations.
Community consensus: CPU-bound cryptographic operations are legitimate CPU work, not waits. Adding wait events everywhere would add overhead without providing useful waiting-state information.
Status: Rejected — use profiling tools for CPU analysis, not wait events.
Recently Added Wait Events
PostgreSQL 19 also adds WAIT_FOR_WAL_WRITE and extends flush waiting to standbys
(7a39f43d).
The WAIT_FOR_WAL_* events now belong to IPC, not Client
(56fa044d).
2026-02-03 — COPY FROM/TO pipe/file/program (part of this gap analysis project)
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"
Commit: e05a24c
2025-12-09 — Group Commit Delay
COMMIT_DELAY— "Waiting for commit delay before WAL flush"
Commit: 3cb5808b
2025-11-05 — LSN Waiting Infrastructure
WAIT_FOR_WAL_FLUSH— "Waiting for WAL flush to reach a target LSN on a primary or standby"WAIT_FOR_WAL_REPLAY— "Waiting for WAL replay to reach a target LSN on a standby"WaitLSN— LWLock for Wait-for-LSN state
Commit: 3b4e53a0
2025-05-29 — Async I/O (io_uring)
AioUringCompletion— LWLock for AIO uring completion
Commit: c3623703
2023-10-13 — Checkpoint Delay
CHECKPOINT_DELAY_COMPLETE— "Waiting for a backend that blocks a checkpoint from completing"CHECKPOINT_DELAY_START— "Waiting for a backend that blocks a checkpoint from starting"
Commit: 0013ba29
Observer Effect
An additional challenge: logging itself can cause observer effects that confuse wait event analysis.
Example: log_min_duration_statement=0 with high TPS on non-fast disks
Logging overhead depends on the destination. A backend may block writing to the logging collector pipe or directly to stderr; the collector writes log files. These uninstrumented writes can appear as CPU or unknown wait, but not every backend log message is a direct disk write.
The very act of observing (logging) changes what's being observed, and the gap in instrumentation makes it invisible.
GSoC 2026
Historical proposal: Google Summer of Code 2026.
→ Wait Event Coverage Improvements (ideas list, Wayback Machine copy of 2026-03-12)
The idea is not among the 7 Google-approved projects that the current GSoC 2026 page lists. The work remains open.
Contributors can use the pinned source audit to evaluate remaining instrumentation work.
Resources
- Full Gap Analysis (GitHub) — Historical candidate inventory (56 locations, including 15 CPU-only candidates); not a current open-gap count
- Mailing List Thread — Community discussion on pgsql-hackers