Log statement sample - take two

Lists: pgsql-hackers
From: Adrien Nayrat <adrien(dot)nayrat(at)anayrat(dot)info>
To: PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Cc: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>, Tomas Vondra <tomas(dot)vondra(at)2ndquadrant(dot)com>
Subject: Log statement sample - take two
Date: 2019-10-19 15:02:01
Message-ID: [email protected]
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Hello,

This patch propose a new way to sample statement to logs.

As a reminder, this feature was committed in PG12[1] then reverted[2] after the
proposition of log_statement_sample_limit[3]

The first implementation added a new GUC to sample statement logged by
log_min_duration_statement. Then, we wanted to add the ability to log all
statement whose duration exceed log_statement_sample_limit.

This was confusing because log_min_duration behaves as a minimum to enable
sampling. While log_statement_sample_limit behave as maximum to disable it.[4]

Tomas Vondra proposed to use two minimum thresholds:

> 1) log_min_duration_sample - enables sampling of commands, using the
> existing GUC log_statement_sample_rate
>
> 2) log_min_duration_statement - logs all commands exceeding this

This patch implement this idea.

PS: I notice I forgot to mention "Only superusers can change this setting" in
the log_transaction_sample_rate documentation. It attached a second patch to fix
this.

Regards,

1:
https://git.postgresql.org/gitweb/?p=postgresql.git;a=commit;h=799e220346f1387e823a4dbdc3b1c8c3cdc5c3e0
2:
https://git.postgresql.org/gitweb/?p=postgresql.git;a=commit;h=75506195da81d75597a4025b72f8367e6c45f60d
3:
https://www.postgresql.org/message-id/CAFj8pRDS8tQ3Wviw9%3DAvODyUciPSrGeMhJi_WPE%2BEB8%2B4gLL-Q%40mail.gmail.com
4:
https://www.postgresql.org/message-id/20190727221948.irg6sfqh57dynoc7%40development

--
Adrien NAYRAT

Attachment Content-Type Size
log_transaction_sample_rate-doc.patch text/x-patch 480 bytes
log_min_duration_sample.patch text/x-patch 10.0 KB

From: Tomas Vondra <tomas(dot)vondra(at)2ndquadrant(dot)com>
To: Adrien Nayrat <adrien(dot)nayrat(at)anayrat(dot)info>
Cc: PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>, Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
Subject: Re: Log statement sample - take two
Date: 2019-11-04 01:08:07
Message-ID: 20191104010807.e2tanu55ny2qqpez@development
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Sat, Oct 19, 2019 at 05:02:01PM +0200, Adrien Nayrat wrote:
>Hello,
>
>This patch propose a new way to sample statement to logs.
>
>As a reminder, this feature was committed in PG12[1] then reverted[2] after the
>proposition of log_statement_sample_limit[3]
>
>The first implementation added a new GUC to sample statement logged by
>log_min_duration_statement. Then, we wanted to add the ability to log all
>statement whose duration exceed log_statement_sample_limit.
>
>This was confusing because log_min_duration behaves as a minimum to enable
>sampling. While log_statement_sample_limit behave as maximum to disable it.[4]
>
>Tomas Vondra proposed to use two minimum thresholds:
>
>> 1) log_min_duration_sample - enables sampling of commands, using the
>> existing GUC log_statement_sample_rate
>>
>> 2) log_min_duration_statement - logs all commands exceeding this
>
>This patch implement this idea.
>
>PS: I notice I forgot to mention "Only superusers can change this setting" in
>the log_transaction_sample_rate documentation. It attached a second patch to fix
>this.
>

Seems fine to me, mostly. I think the docs should explain how
log_min_duration_statement interacts with log_min_duration_sample.
Attached is a patch doing that, by adding one para to each GUC, along
with some minor rewordings. I think the docs are mixing "sampling"
vs. "logging" and "durations" vs. "statements" not sure.

I also think the two new sampling GUCs (log_min_duration_sample and
log_statement_sample_rate) should be next to each other. We're not
ordering the GUCs alphabetically anyway.

I plan to make those changes and push in a couple days.

regards

--
Tomas Vondra http://www.2ndQuadrant.com
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services

Attachment Content-Type Size
0001-fix-log_min_transaction_sample_rate-docs-20191104.patch text/plain 775 bytes
0002-log_min_duration_sample-rework-20191104.patch text/plain 11.4 KB

From: Adrien Nayrat <adrien(dot)nayrat(at)anayrat(dot)info>
To: Tomas Vondra <tomas(dot)vondra(at)2ndquadrant(dot)com>
Cc: PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: Log statement sample - take two
Date: 2019-11-04 16:26:40
Message-ID: [email protected]
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On 11/4/19 2:08 AM, Tomas Vondra wrote:
>
> Seems fine to me, mostly. I think the docs should explain how
> log_min_duration_statement interacts with log_min_duration_sample.
> Attached is a patch doing that, by adding one para to each GUC, along
> with some minor rewordings. I think the docs are mixing "sampling"
> vs. "logging" and "durations" vs. "statements" not sure.

Thanks for the rewording, it's clearer now.

>
> I also think the two new sampling GUCs (log_min_duration_sample and
> log_statement_sample_rate) should be next to each other. We're not
> ordering the GUCs alphabetically anyway.

+1

>
> I plan to make those changes and push in a couple days.
>

Thanks!


From: Tomas Vondra <tomas(dot)vondra(at)2ndquadrant(dot)com>
To: Adrien Nayrat <adrien(dot)nayrat(at)anayrat(dot)info>
Cc: PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: Log statement sample - take two
Date: 2019-11-06 18:16:00
Message-ID: 20191106181600.sci4ww6phbvifhc4@development
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Pushed, with some minor tweaks and rewording to the documentation.

The first bit, documenting the log_transaction_sample_rate as PG_SUSET,
got backpatched to 12, where it was introduced.

regards

--
Tomas Vondra http://www.2ndQuadrant.com
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services


From: Adrien Nayrat <adrien(dot)nayrat(at)anayrat(dot)info>
To: Tomas Vondra <tomas(dot)vondra(at)2ndquadrant(dot)com>
Cc: PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: Log statement sample - take two
Date: 2019-11-06 18:57:38
Message-ID: [email protected]
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On 11/6/19 7:16 PM, Tomas Vondra wrote:
> Pushed, with some minor tweaks and rewording to the documentation.
>
> The first bit, documenting the log_transaction_sample_rate as PG_SUSET,
> got backpatched to 12, where it was introduced.
>
> regards
>

Thanks Tomas!

--
Adrien