What this thread does
Do first: set log_parameter_max_length=0 and log_parameter_max_length_on_error=0, then decide whether aggregated costs are sufficient before enabling raw statement logging.
Short answer
As of November 2026, this recipe uses current PostgreSQL docs and the 18.6 release baseline, August 13, 2026. If sensitive data may appear as SQL literals, use numeric aggregate exports and a reviewed query-ID mapping.
Choose / don't choose
- pg_stat_statements: choose to rank total execution cost, mean latency and call counts; don't treat representative query text as guaranteed anonymization (extension).
- Duration logs: choose for a controlled diagnostic interval when statement text is acceptable; don't turn them on for literal-bearing secrets (maintenance warning).
- Cyclic files: choose for simple time retention; don't equate a rotation threshold with a byte cap or automatic deletion.
Not for: changing a query plan; see agent-tunes-slow-postgres-query-explain-hypopg.
Settings that matter
| Setting or flag | Value / default | Applies to | Source |
|---|---|---|---|
log_min_duration_statement | Example threshold 250ms; -1 disables, 0 logs all | Current PostgreSQL docs, November 2026 | logging |
log_parameter_max_length | 0 suppresses normal bind values; default -1 | Current PostgreSQL docs, November 2026 | logging |
log_parameter_max_length_on_error | 0 suppresses error bind values, also default | Current PostgreSQL docs, November 2026 | logging |
logging_collector | Enables collection of stderr log messages into files; server-start setting | Current PostgreSQL docs, November 2026 | logging |
log_filename | server_log.%a for seven repeating day names | Current PostgreSQL docs, November 2026 | logging |
log_rotation_age | 1440 minutes for that daily cycle | Current PostgreSQL docs, November 2026 | logging |
log_truncate_on_rotation | on; overwrites matching names only on time rotation | Current PostgreSQL docs, November 2026 | logging |
log_rotation_size | 0 disables size-based creation of new log files | Current PostgreSQL docs, November 2026 | logging |
shared_preload_libraries | Add pg_stat_statements without removing existing modules; restart | Current PostgreSQL docs, November 2026 | extension |
compute_query_id | auto or on enables query identifier calculation | Current PostgreSQL docs, November 2026 | extension |
Order of operations
1. Inventory every SQL/error collector and its access policy. Logs can contain plaintext passwords or other authentication details and parts of data rows; restrict file access, exports and backups (maintenance). 2. Enable the extension in each diagnostic database with CREATE EXTENSION pg_stat_statements. Export queryid, calls, total_exec_time, mean_exec_time, rows and block counters; omit query. Compare interval deltas rather than a lifetime total. Constants are normally replaced, but the docs warn that high entry deallocation can leave literal-bearing text; normalization depends on the query-ID provider (extension). 3. If raw diagnostics are acceptable, apply the explicit threshold and both suppression settings. Run harmless parameterized and literal-containing probes in a disposable environment; inspect normal/error outputs and all downstream collectors. Disable the diagnostic interval afterward. 4. For the seven-day cycle, use the filename, age and truncation settings together. This is time retention, not a hard disk bound. Size rotations and server restarts do not truncate matching files. If using timestamped size-rotation names, add external age/byte cleanup that excludes the active file; account for shipped copies too (logging).
Known failures and fixes
| Error (short quote or symptom) | Cause | Fix | Source |
|---|---|---|---|
server processes could be blocked | Collector cannot keep up with emitted volume | Reduce statement volume/raise threshold; provision drain capacity and alert on backlog | logging |
Limits
- The linked source warns: some DDL statements might contain plaintext passwords or other authentication details (maintenance).
- Parameter suppression covers bind values; logged statements may still expose sensitive data (logging).
- No universal safe threshold, disk budget or retention period follows from the server settings. The requirement to never record sensitive parameters also requires application query discipline and review of other error/audit/APM sinks.
Started from a post by @PostgreSQL, packaged by the editor. Original post