Skip to content

Commit 839f94d

Browse files
shinyaaaCommitfest Bot
authored andcommitted
Add mode and triggered_by columns to pg_stat_progress_vacuum
This commit introduces the new mode and triggered_by columns, which specify the vacuum's behavior mode and how the current vacuum was launched, respectively. The mode can be one of the following: - normal - aggressive - failsafe The triggered_by can be one of the following: - manual - autovacuum - autovacuum_wraparound Bump catalog version. Author: Shinya Kato <[email protected]> Reviewed-by: Kirill Reshke <[email protected]> Reviewed-by: Nathan Bossart <[email protected]> Reviewed-by: Robert Treat <[email protected]> Reviewed-by: Masahiko Sawada <[email protected]> Reviewed-by: Sami Imseih <[email protected]> Reviewed-by: Michael Paquier <[email protected]> Discusssion: https://postgr.es/m/CAOzEurQcOY-OBL_ouEVfEaFqe_md3vB5pXjR_m6L71Dcp1JKCQ@mail.gmail.com
1 parent 9d7e851 commit 839f94d

File tree

6 files changed

+126
-8
lines changed

6 files changed

+126
-8
lines changed

doc/src/sgml/maintenance.sgml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1014,8 +1014,11 @@ analyze threshold = analyze base threshold + analyze scale factor * number of tu
10141014
see <xref linkend="table-lock-compatibility"/>. However, if the autovacuum
10151015
is running to prevent transaction ID wraparound (i.e., the autovacuum query
10161016
name in the <structname>pg_stat_activity</structname> view ends with
1017-
<literal>(to prevent wraparound)</literal>), the autovacuum is not
1018-
automatically interrupted.
1017+
<literal>(to prevent wraparound)</literal> or the
1018+
<literal>autovacuum_wraparound</literal> value in the
1019+
<structfield>triggered_by</structfield> column in the
1020+
<structname>pg_stat_progress_vacuum</structname> view), the autovacuum is
1021+
not automatically interrupted.
10191022
</para>
10201023

10211024
<warning>

doc/src/sgml/monitoring.sgml

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6687,6 +6687,73 @@ FROM pg_stat_get_backend_idset() AS backendid;
66876687
stale.
66886688
</para></entry>
66896689
</row>
6690+
6691+
<row>
6692+
<entry role="catalog_table_entry"><para role="column_definition">
6693+
<structfield>mode</structfield> <type>text</type>
6694+
</para>
6695+
<para>
6696+
The mode of the current vacuum operation. Possible values are:
6697+
<itemizedlist>
6698+
<listitem>
6699+
<para>
6700+
<literal>normal</literal>: A standard vacuum operation that is not
6701+
required to be aggressive and has not entered failsafe mode.
6702+
</para>
6703+
</listitem>
6704+
<listitem>
6705+
<para>
6706+
<literal>aggressive</literal>: A vacuum that must scan the entire
6707+
table because <xref linkend="guc-vacuum-freeze-table-age"/> or
6708+
<xref linkend="guc-vacuum-freeze-min-age"/> (or the corresponding
6709+
per-table storage parameters) required it, or because page skipping
6710+
was disabled via <command>VACUUM (DISABLE_PAGE_SKIPPING)</command>.
6711+
</para>
6712+
</listitem>
6713+
<listitem>
6714+
<para>
6715+
<literal>failsafe</literal>: A vacuum operation that entered failsafe
6716+
mode when the system was at risk of transaction ID or multixact ID
6717+
wraparound (see <xref linkend="guc-vacuum-failsafe-age"/> and
6718+
<xref linkend="guc-vacuum-multixact-failsafe-age"/>).
6719+
</para>
6720+
</listitem>
6721+
</itemizedlist>
6722+
</para></entry>
6723+
</row>
6724+
6725+
<row>
6726+
<entry role="catalog_table_entry"><para role="column_definition">
6727+
<structfield>triggered_by</structfield> <type>text</type>
6728+
</para>
6729+
<para>
6730+
The trigger of the current vacuum operation. Possible values are:
6731+
<itemizedlist>
6732+
<listitem>
6733+
<para>
6734+
<literal>manual</literal>: Initiated by an explicit
6735+
<command>VACUUM</command> command.
6736+
</para>
6737+
</listitem>
6738+
<listitem>
6739+
<para>
6740+
<literal>autovacuum</literal>: Launched by autovacuum based on
6741+
<xref linkend="guc-autovacuum-vacuum-threshold"/> or
6742+
<xref linkend="guc-autovacuum-vacuum-insert-threshold"/>.
6743+
</para>
6744+
</listitem>
6745+
<listitem>
6746+
<para>
6747+
<literal>autovacuum_wraparound</literal>: Launched by autovacuum to
6748+
avoid transaction ID or multixact ID wraparound (see
6749+
<xref linkend="vacuum-for-wraparound"/> as well as
6750+
<xref linkend="guc-autovacuum-freeze-max-age"/> and
6751+
<xref linkend="guc-autovacuum-multixact-freeze-max-age"/>).
6752+
</para>
6753+
</listitem>
6754+
</itemizedlist>
6755+
</para></entry>
6756+
</row>
66906757
</tbody>
66916758
</tgroup>
66926759
</table>

src/backend/access/heap/vacuumlazy.c

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

665665
pgstat_progress_start_command(PROGRESS_COMMAND_VACUUM,
666666
RelationGetRelid(rel));
667+
pgstat_progress_update_param(PROGRESS_VACUUM_MODE,
668+
PROGRESS_VACUUM_MODE_NORMAL);
669+
if (AmAutoVacuumWorkerProcess())
670+
pgstat_progress_update_param(PROGRESS_VACUUM_TRIGGERED_BY,
671+
params.is_wraparound
672+
? PROGRESS_VACUUM_TRIGGERED_BY_AUTOVACUUM_WRAPAROUND
673+
: PROGRESS_VACUUM_TRIGGERED_BY_AUTOVACUUM);
674+
else
675+
pgstat_progress_update_param(PROGRESS_VACUUM_TRIGGERED_BY,
676+
PROGRESS_VACUUM_TRIGGERED_BY_MANUAL);
667677

