Обсуждение: log_statement vs log_min_duration_statement

Поиск
Список
Период
Сортировка

log_statement vs log_min_duration_statement

От
Atul Kumar
Дата:
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

Re: log_statement vs log_min_duration_statement

От
Adrian Klaver
Дата:


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, 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 so that you can link the statement message to the later duration message using the process ID or session ID.

"



Regards,
Atul

Re: log_statement vs log_min_duration_statement

От
Maciek Sakrejda
Дата:
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.

Re: log_statement vs log_min_duration_statement

От
Jeff Janes
Дата:
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

Re: log_statement vs log_min_duration_statement

От
Laurenz Albe
Дата:
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