10
Wait Event Sampling
When a process is waiting for something,
this information appears in the pg_stat_activity view
wait_event_type — type of wait event
wait_event — name of the specific wait event
The information may be incomplete
not all code locations where wait events can occur are covered
The information reflects only the current moment
the only way to observe behavior over time is through sampling
a reliable picture emerges only with a large number of measurements
The pg_stat_activity view is used for monitoring wait events. When a
process (system or backend) cannot proceed with its work and is waiting for
something, that wait event appears in the view. The wait_event_type column
shows the type of wait event, while the wait_event column shows the name
of the specific wait event.
Note that the view shows only waits that are properly handled in the source
code. If the view does not show a wait event, this does not guarantee with
100% certainty that the process is not waiting for something.
Unfortunately, the only available information about wait events is the current
information. No cumulative statistics are maintained. The only way to get a
picture of wait events is sampling the state of the view at regular intervals.
While there is no built‑in tool for this, extensions like pg_wait_sampling can
be used.
Remember that sampling has a probabilistic nature: to get a reasonably
reliable picture, the number of samples must be sufficiently high. Therefore,
low‑frequency sampling does not provide accurate data, while increasing the
frequency leads to higher overhead. For the same reason, sampling is
useless for analyzing short-lived sessions.