668678
/*
669679
* Setup error traceback support for ereport() first. The idea is to set
@@ -787,6 +797,9 @@ heap_vacuum_rel(Relation rel, const VacuumParams params,
787797
* to increase the number of dead tuples it can prune away.)
788798
*/
789799
vacrel->aggressive = vacuum_get_cutoffs(rel, params, &vacrel->cutoffs);
800+
if (vacrel->aggressive)
801+
pgstat_progress_update_param(PROGRESS_VACUUM_MODE,
802+
PROGRESS_VACUUM_MODE_AGGRESSIVE);
790803
vacrel->rel_pages = orig_rel_pages = RelationGetNumberOfBlocks(rel);
791804
vacrel->vistest = GlobalVisTestFor(rel);
792805

@@ -808,6 +821,8 @@ heap_vacuum_rel(Relation rel, const VacuumParams params,
808821
* visibility map (even those set all-frozen)
809822
*/
810823
vacrel->aggressive = true;
824+
pgstat_progress_update_param(PROGRESS_VACUUM_MODE,
825+
PROGRESS_VACUUM_MODE_AGGRESSIVE);
811826
skipwithvm = false;
812827
}
813828

@@ -2996,9 +3011,10 @@ lazy_check_wraparound_failsafe(LVRelState *vacrel)
29963011
{
29973012
const int progress_index[] = {
29983013
PROGRESS_VACUUM_INDEXES_TOTAL,
2999-
PROGRESS_VACUUM_INDEXES_PROCESSED
3014+
PROGRESS_VACUUM_INDEXES_PROCESSED,
3015+
PROGRESS_VACUUM_MODE
30003016
};
3001-
int64 progress_val[2] = {0, 0};
3017+
int64 progress_val[3] = {0, 0, PROGRESS_VACUUM_MODE_FAILSAFE};
30023018

30033019
VacuumFailsafeActive = true;
30043020

@@ -3014,8 +3030,8 @@ lazy_check_wraparound_failsafe(LVRelState *vacrel)
30143030
vacrel->do_index_cleanup = false;
30153031
vacrel->do_rel_truncate = false;
30163032

3017-
/* Reset the progress counters */
3018-
pgstat_progress_update_multi_param(2, progress_index, progress_val);
3033+
/* Reset the progress counters and the mode */
3034+
pgstat_progress_update_multi_param(3, progress_index, progress_val);
30193035

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

src/backend/catalog/system_views.sql

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1265,7 +1265,15 @@ CREATE VIEW pg_stat_progress_vacuum AS
12651265
S.param6 AS max_dead_tuple_bytes, S.param7 AS dead_tuple_bytes,
12661266
S.param8 AS num_dead_item_ids, S.param9 AS indexes_total,
12671267
S.param10 AS indexes_processed,
1268-
S.param11 / 1000000::double precision AS delay_time
1268+
S.param11 / 1000000::double precision AS delay_time,
1269+
CASE S.param12 WHEN 1 THEN 'normal'
1270+
WHEN 2 THEN 'aggressive'
1271+
WHEN 3 THEN 'failsafe'
1272+
ELSE NULL END AS mode,
1273+
CASE S.param13 WHEN 1 THEN 'manual'
1274+
WHEN 2 THEN 'autovacuum'
1275+
WHEN 3 THEN 'autovacuum_wraparound'
1276+
ELSE NULL END AS triggered_by
12691277
FROM pg_stat_get_progress_info('VACUUM') AS S
12701278
LEFT JOIN pg_database D ON S.datid = D.oid;
12711279

src/include/commands/progress.h

Lines changed: 12 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_TRIGGERED_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_TRIGGERED_BY) */
49+
#define PROGRESS_VACUUM_TRIGGERED_BY_MANUAL 1
50+
#define PROGRESS_VACUUM_TRIGGERED_BY_AUTOVACUUM 2
51+
#define PROGRESS_VACUUM_TRIGGERED_BY_AUTOVACUUM_WRAPAROUND 3
52+
4153
/* Progress parameters for analyze */
4254
#define PROGRESS_ANALYZE_PHASE 0
4355
#define PROGRESS_ANALYZE_BLOCKS_TOTAL 1

src/test/regress/expected/rules.out

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2104,7 +2104,19 @@ pg_stat_progress_vacuum| SELECT s.pid,
21042104
s.param8 AS num_dead_item_ids,
21052105
s.param9 AS indexes_total,
21062106
s.param10 AS indexes_processed,
2107-
((s.param11)::double precision / (1000000)::double precision) AS delay_time
2107+
((s.param11)::double precision / (1000000)::double precision) AS delay_time,
2108+
CASE s.param12
2109+
WHEN 1 THEN 'normal'::text
2110+
WHEN 2 THEN 'aggressive'::text
2111+
WHEN 3 THEN 'failsafe'::text
2112+
ELSE NULL::text
2113+
END AS mode,
2114+
CASE s.param13
2115+
WHEN 1 THEN 'manual'::text
2116+
WHEN 2 THEN 'autovacuum'::text
2117+
WHEN 3 THEN 'autovacuum_wraparound'::text
2118+
ELSE NULL::text
2119+
END AS triggered_by
21082120
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)
21092121
LEFT JOIN pg_database d ON ((s.datid = d.oid)));
21102122
pg_stat_recovery_prefetch| SELECT stats_reset,

0 commit comments

Comments
 (0)