log_statement vs log_min_duration_statement

Started by Atul Kumarover 2 years ago5 messagesgeneral
Jump to latest
#1Atul Kumar
akumar14871@gmail.com

Hi,

I have a query about parameters and log_statement

my postgres version is 12 and running on centos 7

my log_statement is set to "DDL".

and log_min_duration_statement is set to "1ms"

so technically it should log "ONLY DDLs" that take more than 1ms.

but to my surprise, postgres is logging DML as well which is taking more
than 1ms.

What am I missing here to understand, because as per my understanding
log_statement and log_min_duration_statement are correlated, postgres
should log according to log_statement parameter.

Please advise me on this behavior.

Regards,
Atul

#2Adrian Klaver
adrian.klaver@aklaver.com
In reply to: Atul Kumar (#1)
Re: log_statement vs log_min_duration_statement

On 9/26/23 11:31 AM, Atul Kumar wrote:

Hi,

I have a query about parameters  and log_statement

my postgres version is 12 and running on centos 7

my log_statement is set to "DDL".

and log_min_duration_statement is set to "1ms"

so technically it should log "ONLY DDLs" that take more than 1ms.

but to my surprise, postgres is logging DML as well which is taking
more than 1ms.

What am I missing here to understand, because as per my understanding
log_statement and log_min_duration_statement are correlated, postgres
should log according to log_statement parameter.

Please advise me on this behavior.

https://www.postgresql.org/docs/12/runtime-config-logging.html#RUNTIME-CONFIG-LOGGING-WHAT

"

|log_min_duration_statement| (|integer|)

Causes the duration of each completed statement to be logged if the
statement ran for at least the specified amount of time.

    <...>

Note

When using this option together with log_statement
<https://www.postgresql.org/docs/12/runtime-config-logging.html#GUC-LOG-STATEMENT&gt;,
the text of statements that are logged because of |log_statement| will
not be repeated in the duration log message. If you are not using
syslog, it is recommended that you log the PID or session ID using
log_line_prefix
<https://www.postgresql.org/docs/12/runtime-config-logging.html#GUC-LOG-LINE-PREFIX&gt;
so that you can link the statement message to the later duration message
using the process ID or session ID.

"

Show quoted text

Regards,
Atul

#3Maciek Sakrejda
m.sakrejda@gmail.com
In reply to: Atul Kumar (#1)
Re: log_statement vs log_min_duration_statement

On Tue, Sep 26, 2023, 12:34 Atul Kumar <akumar14871@gmail.com> wrote:

What am I missing here to understand, because as per my understanding
log_statement and log_min_duration_statement are correlated, postgres
should log according to log_statement parameter.

The two settings are independent. One logs *all* statements in the
specified category, and the other *all* statements that execute longer than
the specified threshold. I don't believe there is a built-in way of getting
the behavior you're looking for.

#4Jeff Janes
jeff.janes@gmail.com
In reply to: Atul Kumar (#1)
Re: log_statement vs log_min_duration_statement

On Tue, Sep 26, 2023 at 5:33 PM Atul Kumar <akumar14871@gmail.com> wrote:

Hi,

I have a query about parameters and log_statement

my postgres version is 12 and running on centos 7

my log_statement is set to "DDL".

and log_min_duration_statement is set to "1ms"

so technically it should log "ONLY DDLs" that take more than 1ms.

but to my surprise, postgres is logging DML as well which is taking more
than 1ms.

That doesn't surprise me, it is just what I expected.

What am I missing here to understand, because as per my understanding
log_statement and log_min_duration_statement are correlated, postgres
should log according to log_statement parameter.

If something in the docs led you to this misunderstanding, we should
identify it and fix it. Otherwise, there isn't much we can do, except
point out that that is simply not how it works.

Cheers,

Jeff

Show quoted text
#5Laurenz Albe
laurenz.albe@cybertec.at
In reply to: Atul Kumar (#1)
Re: log_statement vs log_min_duration_statement

On Wed, 2023-09-27 at 00:01 +0530, Atul Kumar wrote:

my postgres version is 12 and running on centos 7

my log_statement is set to "DDL".

and log_min_duration_statement is set to "1ms"

so technically it should log "ONLY DDLs" that take more than 1ms.

but to my surprise, postgres is logging DML as well which is taking more than 1ms.

log_statement = 'ddl' will log all DDL.

log_min_duration_statement = 1 will log all statements that take longer
than a millisecond.

These settings are independent from each other. So PostgreSQL logs
all statements that are DDL *OR* that take longer than a millisecond,
rather than all statements that are DDL *AND* take longer than a
millisecond, as you seem to expect.

Yours,
Laurenz Albe