1
0
mirror of https://github.com/postgres/postgres.git synced 2026-01-05 23:38:41 +03:00

Add log_statement_sample_rate parameter

This allows to set a lower log_min_duration_statement value without
incurring excessive log traffic (which reduces performance).  This can
be useful to analyze workloads with lots of short queries.

Author: Adrien Nayrat
Reviewed-by: David Rowley, Vik Fearing
Discussion: https://postgr.es/m/c30ee535-ee1e-db9f-fa97-146b9f62caed@anayrat.info
This commit is contained in:
Alvaro Herrera
2018-11-29 18:42:53 -03:00
parent 826eff57c4
commit 88bdbd3f74
5 changed files with 61 additions and 12 deletions

View File

@@ -5721,11 +5721,11 @@ local0.* /var/log/postgresql
<para>
Causes the duration of each completed statement to be logged
if the statement ran for at least the specified number of
milliseconds. Setting this to zero prints all statement durations.
Minus-one (the default) disables logging statement durations.
For example, if you set it to <literal>250ms</literal>
then all SQL statements that run 250ms or longer will be
logged. Enabling this parameter can be helpful in tracking down
milliseconds, modulated by <varname>log_statement_sample_rate</varname>.
Setting this to zero prints all statement durations. Minus-one (the default)
disables logging statement durations. For example, if you set it to
<literal>250ms</literal> then all SQL statements that run 250ms or longer
will be logged. Enabling this parameter can be helpful in tracking down
unoptimized queries in your applications.
Only superusers can change this setting.
</para>
@@ -5752,6 +5752,26 @@ local0.* /var/log/postgresql
</listitem>
</varlistentry>
<varlistentry id="guc-log-statement-sample-rate" xreflabel="log_statement_sample_rate">
<term><varname>log_statement_sample_rate</varname> (<type>real</type>)
<indexterm>
<primary><varname>log_statement_sample_rate</varname> configuration parameter</primary>
</indexterm>
</term>
<listitem>
<para>
Determines the fraction of the statements that exceed
<xref linkend="guc-log-min-duration-statement"/> which to log.
The default is <literal>1</literal>, meaning log to all such
statements.
Setting this to zero disables logging, same as setting
<varname>log_min_duration_statement</varname>
to minus-one. <varname>log_statement_sample_rate</varname>
is helpful when the traffic is too high to log all queries.
</para>
</listitem>
</varlistentry>
</variablelist>
<para>