Skip to main content
This document details the features available in each PostgreSQL version supported by pg_stat_ch.

Version Feature Matrix

All versions capture core telemetry (timing, buffer usage, WAL, CPU time, errors, client context). Newer versions add additional instrumentation:
FeaturePG 16PG 17PG 18
Core Metrics
Query timing (duration_us)
Row counts
Query ID
Command type (SELECT/INSERT/UPDATE/DELETE/UTILITY)
Query text
Buffer Usage
Shared blocks (hit/read/dirtied/written)
Local blocks (hit/read/dirtied/written)
Temp blocks (read/written)
I/O Timing
Shared block read/write time
Local block read/write time-
Temp block read/write time
WAL Usage
WAL records/FPI/bytes
CPU Time
User/system CPU time (via getrusage)
JIT Instrumentation
JIT function count
JIT generation/inlining/optimization/emission time
JIT deform time-
Parallel Query
Parallel workers planned/launched--
Command Types
MERGE command
Client Context
Application name
Client IP address
Error Capture
SQLSTATE code
Error level
Observability
Custom wait event name in pg_stat_activity-

Feature Details by Version

PostgreSQL 18

Parallel Worker Statistics

Fields: parallel_workers_planned, parallel_workers_launched Tracks how many parallel workers were planned for a query vs how many were actually launched. This helps identify resource contention - if planned > launched, the system may be hitting max_parallel_workers limits.
-- Find queries where parallel workers couldn't be launched
SELECT query_id, cmd_type,
       parallel_workers_planned,
       parallel_workers_launched,
       parallel_workers_planned - parallel_workers_launched AS workers_missed
FROM pg_stat_ch.events_raw
WHERE parallel_workers_planned > parallel_workers_launched
ORDER BY workers_missed DESC;

ExecutorRun Signature Change

The execute_once parameter was removed from the ExecutorRun hook in PG18. pg_stat_ch handles this transparently via compile-time version checks.

PostgreSQL 17

Separate Local/Shared Block I/O Timing

Fields: local_blk_read_time_us, local_blk_write_time_us PG16 only tracked combined blk_read_time/blk_write_time for shared buffers. PG17 separates local and shared buffer timing, enabling better analysis of temporary table performance.
-- Queries with high local buffer I/O (temporary tables)
SELECT query_id,
       local_blk_read_time_us + local_blk_write_time_us AS local_io_us,
       shared_blk_read_time_us + shared_blk_write_time_us AS shared_io_us
FROM pg_stat_ch.events_raw
WHERE local_blk_read_time_us > 0 OR local_blk_write_time_us > 0;

JIT Deform Time

Field: jit_deform_time_us Time spent JIT-compiling tuple deforming (extracting column values from heap tuples). High deform time may indicate queries touching many columns.
-- Queries with significant JIT deform overhead
SELECT query_id, jit_functions, jit_deform_time_us,
       jit_generation_time_us + jit_inlining_time_us +
       jit_optimization_time_us + jit_emission_time_us AS other_jit_us
FROM pg_stat_ch.events_raw
WHERE jit_deform_time_us > 1000;  -- > 1ms

Custom Wait Event Name

The background worker appears as “PgStatChExporter” in pg_stat_activity.wait_event instead of generic “Extension”. This makes it easier to identify pg_stat_ch activity in monitoring.

Efficient Backend Status Lookup

Uses pgstat_get_beentry_by_proc_number() for O(1) backend status lookup instead of iterating all backends (internal optimization, no user-visible change).

Field Reference

Timing Fields

FieldTypeDescription
ts_startDateTime64(6)Query start timestamp (microsecond precision)
duration_usUInt64Total execution time in microseconds

Identity Fields

FieldTypeDescription
dbStringDatabase name
usernameStringUser name who executed the query
pidInt32Backend process ID
query_idInt64Query identifier (hash of normalized query)
cmd_typeStringCommand type: SELECT, INSERT, UPDATE, DELETE, MERGE, UTILITY, NOTHING, UNKNOWN

Buffer Usage Fields

FieldTypeDescription
shared_blks_hitInt64Shared buffer cache hits
shared_blks_readInt64Shared blocks read from disk
shared_blks_dirtiedInt64Shared blocks dirtied by query
shared_blks_writtenInt64Shared blocks written to disk
local_blks_hitInt64Local buffer cache hits (temp tables)
local_blks_readInt64Local blocks read
local_blks_dirtiedInt64Local blocks dirtied
local_blks_writtenInt64Local blocks written
temp_blks_readInt64Temp blocks read (sorts, hashes spilling to disk)
temp_blks_writtenInt64Temp blocks written

I/O Timing Fields

Requires track_io_timing = on in postgresql.conf.
FieldTypePG VersionDescription
shared_blk_read_time_usInt6416+Time reading shared blocks (μs)
shared_blk_write_time_usInt6416+Time writing shared blocks (μs)
local_blk_read_time_usInt6417+Time reading local blocks (μs)
local_blk_write_time_usInt6417+Time writing local blocks (μs)
temp_blk_read_time_usInt6416+Time reading temp blocks (μs)
temp_blk_write_time_usInt6416+Time writing temp blocks (μs)

WAL Usage Fields

FieldTypeDescription
wal_recordsInt64Number of WAL records generated
wal_fpiInt64Number of WAL full page images
wal_bytesUInt64Total WAL bytes generated

CPU Time Fields

FieldTypeDescription
cpu_user_time_usInt64User CPU time in microseconds
cpu_sys_time_usInt64System CPU time in microseconds

JIT Fields

JIT compilation is triggered for expensive queries when jit = on.
FieldTypePG VersionDescription
jit_functionsInt3216+Number of functions JIT-compiled
jit_generation_time_usInt3216+Time generating JIT code (μs)
jit_deform_time_usInt3217+Time JIT-compiling tuple deforming (μs)
jit_inlining_time_usInt3216+Time inlining functions (μs)
jit_optimization_time_usInt3216+Time optimizing JIT code (μs)
jit_emission_time_usInt3216+Time emitting machine code (μs)

Parallel Query Fields

FieldTypePG VersionDescription
parallel_workers_plannedInt1618+Workers planned by query optimizer
parallel_workers_launchedInt1618+Workers actually launched

Error Fields

FieldTypeDescription
err_sqlstateFixedString(5)SQLSTATE error code (e.g., “42P01” for undefined table)
err_elevelUInt8Error level (0 for successful queries, see table below)
The pg_stat_ch.log_min_elevel GUC controls the minimum level captured (default: warning). Error level values (from PostgreSQL’s elog.h):
LevelValueCaptured by default
DEBUG510No
DEBUG411No
DEBUG312No
DEBUG213No
DEBUG114No
LOG15No
INFO17No
NOTICE18No
WARNING19Yes
ERROR21Yes
FATAL22Yes
PANIC23Yes

Client Context Fields

FieldTypeDescription
appStringApplication name (from application_name GUC)
client_addrStringClient IP address

Query Text

FieldTypeDescription
queryStringQuery text (truncated to 2KB)