Skip to content

Commit 83d63ee

Browse files
shinyaaaCommitfest Bot
authored andcommitted
Add log_autoanalyze_min_duration
The log output functionality of log_autovacuum_min_duration applies to both VACUUM and ANALYZE, so it is not possible to separate the VACUUM and ANALYZE log output thresholds. Logs are likely to be output only for VACUUM and not for ANALYZE. Therefore, we decided to separate the threshold for log output of VACUUM by autovacuum (log_autovacuum_min_duration) and the threshold for log output of ANALYZE by autovacuum (log_autoanalyze_min_duration).
1 parent 317c117 commit 83d63ee

File tree

16 files changed

+124
-31
lines changed

16 files changed

+124
-31
lines changed

doc/src/sgml/config.sgml

Lines changed: 34 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7440,17 +7440,44 @@ local0.* /var/log/postgresql
74407440
</term>
74417441
<listitem>
74427442
<para>
7443-
Causes each action executed by autovacuum to be logged if it ran for at
7443+
Causes vacuum action executed by autovacuum to be logged if it ran for at
74447444
least the specified amount of time. Setting this to zero logs
7445-
all autovacuum actions. <literal>-1</literal> disables logging autovacuum
7446-
actions. If this value is specified without units, it is taken as milliseconds.
7447-
For example, if you set this to
7448-
<literal>250ms</literal> then all automatic vacuums and analyzes that run
7445+
all vacuum actions by autovacuum. <literal>-1</literal> disables logging
7446+
vacuum actions by autovacuum. If this value is specified without units,
7447+
it is taken as milliseconds. For example, if you set this to
7448+
<literal>250ms</literal> then all automatic vacuums that run
74497449
250ms or longer will be logged. In addition, when this parameter is
74507450
set to any value other than <literal>-1</literal>, a message will be
7451-
logged if an autovacuum action is skipped due to a conflicting lock or a
7451+
logged if a vacuum action by autovacuum is skipped due to a conflicting lock or a
74527452
concurrently dropped relation. The default is <literal>10min</literal>.
7453-
Enabling this parameter can be helpful in tracking autovacuum activity.
7453+
Enabling this parameter can be helpful in tracking vacuum activity by autovacuum.
7454+
This parameter can only be set in the <filename>postgresql.conf</filename>
7455+
file or on the server command line; but the setting can be overridden for
7456+
individual tables by changing table storage parameters.
7457+
</para>
7458+
</listitem>
7459+
</varlistentry>
7460+
7461+
<varlistentry id="guc-log-autoanalyze-min-duration" xreflabel="log_autoanalyze_min_duration">
7462+
<term><varname>log_autoanalyze_min_duration</varname> (<type>integer</type>)
7463+
<indexterm>
7464+
<primary><varname>log_autoanalyze_min_duration</varname></primary>
7465+
<secondary>configuration parameter</secondary>
7466+
</indexterm>
7467+
</term>
7468+
<listitem>
7469+
<para>
7470+
Causes analyze action executed by autovacuum to be logged if it ran for at
7471+
least the specified amount of time. Setting this to zero logs
7472+
all analyze actions by autovacuum. <literal>-1</literal> disables logging
7473+
analyze actions by autovacuum. If this value is specified without units,
7474+
it is taken as milliseconds. For example, if you set this to
7475+
<literal>250ms</literal> then all automatic analyzes that run
7476+
250ms or longer will be logged. In addition, when this parameter is
7477+
set to any value other than <literal>-1</literal>, a message will be
7478+
logged if an analyze action by autovacuum is skipped due to a conflicting lock or a
7479+
concurrently dropped relation. The default is <literal>10min</literal>.
7480+
Enabling this parameter can be helpful in tracking analyze activity by autovacuum.
74547481
This parameter can only be set in the <filename>postgresql.conf</filename>
74557482
file or on the server command line; but the setting can be overridden for
74567483
individual tables by changing table storage parameters.

