From 6212276e4343f729b0152e81824f850d1a21d57e Mon Sep 17 00:00:00 2001 From: Alvaro Herrera Date: Fri, 13 Sep 2019 14:51:13 -0300 Subject: [PATCH] Fix progress reporting of CLUSTER / VACUUM FULL MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit The progress state was being clobbered once the first index completed being rebuilt, causing the final phases of the operation not show anything in the progress view. This was inadvertently broken in 03f9e5cba0ee, which added progress tracking for REINDEX. (The reason this bugfix is this small is that I had already noticed this problem when writing monitoring for CREATE INDEX, and had already worked around it, as can be seen in discussion starting at https://postgr.es/m/20190329150218.GA25010@alvherre.pgsql Fixing the problem is just a matter of fixing one place touched by the REINDEX monitoring.) Reported by: Álvaro Herrera Author: Álvaro Herrera Discussion: https://postgr.es/m/20190801184333.GA21369@alvherre.pgsql --- src/backend/catalog/index.c | 24 +++++++++++++++--------- src/backend/commands/indexcmds.c | 4 ++-- src/include/nodes/parsenodes.h | 1 + 3 files changed, 18 insertions(+), 11 deletions(-) diff --git a/src/backend/catalog/index.c b/src/backend/catalog/index.c index 3e1d40662d..54288a498c 100644 --- a/src/backend/catalog/index.c +++ b/src/backend/catalog/index.c @@ -3306,6 +3306,7 @@ reindex_index(Oid indexId, bool skip_constraint_checks, char persistence, IndexInfo *indexInfo; volatile bool skipped_constraint = false; PGRUsage ru0; + bool progress = (options & REINDEXOPT_REPORT_PROGRESS) != 0; pg_rusage_init(&ru0); @@ -3316,12 +3317,15 @@ reindex_index(Oid indexId, bool skip_constraint_checks, char persistence, heapId = IndexGetRelation(indexId, false); heapRelation = table_open(heapId, ShareLock); - pgstat_progress_start_command(PROGRESS_COMMAND_CREATE_INDEX, - heapId); - pgstat_progress_update_param(PROGRESS_CREATEIDX_COMMAND, - PROGRESS_CREATEIDX_COMMAND_REINDEX); - pgstat_progress_update_param(PROGRESS_CREATEIDX_INDEX_OID, - indexId); + if (progress) + { + pgstat_progress_start_command(PROGRESS_COMMAND_CREATE_INDEX, + heapId); + pgstat_progress_update_param(PROGRESS_CREATEIDX_COMMAND, + PROGRESS_CREATEIDX_COMMAND_REINDEX); + pgstat_progress_update_param(PROGRESS_CREATEIDX_INDEX_OID, + indexId); + } /* * Open the target index relation and get an exclusive lock on it, to @@ -3329,8 +3333,9 @@ reindex_index(Oid indexId, bool skip_constraint_checks, char persistence, */ iRel = index_open(indexId, AccessExclusiveLock); - pgstat_progress_update_param(PROGRESS_CREATEIDX_ACCESS_METHOD_OID, - iRel->rd_rel->relam); + if (progress) + pgstat_progress_update_param(PROGRESS_CREATEIDX_ACCESS_METHOD_OID, + iRel->rd_rel->relam); /* * The case of reindexing partitioned tables and indexes is handled @@ -3483,7 +3488,8 @@ reindex_index(Oid indexId, bool skip_constraint_checks, char persistence, errdetail_internal("%s", pg_rusage_show(&ru0)))); - pgstat_progress_end_command(); + if (progress) + pgstat_progress_end_command(); /* Close rels, but keep locks */ index_close(iRel, NoLock); diff --git a/src/backend/commands/indexcmds.c b/src/backend/commands/indexcmds.c index 147775558c..d7c1e1c93f 100644 --- a/src/backend/commands/indexcmds.c +++ b/src/backend/commands/indexcmds.c @@ -2453,7 +2453,7 @@ ReindexTable(RangeVar *relation, int options, bool concurrent) result = reindex_relation(heapOid, REINDEX_REL_PROCESS_TOAST | REINDEX_REL_CHECK_CONSTRAINTS, - options); + options | REINDEXOPT_REPORT_PROGRESS); if (!result) ereport(NOTICE, (errmsg("table \"%s\" has no indexes to reindex", @@ -2657,7 +2657,7 @@ ReindexMultipleTables(const char *objectName, ReindexObjectType objectKind, result = reindex_relation(relid, REINDEX_REL_PROCESS_TOAST | REINDEX_REL_CHECK_CONSTRAINTS, - options); + options | REINDEXOPT_REPORT_PROGRESS); if (result && (options & REINDEXOPT_VERBOSE)) ereport(INFO, diff --git a/src/include/nodes/parsenodes.h b/src/include/nodes/parsenodes.h index f21ff8028a..bb931b2cac 100644 --- a/src/include/nodes/parsenodes.h +++ b/src/include/nodes/parsenodes.h @@ -3313,6 +3313,7 @@ typedef struct ConstraintsSetStmt /* Reindex options */ #define REINDEXOPT_VERBOSE 1 << 0 /* print progress info */ +#define REINDEXOPT_REPORT_PROGRESS 1 << 1 /* report pgstat progress */ typedef enum ReindexObjectType { -- 2.40.0