CLUSTER progress: wrong index_rebuild_count for tables with TOAST
CLUSTER progress: wrong index_rebuild_count for tables with TOAST
Hi, When I run CLUSTER (or VACUUM FULL / REPACK) on a table that has a TOAST table, pg_stat_progress_cluster shows a wrong index_rebuild_count. During the heap scan the count is already equal to the number of indexes, but it should be 0 until the indexes are rebuilt at the end. A simple way to reproduce it. Run CLUSTER in one session, and query the view from another session at the same time: ``` CREATE TABLE t (i int, x text); INSERT INTO t SELECT g, repeat(md5(g::text), 1000) FROM generate_series(1, 5) g; CREATE INDEX ON t (i); CLUSTER t USING t_i_idx; -- phase "seq scanning heap", index_rebuild_count = 2 (should be 0) ``` The reason is that make_new_heap() creates the new TOAST table, and its TOAST index, before the heap is scanned. Building that index reports CREATE INDEX progress. CREATE INDEX and the cluster command use the same progress field for different things, so the cluster command then shows a CREATE INDEX value as its index_rebuild_count. The fix is to not report progress for the TOAST index build, because it is an internal index, not a user CREATE INDEX. The patch also adds an isolation test that pauses CLUSTER at the start of the heap scan and checks that index_rebuild_count is 0. -- Adam
Re: CLUSTER progress: wrong index_rebuild_count for tables with TOAST
От:
Antonin Houska <ah@cybertec.at>
Дата:
Adam Lee wrote: > The reason is that make_new_heap() creates the new TOAST table, and its > TOAST index, before the heap is scanned. Building that index reports > CREATE INDEX progress. CREATE INDEX and the cluster command use the same > progress field for different things, so the cluster command then shows a > CREATE INDEX value as its index_rebuild_count. I'd prefer enhanced progress monitoring that I proposed earlier [1]. The patch needs more work, I'll try to submit it for the next development cycle. [1] https://www.postgresql.org/message-id/30939.1777888333%40localhost -- Antonin Houska Web: https://www.cybertec-postgresql.com
Re: CLUSTER progress: wrong index_rebuild_count for tables with TOAST
On Fri, Jun 26, 2026 at 3:46 PM Adam Lee wrote: > The fix is to not report progress for the TOAST index build, because it > is an internal index, not a user CREATE INDEX. The patch also adds an > isolation test that pauses CLUSTER at the start of the heap scan and > checks that index_rebuild_count is 0. Thanks for the patch! I think the approach in the patch, i.e., passing INDEX_CREATE_SUPPRESS_PROGRESS to suppress progress reporting when creating TOAST indexes, looks good. But, adding that test seems overkill to me. I'd prefer to simplify the patch as in the attached 0001 patch. Thoughts? While working on this patch, I also found a related but separate issue: during REPACK (CONCURRENTLY), index_rebuild_count in pg_stat_progress_repack and pg_stat_progress_cluster did not advance as indexes were rebuilt. The attached 0002 patch fixes this issue. Regards, -- Fujii Masao
Re: CLUSTER progress: wrong index_rebuild_count for tables with TOAST
От:
Fujii Masao <masao.fujii@gmail.com>
Дата:
On Sun, Sep 13, 2026 at 9:52 PM Álvaro Herrera wrote: > I agree that the test is overkill -- after all, we don't test any of > progress reporting, and I'm not sure it's really a great approach to do > that by adding bespoke injection points. > > Your 0001 looks good to me. Thanks for the review! I've pushed the patch. > Maybe in a future release we can discuss a framework for making progress > updates visible in debug builds, so that they can be observed from a > new test framework. +1 > > While working on this patch, I also found a related but separate issue: > > during REPACK (CONCURRENTLY), index_rebuild_count in > > pg_stat_progress_repack and pg_stat_progress_cluster did not advance > > as indexes were rebuilt. The attached 0002 patch fixes this issue. > > Hmm, yeah, this patch looks good also. I've pushed this patch as well. Thanks! Regards, -- Fujii Masao