mirror of
https://git.postgresql.org/git/postgresql.git
synced 2025-02-23 19:39:53 +08:00
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
03f9e5cba0
, 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
This commit is contained in:
parent
eb57bd9c1d
commit
6212276e43
@ -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);
|
||||
|
@ -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,
|
||||
|
@ -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
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user