pg_track_slow_queries
pg_track_slow_queries · Tracks slow queries and their execution plans
Overview
| ID | Extension | Package | Version | Category | License | Language |
|---|---|---|---|---|---|---|
| 100447 | pg_track_slow_queries | pg_track_slow_queries | 1.0 | STAT | PostgreSQL | C |
PostgreSQL · 10, 11, 12, 13, 14, 15, 16, 17, 18
Usage
Sources:
pg_track_slow_queries is a preload extension that writes statements exceeding a duration threshold, their execution metrics, and optionally JSON plans to a dedicated server-side file. SQL functions read and reset that file. Upstream marks the project as still under development, and the checked source is from 2019.
Core Workflow
Preload the library, configure a positive threshold, restart PostgreSQL, and create the extension in the database used for inspection:
The reset call truncates the shared history; export evidence first if it must be retained.
Important Objects
pg_track_slow_queriesreturns timestamp, duration, user, application, database, temporary blocks, cache hit ratio, affected tuples, query text, and JSON plan.pg_track_slow_queries_resetclears the storage file.pg_track_slow_queries.log_min_durationsets the millisecond threshold; -1 disables capture.pg_track_slow_queries.compressioncontrols row compression.pg_track_slow_queries.max_file_sizelimits file size in kilobytes; -1 is unlimited.pg_track_slow_queries.log_plancontrols plan capture.pg_track_slow_queries.cost_analyzeenables EXPLAIN-ANALYZE-like work above a cost threshold; -1 disables it.
Security and Performance Notes
Captured SQL and plans can contain literals, identifiers, and sensitive workload details, while the reset function destroys shared evidence. Restrict function execution and server-file access. The extension does not track utility statements or prepared-statement parameter values. Plan capture, compression, file-size enforcement, and especially analyze-style execution can add substantial overhead; benchmark the exact configuration and monitor disk use before enabling it broadly.