diff options
author | Peter Eisentraut | 2008-11-24 08:46:04 +0000 |
---|---|---|
committer | Peter Eisentraut | 2008-11-24 08:46:04 +0000 |
commit | 0d0e3d12193991707b392f2060503e513334f1d9 (patch) | |
tree | 82169ecf198c6cc369f5bc4324b1691429db4d24 | |
parent | 6b66d7ee8b890e51feba79a51997b8929786b59b (diff) |
CLUSTER VERBOSE and corresponding clusterdb --verbose option
Jim Cox and Peter Eisentraut
-rw-r--r-- | doc/src/sgml/ref/cluster.sgml | 13 | ||||
-rw-r--r-- | doc/src/sgml/ref/clusterdb.sgml | 12 | ||||
-rw-r--r-- | src/backend/commands/cluster.c | 12 | ||||
-rw-r--r-- | src/backend/nodes/copyfuncs.c | 1 | ||||
-rw-r--r-- | src/backend/nodes/equalfuncs.c | 1 | ||||
-rw-r--r-- | src/backend/parser/gram.y | 23 | ||||
-rw-r--r-- | src/bin/scripts/clusterdb.c | 24 | ||||
-rw-r--r-- | src/include/nodes/parsenodes.h | 1 |
8 files changed, 63 insertions, 24 deletions
diff --git a/doc/src/sgml/ref/cluster.sgml b/doc/src/sgml/ref/cluster.sgml index 1a5f212f55..a067725aaa 100644 --- a/doc/src/sgml/ref/cluster.sgml +++ b/doc/src/sgml/ref/cluster.sgml @@ -21,8 +21,8 @@ PostgreSQL documentation <refsynopsisdiv> <synopsis> -CLUSTER <replaceable class="PARAMETER">tablename</replaceable> [ USING <replaceable class="PARAMETER">indexname</replaceable> ] -CLUSTER +CLUSTER [VERBOSE] <replaceable class="PARAMETER">tablename</replaceable> [ USING <replaceable class="PARAMETER">indexname</replaceable> ] +CLUSTER [VERBOSE] </synopsis> </refsynopsisdiv> @@ -95,6 +95,15 @@ CLUSTER </para> </listitem> </varlistentry> + + <varlistentry> + <term><literal>VERBOSE</literal></term> + <listitem> + <para> + Prints a progress report as each table is clustered. + </para> + </listitem> + </varlistentry> </variablelist> </refsect1> diff --git a/doc/src/sgml/ref/clusterdb.sgml b/doc/src/sgml/ref/clusterdb.sgml index 56266dc1af..31950c94ca 100644 --- a/doc/src/sgml/ref/clusterdb.sgml +++ b/doc/src/sgml/ref/clusterdb.sgml @@ -23,12 +23,14 @@ PostgreSQL documentation <cmdsynopsis> <command>clusterdb</command> <arg rep="repeat"><replaceable>connection-option</replaceable></arg> + <group><arg>--verbose</arg><arg>-v</arg></group> <arg>--table | -t <replaceable>table</replaceable> </arg> <arg><replaceable>dbname</replaceable></arg> <sbr> <command>clusterdb</command> <arg rep="repeat"><replaceable>connection-option</replaceable></arg> <group><arg>--all</arg><arg>-a</arg></group> + <group><arg>--verbose</arg><arg>-v</arg></group> </cmdsynopsis> </refsynopsisdiv> @@ -117,6 +119,16 @@ PostgreSQL documentation </listitem> </varlistentry> + <varlistentry> + <term><option>-v</></term> + <term><option>--verbose</></term> + <listitem> + <para> + Print detailed information during processing. + </para> + </listitem> + </varlistentry> + </variablelist> </para> diff --git a/src/backend/commands/cluster.c b/src/backend/commands/cluster.c index d482ffbd8a..456616c18e 100644 --- a/src/backend/commands/cluster.c +++ b/src/backend/commands/cluster.c @@ -61,7 +61,7 @@ typedef struct } RelToCluster; -static void cluster_rel(RelToCluster *rv, bool recheck); +static void cluster_rel(RelToCluster *rv, bool recheck, bool verbose); static void rebuild_relation(Relation OldHeap, Oid indexOid); static TransactionId copy_heap_data(Oid OIDNewHeap, Oid OIDOldHeap, Oid OIDOldIndex); static List *get_tables_to_cluster(MemoryContext cluster_context); @@ -177,7 +177,7 @@ cluster(ClusterStmt *stmt, bool isTopLevel) heap_close(rel, NoLock); /* Do the job */ - cluster_rel(&rvtc, false); + cluster_rel(&rvtc, false, stmt->verbose); } else { @@ -226,7 +226,7 @@ cluster(ClusterStmt *stmt, bool isTopLevel) StartTransactionCommand(); /* functions in indexes may want a snapshot set */ PushActiveSnapshot(GetTransactionSnapshot()); - cluster_rel(rvtc, true); + cluster_rel(rvtc, true, stmt->verbose); PopActiveSnapshot(); CommitTransactionCommand(); } @@ -254,7 +254,7 @@ cluster(ClusterStmt *stmt, bool isTopLevel) * them incrementally while we load the table. */ static void -cluster_rel(RelToCluster *rvtc, bool recheck) +cluster_rel(RelToCluster *rvtc, bool recheck, bool verbose) { Relation OldHeap; @@ -344,6 +344,10 @@ cluster_rel(RelToCluster *rvtc, bool recheck) check_index_is_clusterable(OldHeap, rvtc->indexOid, recheck); /* rebuild_relation does all the dirty work */ + ereport(verbose ? INFO : DEBUG2, + (errmsg("clustering \"%s.%s\"", + get_namespace_name(RelationGetNamespace(OldHeap)), + RelationGetRelationName(OldHeap)))); rebuild_relation(OldHeap, rvtc->indexOid); /* NB: rebuild_relation does heap_close() on OldHeap */ diff --git a/src/backend/nodes/copyfuncs.c b/src/backend/nodes/copyfuncs.c index fde5203ef4..eb7ab4d666 100644 --- a/src/backend/nodes/copyfuncs.c +++ b/src/backend/nodes/copyfuncs.c @@ -2293,6 +2293,7 @@ _copyClusterStmt(ClusterStmt *from) COPY_NODE_FIELD(relation); COPY_STRING_FIELD(indexname); + COPY_SCALAR_FIELD(verbose) ; return newnode; } diff --git a/src/backend/nodes/equalfuncs.c b/src/backend/nodes/equalfuncs.c index 0da3fb40af..d4c57bbacf 100644 --- a/src/backend/nodes/equalfuncs.c +++ b/src/backend/nodes/equalfuncs.c @@ -1032,6 +1032,7 @@ _equalClusterStmt(ClusterStmt *a, ClusterStmt *b) { COMPARE_NODE_FIELD(relation); COMPARE_STRING_FIELD(indexname); + COMPARE_SCALAR_FIELD(verbose); return true; } diff --git a/src/backend/parser/gram.y b/src/backend/parser/gram.y index d0f4993307..244df3b313 100644 --- a/src/backend/parser/gram.y +++ b/src/backend/parser/gram.y @@ -5781,33 +5781,36 @@ CreateConversionStmt: /***************************************************************************** * * QUERY: - * CLUSTER <qualified_name> [ USING <index_name> ] - * CLUSTER - * CLUSTER <index_name> ON <qualified_name> (for pre-8.3) + * CLUSTER [VERBOSE] <qualified_name> [ USING <index_name> ] + * CLUSTER [VERBOSE] + * CLUSTER [VERBOSE] <index_name> ON <qualified_name> (for pre-8.3) * *****************************************************************************/ ClusterStmt: - CLUSTER qualified_name cluster_index_specification + CLUSTER opt_verbose qualified_name cluster_index_specification { ClusterStmt *n = makeNode(ClusterStmt); - n->relation = $2; - n->indexname = $3; + n->relation = $3; + n->indexname = $4; + n->verbose = $2; $$ = (Node*)n; } - | CLUSTER + | CLUSTER opt_verbose { ClusterStmt *n = makeNode(ClusterStmt); n->relation = NULL; n->indexname = NULL; + n->verbose = $2; $$ = (Node*)n; } /* kept for pre-8.3 compatibility */ - | CLUSTER index_name ON qualified_name + | CLUSTER opt_verbose index_name ON qualified_name { ClusterStmt *n = makeNode(ClusterStmt); - n->relation = $4; - n->indexname = $2; + n->relation = $5; + n->indexname = $3; + n->verbose = $2; $$ = (Node*)n; } ; diff --git a/src/bin/scripts/clusterdb.c b/src/bin/scripts/clusterdb.c index e96b25f1e4..052a961d3e 100644 --- a/src/bin/scripts/clusterdb.c +++ b/src/bin/scripts/clusterdb.c @@ -14,11 +14,11 @@ #include "dumputils.h" -static void cluster_one_database(const char *dbname, const char *table, +static void cluster_one_database(const char *dbname, bool verbose, const char *table, const char *host, const char *port, const char *username, bool password, const char *progname, bool echo); -static void cluster_all_databases(const char *host, const char *port, +static void cluster_all_databases(bool verbose, const char *host, const char *port, const char *username, bool password, const char *progname, bool echo, bool quiet); @@ -38,6 +38,7 @@ main(int argc, char *argv[]) {"dbname", required_argument, NULL, 'd'}, {"all", no_argument, NULL, 'a'}, {"table", required_argument, NULL, 't'}, + {"verbose", no_argument, NULL, 'v'}, {NULL, 0, NULL, 0} }; @@ -54,13 +55,14 @@ main(int argc, char *argv[]) bool quiet = false; bool alldb = false; char *table = NULL; + bool verbose = false; progname = get_progname(argv[0]); set_pglocale_pgservice(argv[0], "pgscripts"); handle_help_version_opts(argc, argv, "clusterdb", help); - while ((c = getopt_long(argc, argv, "h:p:U:Weqd:at:", long_options, &optindex)) != -1) + while ((c = getopt_long(argc, argv, "h:p:U:Weqd:at:v", long_options, &optindex)) != -1) { switch (c) { @@ -91,6 +93,9 @@ main(int argc, char *argv[]) case 't': table = optarg; break; + case 'v': + verbose = true; + break; default: fprintf(stderr, _("Try \"%s --help\" for more information.\n"), progname); exit(1); @@ -128,7 +133,7 @@ main(int argc, char *argv[]) exit(1); } - cluster_all_databases(host, port, username, password, + cluster_all_databases(verbose, host, port, username, password, progname, echo, quiet); } else @@ -143,7 +148,7 @@ main(int argc, char *argv[]) dbname = get_user_name(progname); } - cluster_one_database(dbname, table, + cluster_one_database(dbname, verbose, table, host, port, username, password, progname, echo); } @@ -153,7 +158,7 @@ main(int argc, char *argv[]) static void -cluster_one_database(const char *dbname, const char *table, +cluster_one_database(const char *dbname, bool verbose, const char *table, const char *host, const char *port, const char *username, bool password, const char *progname, bool echo) @@ -165,6 +170,8 @@ cluster_one_database(const char *dbname, const char *table, initPQExpBuffer(&sql); appendPQExpBuffer(&sql, "CLUSTER"); + if (verbose) + appendPQExpBuffer(&sql, " VERBOSE"); if (table) appendPQExpBuffer(&sql, " %s", fmtId(table)); appendPQExpBuffer(&sql, ";\n"); @@ -187,7 +194,7 @@ cluster_one_database(const char *dbname, const char *table, static void -cluster_all_databases(const char *host, const char *port, +cluster_all_databases(bool verbose, const char *host, const char *port, const char *username, bool password, const char *progname, bool echo, bool quiet) { @@ -209,7 +216,7 @@ cluster_all_databases(const char *host, const char *port, fflush(stdout); } - cluster_one_database(dbname, NULL, + cluster_one_database(dbname, verbose, NULL, host, port, username, password, progname, echo); } @@ -230,6 +237,7 @@ help(const char *progname) printf(_(" -t, --table=TABLE cluster specific table only\n")); printf(_(" -e, --echo show the commands being sent to the server\n")); printf(_(" -q, --quiet don't write any messages\n")); + printf(_(" -v, --verbose write a lot of output\n")); printf(_(" --help show this help, then exit\n")); printf(_(" --version output version information, then exit\n")); printf(_("\nConnection options:\n")); diff --git a/src/include/nodes/parsenodes.h b/src/include/nodes/parsenodes.h index fff7379c7f..bb71ac199d 100644 --- a/src/include/nodes/parsenodes.h +++ b/src/include/nodes/parsenodes.h @@ -1949,6 +1949,7 @@ typedef struct ClusterStmt NodeTag type; RangeVar *relation; /* relation being indexed, or NULL if all */ char *indexname; /* original index defined */ + bool verbose; /* print progress info */ } ClusterStmt; /* ---------------------- |