| From: | Adam Lee <adam8157(at)gmail(dot)com> |
|---|---|
| To: | Manu <manuelreyesbravo(at)gmail(dot)com> |
| Cc: | Antonin Houska <ah(at)cybertec(dot)at>, 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 |
| Subject: | Re: Allow progress tracking of sub-commands |
| Date: | 2026-11-25 11:05:39 |
| Message-ID: | CABAGCCqr4S1V4JsAUX4tYjTi0DpGKiqejqs6=FgpxMiebCk-3Q@mail.gmail.com |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-hackers |
Hi Antonin,
Thanks for Cc-ing me. I tested and found two problems.
1. The progress row stays after CREATE INDEX CONCURRENTLY and REINDEX
CONCURRENTLY.
CREATE TABLE h (a int, b text);
INSERT INTO h SELECT g, repeat('x', 10)
FROM generate_series(1, 20000) g;
CREATE INDEX CONCURRENTLY h_a ON h (a);
SELECT command, phase FROM pg_stat_progress_create_index
WHERE pid = pg_backend_pid();
command | phase
---------------------------+---------------------------
CREATE INDEX CONCURRENTLY | waiting for old snapshots
The command has finished, but the row is still there. In the same
session, a plain CREATE INDEX then updates this row and leaves it
behind again, and an error does not remove it:
CREATE INDEX h_b ON h (b);
SELECT 1/0;
SELECT command, phase FROM pg_stat_progress_create_index
WHERE pid = pg_backend_pid();
command | phase
---------------------------+----------------------------------------
CREATE INDEX CONCURRENTLY | building index: loading tuples in tree
In a new session, REINDEX TABLE CONCURRENTLY h leaves this row:
---------+-------------------------------------
| waiting for readers before dropping
And a CREATE UNIQUE INDEX CONCURRENTLY that fails on a duplicate key
leaves this one:
command | phase
---------------------------+-------------------------------------
CREATE INDEX CONCURRENTLY | building index: sorting live tuples
On master, all of these queries return no row.
These commands start the report in one transaction and end it in a
later one, and StartTransaction() resets progress_depth to 0. When I
remove that reset, none of the three cases leaves a row.
2. In a parallel BRIN build, the leader's row loses its command and
phase, and the workers get rows of their own.
CREATE TABLE big AS
SELECT g a, g % 97 b FROM generate_series(1, 4000000) g;
ALTER TABLE big SET (parallel_workers = 2);
SET max_parallel_maintenance_workers = 2;
SET min_parallel_table_scan_size = 0;
CREATE INDEX big_brin ON big USING brin (a);
I sampled pg_stat_progress_create_index from another session about
every 1 ms during the build, joined with pg_stat_activity.
master, 101 samples, all the same:
client backend CREATE INDEX building index
v03, 104 of 106 samples:
client backend command NULL initializing
parallel worker command NULL initializing
parallel worker command NULL initializing
The other 2 samples show "CREATE INDEX, building index" for the
leader. blocks_total and blocks_done still advance in the leader's
row.
--
Adam
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Tomas Vondra | 2026-11-25 11:11:00 | BRIN may be missing HOT-updated rows on old snapshots |
| Previous Message | Tomas Vondra | 2026-11-25 10:38:51 | Re: Unify parallel worker handling for index builds and instrumentation |