23

I am running Postgresql 9.1 on Ubuntu. Exact Postgresql version is 9.1+129ubuntu1 as my package manager shows.

I have 2 databases that are actively in use and they are used from a remote server.

I wish to log queries that have a long execution time. So I set following parameters in /etc/postgresql/9.1/main/postgresql.conf file

log_min_duration_statement = 10000
log_statement = 'mod'

so Postgresql will log queries that takes longer than 10 seconds.

But when I reload the postgres configuration, Postgresql begins to log every query that fits log_statement value. That I set duration to 100 seconds to be sure

log_min_duration_statement = 100000

But Postgresql keep logging every query that fits log_statement value, regardless of log_min_duration_statement value.

Setting log_statement to none seemed to stop logging.

Is there something that I missed about the configuration?

3
  • The thing is that you log the union of the two sets, not the intersection of it. I am not aware if it can be done as you'd like. Commented Apr 9, 2014 at 14:15
  • So, should I disable (comment out) log_statement so log_min_duration_statement should work?
    – Mp0int
    Commented Apr 9, 2014 at 14:22
  • If you simply want to log all long-running statements (be it a SELECT, UPDATE or some DDL), then yes. Commented Apr 9, 2014 at 15:24

1 Answer 1

29

You were close. Your last idea is actually the way to go:

log_statement = none
log_min_duration_statement = 10000

Then no statement will be logged, except those running longer than 10 seconds - including the query string itself. Logging may have seemed to stop because 10 seconds is a high threshold. I am using 2 seconds normally, but YMMV.

This related answer on SO has more:

1
  • 5
    Let me add that the default for log_statement is none, so not setting it or setting to none has the same effect. Commented Apr 10, 2014 at 8:11

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.