pg_stat_progress_cluster: do not default to CLUSTER

Started by Zsolt Parragi3 months ago7 messageshackers
Jump to latest
#1Zsolt Parragi
zsolt.parragi@percona.com

Hello

Since ac58465e061, pg_stat_progress_cluster is not built on
pg_stat_get_progress_info() but on pg_stat_progress_repack, and maps
the new REPACK command name back onto the two names the view used to
report. The mapping is a CASE ending in an unconditional ELSE
'CLUSTER'.

pg_stat_get_progress_info() hands pid and datid to every caller, but
NULLs other parameters if the caller no has privileges of the role
running the command.

That includes both command and repack_index_relid used in that CASE,
and we can display a VACUUM (FULL) as CLUSTER because of this default
branch.

The attached patch fixes this to report NULL instead. I also attached
a (LLM generated) script that reproduces the issue.

Attachments:

t253656_1
J4-1.sqlapplication/octet-stream; name=J4-1.sqlDownload
0001-Don-t-report-CLUSTER-for-a-redacted-progress-row.patchapplication/octet-stream; name=0001-Don-t-report-CLUSTER-for-a-redacted-progress-row.patchDownload+6-5
#2Fujii Masao
masao.fujii@gmail.com
In reply to: Zsolt Parragi (#1)
Re: pg_stat_progress_cluster: do not default to CLUSTER

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.

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?

Regards,

--
Fujii Masao

#3Chao Li
li.evan.chao@gmail.com
In reply to: Fujii Masao (#2)
Re: pg_stat_progress_cluster: do not default to CLUSTER

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:

t253656_3
repack_index_relid-fix.diffapplication/octet-stream; name=repack_index_relid-fix.diff; x-unix-mode=0644Download+13-15
#4Fujii Masao
masao.fujii@gmail.com
In reply to: Chao Li (#3)
Re: pg_stat_progress_cluster: do not default to CLUSTER

On Wed, Sep 9, 2026 at 1:03 PM Chao Li <li.evan.chao@gmail.com> wrote:

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.

Thanks for the patch! LGTM.

it will translate any REPACK command into one of these other two.

If we apply the proposed patch, at the same moment, personally I'd like to
update this description of pg_stat_progress_cluster.command in the docs
so that it clearly explains how REPACK is translated. How about:

it will translate a REPACK command into CLUSTER if index ordering
is requested,
or VACUUM FULL otherwise.

Regards,

--
Fujii Masao

#5Chao Li
li.evan.chao@gmail.com
In reply to: Fujii Masao (#4)
Re: pg_stat_progress_cluster: do not default to CLUSTER

On Sep 9, 2026, at 14:55, Fujii Masao <masao.fujii@gmail.com> wrote:

On Wed, Sep 9, 2026 at 1:03 PM Chao Li <li.evan.chao@gmail.com> wrote:

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.

Thanks for the patch! LGTM.

it will translate any REPACK command into one of these other two.

If we apply the proposed patch, at the same moment, personally I'd like to
update this description of pg_stat_progress_cluster.command in the docs
so that it clearly explains how REPACK is translated. How about:

it will translate a REPACK command into CLUSTER if index ordering
is requested,
or VACUUM FULL otherwise.

Yes, that makes sense. I added integrated your suggestion into the patch.

PFA v2:

* 0001 - unchanged from v1-0001
* 0002 - the previous diff plus integrating Fujii-san suggested doc change

Best regards,
--
Chao Li (Evan)
HighGo Software Co., Ltd.
https://www.highgo.com/

Attachments:

t253656_5
v2-0001-Don-t-report-CLUSTER-for-a-redacted-progress-row.patchapplication/octet-stream; name=v2-0001-Don-t-report-CLUSTER-for-a-redacted-progress-row.patch; x-unix-mode=0644Download+6-5
v2-0002-Fix-command-reporting-for-REPACK-using-sequential.patchapplication/octet-stream; name=v2-0002-Fix-command-reporting-for-REPACK-using-sequential.patch; x-unix-mode=0644Download+16-18
#6Zsolt Parragi
zsolt.parragi@percona.com
In reply to: Chao Li (#5)
Re: pg_stat_progress_cluster: do not default to CLUSTER

Yes, this is also a good catch/improvement, looks good to me.

#7Fujii Masao
masao.fujii@gmail.com
In reply to: Zsolt Parragi (#6)
Re: pg_stat_progress_cluster: do not default to CLUSTER

On Wed, Sep 9, 2026 at 6:47 PM Zsolt Parragi <zsolt.parragi@percona.com> wrote:

Yes, this is also a good catch/improvement, looks good to me.

I've pushed the patches. Thanks!

Regards,

--
Fujii Masao