Skip to content

Commit da47e43

Browse files
committed
Fix progress reporting of CLUSTER / VACUUM FULL
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 03f9e5c, 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
1 parent 6eb9b20 commit da47e43

File tree

3 files changed

+18
-11
lines changed

3 files changed

+18
-11
lines changed

src/backend/catalog/index.c

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3328,6 +3328,7 @@ reindex_index(Oid indexId, bool skip_constraint_checks, char persistence,
33283328
IndexInfo *indexInfo;
33293329
volatile bool skipped_constraint = false;
33303330
PGRUsage ru0;
3331+
bool progress = (options & REINDEXOPT_REPORT_PROGRESS) != 0;
33313332

33323333
pg_rusage_init(&ru0);
33333334

@@ -3338,21 +3339,25 @@ reindex_index(Oid indexId, bool skip_constraint_checks, char persistence,
33383339
heapId = IndexGetRelation(indexId, false);
33393340
heapRelation = table_open(heapId, ShareLock);
33403341

3341-
pgstat_progress_start_command(PROGRESS_COMMAND_CREATE_INDEX,
3342-
heapId);
3343-
pgstat_progress_update_param(PROGRESS_CREATEIDX_COMMAND,
3344-
PROGRESS_CREATEIDX_COMMAND_REINDEX);
3345-
pgstat_progress_update_param(PROGRESS_CREATEIDX_INDEX_OID,
3346-
indexId);
3342+
if (progress)
3343+
{
3344+
pgstat_progress_start_command(PROGRESS_COMMAND_CREATE_INDEX,
3345+
heapId);
3346+
pgstat_progress_update_param(PROGRESS_CREATEIDX_COMMAND,
3347+
PROGRESS_CREATEIDX_COMMAND_REINDEX);
3348+
pgstat_progress_update_param(PROGRESS_CREATEIDX_INDEX_OID,
3349+
indexId);
3350+
}
33473351

33483352
/*
33493353
* Open the target index relation and get an exclusive lock on it, to
33503354
* ensure that no one else is touching this particular index.
33513355
*/
33523356
iRel = index_open(indexId, AccessExclusiveLock);
33533357

3354-
pgstat_progress_update_param(PROGRESS_CREATEIDX_ACCESS_METHOD_OID,
3355-
iRel->rd_rel->relam);
3358+
if (progress)
3359+
pgstat_progress_update_param(PROGRESS_CREATEIDX_ACCESS_METHOD_OID,
3360+
iRel->rd_rel->relam);
33563361

33573362
/*
33583363
* The case of reindexing partitioned tables and indexes is handled
@@ -3505,7 +3510,8 @@ reindex_index(Oid indexId, bool skip_constraint_checks, char persistence,
35053510
errdetail_internal("%s",
35063511
pg_rusage_show(&ru0))));
35073512

3508-
pgstat_progress_end_command();
3513+
if (progress)
3514+
pgstat_progress_end_command();
35093515

35103516
/* Close rels, but keep locks */
35113517
index_close(iRel, NoLock);

src/backend/commands/indexcmds.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2454,7 +2454,7 @@ ReindexTable(RangeVar *relation, int options, bool concurrent)
24542454
result = reindex_relation(heapOid,
24552455
REINDEX_REL_PROCESS_TOAST |
24562456
REINDEX_REL_CHECK_CONSTRAINTS,
2457-
options);
2457+
options | REINDEXOPT_REPORT_PROGRESS);
24582458
if (!result)
24592459
ereport(NOTICE,
24602460
(errmsg("table \"%s\" has no indexes to reindex",
@@ -2658,7 +2658,7 @@ ReindexMultipleTables(const char *objectName, ReindexObjectType objectKind,
26582658
result = reindex_relation(relid,
26592659
REINDEX_REL_PROCESS_TOAST |
26602660
REINDEX_REL_CHECK_CONSTRAINTS,
2661-
options);
2661+
options | REINDEXOPT_REPORT_PROGRESS);
26622662

26632663
if (result && (options & REINDEXOPT_VERBOSE))
26642664
ereport(INFO,

src/include/nodes/parsenodes.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3301,6 +3301,7 @@ typedef struct ConstraintsSetStmt
33013301

33023302
/* Reindex options */
33033303
#define REINDEXOPT_VERBOSE 1 << 0 /* print progress info */
3304+
#define REINDEXOPT_REPORT_PROGRESS 1 << 1 /* report pgstat progress */
33043305

33053306
typedef enum ReindexObjectType
33063307
{

0 commit comments

Comments
 (0)