PostgreSQL Wait Events Coverage Gaps

Analysis and improvement proposals for PostgreSQL wait event instrumentation

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.

Authentication review
12 potentially blocking
10 need validation
5 rejected DNS claims
5 removed RADIUS rows
8
I/O source locations
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

I/O operations: 8 identified source locations

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.

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)

Commit: e05a24c

2025-12-09 — Group Commit Delay

Commit: 3cb5808b

2025-11-05 — LSN Waiting Infrastructure

Commit: 3b4e53a0

2025-05-29 — Async I/O (io_uring)

Commit: c3623703

2024-01-02 — WAL Summarizer

Commit: 5c430f9d

2023-10-13 — Checkpoint Delay

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