Skip to content

pg_enhanced_query_logging

Cluster-wide slow-query metrics for pt-query-digest

pg_enhanced_query_logging · Cluster-wide slow-query metrics for pt-query-digest

Overview

IDExtensionPackageVersionCategoryLicenseLanguage
102458pg_enhanced_query_loggingpg_enhanced_query_logging1.3STATPostgreSQLC

PostgreSQL · 17, 18, 19

Usage

Sources:

pg_enhanced_query_logging 1.3 writes PostgreSQL query metrics in a slow-log format consumable by pt-query-digest. Upstream requires PostgreSQL 17 or later, reports testing on 18, and explicitly limits this development version to development/testing use.

Enable Logging

Add the module to the existing preload list, choose a writable log directory, and restart PostgreSQL. Logging is cluster-wide once preloaded; SQL helpers are installed per database by a superuser.

shared_preload_libraries = 'pg_enhanced_query_logging'
peql.log_min_duration = 500
peql.log_verbosity = 'standard'
CREATE EXTENSION pg_enhanced_query_logging;
SELECT * FROM pg_enhanced_query_logging_stats();
SET peql.rate_limit = 10;
SET peql.rate_limit_type = 'query';

Preserve other entries in shared_preload_libraries. CREATE EXTENSION, LOAD, or session_preload_libraries alone does not initialize the required shared memory. The default peql.log_min_duration = -1 disables logging even though peql.enabled defaults to on. A duration of 0 logs all eligible queries.

Output and Controls

The default filename is peql-slow.log; an empty peql.log_directory uses PostgreSQL’s log directory. Directory and filename changes require reload. Most other peql.* settings are superuser-settable at runtime. Analyze the actual file path with pt-query-digest --type slowlog /path/to/peql-slow.log.

peql.log_verbosity accepts minimal, standard, or full. Buffer/WAL/JIT detail and plan-derived scan/sort flags are available; I/O times also require PostgreSQL track_io_timing = on. Lock_time is always zero. Memory and wait-event tracking are experimental.

Sampling can be per query or session. peql.rate_limit_always_log_duration defaults to 10000 ms and bypasses sampling for very slow queries. Utility, nested and transaction logging are opt-in. Nested query durations overlap the enclosing call, so aggregate totals can double-count time.

Operations and Boundaries

pg_enhanced_query_logging_stats() returns queries_logged, queries_skipped, bytes_written, disk_paused, and disk_skipped. pg_enhanced_query_logging_reset() rotates the file to an .old name and resets counters; both helpers require superuser privileges.

Disk protection pauses logging below 5% free space by default and checks at 5000 ms intervals during query activity. Automatic deletion of rotated files is disabled unless peql.disk_auto_purge is enabled. Keep an independent retention policy and monitor skipped entries; this protection is not a guarantee against a full filesystem and is unavailable on Windows.

Query text can contain sensitive data. Bind-value logging is off by default; enabling peql.log_parameter_values exposes those values too. peql.log_query_plan adds per-node timing overhead to every query, including queries that are not logged. Test overhead and protect log permissions before enabling either option. Existing 1.0–1.2 SQL installations have sequential upgrade scripts to 1.3.

Table reader