Report index currently being vacuumed in pg_stat_progress_vacuum
Report index currently being vacuumed in pg_stat_progress_vacuum
Hi,
When VACUUM is in the "vacuuming indexes" or "cleaning up indexes" phase, there is currently no easy way to tell which specific index is being processed. The progress report view shows indexes_total and indexes_processed counters, but not which index is actively being worked on.
This makes it difficult to debug slow or stuck autovacuum workers on tables with multiple indexes of different types (btree, GIN, GiST, BRIN, HNSW, etc.), since one cannot determine which index type or which specific index is causing the delay.
Please find the attached patch adds a new column current_index_relid to pg_stat_progress_vacuum that reports the OID of the index currently being vacuumed or cleaned up. The column is reported for both the "vacuuming indexes" phase and the "cleaning up indexes" phase.
When indexes are being vacuumed in parallel, each parallel worker emits its own row in pg_stat_progress_vacuum with current_index_relid set to the index it is currently processing, and leader_pid pointing to the leader process.
Appreciate any feedback. Thank you!
[1] Example output:
pid | datname | relid | table_name | phase | started_by | current_index_relid | index_name | leader_pid
------+----------+-------+------------+-------------------+------------+---------------------+---------------+------------
1420 | postgres | 16395 | vac_test | vacuuming indexes | autovacuum | 16398 | vac_test_idx1 |
1421 | postgres | 16395 | vac_test | vacuuming indexes | | 16399 | vac_test_idx2 | 1420
1423 | postgres | 16395 | vac_test | vacuuming indexes | | 16400 | vac_test_idx3 | 1420
(3 rows)
pid | datname | relid | table_name | phase | started_by | current_index_relid | index_name | leader_pid
------+----------+-------+------------+-------------------+------------+---------------------+---------------+------------
1346 | postgres | 16395 | vac_test | vacuuming indexes | manual | 16398 | vac_test_idx1 |
(1 row)
[2]
SELECT v.pid, v.datname, v.relid, c.relname AS table_name,
v.phase, v.started_by, v.current_index_relid,
COALESCE(ic.relname, '') AS index_name, v.leader_pid
FROM pg_stat_progress_vacuum v
JOIN pg_class c
ON c.oid = v.relid
LEFT JOIN pg_class ic
ON ic.oid = v.current_index_relid
WHERE v.relid = $tbl_oid
ORDER BY
v.leader_pid,
v.pid;
--
Bharath Rupireddy
Amazon Web Services: https://aws.amazon.com
When VACUUM is in the "vacuuming indexes" or "cleaning up indexes" phase, there is currently no easy way to tell which specific index is being processed. The progress report view shows indexes_total and indexes_processed counters, but not which index is actively being worked on.
This makes it difficult to debug slow or stuck autovacuum workers on tables with multiple indexes of different types (btree, GIN, GiST, BRIN, HNSW, etc.), since one cannot determine which index type or which specific index is causing the delay.
Please find the attached patch adds a new column current_index_relid to pg_stat_progress_vacuum that reports the OID of the index currently being vacuumed or cleaned up. The column is reported for both the "vacuuming indexes" phase and the "cleaning up indexes" phase.
When indexes are being vacuumed in parallel, each parallel worker emits its own row in pg_stat_progress_vacuum with current_index_relid set to the index it is currently processing, and leader_pid pointing to the leader process.
Appreciate any feedback. Thank you!
[1] Example output:
pid | datname | relid | table_name | phase | started_by | current_index_relid | index_name | leader_pid
------+----------+-------+------------+-------------------+------------+---------------------+---------------+------------
1420 | postgres | 16395 | vac_test | vacuuming indexes | autovacuum | 16398 | vac_test_idx1 |
1421 | postgres | 16395 | vac_test | vacuuming indexes | | 16399 | vac_test_idx2 | 1420
1423 | postgres | 16395 | vac_test | vacuuming indexes | | 16400 | vac_test_idx3 | 1420
(3 rows)
pid | datname | relid | table_name | phase | started_by | current_index_relid | index_name | leader_pid
------+----------+-------+------------+-------------------+------------+---------------------+---------------+------------
1346 | postgres | 16395 | vac_test | vacuuming indexes | manual | 16398 | vac_test_idx1 |
(1 row)
[2]
SELECT v.pid, v.datname, v.relid, c.relname AS table_name,
v.phase, v.started_by, v.current_index_relid,
COALESCE(ic.relname, '') AS index_name, v.leader_pid
FROM pg_stat_progress_vacuum v
JOIN pg_class c
ON c.oid = v.relid
LEFT JOIN pg_class ic
ON ic.oid = v.current_index_relid
WHERE v.relid = $tbl_oid
ORDER BY
v.leader_pid,
v.pid;
--
Bharath Rupireddy
Amazon Web Services: https://aws.amazon.com
Re: Report index currently being vacuumed in pg_stat_progress_vacuum
От:
SATYANARAYANA NARLAPURAM <satyanarlapuram@gmail.com>
Дата:
Hi,
On Sun, May 3, 2026 at 7:01 PM Bharath Rupireddy <bharath.rupireddyforpostgres@gmail.com> wrote:
Hi,
When VACUUM is in the "vacuuming indexes" or "cleaning up indexes" phase, there is currently no easy way to tell which specific index is being processed. The progress report view shows indexes_total and indexes_processed counters, but not which index is actively being worked on.
This makes it difficult to debug slow or stuck autovacuum workers on tables with multiple indexes of different types (btree, GIN, GiST, BRIN, HNSW, etc.), since one cannot determine which index type or which specific index is causing the delay.
Please find the attached patch adds a new column current_index_relid to pg_stat_progress_vacuum that reports the OID of the index currently being vacuumed or cleaned up. The column is reported for both the "vacuuming indexes" phase and the "cleaning up indexes" phase.
When indexes are being vacuumed in parallel, each parallel worker emits its own row in pg_stat_progress_vacuum with current_index_relid set to the index it is currently processing, and leader_pid pointing to the leader process.
Appreciate any feedback. Thank you!
[1] Example output:
pid | datname | relid | table_name | phase | started_by | current_index_relid | index_name | leader_pid
------+----------+-------+------------+-------------------+------------+---------------------+---------------+------------
1420 | postgres | 16395 | vac_test | vacuuming indexes | autovacuum | 16398 | vac_test_idx1 |
1421 | postgres | 16395 | vac_test | vacuuming indexes | | 16399 | vac_test_idx2 | 1420
1423 | postgres | 16395 | vac_test | vacuuming indexes | | 16400 | vac_test_idx3 | 1420
(3 rows)
pid | datname | relid | table_name | phase | started_by | current_index_relid | index_name | leader_pid
------+----------+-------+------------+-------------------+------------+---------------------+---------------+------------
1346 | postgres | 16395 | vac_test | vacuuming indexes | manual | 16398 | vac_test_idx1 |
(1 row)
[2]
SELECT v.pid, v.datname, v.relid, c.relname AS table_name,
v.phase, v.started_by, v.current_index_relid,
COALESCE(ic.relname, '') AS index_name, v.leader_pid
FROM pg_stat_progress_vacuum v
JOIN pg_class c
ON c.oid = v.relid
LEFT JOIN pg_class ic
ON ic.oid = v.current_index_relid
WHERE v.relid = $tbl_oid
ORDER BY
v.leader_pid,
v.pid;
Bharath, thanks for the patch! A few comments:
(1) Do we need a global API? Can we add a leader_pid field in PVShared?
+pid_t
+GetParallelLeaderPid(void)
+{
+ return ParallelLeaderPid;
+}
+GetParallelLeaderPid(void)
+{
+ return ParallelLeaderPid;
+}
(2): Looks like current_index_relid is not cleared when we leave the index phases.As a result, once any index has been processed,
pg_stat_progress_vacuum.current_index_relid keeps reporting that relid through vacuuming heap, truncating heap, cleaning up indexes.
This will be confusing to the user. Something like below:
1795819|vacuuming heap|0/0|16392|t1_pkey|LEADER
(3) leader_pid type should be integer type similar to pg_Stat_activity?
Thanks,
Satya
Re: Report index currently being vacuumed in pg_stat_progress_vacuum
Bharath Rupireddy wrote: > When VACUUM is in the "vacuuming indexes" or "cleaning up indexes" phase, there is currently no easy way to tell which specific index is > being processed. The progress report view shows indexes_total and indexes_processed counters, but not which index is actively being worked > on. > > This makes it difficult to debug slow or stuck autovacuum workers on tables with multiple indexes of different types (btree, GIN, GiST, BRIN, > HNSW, etc.), since one cannot determine which index type or which specific index is causing the delay. > > Please find the attached patch adds a new column current_index_relid to pg_stat_progress_vacuum that reports the OID of the index > currently being vacuumed or cleaned up. The column is reported for both the "vacuuming indexes" phase and the "cleaning up indexes" > phase. > > When indexes are being vacuumed in parallel, each parallel worker emits its own row in pg_stat_progress_vacuum with current_index_relid > set to the index it is currently processing, and leader_pid pointing to the leader process. > > Appreciate any feedback. Thank you! This problem seems to be similar to what I noticed when workign on the REPACK command: progress reporting of index build needs to be disabled if the build is part of REPACK, otherwise the index build can overwrite the counters of REPACK (whether the overwriting actually happens or not is another question). The solution I suggest is to allow progress tracking of a "sub-command" - see the attached patch. Wouldn't that also resolve your problem? (My plan is to incorporate this in the series of REPACK enhancements soon.) -- Antonin Houska Web: https://www.cybertec-postgresql.com
Re: Report index currently being vacuumed in pg_stat_progress_vacuum
От:
Sami Imseih <samimseih@gmail.com>
Дата:
Hi, > Appreciate any feedback. Thank you! I think it is valuable to show the index being processed. There is really no other easy way to get this information except for pstack, etc. I am +1 for the idea. However, I am not sure that having a separate row for every parallel worker is the right approach. The pg_stat_progress_* views are designed to show progress per row. Each row represents one command with meaningful progress counters (heap_blks_scanned, indexes_total, indexes_processed, etc.). A parallel worker row would only show current_index_relid and leader_pid with no actual progress information of its own. That is status, not progress, and it does not fit the view. Also, many columns would remain empty or redundant with the leader's row. Instead, could we aggregate the parallel worker information into the leader's row. For example, an array of worker PIDs in one column and an array of index relids in another? -- Sami Imseih Amazon Web Services (AWS)
Re: Report index currently being vacuumed in pg_stat_progress_vacuum
От:
Bharath Rupireddy <bharath.rupireddyforpostgres@gmail.com>
Дата:
Hi,
On Tue, May 5, 2026 at 10:54 AM Sami Imseih wrote:
>
> I think it is valuable to show the index being processed. There is
> really no other easy way to get this information except for pstack,
> etc. I am +1 for the idea.
Thanks for reviewing this!
> However, I am not sure that having a separate row for every parallel
> worker is the right approach. The pg_stat_progress_* views are designed
> to show progress per row. Each row represents one command with
> meaningful progress counters (heap_blks_scanned, indexes_total,
> indexes_processed, etc.). A parallel worker row would only show
> current_index_relid and leader_pid with no actual progress information
> of its own. That is status, not progress, and it does not fit the
> view. Also, many columns would remain empty or redundant with the
> leader's row.
>
> Instead, could we aggregate the parallel worker information into the
> leader's row. For example, an array of worker PIDs in one column and an
> array of index relids in another?
Thanks for the review. I read f1889729 and it looks like the
preference was to keep one command = one row, with workers feeding the
leader's row rather than showing up as separate rows. I want to stay
with that approach.
I considered having the leader set up a DSA that workers write into,
shown as an extra column on the leader's row. But that means new
shared memory whose handle has to be stored somewhere other backends
can find it, attached by the reader, and freed safely while a
monitoring query might still be reading it - that's a lot of work for
a small amount of per-worker data.
The simpler approach is to have workers report the index they're
currently on into their own st_progress_param[] slots, which already
exist per backend, along with their leader's pid. The view then groups
the worker entries under the matching leader's pid and shows only the
leader rows, so no new shared memory is needed. The current index oid
column has to be added to that array anyway for the non-parallel case,
which needs it just as much, and the parallel workers already have
their own slots to report into, so there's nothing extra to set up.
One thing to note is that pg_stat_get_progress_info('VACUUM') itself
would still return the worker rows, and the grouping happens in the
pg_stat_progress_vacuum view instead. I prefer keeping it in the view
rather than the function. The function is shared by all the progress
commands and only deals with raw params, while the leader pid grouping
is specific to VACUUM. This way the shared function stays unchanged
and the other progress views are not affected.
While I'm here, in the "vacuuming indexes" phase I also want to report
the total index pages to scan and the pages scanned so far, for the
index currently being vacuumed. On a large index this phase can run
for a long time with no way to tell whether it's making progress.
Does this direction sound reasonable, or do you see a reason to prefer
a different approach?
--
Bharath Rupireddy
Amazon Web Services: https://aws.amazon.com
Re: Report index currently being vacuumed in pg_stat_progress_vacuum
От:
Sami Imseih <samimseih@gmail.com>
Дата:
Hi,
> The simpler approach is to have workers report the index they're
> currently on into their own st_progress_param[] slots, which already
> exist per backend, along with their leader's pid. The view then groups
> the worker entries under the matching leader's pid and shows only the
> leader rows, so no new shared memory is needed.
Right, that is what I am thinking also.
> One thing to note is that pg_stat_get_progress_info('VACUUM') itself
> would still return the worker rows, and the grouping happens in the
> pg_stat_progress_vacuum view instead.
Yes, that would be the best way. Do the aggregation on the SQL level
using array_agg.
> While I'm here, in the "vacuuming indexes" phase I also want to report
> the total index pages to scan and the pages scanned so far, for the
> index currently being vacuumed. On a large index this phase can run
> for a long time with no way to tell whether it's making progress.
This was brought up when the "index progress" columns were being worked on, and
knowing the total was not possible for all index types [1]
> Does this direction sound reasonable, or do you see a reason to prefer
> a different approach?
Yes, I think the SQL level aggregation is sane.
[1] https://www.postgresql.org/message-id/CAH2-Wz%3D3JGBty%3D3tXoBoEYYwQNd7fXJuN9oPcnBAj3JYroBv3w%40mail.gmail.com
--
Sami Imseih
Amazon Web Services (AWS)
Re: Report index currently being vacuumed in pg_stat_progress_vacuum
Hi,
See the attached v2.
It aggregates on the leader (if parallel) at the SQL level with two new
columns: index_vacuum_pids and index_vacuum_oids. These are pid and oid
arrays respectively and are order-aligned. The leader is listed first when
it is itself processing an index; otherwise one of the workers is,
obviously, first.
For a serial vacuum, each array is a single value. The array fields will be
NULL if no index is currently being processed.
Using array typed columns is new for the pg_stat_progress_* views, none of
them expose arrays today, or any other pg_stat_* views. It's a bit unusual here,
but I think it's the natural fit.
Now, with this, parallel workers now register their own progress entry
so they show up as additional rows in pg_stat_get_progress_info('VACUUM').
The progress_vacuum view filters them out, but any code that reads the function
directly will now see an extra (mostly zeros) row per worker.
pg_stat_get_progress_info()
is not meant to be used directly, hence it's not documented for direct
use, so I think this is OK.
I also noticed in v1 that we weren't resetting the index after the vacuum
completed, and the index was being set in the wrong place. I fixed that. I
also removed the unnecessary typecast for InvalidOid.
Lastly, with this approach we no longer need the external function to
retrieve the leader pid.
What do you think?
--
Sami
Re: Report index currently being vacuumed in pg_stat_progress_vacuum
От:
Sami Imseih <samimseih@gmail.com>
Дата:
Thanks for the feedback, Michael!
The view already reports indexes_total and indexes_processed, how many
indexes are done. These columns add which ones are in progress, and by
which PID.
> Exposing the information of an index a worker is processing is a good
> idea, but I think that this choice lacks a long-term vision. I think
> that we should expose one row for each worker rather than an array of
> PIDs and index OIDs in the row of a leader.
I put the PID and OID in the leader's row as two position-aligned arrays
precisely to keep the shape of the view, one row per command. The docs
describe pg_stat_progress_vacuum as "one row for each backend (including
autovacuum worker processes) that is currently vacuuming". I read that
as one row for the backend that launched the operation. A parallel
worker isn't running a command, it's a consequence of the configuration,
so it belongs in the leader's row, not a row of its own.
> The main issue for me is the granularity of the information provided,
> where it would actually make sense to provide more information for
> each worker. Choosing how an index clean works in vacuum for parallel
> workers is an implementation choice, where we could think about
> approaches like:
> - Distribute the workload of one index across N workers (for a 1TB
> index, spawn N workers each sharing 1/N TB of data to clean)
> - Have each worker do one index.
> - Or more strategies, etc.
The two arrays already roll up what we care about, which PID is on which
index, into the leader's row, and the approach we pick only changes
whether an OID repeats.
Today, index vacuuming is one PID per OID. An index is claimed in full by
one process and never scanned by two at once, so the OIDs are distinct.
```
leader_pid | vacuum_pids | vacuum_oids
------------+---------------+---------------------
100 | {100,200,300} | {10000,10001,10002}
```
More than one PID on a single OID, whether that's distributing one index
across workers as you describe, or parallel heap vacuum [1] which is
still being discussed, is handled by repeating the OID. The phase says
what the OID is, here a table's relid rather than an index.
```
leader_pid | phase | vacuum_pids | vacuum_oids
------------+----------------+-------------------+-----------------------
100 | vacuuming heap | {100,200,300,400} | {9000,9000,9000,9000}
```
On naming, we should probablt call the columns vacuum_pids and vacuum_oids
rather than index_vacuum_*, since the phase says what they are for.
So this doesn't hamstring us, and it doesn't need a row per worker.
> One thing could be for example reusing heap_blks_total and
> heap_blks_scanned for indexes, so as it is possible how much each
> worker has done (let's perhaps rename them).
Right, there's a need here. For some indexes we know how far we need to
scan, like btree, and for some we can't, like GIN. This was discussed
before for index scan progress [2].
Also, reusing heap_blks_* isn't the right interface for it. They hold
how far the heap got, and even though they stop advancing once we're
vacuuming indexes, a user still wants to know at any given moment just
how far the table has been vacuumed. Double purposing the same field to
count index blocks would overwrite it, which makes monitoring this field
impractical.
If we do expose per-worker progress, a separate view is the better home.
Most columns here are the leader's or shared, so a per-worker row would
be mostly empty anyway.
> Being able to map a leader with its worker is an information already
> provided by pg_stat_activity, adding this information in the progress
> view seems unnecessary for me to add here as a JOIN is already able to
> solve that anyway.
This isn't really about mapping a leader to its workers. A JOIN with
pg_stat_activity relates the PIDs, but it can't tell you which index
each worker is on, and that's what these two columns add.
[1] https://www.postgresql.org/message-id/flat/CAD21AoAEfCNv-GgaDheDJ%2Bs-p_Lv1H24AiJeNoPGCmZNSwL1YA%40mail.gmail.com
[2] https://www.postgresql.org/message-id/CAH2-Wz=3JGBty=3tXoBoEYYwQNd7fXJuN9oPcnBAj3JYroBv3w@mail.gmail.com
--
Sami Imseih
Amazon Web Services (AWS)
Re: Report index currently being vacuumed in pg_stat_progress_vacuum
In short, I tend to agree with having one row per worker in the vacuum
progress report, joining pg_stat_activity's leader_pid for simpler
usability, extensibility, and less information bloat, along with doc
changes to explain this. One concern is that some progress fields
would be null on worker rows, but documenting this should be
sufficient. I could be missing something here, so I would like to hear
some thoughts before coming up with a patch.
I will look at the rest of the points later in detail, but it does sound like to me that a new worker view will be a better place to hold extra per worker ( or leader ) details and the current view will remain high level/progress data. Unused progress fields do not sound right to me, and I also worry we will bloat the existing view over time if we want to add more per worker fields.
--
Sami
Sami
Re: Report index currently being vacuumed in pg_stat_progress_vacuum
Hi,
Thanks Sami for the thoughts. I addressed most of these upthread [1],
responding to the remaining ones here.
[1] https://www.postgresql.org/message-id/CALj2ACX6gyBmQfaqbCsycDmaSPbq1%3DiPJw1OqUT%2BaLqaKjW8dQ%40mail.gmail.com
On Fri, Aug 14, 2026 at 2:26 PM Sami Imseih wrote:
>
> The two arrays already roll up what we care about, which PID is on which
> index, into the leader's row, and the approach we pick only changes
> whether an OID repeats.
>
> Today, index vacuuming is one PID per OID. An index is claimed in full by
> one process and never scanned by two at once, so the OIDs are distinct.
>
> ```
> leader_pid | vacuum_pids | vacuum_oids
> ------------+---------------+---------------------
> 100 | {100,200,300} | {10000,10001,10002}
> ```
Right, and this holds only for BTree. Some other index AM might
implement intra-parallel index vacuum (vacuuming one index with
multiple workers), in which case OIDs would repeat.
> More than one PID on a single OID, whether that's distributing one index
> across workers as you describe, or parallel heap vacuum [1] which is
> still being discussed, is handled by repeating the OID. The phase says
> what the OID is, here a table's relid rather than an index.
>
> ```
> leader_pid | phase | vacuum_pids | vacuum_oids
> ------------+----------------+-------------------+-----------------------
> 100 | vacuuming heap | {100,200,300,400} | {9000,9000,9000,9000}
> ```
>
> [1] https://www.postgresql.org/message-id/flat/CAD21AoAEfCNv-GgaDheDJ%2Bs-p_Lv1H24AiJeNoPGCmZNSwL1YA%40mail.gmail.com
I haven't thought about parallel heap vacuum in depth yet and will do
that as part of that thread. Quick thoughts. One row per worker lets
us report heap_blks_* per worker naturally. Alternatively, we could
report a single overall value in the leader's heap_blks_*, the way
parallel CREATE INDEX does today, tracking total scan progress across
all workers rather than any one worker's share.
> > One thing could be for example reusing heap_blks_total and
> > heap_blks_scanned for indexes, so as it is possible how much each
> > worker has done (let's perhaps rename them).
>
> Right, there's a need here. For some indexes we know how far we need to
> scan, like btree, and for some we can't, like GIN. This was discussed
> before for index scan progress [2].
>
> [2] https://www.postgresql.org/message-id/CAH2-Wz=3JGBty=3tXoBoEYYwQNd7fXJuN9oPcnBAj3JYroBv3w@mail.gmail.com
Correct, but today BTree scan progress is supported via create index
progress reporting (see my response upthread around
PROGRESS_SCAN_BLOCKS_TOTAL/DONE).
> > If we do expose per-worker progress, a separate view is the better home.
> > Most columns here are the leader's or shared, so a per-worker row would
> > be mostly empty anyway.
>
> A different idea other than aggregating the pids and oid's into a list
> as is currently
> being proposed, would be to have a "pg_stat_progress_vacuum_worker" view,
> which initially will be 4 columns:
>
> "pid"
> "leader_pid"
> "phase"
> "oid"
>
> and it will have a row for every worker ( or leader ) and the "oid" they are
> processing, which could be a index ( or a heap if we get to that point of
> parallel heap vacuum ).
I don't think a separate view is the right approach at least for two
reasons. One, to know the progress of a vacuum one has to query two
views and relate them. Two, since the leader itself participates in
vacuuming indexes alongside workers (and will also for parallel heap
vacuum), splitting the same command's progress into two views adds
complexity. Keeping everything in a single view with one row per
worker (as discussed upthread) is simpler. Some fields would be null
on worker rows, but documenting this should be sufficient. That said,
I'm open to hear more thoughts on this.
--
Bharath Rupireddy
Amazon Web Services: https://aws.amazon.com
Re: Report index currently being vacuumed in pg_stat_progress_vacuum
On Wed, Aug 19, 2026 at 07:37:00PM -0700, Bharath Rupireddy wrote:
> I don't think a separate view is the right approach at least for two
> reasons. One, to know the progress of a vacuum one has to query two
> views and relate them. Two, since the leader itself participates in
> vacuuming indexes alongside workers (and will also for parallel heap
> vacuum), splitting the same command's progress into two views adds
> complexity. Keeping everything in a single view with one row per
> worker (as discussed upthread) is simpler. Some fields would be null
> on worker rows, but documenting this should be sufficient. That said,
> I'm open to hear more thoughts on this.
Having a single progress view feels like the natural approach here,
for both the leader and the workers. The leader triggers the
existence of the workers, but both leader and workers may finish by
doing the same job as there could be usually little meaning for a
leader to stand idle, waiting for all the workers to do the work.
Such choices are implementation-agnostic, of course; we should not
lock ourselves.
This sounds to me that we are ok with breaking the principle design of the progress views, at least how I understand it, which is that we only have one row associated with the backend from which the user issued command. Background workers that are started as a result of that command, and are transient during the life of the command, don’t fit into that.
Also, If we include workers in a separate row, we will need to mix stats that are aggregate of the entire command with stats that are specific to the work that leader done on its own. what would heap_blks_* refer to in this case? The aggregate of heap blocks accessed by the leader and workers -or— just the blocks accessed by the leader?
I think monitoring tools/users consuming this view can better deal with the separation of worker level details ( worker here is also the leader ) in one view and the aggregate/high level information in the separate existing view(s) much better than having to deal with documented caveats about what the stats mean.
--
Sami
Re: Report index currently being vacuumed in pg_stat_progress_vacuum
On Wed, Sep 02, 2026 at 07:23:00PM -0700, Bharath Rupireddy wrote: > Thanks Michael for the off-list chat. I agree that emitting leader_pid > via the vacuum progress report is information bloat, since one can > easily identify the workers for a given leader by looking at the > database OID and relation name, and if needed, can also join with > pg_stat_activity.leader_pid. So, I removed leader_pid in the 0001 > patch. Full disclosure. I have discussed this patch set a bit with Bharath. The discussion can be summed up like: - leader_pid in the progress view with a JOIN to pg_stat_activity feels like bloating the view with duplicated information. - The database OID, the relation OID and the index OID gain in visibility by being specified in the lines for the workers. Note: it looks like we are doing so based on your output posted upthread, missed that during our discussion, initially. - The two new fields for total index blocks and index blocks processed make more sense than trying to reuse the heap attributes because a leader may do itself some of the cleanup. Multiple passes are less likely lately, but could still be possible, and we want to know where the leader is at for the heap part while working on the indexes. Reading through v5-0001 and v5-0002, it looks like all these check boxes are ticked. In terms of review clarity, splitting both patches slightly helps, but I'd rather merge both things together at the end: the first patch gains a lot in value thanks to the second patch where the two block aggregates are added. Perhaps I am missing something else? In this case, please feel free to overwrite my words.. -- Michael
Re: Report index currently being vacuumed in pg_stat_progress_vacuum
От:
Sami Imseih <samimseih.pg@gmail.com>
Дата:
Hi,
> I think it's fine for a progress view to have an entry per backend,
> including parallel workers, so more than one row for a single command.
My worry is that if we do not separate high level command stats from
per-worker (or leader) stats, we will end up with a confusing view and
tie our hands in the future.
For example, in v6 we have heap_blks_total and heap_blks_scanned, which
represent aggregate progress for how much of the table has been scanned,
while index_blks_total and index_blks_done represent how much one worker
has processed for a specific index. This is probably OK today only
because we do not support parallel heap scan.
But if we ever support parallel heap scan during VACUUM, what would
heap_blks_total and heap_blks_scanned represent at that point? Would
they remain command-level aggregate progress, or become per-worker
progress?
My point is that the existing progress views have historically exposed
command-level aggregate stats. Trying to also use them for per-worker
stats in the same view does not seem right to me.
> If we ever implement parallel index rebuilding for REINDEX TABLE,
> where different workers rebuild different indexes, having one entry
> per worker in pg_stat_progress_create_index seems the straightforward
> thing to do.
For parallel REINDEX TABLE, a command-level progress model with
indexes_total and
indexes_done would seem more natural, similar to VACUUM.
One separate question is whether each individual index rebuild would
itself run in parallel.
Today, an individual REINDEX INDEX may already use parallel build, but
that is leader-driven
parallelism for one index. Parallel workers do not in turn spawn more
parallel workers. So
if REINDEX TABLE were implemented by assigning different indexes to
different workers, It seems
likely each worker’s assigned index rebuild to be serial unless we
introduced a more complex
nested-parallel design.
> A dedicated view for workers, say
> pg_stat_progress_create_index_worker, would end up with mostly the
> same columns as pg_stat_progress_create_index.
That may be the case, but at least the meaning of each view will be well
understood and clear. Not mixing per-command vs per-worker stats.
> I can also see Sami's point that the patch makes many of the existing
> columns of pg_stat_progress_vacuum no-op. But I'm not sure a dedicated
> worker view really avoids that. If a user wants the progress of one
> vacuum command they would join the two views, get one row per
> participant anyway, and the leader's heap columns would be repeated on
> every row.
I don't really think most users will actually perform this join. They would
start with the command-level view and if they need to understand more
of what the worker is doing they can query a separate worker specific view.
So my hang up is the semantic differences each row will carry and
how hard it may be for a (monitoring) user to reason about this. It is
also clear that others are not as worried about this as me, so I will
concede, because getting this information is important.
As far as v6: The code looks overall good to me, but I have some
comments.
1/
I do think it will be better to do one more split of v6-0001 to separate
current_index_relid and index_blks_*; they are 2 distinct features. Also
you can fold the 0002 into the index_blks_* commit.
Also, there are some comment updates still needed:
2/
+ index_blks_done. The remaining columns track
+ command-level heap progress that only the leader maintains; they read as
+ zero on worker rows.
We should mention mode and started_by as NULL, such as:
".... read as zero on worker rows, except that
mode and
started_by appear as NULL."
3/
+ working. A worker row with a NULL
+ phase is a worker that has been launched but has
+ not started on an index yet, which also happens when every index was
+ claimed by another participant before this worker got to it. Because a
+ table can be vacuumed by only one
I don't think phase will ever be NULL here since phase will be set to
"initializing" at minimum.
4/
/*
* Perform work within a launched parallel process.
*
* Since parallel vacuum workers perform only index vacuum or index cleanup,
* we don't need to report progress information.
*/
void
parallel_vacuum_main(dsm_segment *seg, shm_toc *toc)
{
This comment is now out-of-date and should be updated.
--
Sami Imseih
Amazon Web Services (AWS)
Re: Report index currently being vacuumed in pg_stat_progress_vacuum
Hi,
On Tue, Sep 15, 2026 at 10:11 AM Sami Imseih wrote:
>
> As far as v6: The code looks overall good to me, but I have some
> comments.
Thanks for reviewing.
> 1/
>
> I do think it will be better to do one more split of v6-0001 to separate
> current_index_relid and index_blks_*; they are 2 distinct features. Also
> you can fold the 0002 into the index_blks_* commit.
I prefer to keep them as one patch as I see them as closely related,
but I'm open to splitting if anyone thinks otherwise.
> Also, there are some comment updates still needed:
> 2/
>
> + index_blks_done. The remaining columns track
> + command-level heap progress that only the leader maintains; they read as
> + zero on worker rows.
>
> We should mention mode and started_by as NULL, such as:
>
> ".... read as zero on worker rows, except that
> mode and
> started_by appear as NULL."
>
> 3/
>
> + working. A worker row with a NULL
> + phase is a worker that has been launched but has
> + not started on an index yet, which also happens when every index was
> + claimed by another participant before this worker got to it. Because a
> + table can be vacuumed by only one
>
> I don't think phase will ever be NULL here since phase will be set to
> "initializing" at minimum.
>
> 4/
>
> /*
> * Perform work within a launched parallel process.
> *
> * Since parallel vacuum workers perform only index vacuum or index cleanup,
> * we don't need to report progress information.
> */
> void
> parallel_vacuum_main(dsm_segment *seg, shm_toc *toc)
> {
>
> This comment is now out-of-date and should be updated.
I agree with all three comments above and have updated the v6 patches
accordingly. Please have a look.
--
Bharath Rupireddy
Amazon Web Services: https://aws.amazon.com
Re: Report index currently being vacuumed in pg_stat_progress_vacuum
Hi Bharath,
v7 looks good here. Tested sequential, parallel on btree and GIN, all as the
docs describe, including GIN reporting zero blocks and the reset
clearing the previous index. Applies cleanly on 5e595d659fd, suites
pass.
You were right that this needs an injection point, polling is not
reliable when the value is set and reset around every index. One thing
to add: the sequential path needs one too, not just the parallel
workers, since lazy_vacuum_one_index sets and resets just as tightly. A
single point in the per index loop covers both.
Attached as two patches, take either half. v7-0003 is the injection
point, v7-0004 a TAP test in test_misc. Runs in about a second, under
both meson and make. Sanity check, it does fail if you take out the
progress update.
It does not cover the reset to 0, only that the value moves on. That
needs a second point after the reset.
v7 looks good here. Tested sequential, parallel on btree and GIN, all as the
docs describe, including GIN reporting zero blocks and the reset
clearing the previous index. Applies cleanly on 5e595d659fd, suites
pass.
You were right that this needs an injection point, polling is not
reliable when the value is set and reset around every index. One thing
to add: the sequential path needs one too, not just the parallel
workers, since lazy_vacuum_one_index sets and resets just as tightly. A
single point in the per index loop covers both.
Attached as two patches, take either half. v7-0003 is the injection
point, v7-0004 a TAP test in test_misc. Runs in about a second, under
both meson and make. Sanity check, it does fail if you take out the
progress update.
It does not cover the reset to 0, only that the value moves on. That
needs a second point after the reset.
Thanks,
Shihao
Re: Report index currently being vacuumed in pg_stat_progress_vacuum
On Tue, Sep 15, 2026 at 03:28:00PM -0700, Bharath Rupireddy wrote: > On Tue, Sep 15, 2026 at 10:11 AM Sami Imseih wrote: >> I do think it will be better to do one more split of v6-0001 to separate >> current_index_relid and index_blks_*; they are 2 distinct features. Also >> you can fold the 0002 into the index_blks_* commit. > > I prefer to keep them as one patch as I see them as closely related, > but I'm open to splitting if anyone thinks otherwise. In terms of the "core" patch that introduces the counters, grouping them together is fine by me. > I agree with all three comments above and have updated the v6 patches > accordingly. Please have a look. Reading through the patches. 0002 is a nice cleanup. 0003 and 0004 are not things I can get much into, echoing with the recent following message: https://www.postgresql.org/message-id/aqqmGGS6qqm5LI0Z%40alvherre.pgsql I think that we should try to think harder regarding what kind of facility we are looking for: https://www.postgresql.org/message-id/aqqmGGS6qqm5LI0Z%40alvherre.pgsql Your proposal based on TAP is not as heavy as the other message, but I'm worried about the bloat this could create long-term if the same pattern flourishes in more code paths of the tree (aka 0004 seems AI-generated to me based on the current facilities we have, I'd consider more building pieces before that). Switching to python may make these test patterns much easier compared to perl, though I have to be honest I have not looked at the recent proposals based on pypi and such. -- Michael
Re: Report index currently being vacuumed in pg_stat_progress_vacuum
Hi Michael,
> 0003 and 0004 are not things I can get much into, echoing with the
> recent following message:
> https://www.postgresql.org/message-id/aqqmGGS6qqm5LI0Z%40alvherre.pgsql
Thanks for the pointer. I had not seen that thread, withdraw 0003 and 0004.
> recent following message:
> https://www.postgresql.org/message-id/aqqmGGS6qqm5LI0Z%40alvherre.pgsql
Thanks for the pointer. I had not seen that thread, withdraw 0003 and 0004.
I will work with Manu and Alvaro on the progress reporting test
framework in that thread. This patch would make a good first user.
framework in that thread. This patch would make a good first user.
Thanks,
Shihao
Re: Report index currently being vacuumed in pg_stat_progress_vacuum
От:
Bharath Rupireddy <bharath.rupireddyforpostgres@gmail.com>
Дата:
Hi, On Thu, Sep 17, 2026 at 6:00 PM shihao zhong wrote: > > v7 looks good here. Tested sequential, parallel on btree and GIN, all as the > docs describe, including GIN reporting zero blocks and the reset > clearing the previous index. Applies cleanly on 5e595d659fd, suites > pass. Thanks for testing v7 on these and for confirming the behavior matches the docs. > > 0003 and 0004 are not things I can get much into, echoing with the > > recent following message: > > https://www.postgresql.org/message-id/aqqmGGS6qqm5LI0Z%40alvherre.pgsql > > Thanks for the pointer. I had not seen that thread, withdraw 0003 and 0004. > > I will work with Manu and Alvaro on the progress reporting test > framework in that thread. This patch would make a good first user. +1 to discussing a general approach for progress reporting tests separately. We haven't had progress reporting tests so far, but that doesn't mean we must not have them. One idea is to look at whether there are any bugs or inconsistencies reported for any of the progress reporting commands and start from there (but that's a discussion for the other thread). -- Bharath Rupireddy Amazon Web Services: https://aws.amazon.com
Re: Report index currently being vacuumed in pg_stat_progress_vacuum
On Tue, Sep 15, 2026 at 12:10:54PM -0500, Sami Imseih wrote: > But if we ever support parallel heap scan during VACUUM, what would > heap_blks_total and heap_blks_scanned represent at that point? Would > they remain command-level aggregate progress, or become per-worker > progress? My best reply for this set of questions is that I don't really have a clear reply because I don't know what the future is made of, because the choices of the progress fields are driven by the way the implementations are done for parallelization. Here the choices are based on how index cleanup phases are done in [auto]vacuum, so the fields make sense, in the existing view, with one entry in the progress view for each worker that's been spawned. > My point is that the existing progress views have historically exposed > command-level aggregate stats. Trying to also use them for per-worker > stats in the same view does not seem right to me. Perhaps so, but it does not mean that this cannot be overruled if another reason justifies so. I'm seeing a reason here in terms of the granularity of the data reported per worker: the index actually processed by each worker, and the block area that's being browsed. -- Michael
Re: Report index currently being vacuumed in pg_stat_progress_vacuum
On Fri, Sep 18, 2026 at 11:23:37AM -0700, Bharath Rupireddy wrote:
> On Thu, Sep 17, 2026 at 6:00 PM shihao zhong wrote:
>> v7 looks good here. Tested sequential, parallel on btree and GIN, all as the
>> docs describe, including GIN reporting zero blocks and the reset
>> clearing the previous index. Applies cleanly on 5e595d659fd, suites
>> pass.
>
> Thanks for testing v7 on these and for confirming the behavior matches the docs.
I've looked at v7, and my main comment is that this is bloated in
terms of docs and comments. My hands-on is leading me to the attached
result, that reduces the docs to actually explain what these new
counters do, and only that, including your note at the bottom about
the workers and the relevant fields. :D
* Since parallel vacuum workers perform only index vacuum or index cleanup,
- * we don't need to report progress information.
+ * they report progress for the index they are processing.
This reads a bit weird as well..
Just for transparency, I've used the following thing to check the
state of the progress. One session to create and destroy:
CREATE TABLE pvac (a int, b int, c int, d int[]);
INSERT INTO pvac
SELECT i, i, i, ARRAY[i, i+1, i+2] FROM generate_series(1, 3000000) i;
CREATE INDEX pvac_a ON pvac (a);
CREATE INDEX pvac_b ON pvac (b);
CREATE INDEX pvac_c ON pvac (c);
CREATE INDEX pvac_d ON pvac USING gin (d);
DELETE FROM pvac WHERE a % 3 = 0;
SET maintenance_work_mem = '1MB';
SET max_parallel_maintenance_workers = 4;
VACUUM (PARALLEL 4, VERBOSE) pvac;
And a second session to monitor (lower \watch for more output):
SELECT a.pid, a.leader_pid, v.phase,
v.current_index_relid::regclass AS idx,
v.index_blks_done, v.index_blks_total,
v.indexes_processed, v.indexes_total,
v.heap_blks_scanned, v.heap_blks_total
FROM pg_stat_progress_vacuum v
JOIN pg_stat_activity a USING (pid)
WHERE v.relid = 'pvac'::regclass
ORDER BY a.leader_pid NULLS FIRST, a.pid \watch 0.5
And I'd say that this is pretty nice to see all this information.
Nice result for a limited amount of code added.
Then, I don't really have a lot of feelings for v7-0002. Even if all
the paths set the progress flag to true in the backend core code,
I think that there is an out-of-core argument in favor of keeping it,
as some code out there may want to control if progress should show up
or not. And I suspect that we will need it at some point..
--
Michael
Re: Report index currently being vacuumed in pg_stat_progress_vacuum
От:
Sami Imseih <samimseih.pg@gmail.com>
Дата:
v8- looks good to me. Only one doc nit: + During a parallel vacuum, the leader and each of its workers reports its + own row, all sharing the same relid. Only + phase, I think we should make it more clear about how long the worker rows exist for. Maybe the below: During parallel index vacuuming or cleanup, the leader and each active worker report separate rows, all sharing the same relid. Worker rows exist only while the worker is performing parallel vacuum work. -- Sami
Re: Report index currently being vacuumed in pg_stat_progress_vacuum
От:
shihao zhong <zhong950419@gmail.com>
Дата:
> I've looked at v7, and my main comment is that this is bloated in
> terms of docs and comments.
+1 for v8. I tested serial, parallel and parallel autovacuum. The view
matches the new docs.
> terms of docs and comments.
+1 for v8. I tested serial, parallel and parallel autovacuum. The view
matches the new docs.
> + * they report progress for the index they are processing.
>
> This reads a bit weird as well..
Maybe this:
* Parallel vacuum workers perform only index vacuum or index cleanup,
* so their progress row only shows the phase and the current index.
>
> This reads a bit weird as well..
Maybe this:
* Parallel vacuum workers perform only index vacuum or index cleanup,
* so their progress row only shows the phase and the current index.
Thanks,
Shihao
Re: Report index currently being vacuumed in pg_stat_progress_vacuum
On Wed, Sep 30, 2026 at 10:16:23PM -0500, Sami Imseih wrote: > During parallel index vacuuming or cleanup, the leader and each active > worker report separate rows, all sharing the same > relid. Worker rows exist only while the worker is > performing parallel vacuum work. Okay, your extra sentence works here. -- Michael
Re: Report index currently being vacuumed in pg_stat_progress_vacuum
От:
Bharath Rupireddy <bharath.rupireddyforpostgres@gmail.com>
Дата:
Hi, On Wed, Sep 30, 2026 at 6:55 PM Michael Paquier wrote: > > I've looked at v7, and my main comment is that this is bloated in > terms of docs and comments. My hands-on is leading me to the attached > result, that reduces the docs to actually explain what these new > counters do, and only that, including your note at the bottom about > the workers and the relevant fields. :D Agreed. Simplifying the wording and dropping the code-level details, such as how and when a worker shows the initializing phase, is nice. Also, dropping the sentence about the pg_read_all_stats role is fine too, since monitoring.sgml already covers that at the top. > Then, I don't really have a lot of feelings for v7-0002. Even if all > the paths set the progress flag to true in the backend core code, > I think that there is an out-of-core argument in favor of keeping it, > as some code out there may want to control if progress should show up > or not. And I suspect that we will need it at some point.. Agreed. A non-core index AM might want to use it. > During parallel index vacuuming or cleanup, the leader and each active > worker report separate rows, all sharing the same > relid. Worker rows exist only while the worker is > performing parallel vacuum work. The repeated use of "worker" here reads a bit hard to follow for me. "During parallel vacuum" already implies the workers are running, and per the docs today, parallel vacuum applies to index vacuuming (I don't see "parallel index vacuum" or "cleanup" used elsewhere in the docs, though they do appear in the code), so what v8 has reads fine to me. Thanks, Michael, for attaching the v8 patch. It looks good to me as-is. -- Bharath Rupireddy Amazon Web Services: https://aws.amazon.com
Re: Report index currently being vacuumed in pg_stat_progress_vacuum
On Thu, Oct 01, 2026 at 01:23:50PM +0900, Michael Paquier wrote: > On Wed, Sep 30, 2026 at 10:16:23PM -0500, Sami Imseih wrote: >> During parallel index vacuuming or cleanup, the leader and each active >> worker report separate rows, all sharing the same >> relid. Worker rows exist only while the worker is >> performing parallel vacuum work. > > Okay, your extra sentence works here. I've slept over this suggestion, and it still felt a bit redundant with the first sentence and the final one in the last paragraph added. v8 applied. Thanks all for the discussion, nice addition to the monitoring kit. -- Michael