pg_wait_sampling

sampling based statistics of wait events

Overview

PackageVersionCategoryLicenseLanguage
pg_wait_sampling1.1.9STATPostgreSQLC
IDExtensionBinLibLoadCreateTrustRelocSchema
6280pg_wait_samplingNoYesYesYesNoYes-
Relatedpowa pg_stat_statements pg_background pg_stat_kcache system_stats pgnodemx pg_profile pgsentinel

Version

TypeRepoVersionPG VerPackageDeps
EXTPGDG1.1.91817161514pg_wait_sampling-
RPMPGDG1.1.91817161514pg_wait_sampling_$v-
DEBPGDG1.1.91817161514postgresql-$v-pg-wait-sampling-
OS / PGPG18PG17PG16PG15PG14
el8.x86_64
el8.aarch64
el9.x86_64
el9.aarch64
el10.x86_64
el10.aarch64
PGDG 1.1.9
d12.x86_64
PGDG 1.1.9
PGDG 1.1.9
PGDG 1.1.9
PGDG 1.1.9
PGDG 1.1.9
d12.aarch64
PGDG 1.1.9
PGDG 1.1.9
PGDG 1.1.9
PGDG 1.1.9
PGDG 1.1.9
d13.x86_64
PGDG 1.1.9
PGDG 1.1.9
PGDG 1.1.9
PGDG 1.1.9
PGDG 1.1.9
d13.aarch64
PGDG 1.1.9
PGDG 1.1.9
PGDG 1.1.9
PGDG 1.1.9
PGDG 1.1.9
u22.x86_64
PGDG 1.1.9
PGDG 1.1.9
PGDG 1.1.9
PGDG 1.1.9
PGDG 1.1.9
u22.aarch64
PGDG 1.1.9
PGDG 1.1.9
PGDG 1.1.9
PGDG 1.1.9
PGDG 1.1.9
u24.x86_64
PGDG 1.1.9
PGDG 1.1.9
PGDG 1.1.9
PGDG 1.1.9
PGDG 1.1.9
u24.aarch64
PGDG 1.1.9
PGDG 1.1.9
PGDG 1.1.9
PGDG 1.1.9
PGDG 1.1.9

Install

You can install pg_wait_sampling directly. First, make sure the PGDG repository is added and enabled:

pig repo add pgdg -u          # Add PGDG repo and update cache

Install the extension using pig or apt/yum/dnf:

pig install pg_wait_sampling;          # Install for current active PG version
pig ext install -y pg_wait_sampling -v 18  # PG 18
pig ext install -y pg_wait_sampling -v 17  # PG 17
pig ext install -y pg_wait_sampling -v 16  # PG 16
pig ext install -y pg_wait_sampling -v 15  # PG 15
pig ext install -y pg_wait_sampling -v 14  # PG 14
dnf install -y pg_wait_sampling_18       # PG 18
dnf install -y pg_wait_sampling_17       # PG 17
dnf install -y pg_wait_sampling_16       # PG 16
dnf install -y pg_wait_sampling_15       # PG 15
dnf install -y pg_wait_sampling_14       # PG 14
apt install -y postgresql-18-pg-wait-sampling   # PG 18
apt install -y postgresql-17-pg-wait-sampling   # PG 17
apt install -y postgresql-16-pg-wait-sampling   # PG 16
apt install -y postgresql-15-pg-wait-sampling   # PG 15
apt install -y postgresql-14-pg-wait-sampling   # PG 14

Preload:

shared_preload_libraries = 'pg_wait_sampling';

Create Extension:

CREATE EXTENSION pg_wait_sampling;

Usage

pg_wait_sampling: sampling based statistics of wait events

pg_wait_sampling collects wait event statistics by periodically sampling what each backend is waiting on. It provides both a recent history ring buffer and a cumulative profile.

Views

Current wait events:

SELECT * FROM pg_wait_sampling_current;
ColumnTypeDescription
pidint4Process ID
event_typetextWait event type
eventtextWait event name
queryidint8Query ID

Wait event history (ring buffer of recent samples):

SELECT * FROM pg_wait_sampling_history;
ColumnTypeDescription
pidint4Process ID
tstimestamptzSample timestamp
event_typetextWait event type
eventtextWait event name
queryidint8Query ID

Wait event profile (cumulative counts):

SELECT * FROM pg_wait_sampling_profile;
ColumnTypeDescription
pidint4Process ID
event_typetextWait event type
eventtextWait event name
queryidint8Query ID
counttextCount of samples

Get current wait event for a specific process:

SELECT * FROM pg_wait_sampling_get_current(12345);

Reset Profile

SELECT pg_wait_sampling_reset_profile();

Configuration

ParameterDefaultDescription
pg_wait_sampling.history_size5000Ring buffer size
pg_wait_sampling.history_period10History sampling period (ms)
pg_wait_sampling.profile_period10Profile sampling period (ms)
pg_wait_sampling.profile_pidtrueCollect profile per-process
pg_wait_sampling.profile_queriestopPer-query profile: none, top, all
pg_wait_sampling.sample_cputrueSample on-CPU backends (event columns NULL)

Example: Top Wait Events

SELECT event_type, event, count
FROM pg_wait_sampling_profile
ORDER BY count DESC
LIMIT 10;

Last Modified 2026-03-12: add pg extension catalog (95749bf)