From f41da096b1f36118917fe345e2a6fc89530a40c9 Mon Sep 17 00:00:00 2001 From: Matthias van de Meent Date: Thu, 24 Sep 2020 20:41:10 +0200 Subject: [PATCH] Report the active index for reindex table concurrently The pgstat_progress reporting for the multi-index path of reindexing failed to set the index and relation OIDs correctly for various stages, which resulted in a pg_stat_progress_create_index view that did not accurately represent the index that the progress was being reported on. This commit tags the correct index and relation for each of the concurrent index creation stages. Signed-off-by: Matthias van de Meent --- src/backend/commands/indexcmds.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/backend/commands/indexcmds.c b/src/backend/commands/indexcmds.c index f1b5f87e6a..b2f04012a4 100644 --- a/src/backend/commands/indexcmds.c +++ b/src/backend/commands/indexcmds.c @@ -3431,6 +3431,15 @@ ReindexRelationConcurrently(Oid relationOid, int options) heapId = indexRel->rd_index->indrelid; index_close(indexRel, NoLock); + /* + * Configure progress reporting to report for this index. + * While we're at it, reset the phase as it is cleared by start_command. + */ + pgstat_progress_start_command(PROGRESS_COMMAND_CREATE_INDEX, heapId); + pgstat_progress_update_param(PROGRESS_CREATEIDX_INDEX_OID, newIndexId); + pgstat_progress_update_param(PROGRESS_CREATEIDX_PHASE, + PROGRESS_CREATEIDX_PHASE_WAIT_1); + /* Perform concurrent build of new index */ index_concurrently_build(heapId, newIndexId); @@ -3477,6 +3486,15 @@ ReindexRelationConcurrently(Oid relationOid, int options) snapshot = RegisterSnapshot(GetTransactionSnapshot()); PushActiveSnapshot(snapshot); + /* + * Configure progress reporting to report for this index. + * While we're at it, reset the phase as it is cleared by start_command. + */ + pgstat_progress_start_command(PROGRESS_COMMAND_CREATE_INDEX, heapId); + pgstat_progress_update_param(PROGRESS_CREATEIDX_INDEX_OID, newIndexId); + pgstat_progress_update_param(PROGRESS_CREATEIDX_PHASE, + PROGRESS_CREATEIDX_PHASE_WAIT_2); + validate_index(heapId, newIndexId, snapshot); /* -- 2.20.1