Conceptual
Login

The Slow Query Log: Catching Slow Statements in Production With a Minimum Duration Threshold

Set log_min_duration_statement to a number of milliseconds and PostgreSQL logs every statement that takes longer than that, with its duration and parameters; MySQL does the same with the slow query log and long_query_time. This catches the queries that are only slow with real data, real concurrency and real parameter values, which is most of them. Set the threshold too low and you drown the log and slow the server down; start high, find the worst offenders, then lower it.

Questions this Concept answers

  • Why does a production threshold log catch problems that local testing never reproduces?