Skip to content

pg_logqueryid

Logs pg_stat_statements query IDs alongside auto_explain output.

pg_logqueryid · Logs pg_stat_statements query IDs alongside auto_explain output.

Overview

IDExtensionPackageVersionCategoryLicenseLanguage
100433pg_logqueryidpg_logqueryid0.0.1STATPostgreSQLC

PostgreSQL · 10, 11, 12, 13, 14, 15, 16, 17, 18

Relationships
Requiresauto_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.

logging_collector = on
shared_preload_libraries = 'pg_stat_statements,auto_explain,pg_logqueryid'
pg_stat_statements.track = 'all'
auto_explain.log_min_duration = '1s'
SELECT queryid, query
FROM pg_stat_statements
WHERE queryid = 5917340101676597114;

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.

Table reader