]> 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:51:13 +0000 (14:51 -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 795597b7e51413a20e4d4233f5040216d21e40fe..1dac2803b00f221a66c627400c3a325964eb669c 100644 (file)
@@ -3328,6 +3328,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);
 
@@ -3338,12 +3339,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
@@ -3351,8 +3355,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
@@ -3505,7 +3510,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 cbac31476c495927d09bd164dfd5b0a84bc917c8..d3824cd45a225ab49a006c14308b007906751331 100644 (file)
@@ -2454,7 +2454,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",
@@ -2658,7 +2658,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 94ded3c135ed8efea3b417820607bfeceb10ce22..c9c72ab94a6d9e3c654a2a91ec6fea24ba2ff422 100644 (file)
@@ -3301,6 +3301,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
 {