From: Chao Li <li.evan.chao@gmail.com>
To: Fujii Masao <masao.fujii@gmail.com>
Cc: Zsolt Parragi <zsolt.parragi@percona.com>
Cc: PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>
Cc: Álvaro Herrera <alvherre@kurilemu.de>
Subject: Re: pg_stat_progress_cluster: do not default to CLUSTER
Date: Wed, 9 Sep 2026 12:02:22 +0800
Message-ID: <6EB0849E-79FC-4FBA-A73A-8B076DE5CA33@gmail.com> (raw)
In-Reply-To: <CAHGQGwH6rAd+fxWKRw=-i+SbzFtFRGDA5VBGJdMNNEsPO9YTqg@mail.gmail.com>
References: <CAN4CZFMzy2V_wvRCBW5K8=wVCk1-C7nq=8otXO=u+s_1KZHqyA@mail.gmail.com>
<CAHGQGwH6rAd+fxWKRw=-i+SbzFtFRGDA5VBGJdMNNEsPO9YTqg@mail.gmail.com>
> On Sep 9, 2026, at 07:46, Fujii Masao <masao.fujii@gmail.com> wrote:
>
> On Thu, Sep 3, 2026 at 7:39 PM Zsolt Parragi <zsolt.parragi@percona.com> wrote:
>> The attached patch fixes this to report NULL instead.
>
> Thanks for the patch! It looks good to me. So, barring any objections,
> I'll commit it.
Also looks good to me.
>
> BTW, as a separate issue, is the following also problematic?
>
> WHEN command = 'REPACK' AND repack_index_relid = 0 THEN 'VACUUM FULL'
>
> REPACK ... USING INDEX ... should basically be displayed as "CLUSTER".
> But, if an index scan is not used (for example, when
> enable_indexscan is disabled), repack_index_relid can be 0, causing
> it to be displayed as "VACUUM FULL" unexpectedly. Thoughts?
>
Yes, this is true. Now heapam_relation_copy_for_cluster() only sets PROGRESS_REPACK_INDEX_RELID if (OldIndex != NULL && !use_sort). So when enable_indexscan is off, REPACK ... USING INDEX shows VACUUM FULL:
```
REPACK USING INDEX with enable_indexscan = off
SET
pg_sleep
----------
(1 row)
pid | relid | repack_command | repack_index_relid | compatibility_command | phase
-------+--------+----------------+--------------------+-----------------------+------------------
57523 | j4_1.t | REPACK | 0 | VACUUM FULL | rebuilding index
(1 row)
```
When enable_indexscan is on, it show CLUSTER:
```
REPACK USING INDEX with enable_indexscan = on
SET
pg_sleep
----------
(1 row)
pid | relid | repack_command | repack_index_relid | compatibility_command | phase
-------+--------+----------------+--------------------+-----------------------+------------------
57591 | j4_1.t | REPACK | 16455 | CLUSTER | rebuilding index
(1 row)
```
So, repack_index_relid now describes the actual scan method but not if index ordering was requested. Maybe we should set PROGRESS_REPACK_INDEX_RELID in cluster_rel() rather than heapam_relation_copy_for_cluster()? Like in the attache diff.
Best regards,
--
Chao Li (Evan)
HighGo Software Co., Ltd.
https://www.highgo.com/Attachments:repack_index_relid-fix.diff (application/octet-stream, 3.0K) downloaddiff --git a/doc/src/sgml/monitoring.sgml b/doc/src/sgml/monitoring.sgmlindex b403fb990a7..4c1d4b2a80a 100644--- a/doc/src/sgml/monitoring.sgml+++ b/doc/src/sgml/monitoring.sgml@@ -6806,8 +6806,8 @@ FROM pg_stat_get_backend_idset() AS backendid;
<structfield>cluster_index_relid</structfield> <type>oid</type>
</para>
<para>
- If the table is being scanned using an index, this is the OID of the- index being used; otherwise, it is zero.+ OID of the index defining the order of the rewritten table, or zero+ if no index ordering is requested.
</para></entry>
</row>
@@ -7480,8 +7480,8 @@ FROM pg_stat_get_backend_idset() AS backendid;
<structfield>repack_index_relid</structfield> <type>oid</type>
</para>
<para>
- If the table is being scanned using an index, this is the OID of the- index being used; otherwise, it is zero.+ OID of the index defining the order of the rewritten table, or zero+ if no index ordering is requested.
</para></entry>
</row>
diff --git a/src/backend/access/heap/heapam_handler.c b/src/backend/access/heap/heapam_handler.cindex 0f24a132564..dd2218bbbaf 100644--- a/src/backend/access/heap/heapam_handler.c+++ b/src/backend/access/heap/heapam_handler.c@@ -660,16 +660,8 @@ heapam_relation_copy_for_cluster(Relation OldHeap, Relation NewHeap,
*/
if (OldIndex != NULL && !use_sort)
{
- const int ci_index[] = {- PROGRESS_REPACK_PHASE,- PROGRESS_REPACK_INDEX_RELID- };- int64 ci_val[2];-- /* Set phase and OIDOldIndex to columns */- ci_val[0] = PROGRESS_REPACK_PHASE_INDEX_SCAN_HEAP;- ci_val[1] = RelationGetRelid(OldIndex);- pgstat_progress_update_multi_param(2, ci_index, ci_val);+ pgstat_progress_update_param(PROGRESS_REPACK_PHASE,+ PROGRESS_REPACK_PHASE_INDEX_SCAN_HEAP);
tableScan = NULL;
heapScan = NULL;
diff --git a/src/backend/commands/repack.c b/src/backend/commands/repack.cindex 57f28f1a420..6f7c37c39b2 100644--- a/src/backend/commands/repack.c+++ b/src/backend/commands/repack.c@@ -511,6 +511,11 @@ cluster_rel(RepackCommand cmd, Relation OldHeap, Oid indexOid,
bool recheck = ((params->options & CLUOPT_RECHECK) != 0);
bool concurrent = ((params->options & CLUOPT_CONCURRENT) != 0);
Oid ident_idx = InvalidOid;
+ const int progress_index[] = {+ PROGRESS_REPACK_COMMAND,+ PROGRESS_REPACK_INDEX_RELID+ };+ const int64 progress_values[] = {cmd, indexOid};
/* Determine the lock mode to use. */
lmode = RepackLockLevel(concurrent);
@@ -526,7 +531,8 @@ cluster_rel(RepackCommand cmd, Relation OldHeap, Oid indexOid,
CHECK_FOR_INTERRUPTS();
pgstat_progress_start_command(PROGRESS_COMMAND_REPACK, tableOid);
- pgstat_progress_update_param(PROGRESS_REPACK_COMMAND, cmd);+ /* Report the ordering index even when using a sequential scan and sort. */+ pgstat_progress_update_multi_param(2, progress_index, progress_values);
/*
* Switch to the table owner's userid, so that any index functions are run
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-hackers@postgresql.org
Cc: li.evan.chao@gmail.com, masao.fujii@gmail.com, zsolt.parragi@percona.com, alvherre@kurilemu.de
Subject: Re: pg_stat_progress_cluster: do not default to CLUSTER
In-Reply-To: <6EB0849E-79FC-4FBA-A73A-8B076DE5CA33@gmail.com>
References: <CAN4CZFMzy2V_wvRCBW5K8=wVCk1-C7nq=8otXO=u+s_1KZHqyA@mail.gmail.com> <CAHGQGwH6rAd+fxWKRw=-i+SbzFtFRGDA5VBGJdMNNEsPO9YTqg@mail.gmail.com> <6EB0849E-79FC-4FBA-A73A-8B076DE5CA33@gmail.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox