pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
log_statement vs log_min_duration_statement
5+ messages / 5 participants
[nested] [flat]

* log_statement vs log_min_duration_statement
@ 2023-09-26 18:31  Atul Kumar <akumar14871@gmail.com>
  0 siblings, 4 replies; 5+ messages in thread

From: Atul Kumar @ 2023-09-26 18:31 UTC (permalink / raw)
  To: pgsql-general <pgsql-general@lists.postgresql.org>

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

^ permalink  raw  reply  [nested|flat] 5+ messages in thread

* Re: log_statement vs log_min_duration_statement
@ 2023-09-26 18:39  Adrian Klaver <adrian.klaver@aklaver.com>
  parent: Atul Kumar <akumar14871@gmail.com>
  3 siblings, 0 replies; 5+ messages in thread

From: Adrian Klaver @ 2023-09-26 18:39 UTC (permalink / raw)
  To: Atul Kumar <akumar14871@gmail.com>; pgsql-general <pgsql-general@lists.postgresql.org>


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

"

>
>
> Regards,
> Atul

^ permalink  raw  reply  [nested|flat] 5+ messages in thread

* Re: log_statement vs log_min_duration_statement
@ 2023-09-26 19:43  Maciek Sakrejda <m.sakrejda@gmail.com>
  parent: Atul Kumar <akumar14871@gmail.com>
  3 siblings, 0 replies; 5+ messages in thread

From: Maciek Sakrejda @ 2023-09-26 19:43 UTC (permalink / raw)
  To: Atul Kumar <akumar14871@gmail.com>; +Cc: pgsql-general <pgsql-general@lists.postgresql.org>

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.

^ permalink  raw  reply  [nested|flat] 5+ messages in thread

* Re: log_statement vs log_min_duration_statement
@ 2023-09-26 23:51  Jeff Janes <jeff.janes@gmail.com>
  parent: Atul Kumar <akumar14871@gmail.com>
  3 siblings, 0 replies; 5+ messages in thread

From: Jeff Janes @ 2023-09-26 23:51 UTC (permalink / raw)
  To: Atul Kumar <akumar14871@gmail.com>; +Cc: pgsql-general <pgsql-general@lists.postgresql.org>

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

>

^ permalink  raw  reply  [nested|flat] 5+ messages in thread

* Re: log_statement vs log_min_duration_statement
@ 2023-09-27 08:12  Laurenz Albe <laurenz.albe@cybertec.at>
  parent: Atul Kumar <akumar14871@gmail.com>
  3 siblings, 0 replies; 5+ messages in thread

From: Laurenz Albe @ 2023-09-27 08:12 UTC (permalink / raw)
  To: Atul Kumar <akumar14871@gmail.com>; pgsql-general <pgsql-general@lists.postgresql.org>

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





^ permalink  raw  reply  [nested|flat] 5+ messages in thread


end of thread, other threads:[~2023-09-27 08:12 UTC | newest]

Thread overview: 5+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2023-09-26 18:31 log_statement vs log_min_duration_statement Atul Kumar <akumar14871@gmail.com>
2023-09-26 18:39 ` Adrian Klaver <adrian.klaver@aklaver.com>
2023-09-26 19:43 ` Maciek Sakrejda <m.sakrejda@gmail.com>
2023-09-26 23:51 ` Jeff Janes <jeff.janes@gmail.com>
2023-09-27 08:12 ` Laurenz Albe <laurenz.albe@cybertec.at>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox