Slow Query Detection¶
pgtail can highlight and track slow queries based on configurable duration thresholds.
Enabling Slow Query Highlighting¶
In tail mode:
Threshold Levels¶
Queries are highlighted based on three severity levels:
| Level | Default | Color |
|---|---|---|
| Warning | > 100ms | Yellow |
| Slow | > 500ms | Bold yellow |
| Critical | > 1000ms | Bold red |
Configuring Thresholds¶
Set thresholds in config:
Or edit config.toml:
[slow]
warn = 50 # Warning threshold (ms)
error = 200 # Slow threshold (ms)
critical = 500 # Critical threshold (ms)
Query Duration Statistics¶
View statistics for queries observed during tailing:
Shows:
Query Duration Statistics
─────────────────────────
Queries: 1,234
Average: 45.2ms
Percentiles:
p50: 12.3ms
p95: 234.5ms
p99: 567.8ms
max: 1234.5ms
PostgreSQL Configuration¶
For duration tracking, enable in postgresql.conf:
Duration appears in logs as:
Notifications for Slow Queries¶
Get notified when queries exceed a threshold:
See Notifications for more options.