Skip to content

Commit 509c94f

Browse files
author
Commitfest Bot
committed
[CF 5969] v1 - Add mode column 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/CAOzEurQcOY-OBL_ouEVfEaFqe_md3vB5pXjR_m6L71Dcp1JKCQ@mail.gmail.com Author(s): Shinya Kato
2 parents 317c117 + 7fcd8c8 commit 509c94f

File tree

5 files changed

+59
-6
lines changed

5 files changed

+59
-6
lines changed

doc/src/sgml/monitoring.sgml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6607,6 +6607,38 @@ FROM pg_stat_get_backend_idset() AS backendid;
66076607
stale.
66086608
</para></entry>
66096609
</row>
6610+
6611+
<row>
6612+
<entry role="catalog_table_entry"><para role="column_definition">
6613+
<structfield>mode</structfield> <type>text</type>
6614+
</para>
6615+
<para>
6616+
The mode of the current vacuum operation. Possible values are:
6617+
<itemizedlist>
6618+
<listitem>
6619+
<para>
6620+
<literal>normal</literal>: A standard vacuum operation, including
6621+
user-initiated <command>VACUUM</command> command and autovacuum runs
6622+
not triggered for anti-wraparound purposes.
6623+
</para>
6624+
</listitem>
6625+
<listitem>
6626+
<para>
6627+
<literal>anti-wraparound</literal>: An autovacuum run specifically to
6628+
prevent transaction ID or multixact ID wraparound.
6629+
</para>
6630+
</listitem>
6631+
<listitem>
6632+
<para>
6633+
<literal>failsafe</literal>: A vacuum operation that entered failsafe
6634+
mode when the system was at risk of transaction ID or multixact ID
6635+
wraparound (see <xref linkend="guc-vacuum-failsafe-age"/> and
6636+
<xref linkend="guc-vacuum-multixact-failsafe-age"/>).
6637+
</para>
6638+
</listitem>
6639+
</itemizedlist>
6640+
</para></entry>
6641+
</row>
66106642
</tbody>
66116643
</tgroup>
66126644
</table>

src/backend/access/heap/vacuumlazy.c

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -651,6 +651,10 @@ heap_vacuum_rel(Relation rel, const VacuumParams params,
651651

652652
pgstat_progress_start_command(PROGRESS_COMMAND_VACUUM,
653653
RelationGetRelid(rel));
654+
pgstat_progress_update_param(PROGRESS_VACUUM_MODE,
655+
params.is_wraparound
656+
? PROGRESS_VACUUM_MODE_ANTI_WRAPAROUND
657+
: PROGRESS_VACUUM_MODE_NORMAL);
654658

655659
/*
656660
* Setup error traceback support for ereport() first. The idea is to set
@@ -2956,9 +2960,10 @@ lazy_check_wraparound_failsafe(LVRelState *vacrel)
29562960
{
29572961
const int progress_index[] = {
29582962
PROGRESS_VACUUM_INDEXES_TOTAL,
2959-
PROGRESS_VACUUM_INDEXES_PROCESSED
2963+
PROGRESS_VACUUM_INDEXES_PROCESSED,
2964+
PROGRESS_VACUUM_MODE
29602965
};
2961-
int64 progress_val[2] = {0, 0};
2966+
int64 progress_val[3] = {0, 0, PROGRESS_VACUUM_MODE_FAILSAFE};
29622967

29632968
VacuumFailsafeActive = true;
29642969

@@ -2974,8 +2979,8 @@ lazy_check_wraparound_failsafe(LVRelState *vacrel)
29742979
vacrel->do_index_cleanup = false;
29752980
vacrel->do_rel_truncate = false;
29762981

2977-
/* Reset the progress counters */
2978-
pgstat_progress_update_multi_param(2, progress_index, progress_val);
2982+
/* Reset the progress counters and the mode */
2983+
pgstat_progress_update_multi_param(3, progress_index, progress_val);
29792984

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

src/backend/catalog/system_views.sql

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1248,7 +1248,11 @@ CREATE VIEW pg_stat_progress_vacuum AS
12481248
S.param6 AS max_dead_tuple_bytes, S.param7 AS dead_tuple_bytes,
12491249
S.param8 AS num_dead_item_ids, S.param9 AS indexes_total,
12501250
S.param10 AS indexes_processed,
1251-
S.param11 / 1000000::double precision AS delay_time
1251+
S.param11 / 1000000::double precision AS delay_time,
1252+
CASE S.param12 WHEN 1 THEN 'normal'
1253+
WHEN 2 THEN 'anti-wraparound'
1254+
WHEN 3 THEN 'failsafe'
1255+
END AS mode
12521256
FROM pg_stat_get_progress_info('VACUUM') AS S
12531257
LEFT JOIN pg_database D ON S.datid = D.oid;
12541258

src/include/commands/progress.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
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
3233

3334
/* Phases of vacuum (as advertised via PROGRESS_VACUUM_PHASE) */
3435
#define PROGRESS_VACUUM_PHASE_SCAN_HEAP 1
@@ -38,6 +39,11 @@
3839
#define PROGRESS_VACUUM_PHASE_TRUNCATE 5
3940
#define PROGRESS_VACUUM_PHASE_FINAL_CLEANUP 6
4041

42+
/* Modes of vacuum (as advertised via PROGRESS_VACUUM_MODE) */
43+
#define PROGRESS_VACUUM_MODE_NORMAL 1
44+
#define PROGRESS_VACUUM_MODE_ANTI_WRAPAROUND 2
45+
#define PROGRESS_VACUUM_MODE_FAILSAFE 3
46+
4147
/* Progress parameters for analyze */
4248
#define PROGRESS_ANALYZE_PHASE 0
4349
#define PROGRESS_ANALYZE_BLOCKS_TOTAL 1

src/test/regress/expected/rules.out

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2094,7 +2094,13 @@ pg_stat_progress_vacuum| SELECT s.pid,
20942094
s.param8 AS num_dead_item_ids,
20952095
s.param9 AS indexes_total,
20962096
s.param10 AS indexes_processed,
2097-
((s.param11)::double precision / (1000000)::double precision) AS delay_time
2097+
((s.param11)::double precision / (1000000)::double precision) AS delay_time,
2098+
CASE s.param12
2099+
WHEN 1 THEN 'normal'::text
2100+
WHEN 2 THEN 'anti-wraparound'::text
2101+
WHEN 3 THEN 'failsafe'::text
2102+
ELSE NULL::text
2103+
END AS mode
20982104
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)
20992105
LEFT JOIN pg_database d ON ((s.datid = d.oid)));
21002106
pg_stat_recovery_prefetch| SELECT stats_reset,

0 commit comments

Comments
 (0)