query_recorder
query_recorder · query_recorder: record executed SQL queries to rotating files for later analysis or replay
Overview
| ID | Extension | Package | Version | Category | License | Language |
|---|---|---|---|---|---|---|
| 100481 | query_recorder | query_recorder | 1.0.1 | STAT | BSD-2-Clause | C |
Usage
Sources:
query_recorder is a PostgreSQL query-capture module that writes executed SQL and timing metadata to rotating files. Use it for controlled workload analysis or replay preparation, not as a general audit log: it can capture sensitive SQL text, file ordering is not guaranteed, and the reviewed 1.0.1 code is an old preview release.
Core Workflow
The module allocates shared memory, so add it to shared_preload_libraries and restart PostgreSQL. Configure a writable base filename and bounded rotation before enabling capture:
After restart, install the extension and enable recording only for the sessions or interval you intend to observe:
The output uses numeric suffixes such as .000. Each record contains a timestamp in microseconds, backend identifier, duration, query length, and query text. When query_recorder.normalize is enabled, embedded line endings are replaced with spaces; otherwise consumers must use the recorded length rather than line boundaries to parse SQL safely.
Configuration Index
query_recorder.filenamesets the output base path.query_recorder.max_filesbounds the rotating file set.query_recorder.size_limitsets the rotation threshold per file.query_recorder.buffer_sizecontrols the shared output buffer.query_recorder.enabledstarts or stops capture and can be changed withSET.query_recorder.normalizeconverts query line endings to spaces.
Operational Boundaries
Provision directory ownership, restrictive file permissions, retention, disk monitoring, and secure disposal before enabling the recorder. The stream may contain credentials, personal data, and very large statements, while concurrent backends may appear out of order. Test the exact build and parser on representative traffic, and keep capture windows short; query_recorder does not provide audit-grade integrity, attribution, or tamper resistance.