How to crop a log statement in Postgres 9.6

We have a big request, which, as you know, takes a lot of time, and it works often. We are interested in the duration of this request, but not a complete request, whose length is about 10-20 m, and takes up a lot of disk space.

Currently in / var / lib / pgsql / 9.6 / data / pg_log / postgresql-2017-09-01.log:

2017-09-01 01: 00: 12.511 UTC user @dbname 25304 xxxx LOG: duration: 966.603 ms statement: INSERT INTO table_name (col1, col2, col3 ...) VALUES (val1) (val2) (val3) ... .

What we hope to achieve:

  • Keep the duration, but perhaps record only the first xxx (say 200) characters of the instruction.
  • We can potentially increase log_min_duration_statement so that this request is not logged at all, but we have other requests that we also want to register so that this is not a good solution.
  • If a log incomplete query is not possible, can we exclude this query from registration or exclude this table from the log and still record other queries longer than log_min_duration_statement?

Current settings

I searched for a while and did not find a solution. If someone can shed light, it will be great. Thank!

+4
source share

Source: https://habr.com/ru/post/1684864/


All Articles