postgres.git / summary / log / commit / refs
commit e418e8eb92aa1dccca18b297a85c7ff38a7ee2a0
Author: Fujii Masao <fujii@postgresql.org>
Date: Thu Sep 10 02:54:08 2026 +0000
Fix REPACK command reporting in pg_stat_progress_cluster
pg_stat_progress_cluster translates REPACK into VACUUM FULL when
pg_stat_progress_repack.repack_index_relid is zero, and into CLUSTER
otherwise.
Previously, repack_index_relid was set only when an index scan was used.
When REPACK used a sequential scan and sort to order the table by an index,
the field remained zero even though index ordering had been requested. As a
result, pg_stat_progress_cluster incorrectly reported the command as
VACUUM FULL instead of CLUSTER.
Fix this by setting repack_index_relid to the OID of the requested ordering
index when progress reporting starts, regardless of the scan method. This
allows pg_stat_progress_cluster to correctly report REPACK as CLUSTER when
index ordering is requested.
Also update the documentation to clarify the meaning of the index columns
and how REPACK is translated into CLUSTER or VACUUM FULL.
Suggested-by: Fujii Masao <masao.fujii@gmail.com>
Author: Chao Li <lic@highgo.com>
Reviewed-by: Fujii Masao <masao.fujii@gmail.com>
Reviewed-by: Zsolt Parragi <zsolt.parragi@percona.com>
Discussion: https://postgr.es/m/CAN4CZFMzy2V_wvRCBW5K8=wVCk1-C7nq=8otXO=u+s_1KZHqyA@mail.gmail.com
Backpatch-through: 19
doc/src/sgml/monitoring.sgml | 13 +++++++------
src/backend/access/heap/heapam_handler.c | 12 ++----------
src/backend/commands/repack.c | 8 +++++++-
3 files changed, 16 insertions(+), 17 deletions(-)
diff --git a/doc/src/sgml/monitoring.sgml b/doc/src/sgml/monitoring.sgml
index b5fe179d9ab..4d8295ab69d 100644
--- a/doc/src/sgml/monitoring.sgml
+++ b/doc/src/sgml/monitoring.sgml
@@ -6474,8 +6474,9 @@ FROM pg_stat_get_backend_idset() AS backendid;
The command that is running. Either <command>CLUSTER</command> or
<command>VACUUM FULL</command>.
Because this view exists for backwards-compatibility purposes only,
- it will translate any <command>REPACK</command> command into one of
- these other two.
+ it will translate a <command>REPACK</command> command into
+ <command>CLUSTER</command> if index ordering is requested,
+ or <command>VACUUM FULL</command> otherwise.
</para></entry>
</row>
@@ -6493,8 +6494,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>
@@ -7167,8 +7168,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.c
index 2268cc277bc..b597f54e182 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -666,16 +666,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.c
index 0533217968e..2924d884b10 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
[parent: d1f742d5d126]