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?

  • 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.
    – dezso
    Apr 9 '14 at 14:15
  • So, should I disable (comment out) log_statement so log_min_duration_statement should work? Apr 9 '14 at 14:22
  • If you simply want to log all long-running statements (be it a SELECT, UPDATE or some DDL), then yes.
    – dezso
    Apr 9 '14 at 15:24

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:
Cannot get log_min_duration_statement to work

  • 3
    Let me add that the default for log_statement is none, so not setting it or setting to none has the same effect.
    – dezso
    Apr 10 '14 at 8:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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