pg_querylog
pg_querylog · Captures current and recently completed backend queries in shared memory for SQL inspection.
Overview
| ID | Extension | Package | Version | Category | License | Language |
|---|---|---|---|---|---|---|
| 100497 | pg_querylog | pg_querylog | 0.1 | STAT | Unknown | C |
PostgreSQL · 10, 11, 12
Usage
Sources:
pg_querylog captures each backend’s current or most recently completed query and rendered parameters in shared memory. Use it for short-lived diagnostics on old, explicitly tested PostgreSQL versions; captured text can contain credentials, personal data, and application secrets.
Load and Query
Add the library to shared_preload_libraries and restart PostgreSQL, then install its SQL objects in a restricted schema:
get_queries(only_running, skip_overflow) returns pid, query, params, start_time, end_time, running, and overflow. running_queries filters to active entries. An overflow flag means the per-backend buffer could not retain the complete item.
Configuration and Security
pg_querylog.buffer_size is a superuser setting with a 10 kB minimum and is allocated per backend; plan approximately that value times max_connections, plus overhead. pg_querylog.enabled is also superuser-only. The README calls it disabled by default, while the reviewed C source initializes it to true; set it explicitly and verify with SHOW pg_querylog.enabled.
The README also permits session_preload_libraries, but warns that every starting backend rewrites the shared enabled value. Prefer cluster preload for deterministic behavior. Restrict both schema and function/view privileges, define a short diagnostic window, and disable collection afterward. This unmaintained code hooks executor internals and lists only old PostgreSQL releases, so test crashes, prepared statements, parameter rendering, concurrent backends, truncation, and memory use on the exact target build.