Skip to content

Commit 7510003

Browse files
author
Commitfest Bot
committed
[CF 5969] v9 - Add mode and reason columns to pg_stat_progress_vacuum
This branch was automatically generated by a robot using patches from an email thread registered at: https://commitfest.postgresql.org/patch/5969 The branch will be overwritten each time a new patch version is posted to the thread, and also periodically to check for bitrot caused by changes on the master branch. Patch(es): https://www.postgresql.org/message-id/CAOzEurQT9dd59au+EbXN_huX8NLYoEPZJiUxyODdUKGstViJ0Q@mail.gmail.com Author(s): Shinya Kato
2 parents 4eda42e + e6c0f39 commit 7510003

File tree

7 files changed

+179
-10
lines changed

7 files changed

+179
-10
lines changed

doc/src/sgml/maintenance.sgml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1018,8 +1018,11 @@ analyze threshold = analyze base threshold + analyze scale factor * number of tu
10181018
see <xref linkend="table-lock-compatibility"/>. However, if the autovacuum
10191019
is running to prevent transaction ID wraparound (i.e., the autovacuum query
10201020
name in the <structname>pg_stat_activity</structname> view ends with
1021-
<literal>(to prevent wraparound)</literal>), the autovacuum is not
1022-
automatically interrupted.
1021+
<literal>(to prevent wraparound)</literal> or the
1022+
<literal>autovacuum_wraparound</literal> value in the
1023+
<structfield>started_by</structfield> column in the
1024+
<structname>pg_stat_progress_vacuum</structname> view), the autovacuum is
1025+
not automatically interrupted.
10231026
</para>
10241027

10251028
<warning>

doc/src/sgml/monitoring.sgml

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5770,6 +5770,31 @@ FROM pg_stat_get_backend_idset() AS backendid;
57705770
zero).
57715771
</para></entry>
57725772
</row>
5773+
5774+
<row>
5775+
<entry role="catalog_table_entry"><para role="column_definition">
5776+
<structfield>started_by</structfield> <type>text</type>
5777+
</para>
5778+
<para>
5779+
Shows what caused the current <command>ANALYZE</command> operation to be
5780+
started. Possible values are:
5781+
<itemizedlist>
5782+
<listitem>
5783+
<para>
5784+
<literal>manual</literal>: The analyze was started by an explicit
5785+
<command>ANALYZE</command> or <command>VACUUM</command> with the
5786+
<option>ANALYZE</option> option.
5787+
</para>
5788+
</listitem>
5789+
<listitem>
5790+
<para>
5791+
<literal>autovacuum</literal>: The analyze was started by an
5792+
autovacuum worker.
5793+
</para>
5794+
</listitem>
5795+
</itemizedlist>
5796+
</para></entry>
5797+
</row>
57735798
</tbody>
57745799
</tgroup>
57755800
</table>
@@ -6710,6 +6735,81 @@ FROM pg_stat_get_backend_idset() AS backendid;
67106735
stale.
67116736
</para></entry>
67126737
</row>
6738+
6739+
<row>
6740+
<entry role="catalog_table_entry"><para role="column_definition">
6741+
<structfield>mode</structfield> <type>text</type>
6742+
</para>
6743+
<para>
6744+
The mode in which the current <command>VACUUM</command> operation is
6745+
running. See <xref linkend="vacuum-for-wraparound"/> for details of each
6746+
mode. Possible values are:
6747+
<itemizedlist>
6748+
<listitem>
6749+
<para>
6750+
<literal>normal</literal>: The operation is performing a standard
6751+
vacuum. It is neither required to run in aggressive mode nor operating
6752+
in failsafe mode.
6753+
</para>
6754+
</listitem>
6755+
<listitem>
6756+
<para>
6757+
<literal>aggressive</literal>: The operation is running an aggressive
6758+
vacuum, which must scan every page that is not marked all-frozen.
6759+
The parameters <xref linkend="guc-vacuum-freeze-table-age"/> and
6760+
<xref linkend="guc-vacuum-multixact-freeze-table-age"/> determine when a
6761+
table requires aggressive vacuuming.
6762+
</para>
6763+
</listitem>
6764+
<listitem>
6765+
<para>
6766+
<literal>failsafe</literal>: The vacuum has entered failsafe mode,
6767+
in which it performs only the minimum work necessary to avoid
6768+
transaction ID or multixact ID wraparound failure.
6769+
The parameters <xref linkend="guc-vacuum-failsafe-age"/> and
6770+
<xref linkend="guc-vacuum-multixact-failsafe-age"/> determine when the
6771+
vacuum enters failsafe mode. The vacuum may start in this mode or
6772+
switch to it while running; the value of the
6773+
<structfield>mode</structfield> column may transition from another
6774+
mode to <literal>failsafe</literal> during the operation.
6775+
</para>
6776+
</listitem>
6777+
</itemizedlist>
6778+
</para></entry>
6779+
</row>
6780+
6781+
<row>
6782+
<entry role="catalog_table_entry"><para role="column_definition">
6783+
<structfield>started_by</structfield> <type>text</type>
6784+
</para>
6785+
<para>
6786+
Shows what caused the current <command>VACUUM</command> operation to be
6787+
started. Possible values are:
6788+
<itemizedlist>
6789+
<listitem>
6790+
<para>
6791+
<literal>manual</literal>: The vacuum was started by an explicit
6792+
<command>VACUUM</command> command.
6793+
</para>
6794+
</listitem>
6795+
<listitem>
6796+
<para>
6797+
<literal>autovacuum</literal>: The vacuum was started by an autovacuum
6798+
worker. Vacuums run by autovacuum workers may be interrupted due to
6799+
lock conflicts.
6800+
</para>
6801+
</listitem>
6802+
<listitem>
6803+
<para>
6804+
<literal>autovacuum_wraparound</literal>: The vacuum was started by an
6805+
autovacuum worker to prevent transaction ID or multixact ID
6806+
wraparound. Vacuums run for wraparound protection are not interrupted
6807+
due to lock conflicts.
6808+
</para>
6809+
</listitem>
6810+
</itemizedlist>
6811+
</para></entry>
6812+
</row>
67136813
</tbody>
67146814
</tgroup>
67156815
</table>

