Logging difficult queries
A straightforward way to generate log files only for the complex, long running queries on your server—cutting out routine logging of small queries and therefore reducing logging overhead—is to set a minimum statement duration to log. A typical configuration would be:
log_min_duration_statement = 1000 log_duration = off log_statement = 'none'
The first line there will log every statement that takes over 1000 ms (one second) without logging anything else. The other two are actually the defaults.
An alternate approach you'll sometimes see instead aims to just capture every query:
log_min_duration_statement = -1 log_duration = on log_statement = 'all'
Since setting log_min_duration_statement
to 0 will also log every statement with a duration, that's an easier way to get this behavior. It only requires tweaking one value, and it's easy to adjust upward so that it's only triggered when appropriate. Because...