doc/src/sgml/maintenance.sgml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -892,7 +892,8 @@ HINT: Execute a database-wide VACUUM in that database.
892892
the next database will be processed as soon as the first worker finishes.
893893
Each worker process will check each table within its database and
894894
execute <command>VACUUM</command> and/or <command>ANALYZE</command> as needed.
895-
<xref linkend="guc-log-autovacuum-min-duration"/> can be set to monitor
895+
<xref linkend="guc-log-autovacuum-min-duration"/> and
896+
<xref linkend="guc-log-autoanalyze-min-duration"/> can be set to monitor
896897
autovacuum workers' activity.
897898
</para>
898899

doc/src/sgml/ref/create_table.sgml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1966,6 +1966,21 @@ WITH ( MODULUS <replaceable class="parameter">numeric_literal</replaceable>, REM
19661966
</listitem>
19671967
</varlistentry>
19681968

1969+
<varlistentry id="reloption-log-autoanalyze-min-duration" xreflabel="log_autoanalyze_min_duration">
1970+
<term><literal>log_autoanalyze_min_duration</literal> (<type>integer</type>)
1971+
<indexterm>
1972+
<primary><varname>log_autoanalyze_min_duration</varname></primary>
1973+
<secondary>storage parameter</secondary>
1974+
</indexterm>
1975+
</term>
1976+
<listitem>
1977+
<para>
1978+
Per-table value for <xref linkend="guc-log-autoanalyze-min-duration"/>
1979+
parameter.
1980+
</para>
1981+
</listitem>
1982+
</varlistentry>
1983+
19691984
<varlistentry id="reloption-vacuum-max-eager-freeze-failure-rate" xreflabel="vacuum_max_eager_freeze_failure_rate">
19701985
<term><literal>vacuum_max_eager_freeze_failure_rate</literal>, <literal>toast.vacuum_max_eager_freeze_failure_rate</literal> (<type>floating point</type>)
19711986
<indexterm>

src/backend/access/common/reloptions.c

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -322,12 +322,21 @@ static relopt_int intRelOpts[] =
322322
{
323323
{
324324
"log_autovacuum_min_duration",
325-
"Sets the minimum execution time above which autovacuum actions will be logged",
325+
"Sets the minimum execution time above which vacuum actions by autovacuum will be logged",
326326
RELOPT_KIND_HEAP | RELOPT_KIND_TOAST,
327327
ShareUpdateExclusiveLock
328328
},
329329
-1, -1, INT_MAX
330330
},
331+
{
332+
{
333+
"log_autoanalyze_min_duration",
334+
"Sets the minimum execution time above which analyze actions by autovacuum will be logged",
335+
RELOPT_KIND_HEAP,
336+
ShareUpdateExclusiveLock
337+
},
338+
-1, -1, INT_MAX
339+
},
331340
{
332341
{
333342
"toast_tuple_target",
@@ -1895,7 +1904,9 @@ default_reloptions(Datum reloptions, bool validate, relopt_kind kind)
18951904
{"autovacuum_multixact_freeze_table_age", RELOPT_TYPE_INT,
18961905
offsetof(StdRdOptions, autovacuum) + offsetof(AutoVacOpts, multixact_freeze_table_age)},
18971906
{"log_autovacuum_min_duration", RELOPT_TYPE_INT,
1898-
offsetof(StdRdOptions, autovacuum) + offsetof(AutoVacOpts, log_min_duration)},
1907+
offsetof(StdRdOptions, autovacuum) + offsetof(AutoVacOpts, log_vacuum_min_duration)},
1908+
{"log_autoanalyze_min_duration", RELOPT_TYPE_INT,
1909+
offsetof(StdRdOptions, autovacuum) + offsetof(AutoVacOpts, log_analyze_min_duration)},
18991910
{"toast_tuple_target", RELOPT_TYPE_INT,
19001911
offsetof(StdRdOptions, toast_tuple_target)},
19011912
{"autovacuum_vacuum_cost_delay", RELOPT_TYPE_REAL,

src/backend/access/heap/vacuumlazy.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -635,7 +635,7 @@ heap_vacuum_rel(Relation rel, const VacuumParams params,
635635

636636
verbose = (params.options & VACOPT_VERBOSE) != 0;
637637
instrument = (verbose || (AmAutoVacuumWorkerProcess() &&
638-
params.log_min_duration >= 0));
638+
params.log_vacuum_min_duration >= 0));
639639
if (instrument)
640640
{
641641
pg_rusage_init(&ru0);
@@ -946,9 +946,9 @@ heap_vacuum_rel(Relation rel, const VacuumParams params,
946946
{
947947
TimestampTz endtime = GetCurrentTimestamp();
948948

949-
if (verbose || params.log_min_duration == 0 ||
949+
if (verbose || params.log_vacuum_min_duration == 0 ||
950950
TimestampDifferenceExceeds(starttime, endtime,
951-
params.log_min_duration))
951+
params.log_vacuum_min_duration))
952952
{
953953
long secs_dur;
954954
int usecs_dur;

src/backend/commands/analyze.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ analyze_rel(Oid relid, RangeVar *relation,
138138
* Make sure to generate only logs for ANALYZE in this case.
139139
*/
140140
onerel = vacuum_open_relation(relid, relation, params.options & ~(VACOPT_VACUUM),
141-
params.log_min_duration >= 0,
141+
params.log_analyze_min_duration >= 0,
142142
ShareUpdateExclusiveLock);
143143

144144
/* leave if relation could not be opened or locked */
@@ -310,7 +310,7 @@ do_analyze_rel(Relation onerel, const VacuumParams params,
310310

311311
verbose = (params.options & VACOPT_VERBOSE) != 0;
312312
instrument = (verbose || (AmAutoVacuumWorkerProcess() &&
313-
params.log_min_duration >= 0));
313+
params.log_analyze_min_duration >= 0));
314314
if (inh)
315315
ereport(elevel,
316316
(errmsg("analyzing \"%s.%s\" inheritance tree",
@@ -735,9 +735,9 @@ do_analyze_rel(Relation onerel, const VacuumParams params,
735735
{
736736
TimestampTz endtime = GetCurrentTimestamp();
737737

738-
if (verbose || params.log_min_duration == 0 ||
738+
if (verbose || params.log_analyze_min_duration == 0 ||
739739
TimestampDifferenceExceeds(starttime, endtime,
740-
params.log_min_duration))
740+
params.log_analyze_min_duration))
741741
{
742742
long delay_in_ms;
743743
WalUsage walusage;

src/backend/commands/vacuum.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -416,8 +416,12 @@ ExecVacuum(ParseState *pstate, VacuumStmt *vacstmt, bool isTopLevel)
416416
/* user-invoked vacuum is never "for wraparound" */
417417
params.is_wraparound = false;
418418

419-
/* user-invoked vacuum uses VACOPT_VERBOSE instead of log_min_duration */
420-
params.log_min_duration = -1;
419+
/*
420+
* user-invoked vacuum uses VACOPT_VERBOSE instead of
421+
* log_vacuum_min_duration and log_analyze_min_duration
422+
*/
423+
params.log_vacuum_min_duration = -1;
424+
params.log_analyze_min_duration = -1;
421425

422426
/*
423427
* Later, in vacuum_rel(), we check if a reloption override was specified.
@@ -2073,7 +2077,7 @@ vacuum_rel(Oid relid, RangeVar *relation, VacuumParams params,
20732077

20742078
/* open the relation and get the appropriate lock on it */
20752079
rel = vacuum_open_relation(relid, relation, params.options,
2076-
params.log_min_duration >= 0, lmode);
2080+
params.log_vacuum_min_duration >= 0, lmode);
20772081

20782082
/* leave if relation could not be opened or locked */
20792083
if (!rel)

src/backend/postmaster/autovacuum.c

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@ double autovacuum_vac_cost_delay;
133133
int autovacuum_vac_cost_limit;
134134

135135
int Log_autovacuum_min_duration = 600000;
136+
int Log_autoanalyze_min_duration = 600000;
136137

137138
/* the minimum allowed time between two awakenings of the launcher */
138139
#define MIN_AUTOVAC_SLEEPTIME 100.0 /* milliseconds */
@@ -2814,7 +2815,8 @@ table_recheck_autovac(Oid relid, HTAB *table_toast_map,
28142815
int freeze_table_age;
28152816
int multixact_freeze_min_age;
28162817
int multixact_freeze_table_age;
2817-
int log_min_duration;
2818+
int log_vacuum_min_duration;
2819+
int log_analyze_min_duration;
28182820

28192821
/*
28202822
* Calculate the vacuum cost parameters and the freeze ages. If there
@@ -2824,10 +2826,15 @@ table_recheck_autovac(Oid relid, HTAB *table_toast_map,
28242826
*/
28252827

28262828
/* -1 in autovac setting means use log_autovacuum_min_duration */
2827-
log_min_duration = (avopts && avopts->log_min_duration >= 0)
2828-
? avopts->log_min_duration
2829+
log_vacuum_min_duration = (avopts && avopts->log_vacuum_min_duration >= 0)
2830+
? avopts->log_vacuum_min_duration
28292831
: Log_autovacuum_min_duration;
28302832

2833+
/* -1 in autovac setting means use log_autoanalyze_min_duration */
2834+
log_analyze_min_duration = (avopts && avopts->log_analyze_min_duration >= 0)
2835+
? avopts->log_analyze_min_duration
2836+
: Log_autoanalyze_min_duration;
2837+
28312838
/* these do not have autovacuum-specific settings */
28322839
freeze_min_age = (avopts && avopts->freeze_min_age >= 0)
28332840
? avopts->freeze_min_age
@@ -2877,7 +2884,8 @@ table_recheck_autovac(Oid relid, HTAB *table_toast_map,
28772884
tab->at_params.multixact_freeze_min_age = multixact_freeze_min_age;
28782885
tab->at_params.multixact_freeze_table_age = multixact_freeze_table_age;
28792886
tab->at_params.is_wraparound = wraparound;
2880-
tab->at_params.log_min_duration = log_min_duration;
2887+
tab->at_params.log_vacuum_min_duration = log_vacuum_min_duration;
2888+
tab->at_params.log_analyze_min_duration = log_analyze_min_duration;
28812889
tab->at_params.toast_parent = InvalidOid;
28822890

28832891
/*

src/backend/utils/misc/guc_tables.c

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3258,15 +3258,29 @@ struct config_int ConfigureNamesInt[] =
32583258
{
32593259
{"log_autovacuum_min_duration", PGC_SIGHUP, LOGGING_WHAT,
32603260
gettext_noop("Sets the minimum execution time above which "
3261-
"autovacuum actions will be logged."),
3262-
gettext_noop("-1 disables logging autovacuum actions. 0 means log all autovacuum actions."),
3261+
"vacuum actions by autovacuum will be logged."),
3262+
gettext_noop("-1 disables logging vacuum actions by autovacuum. "
3263+
"0 means log all vacuum actions by autovacuum."),
32633264
GUC_UNIT_MS
32643265
},
32653266
&Log_autovacuum_min_duration,
32663267
600000, -1, INT_MAX,
32673268
NULL, NULL, NULL
32683269
},
32693270

3271+
{
3272+
{"log_autoanalyze_min_duration", PGC_SIGHUP, LOGGING_WHAT,
3273+
gettext_noop("Sets the minimum execution time above which "
3274+
"analyze actions by autovacuum will be logged."),
3275+
gettext_noop("-1 disables logging analyze actions by autovacuum. "
3276+
"0 means log all analyze actions by autovacuum."),
3277+
GUC_UNIT_MS
3278+
},
3279+
&Log_autoanalyze_min_duration,
3280+
600000, -1, INT_MAX,
3281+
NULL, NULL, NULL
3282+
},
3283+
32703284
{
32713285
{"log_parameter_max_length", PGC_SUSET, LOGGING_WHAT,
32723286
gettext_noop("Sets the maximum length in bytes of data logged for bind "

src/backend/utils/misc/postgresql.conf.sample

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -585,7 +585,12 @@
585585
#debug_print_rewritten = off
586586
#debug_print_plan = off
587587
#debug_pretty_print = on
588-
#log_autovacuum_min_duration = 10min # log autovacuum activity;
588+
#log_autovacuum_min_duration = 10min # log vacuum activity by autovacuum;
589+
# -1 disables, 0 logs all actions and
590+
# their durations, > 0 logs only
591+
# actions running at least this number
592+
# of milliseconds.
593+
#log_autoanalyze_min_duration = 10min # log analyze activity by autovacuum;
589594
# -1 disables, 0 logs all actions and
590595
# their durations, > 0 logs only
591596
# actions running at least this number

0 commit comments

Comments
 (0)