src/backend/access/heap/vacuumlazy.c

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -664,6 +664,14 @@ heap_vacuum_rel(Relation rel, const VacuumParams params,
664664

665665
pgstat_progress_start_command(PROGRESS_COMMAND_VACUUM,
666666
RelationGetRelid(rel));
667+
if (AmAutoVacuumWorkerProcess())
668+
pgstat_progress_update_param(PROGRESS_VACUUM_STARTED_BY,
669+
params.is_wraparound
670+
? PROGRESS_VACUUM_STARTED_BY_AUTOVACUUM_WRAPAROUND
671+
: PROGRESS_VACUUM_STARTED_BY_AUTOVACUUM);
672+
else
673+
pgstat_progress_update_param(PROGRESS_VACUUM_STARTED_BY,
674+
PROGRESS_VACUUM_STARTED_BY_MANUAL);
667675

668676
/*
669677
* Setup error traceback support for ereport() first. The idea is to set
@@ -820,6 +828,12 @@ heap_vacuum_rel(Relation rel, const VacuumParams params,
820828
*/
821829
heap_vacuum_eager_scan_setup(vacrel, params);
822830

831+
/* Report the vacuum mode: 'normal' or 'aggressive' */
832+
pgstat_progress_update_param(PROGRESS_VACUUM_MODE,
833+
vacrel->aggressive
834+
? PROGRESS_VACUUM_MODE_AGGRESSIVE
835+
: PROGRESS_VACUUM_MODE_NORMAL);
836+
823837
if (verbose)
824838
{
825839
if (vacrel->aggressive)
@@ -3001,9 +3015,10 @@ lazy_check_wraparound_failsafe(LVRelState *vacrel)
30013015
{
30023016
const int progress_index[] = {
30033017
PROGRESS_VACUUM_INDEXES_TOTAL,
3004-
PROGRESS_VACUUM_INDEXES_PROCESSED
3018+
PROGRESS_VACUUM_INDEXES_PROCESSED,
3019+
PROGRESS_VACUUM_MODE
30053020
};
3006-
int64 progress_val[2] = {0, 0};
3021+
int64 progress_val[3] = {0, 0, PROGRESS_VACUUM_MODE_FAILSAFE};
30073022

30083023
VacuumFailsafeActive = true;
30093024

@@ -3019,8 +3034,8 @@ lazy_check_wraparound_failsafe(LVRelState *vacrel)
30193034
vacrel->do_index_cleanup = false;
30203035
vacrel->do_rel_truncate = false;
30213036

3022-
/* Reset the progress counters */
3023-
pgstat_progress_update_multi_param(2, progress_index, progress_val);
3037+
/* Reset the progress counters and set the failsafe mode */
3038+
pgstat_progress_update_multi_param(3, progress_index, progress_val);
30243039

30253040
ereport(WARNING,
30263041
(errmsg("bypassing nonessential maintenance of table \"%s.%s.%s\" as a failsafe after %d index scans",

src/backend/catalog/system_views.sql

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1247,7 +1247,10 @@ CREATE VIEW pg_stat_progress_analyze AS
12471247
S.param6 AS child_tables_total,
12481248
S.param7 AS child_tables_done,
12491249
CAST(S.param8 AS oid) AS current_child_table_relid,
1250-
S.param9 / 1000000::double precision AS delay_time
1250+
S.param9 / 1000000::double precision AS delay_time,
1251+
CASE S.param10 WHEN 1 THEN 'manual'
1252+
WHEN 2 THEN 'autovacuum'
1253+
ELSE NULL END AS started_by
12511254
FROM pg_stat_get_progress_info('ANALYZE') AS S
12521255
LEFT JOIN pg_database D ON S.datid = D.oid;
12531256

@@ -1268,7 +1271,15 @@ CREATE VIEW pg_stat_progress_vacuum AS
12681271
S.param6 AS max_dead_tuple_bytes, S.param7 AS dead_tuple_bytes,
12691272
S.param8 AS num_dead_item_ids, S.param9 AS indexes_total,
12701273
S.param10 AS indexes_processed,
1271-
S.param11 / 1000000::double precision AS delay_time
1274+
S.param11 / 1000000::double precision AS delay_time,
1275+
CASE S.param12 WHEN 1 THEN 'normal'
1276+
WHEN 2 THEN 'aggressive'
1277+
WHEN 3 THEN 'failsafe'
1278+
ELSE NULL END AS mode,
1279+
CASE S.param13 WHEN 1 THEN 'manual'
1280+
WHEN 2 THEN 'autovacuum'
1281+
WHEN 3 THEN 'autovacuum_wraparound'
1282+
ELSE NULL END AS started_by
12721283
FROM pg_stat_get_progress_info('VACUUM') AS S
12731284
LEFT JOIN pg_database D ON S.datid = D.oid;
12741285

src/backend/commands/analyze.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,12 @@ analyze_rel(Oid relid, RangeVar *relation,
239239
*/
240240
pgstat_progress_start_command(PROGRESS_COMMAND_ANALYZE,
241241
RelationGetRelid(onerel));
242+
if (AmAutoVacuumWorkerProcess())
243+
pgstat_progress_update_param(PROGRESS_ANALYZE_STARTED_BY,
244+
PROGRESS_ANALYZE_STARTED_BY_AUTOVACUUM);
245+
else
246+
pgstat_progress_update_param(PROGRESS_ANALYZE_STARTED_BY,
247+
PROGRESS_ANALYZE_STARTED_BY_MANUAL);
242248

243249
/*
244250
* Do the normal non-recursive ANALYZE. We can skip this for partitioned

src/include/commands/progress.h

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@
2929
#define PROGRESS_VACUUM_INDEXES_TOTAL 8
3030
#define PROGRESS_VACUUM_INDEXES_PROCESSED 9
3131
#define PROGRESS_VACUUM_DELAY_TIME 10
32+
#define PROGRESS_VACUUM_MODE 11
33+
#define PROGRESS_VACUUM_STARTED_BY 12
3234

3335
/* Phases of vacuum (as advertised via PROGRESS_VACUUM_PHASE) */
3436
#define PROGRESS_VACUUM_PHASE_SCAN_HEAP 1
@@ -38,6 +40,16 @@
3840
#define PROGRESS_VACUUM_PHASE_TRUNCATE 5
3941
#define PROGRESS_VACUUM_PHASE_FINAL_CLEANUP 6
4042

43+
/* Modes of vacuum (as advertised via PROGRESS_VACUUM_MODE) */
44+
#define PROGRESS_VACUUM_MODE_NORMAL 1
45+
#define PROGRESS_VACUUM_MODE_AGGRESSIVE 2
46+
#define PROGRESS_VACUUM_MODE_FAILSAFE 3
47+
48+
/* Reasons for vacuum (as advertised via PROGRESS_VACUUM_STARTED_BY) */
49+
#define PROGRESS_VACUUM_STARTED_BY_MANUAL 1
50+
#define PROGRESS_VACUUM_STARTED_BY_AUTOVACUUM 2
51+
#define PROGRESS_VACUUM_STARTED_BY_AUTOVACUUM_WRAPAROUND 3
52+
4153
/* Progress parameters for analyze */
4254
#define PROGRESS_ANALYZE_PHASE 0
4355
#define PROGRESS_ANALYZE_BLOCKS_TOTAL 1
@@ -48,6 +60,7 @@
4860
#define PROGRESS_ANALYZE_CHILD_TABLES_DONE 6
4961
#define PROGRESS_ANALYZE_CURRENT_CHILD_TABLE_RELID 7
5062
#define PROGRESS_ANALYZE_DELAY_TIME 8
63+
#define PROGRESS_ANALYZE_STARTED_BY 9
5164

5265
/* Phases of analyze (as advertised via PROGRESS_ANALYZE_PHASE) */
5366
#define PROGRESS_ANALYZE_PHASE_ACQUIRE_SAMPLE_ROWS 1
@@ -56,6 +69,10 @@
5669
#define PROGRESS_ANALYZE_PHASE_COMPUTE_EXT_STATS 4
5770
#define PROGRESS_ANALYZE_PHASE_FINALIZE_ANALYZE 5
5871

72+
/* Reasons for analyze (as advertised via PROGRESS_ANALYZE_STARTED_BY) */
73+
#define PROGRESS_ANALYZE_STARTED_BY_MANUAL 1
74+
#define PROGRESS_ANALYZE_STARTED_BY_AUTOVACUUM 2
75+
5976
/* Progress parameters for cluster */
6077
#define PROGRESS_CLUSTER_COMMAND 0
6178
#define PROGRESS_CLUSTER_PHASE 1

src/test/regress/expected/rules.out

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1969,7 +1969,12 @@ pg_stat_progress_analyze| SELECT s.pid,
19691969
s.param6 AS child_tables_total,
19701970
s.param7 AS child_tables_done,
19711971
(s.param8)::oid AS current_child_table_relid,
1972-
((s.param9)::double precision / (1000000)::double precision) AS delay_time
1972+
((s.param9)::double precision / (1000000)::double precision) AS delay_time,
1973+
CASE s.param10
1974+
WHEN 1 THEN 'manual'::text
1975+
WHEN 2 THEN 'autovacuum'::text
1976+
ELSE NULL::text
1977+
END AS started_by
19731978
FROM (pg_stat_get_progress_info('ANALYZE'::text) s(pid, datid, relid, param1, param2, param3, param4, param5, param6, param7, param8, param9, param10, param11, param12, param13, param14, param15, param16, param17, param18, param19, param20)
19741979
LEFT JOIN pg_database d ON ((s.datid = d.oid)));
19751980
pg_stat_progress_basebackup| SELECT pid,
@@ -2105,7 +2110,19 @@ pg_stat_progress_vacuum| SELECT s.pid,
21052110
s.param8 AS num_dead_item_ids,
21062111
s.param9 AS indexes_total,
21072112
s.param10 AS indexes_processed,
2108-
((s.param11)::double precision / (1000000)::double precision) AS delay_time
2113+
((s.param11)::double precision / (1000000)::double precision) AS delay_time,
2114+
CASE s.param12
2115+
WHEN 1 THEN 'normal'::text
2116+
WHEN 2 THEN 'aggressive'::text
2117+
WHEN 3 THEN 'failsafe'::text
2118+
ELSE NULL::text
2119+
END AS mode,
2120+
CASE s.param13
2121+
WHEN 1 THEN 'manual'::text
2122+
WHEN 2 THEN 'autovacuum'::text
2123+
WHEN 3 THEN 'autovacuum_wraparound'::text
2124+
ELSE NULL::text
2125+
END AS started_by
21092126
FROM (pg_stat_get_progress_info('VACUUM'::text) s(pid, datid, relid, param1, param2, param3, param4, param5, param6, param7, param8, param9, param10, param11, param12, param13, param14, param15, param16, param17, param18, param19, param20)
21102127
LEFT JOIN pg_database d ON ((s.datid = d.oid)));
21112128
pg_stat_recovery_prefetch| SELECT stats_reset,

0 commit comments

Comments
 (0)