pg_logqueryid
pg_logqueryid · Logs pg_stat_statements query IDs alongside auto_explain output.
Overview
| ID | Extension | Package | Version | Category | License | Language |
|---|---|---|---|---|---|---|
| 100433 | pg_logqueryid | pg_logqueryid | 0.0.1 | STAT | PostgreSQL | C |
PostgreSQL · 10, 11, 12, 13, 14, 15, 16, 17, 18
| Relationships | |
|---|---|
| Requires | auto_explain pg_stat_statements |
Usage
Sources:
pg_logqueryid writes the pg_stat_statements query identifier next to plans emitted by auto_explain, allowing operators to correlate a logged plan with the normalized statement statistics. It adds no queryable SQL API or custom GUC of its own.
Core Workflow
Load and configure pg_stat_statements and auto_explain, enable log collection, then load pg_logqueryid in a session or through a preload setting.
The module can instead be activated for selected connections with LOAD 'pg_logqueryid' or session_preload_libraries. It remains inactive if the two prerequisite modules are not loaded and configured.
Version and Logging Boundaries
The cataloged control file reports 0.0.1, while PGXN publishes later distributions through 1.0.1; pin the actual installed artifact rather than inferring its version from the repository README. Upstream reports validation through PostgreSQL 18, but hook interaction and log format still need an exact-build test.
On PostgreSQL 16 and later, auto_explain can already print the query ID when auto_explain.log_verbose is enabled, so this extension may be redundant. Logging every plan with a zero duration threshold can impose heavy overhead and expose SQL text or sensitive values. Start with a selective threshold and sampling policy, secure log access and retention, and verify that the logged query ID matches the intended pg_stat_statements entry.