Re: Allow progress tracking of sub-commands

From: Antonin Houska <ah(at)cybertec(dot)at>
To: Manu <manuelreyesbravo(at)gmail(dot)com>
Cc: Alberto Piai <alberto(dot)piai(at)gmail(dot)com>, Rahila Syed <rahilasyed90(at)gmail(dot)com>, Fujii Masao <masao(dot)fujii(at)gmail(dot)com>, alvherre(at)kurilemu(dot)de, pgsql-hackers(at)lists(dot)postgresql(dot)org, bharath(dot)rupireddyforpostgres(at)gmail(dot)com, mihailnikalayeu(at)gmail(dot)com, adam8157(at)gmail(dot)com
Subject: Re: Allow progress tracking of sub-commands
Date: 2026-11-23 18:29:37
Message-ID: 113403.1795458577@chrudos
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Manu <manuelreyesbravo(at)gmail(dot)com> wrote:

> On Fri, Nov 13, 2026 at 7:35 PM Antonin Houska <ah(at)cybertec(dot)at> wrote:
> > In [1] I tried a different approach: only the progress of the actually running
> > command is displayed, while there's no limit on the nesting level. What do you
> > think about that?
>
> The stack works until an error hits a nested command.

Thanks for finding this problem. v03 should handle errors in file_fdw
correctly.

> But when a COPY fails under another COPY, or a PL/pgSQL block catches a
> COPY's error, a COPY row stays and hides a later CREATE INDEX
> (indexcmds.c:646). AbortTransaction() ends one level (xact.c:2910);
> pgstat_progress_depth() skips the running command and returns 0 with one
> parent (backend_progress.c:260), so the subtransaction abort ends
> nothing (xact.c:5370).

Likewise, error handling fixed in v03.

> 10,000 COPYs failing under another COPY added
> 2.7 MB to TopMemoryContext. Counting the running command and ending all
> levels on abort fixed both (make check passes).

Not sure the number of tests/failures matters. LLM?

> On hiding the parent: during REPACK of a 2M-row table with three
> indexes, pg_stat_progress_repack had no row in 80-90% of the samples
> (master: under 3%); pg_stat_progress_create_index showed REINDEX on
> that table. Same for CLUSTER and VACUUM FULL.

v03 shows the the inner-most command as well as the outer-most one. Anything
in between is not displayed. For more information please see the commit
message of v03-0001.

I considered the stack approach proposed by Alberto [1], where a sub-command
is ignored if its nested too deeply, but I realized that it wouldn't work. The
problem is that some commands (mis)use the progress monitoring infrastructure
to get information for their own purposes, e.g. this in analyze.c:

/*
* We bypass the changecount mechanism because this value is
* only updated by the calling process.
*/
appendStringInfo(&buf, _("delay time: %.3f ms\n"),
(double) MyBEEntry->st_progress.param[PROGRESS_ANALYZE_DELAY_TIME] / 1000000.0);

Thanks.

[1] https://www.postgresql.org/message-id/DK5EWY6GK6Q8.1LPLR26F3RDWA%40gmail.com

--
Antonin Houska
Web: https://www.cybertec-postgresql.com

Attachment Content-Type Size
v03-0001-Allow-progress-tracking-of-sub-commands.patch application/mbox 48.5 KB
v03-0002-Do-not-report-progress-of-two-or-more-COPY-commands-.patch application/mbox 5.6 KB

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Nathan Bossart 2026-11-23 18:33:09 Re: pg_restore fails on extracted tar archives with large objects
Previous Message Fabrice Chapuis 2026-11-23 16:50:53 unidirectional logical replication logging issue