]> granicus.if.org Git - postgresql/commitdiff
Fix progress reporting of CLUSTER / VACUUM FULL
authorAlvaro Herrera <alvherre@alvh.no-ip.org>
Fri, 13 Sep 2019 17:51:13 +0000 (14:51 -0300)
committerAlvaro Herrera <alvherre@alvh.no-ip.org>
Fri, 13 Sep 2019 17:54:26 +0000 (14:54 -0300)
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
src/backend/commands/indexcmds.c
src/include/nodes/parsenodes.h

index 3e1d40662d13677370d253fbe2eb896310442613..54288a498c1057606d6d56aed10bad5e6940fecb 100644 (file)
@@ -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);
index 147775558c1390e6c6c18cd57b096010f646748b..d7c1e1c93f8c951f464c961375093091e01fa06f 100644 (file)
@@ -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,
index f21ff8028a1924e7005347a5fc0027188ad8e5c8..bb931b2cacf5fed64f95bc5b3ffd33799a595c3e 100644 (file)
@@ -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
 {