pg_query_state
pg_query_state · Tool for query progress monitoring in PostgreSQL
Overview
| ID | Extension | Package | Version | Category | License | Language |
|---|---|---|---|---|---|---|
| 100030 | pg_query_state | pg_query_state | 1.2 | STAT | PostgreSQL | C |
PostgreSQL · 10, 11, 12, 13, 14, 15, 16, 17, 18
Usage
Sources:
- Pinned current upstream README
- Pinned extension control file
- Pinned executor and messaging implementation
- PostgreSQL 18 custom-signal patch
- PostgreSQL 18 runtime-EXPLAIN patch
pg_query_state version 1.2 extracts the live execution state of a query running in another backend. It can return nested query frames and parallel-worker plans with current row, loop, timing, and buffer statistics, and it offers numeric and repeatedly printed progress estimates.
Patched-server setup and query
This is not a drop-in extension. Apply both upstream patches for the exact PostgreSQL major, rebuild and deploy the server, then preload the module and restart:
Replace the PID with a currently executing backend. A caller must be superuser or have the same effective role as the target backend.
Invasive monitoring boundary
The server patches add custom process signals and runtime EXPLAIN state to PostgreSQL internals. The preloaded module installs executor hooks, allocates shared memory, sends signals to the leader and parallel workers, and transfers query text and plan state through shared-memory queues. It always requests row instrumentation when enabled; timing and buffer collection add further overhead. Validate the complete patched server build, not just the shared library, for every minor update and extension interaction.
Output contains live query text, literals, object names, nested function queries, and plan details. Same-role access can therefore reveal another session’s data-bearing SQL. Restrict role sharing and function execution, protect monitoring output, and test timeout and cancellation behavior so an unresponsive target cannot stall monitors.
Progress is a heuristic derived from plan rows and is unavailable or misleading for uncountable operations, inaccurate estimates, blocking waits, and many write plans. The current repository contains patches through PostgreSQL 18 and was active in 2026, but that does not make a patched production server low-risk. Deploy first to a dedicated diagnostics build and measure overhead with realistic parallel and nested workloads.