summaryrefslogtreecommitdiff
path: root/src/backend/catalog
diff options
context:
space:
mode:
authorFujii Masao <fujii@postgresql.org>2015-05-15 20:09:57 +0900
committerFujii Masao <fujii@postgresql.org>2015-05-15 20:09:57 +0900
commitecd222e770d352121590363ffdf981147a43e976 (patch)
tree9fa6f9d3ad7002f5d8ced9948d49b72206bad713 /src/backend/catalog
parent4b8f797f672bef07b4e87b4650b4035731b61d84 (diff)
downloadpostgresql-ecd222e770d352121590363ffdf981147a43e976.tar.gz
Support VERBOSE option in REINDEX command.
When this option is specified, a progress report is printed as each index is reindexed. Per discussion, we agreed on the following syntax for the extensibility of the options. REINDEX (flexible options) { INDEX | ... } name Sawada Masahiko. Reviewed by Robert Haas, Fabrízio Mello, Alvaro Herrera, Kyotaro Horiguchi, Jim Nasby and me. Discussion: CAD21AoA0pK3YcOZAFzMae+2fcc3oGp5zoRggDyMNg5zoaWDhdQ@mail.gmail.com
Diffstat (limited to 'src/backend/catalog')
-rw-r--r--src/backend/catalog/index.c21
1 files changed, 17 insertions, 4 deletions
diff --git a/src/backend/catalog/index.c b/src/backend/catalog/index.c
index 8c8a9eafee..bac9fbe7eb 100644
--- a/src/backend/catalog/index.c
+++ b/src/backend/catalog/index.c
@@ -63,6 +63,7 @@
#include "utils/inval.h"
#include "utils/lsyscache.h"
#include "utils/memutils.h"
+#include "utils/pg_rusage.h"
#include "utils/syscache.h"
#include "utils/tuplesort.h"
#include "utils/snapmgr.h"
@@ -3184,13 +3185,17 @@ IndexGetRelation(Oid indexId, bool missing_ok)
* reindex_index - This routine is used to recreate a single index
*/
void
-reindex_index(Oid indexId, bool skip_constraint_checks, char persistence)
+reindex_index(Oid indexId, bool skip_constraint_checks, char persistence,
+ int options)
{
Relation iRel,
heapRelation;
Oid heapId;
IndexInfo *indexInfo;
volatile bool skipped_constraint = false;
+ PGRUsage ru0;
+
+ pg_rusage_init(&ru0);
/*
* Open and lock the parent heap relation. ShareLock is sufficient since
@@ -3334,6 +3339,14 @@ reindex_index(Oid indexId, bool skip_constraint_checks, char persistence)
heap_close(pg_index, RowExclusiveLock);
}
+ /* Log what we did */
+ if (options & REINDEXOPT_VERBOSE)
+ ereport(INFO,
+ (errmsg("index \"%s\" was reindexed",
+ get_rel_name(indexId)),
+ errdetail("%s.",
+ pg_rusage_show(&ru0))));
+
/* Close rels, but keep locks */
index_close(iRel, NoLock);
heap_close(heapRelation, NoLock);
@@ -3375,7 +3388,7 @@ reindex_index(Oid indexId, bool skip_constraint_checks, char persistence)
* index rebuild.
*/
bool
-reindex_relation(Oid relid, int flags)
+reindex_relation(Oid relid, int flags, int options)
{
Relation rel;
Oid toast_relid;
@@ -3466,7 +3479,7 @@ reindex_relation(Oid relid, int flags)
RelationSetIndexList(rel, doneIndexes, InvalidOid);
reindex_index(indexOid, !(flags & REINDEX_REL_CHECK_CONSTRAINTS),
- persistence);
+ persistence, options);
CommandCounterIncrement();
@@ -3501,7 +3514,7 @@ reindex_relation(Oid relid, int flags)
* still hold the lock on the master table.
*/
if ((flags & REINDEX_REL_PROCESS_TOAST) && OidIsValid(toast_relid))
- result |= reindex_relation(toast_relid, flags);
+ result |= reindex_relation(toast_relid, flags, options);
return result;
}