1

We're logging slow running queries in PG (on AWS RDS) with log_min_duration_statement along with log_error_verbosity = default so we get DETAIL lines, because our app's libraries uses prepared statements under the covers. We are using log_destination = stderr -- we can't use csvlog in this case.

What we end up with though are two disparate log lines:

LOG: duration: 1680.110 ms execute <unnamed>: SELECT.... = $1
DETAIL: parameters: $1 = 'foo'

These are two distinct log lines in the log file.

Is there any combination of settings that either (a) can combine these in a single line, so we get both the LOG and the DETAIL in the same message, or (b) is there some ID that can be used to correlate these two messages together?

1
  • This is an issue that I have actually faced myself, but never spent much time thinking about a solution. Thanks for prompting me to look into it!
    – hmallett
    Commented Nov 4, 2021 at 11:19

1 Answer 1

1

The PostgreSQL documentation on logging suggests that "...it is recommended that you log the PID or session ID using log_line_prefix so that you can link the statement message to the later duration message using the process ID or session ID."

This should allow the correlation of the LOG and DETAIL lines.

3
  • is one or the other preferable or more granular?
    – Joe
    Commented Nov 3, 2021 at 18:32
  • no looks like one just packages up the ID. I hope our log parsing can keep these sets of logs together in a batch so we can correlate them.
    – Joe
    Commented Nov 3, 2021 at 18:50
  • I would guess that the session ID would be more granular. I don't have any information to support one being more preferable than the other.
    – hmallett
    Commented Nov 4, 2021 at 11:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.