From fdb07aaa082580433046e184b2c0d6b470862786 Mon Sep 17 00:00:00 2001 From: Lukas Fittl Date: Sat, 31 Oct 2026 11:32:49 -0700 Subject: [PATCH v2 1/5] Fix query ID reporting in parallel workers for GIN index builds Commit 6fd5071909a made parallel workers for VACUUM, BRIN and btree index builds report the query ID of the leader, so that they show up with the correct query_id in pg_stat_activity. Parallel GIN index builds were added later by 8492feb98f6, but did not include this, so GIN build workers have always reported a query ID of 0. Fix by storing the leader's query ID in the shared build state and reporting it in the worker, like the other index AMs already do. Author: Lukas Fittl Discussion: https://postgr.es/m/CAP53Pkw3WcVbg61G29AmN=6XkuxGryoWKnhTyC1JmkT08i8qVA@mail.gmail.com --- src/backend/access/gin/gininsert.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/backend/access/gin/gininsert.c b/src/backend/access/gin/gininsert.c index 564b1509f1b..cbfaa5075b0 100644 --- a/src/backend/access/gin/gininsert.c +++ b/src/backend/access/gin/gininsert.c @@ -64,6 +64,9 @@ typedef struct GinBuildShared bool isconcurrent; int scantuplesortstates; + /* Query ID, for report in worker processes */ + int64 queryid; + /* * workersdonecv is used to monitor the progress of workers. All parallel * participants must indicate that they are done before leader can use @@ -1031,6 +1034,7 @@ _gin_begin_parallel(GinBuildState *buildstate, Relation heap, Relation index, ginshared->indexrelid = RelationGetRelid(index); ginshared->isconcurrent = isconcurrent; ginshared->scantuplesortstates = scantuplesortstates; + ginshared->queryid = pgstat_get_my_query_id(); ConditionVariableInit(&ginshared->workersdonecv); SpinLockInit(&ginshared->mutex); @@ -2145,6 +2149,9 @@ _gin_parallel_build_main(dsm_segment *seg, shm_toc *toc) indexLockmode = RowExclusiveLock; } + /* Track query ID */ + pgstat_report_query_id(ginshared->queryid, false); + /* Open relations within worker */ heapRel = table_open(ginshared->heaprelid, heapLockmode); indexRel = index_open(ginshared->indexrelid, indexLockmode); -- 2.47.1