Commit a3785555 authored by Peter Eisentraut's avatar Peter Eisentraut

CLUSTER VERBOSE and corresponding clusterdb --verbose option

Jim Cox and Peter Eisentraut
parent 6f6a6d8b
<!-- <!--
$PostgreSQL: pgsql/doc/src/sgml/ref/cluster.sgml,v 1.45 2008/11/14 10:22:45 petere Exp $ $PostgreSQL: pgsql/doc/src/sgml/ref/cluster.sgml,v 1.46 2008/11/24 08:46:03 petere Exp $
PostgreSQL documentation PostgreSQL documentation
--> -->
...@@ -21,8 +21,8 @@ PostgreSQL documentation ...@@ -21,8 +21,8 @@ PostgreSQL documentation
<refsynopsisdiv> <refsynopsisdiv>
<synopsis> <synopsis>
CLUSTER <replaceable class="PARAMETER">tablename</replaceable> [ USING <replaceable class="PARAMETER">indexname</replaceable> ] CLUSTER [VERBOSE] <replaceable class="PARAMETER">tablename</replaceable> [ USING <replaceable class="PARAMETER">indexname</replaceable> ]
CLUSTER CLUSTER [VERBOSE]
</synopsis> </synopsis>
</refsynopsisdiv> </refsynopsisdiv>
...@@ -95,6 +95,15 @@ CLUSTER ...@@ -95,6 +95,15 @@ CLUSTER
</para> </para>
</listitem> </listitem>
</varlistentry> </varlistentry>
<varlistentry>
<term><literal>VERBOSE</literal></term>
<listitem>
<para>
Prints a progress report as each table is clustered.
</para>
</listitem>
</varlistentry>
</variablelist> </variablelist>
</refsect1> </refsect1>
......
<!-- <!--
$PostgreSQL: pgsql/doc/src/sgml/ref/clusterdb.sgml,v 1.23 2007/12/11 19:57:32 tgl Exp $ $PostgreSQL: pgsql/doc/src/sgml/ref/clusterdb.sgml,v 1.24 2008/11/24 08:46:03 petere Exp $
PostgreSQL documentation PostgreSQL documentation
--> -->
...@@ -23,12 +23,14 @@ PostgreSQL documentation ...@@ -23,12 +23,14 @@ PostgreSQL documentation
<cmdsynopsis> <cmdsynopsis>
<command>clusterdb</command> <command>clusterdb</command>
<arg rep="repeat"><replaceable>connection-option</replaceable></arg> <arg rep="repeat"><replaceable>connection-option</replaceable></arg>
<group><arg>--verbose</arg><arg>-v</arg></group>
<arg>--table | -t <replaceable>table</replaceable> </arg> <arg>--table | -t <replaceable>table</replaceable> </arg>
<arg><replaceable>dbname</replaceable></arg> <arg><replaceable>dbname</replaceable></arg>
<sbr> <sbr>
<command>clusterdb</command> <command>clusterdb</command>
<arg rep="repeat"><replaceable>connection-option</replaceable></arg> <arg rep="repeat"><replaceable>connection-option</replaceable></arg>
<group><arg>--all</arg><arg>-a</arg></group> <group><arg>--all</arg><arg>-a</arg></group>
<group><arg>--verbose</arg><arg>-v</arg></group>
</cmdsynopsis> </cmdsynopsis>
</refsynopsisdiv> </refsynopsisdiv>
...@@ -117,6 +119,16 @@ PostgreSQL documentation ...@@ -117,6 +119,16 @@ PostgreSQL documentation
</listitem> </listitem>
</varlistentry> </varlistentry>
<varlistentry>
<term><option>-v</></term>
<term><option>--verbose</></term>
<listitem>
<para>
Print detailed information during processing.
</para>
</listitem>
</varlistentry>
</variablelist> </variablelist>
</para> </para>
......
...@@ -11,7 +11,7 @@ ...@@ -11,7 +11,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/commands/cluster.c,v 1.178 2008/10/14 17:19:50 alvherre Exp $ * $PostgreSQL: pgsql/src/backend/commands/cluster.c,v 1.179 2008/11/24 08:46:03 petere Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -61,7 +61,7 @@ typedef struct ...@@ -61,7 +61,7 @@ typedef struct
} RelToCluster; } 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 void rebuild_relation(Relation OldHeap, Oid indexOid);
static TransactionId copy_heap_data(Oid OIDNewHeap, Oid OIDOldHeap, Oid OIDOldIndex); static TransactionId copy_heap_data(Oid OIDNewHeap, Oid OIDOldHeap, Oid OIDOldIndex);
static List *get_tables_to_cluster(MemoryContext cluster_context); static List *get_tables_to_cluster(MemoryContext cluster_context);
...@@ -177,7 +177,7 @@ cluster(ClusterStmt *stmt, bool isTopLevel) ...@@ -177,7 +177,7 @@ cluster(ClusterStmt *stmt, bool isTopLevel)
heap_close(rel, NoLock); heap_close(rel, NoLock);
/* Do the job */ /* Do the job */
cluster_rel(&rvtc, false); cluster_rel(&rvtc, false, stmt->verbose);
} }
else else
{ {
...@@ -226,7 +226,7 @@ cluster(ClusterStmt *stmt, bool isTopLevel) ...@@ -226,7 +226,7 @@ cluster(ClusterStmt *stmt, bool isTopLevel)
StartTransactionCommand(); StartTransactionCommand();
/* functions in indexes may want a snapshot set */ /* functions in indexes may want a snapshot set */
PushActiveSnapshot(GetTransactionSnapshot()); PushActiveSnapshot(GetTransactionSnapshot());
cluster_rel(rvtc, true); cluster_rel(rvtc, true, stmt->verbose);
PopActiveSnapshot(); PopActiveSnapshot();
CommitTransactionCommand(); CommitTransactionCommand();
} }
...@@ -254,7 +254,7 @@ cluster(ClusterStmt *stmt, bool isTopLevel) ...@@ -254,7 +254,7 @@ cluster(ClusterStmt *stmt, bool isTopLevel)
* them incrementally while we load the table. * them incrementally while we load the table.
*/ */
static void static void
cluster_rel(RelToCluster *rvtc, bool recheck) cluster_rel(RelToCluster *rvtc, bool recheck, bool verbose)
{ {
Relation OldHeap; Relation OldHeap;
...@@ -344,6 +344,10 @@ cluster_rel(RelToCluster *rvtc, bool recheck) ...@@ -344,6 +344,10 @@ cluster_rel(RelToCluster *rvtc, bool recheck)
check_index_is_clusterable(OldHeap, rvtc->indexOid, recheck); check_index_is_clusterable(OldHeap, rvtc->indexOid, recheck);
/* rebuild_relation does all the dirty work */ /* 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); rebuild_relation(OldHeap, rvtc->indexOid);
/* NB: rebuild_relation does heap_close() on OldHeap */ /* NB: rebuild_relation does heap_close() on OldHeap */
......
...@@ -15,7 +15,7 @@ ...@@ -15,7 +15,7 @@
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* IDENTIFICATION * IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/nodes/copyfuncs.c,v 1.412 2008/11/15 19:43:46 tgl Exp $ * $PostgreSQL: pgsql/src/backend/nodes/copyfuncs.c,v 1.413 2008/11/24 08:46:03 petere Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -2293,6 +2293,7 @@ _copyClusterStmt(ClusterStmt *from) ...@@ -2293,6 +2293,7 @@ _copyClusterStmt(ClusterStmt *from)
COPY_NODE_FIELD(relation); COPY_NODE_FIELD(relation);
COPY_STRING_FIELD(indexname); COPY_STRING_FIELD(indexname);
COPY_SCALAR_FIELD(verbose) ;
return newnode; return newnode;
} }
......
...@@ -22,7 +22,7 @@ ...@@ -22,7 +22,7 @@
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* IDENTIFICATION * IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/nodes/equalfuncs.c,v 1.337 2008/11/15 19:43:46 tgl Exp $ * $PostgreSQL: pgsql/src/backend/nodes/equalfuncs.c,v 1.338 2008/11/24 08:46:03 petere Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -1032,6 +1032,7 @@ _equalClusterStmt(ClusterStmt *a, ClusterStmt *b) ...@@ -1032,6 +1032,7 @@ _equalClusterStmt(ClusterStmt *a, ClusterStmt *b)
{ {
COMPARE_NODE_FIELD(relation); COMPARE_NODE_FIELD(relation);
COMPARE_STRING_FIELD(indexname); COMPARE_STRING_FIELD(indexname);
COMPARE_SCALAR_FIELD(verbose);
return true; return true;
} }
......
...@@ -11,7 +11,7 @@ ...@@ -11,7 +11,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/parser/gram.y,v 2.639 2008/11/21 11:47:55 petere Exp $ * $PostgreSQL: pgsql/src/backend/parser/gram.y,v 2.640 2008/11/24 08:46:03 petere Exp $
* *
* HISTORY * HISTORY
* AUTHOR DATE MAJOR EVENT * AUTHOR DATE MAJOR EVENT
...@@ -5781,33 +5781,36 @@ CreateConversionStmt: ...@@ -5781,33 +5781,36 @@ CreateConversionStmt:
/***************************************************************************** /*****************************************************************************
* *
* QUERY: * QUERY:
* CLUSTER <qualified_name> [ USING <index_name> ] * CLUSTER [VERBOSE] <qualified_name> [ USING <index_name> ]
* CLUSTER * CLUSTER [VERBOSE]
* CLUSTER <index_name> ON <qualified_name> (for pre-8.3) * CLUSTER [VERBOSE] <index_name> ON <qualified_name> (for pre-8.3)
* *
*****************************************************************************/ *****************************************************************************/
ClusterStmt: ClusterStmt:
CLUSTER qualified_name cluster_index_specification CLUSTER opt_verbose qualified_name cluster_index_specification
{ {
ClusterStmt *n = makeNode(ClusterStmt); ClusterStmt *n = makeNode(ClusterStmt);
n->relation = $2; n->relation = $3;
n->indexname = $3; n->indexname = $4;
n->verbose = $2;
$$ = (Node*)n; $$ = (Node*)n;
} }
| CLUSTER | CLUSTER opt_verbose
{ {
ClusterStmt *n = makeNode(ClusterStmt); ClusterStmt *n = makeNode(ClusterStmt);
n->relation = NULL; n->relation = NULL;
n->indexname = NULL; n->indexname = NULL;
n->verbose = $2;
$$ = (Node*)n; $$ = (Node*)n;
} }
/* kept for pre-8.3 compatibility */ /* kept for pre-8.3 compatibility */
| CLUSTER index_name ON qualified_name | CLUSTER opt_verbose index_name ON qualified_name
{ {
ClusterStmt *n = makeNode(ClusterStmt); ClusterStmt *n = makeNode(ClusterStmt);
n->relation = $4; n->relation = $5;
n->indexname = $2; n->indexname = $3;
n->verbose = $2;
$$ = (Node*)n; $$ = (Node*)n;
} }
; ;
......
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
* *
* Portions Copyright (c) 2002-2008, PostgreSQL Global Development Group * Portions Copyright (c) 2002-2008, PostgreSQL Global Development Group
* *
* $PostgreSQL: pgsql/src/bin/scripts/clusterdb.c,v 1.20 2008/01/01 19:45:56 momjian Exp $ * $PostgreSQL: pgsql/src/bin/scripts/clusterdb.c,v 1.21 2008/11/24 08:46:04 petere Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -14,11 +14,11 @@ ...@@ -14,11 +14,11 @@
#include "dumputils.h" #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 *host, const char *port,
const char *username, bool password, const char *username, bool password,
const char *progname, bool echo); 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 *username, bool password,
const char *progname, bool echo, bool quiet); const char *progname, bool echo, bool quiet);
...@@ -38,6 +38,7 @@ main(int argc, char *argv[]) ...@@ -38,6 +38,7 @@ main(int argc, char *argv[])
{"dbname", required_argument, NULL, 'd'}, {"dbname", required_argument, NULL, 'd'},
{"all", no_argument, NULL, 'a'}, {"all", no_argument, NULL, 'a'},
{"table", required_argument, NULL, 't'}, {"table", required_argument, NULL, 't'},
{"verbose", no_argument, NULL, 'v'},
{NULL, 0, NULL, 0} {NULL, 0, NULL, 0}
}; };
...@@ -54,13 +55,14 @@ main(int argc, char *argv[]) ...@@ -54,13 +55,14 @@ main(int argc, char *argv[])
bool quiet = false; bool quiet = false;
bool alldb = false; bool alldb = false;
char *table = NULL; char *table = NULL;
bool verbose = false;
progname = get_progname(argv[0]); progname = get_progname(argv[0]);
set_pglocale_pgservice(argv[0], "pgscripts"); set_pglocale_pgservice(argv[0], "pgscripts");
handle_help_version_opts(argc, argv, "clusterdb", help); 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) switch (c)
{ {
...@@ -91,6 +93,9 @@ main(int argc, char *argv[]) ...@@ -91,6 +93,9 @@ main(int argc, char *argv[])
case 't': case 't':
table = optarg; table = optarg;
break; break;
case 'v':
verbose = true;
break;
default: default:
fprintf(stderr, _("Try \"%s --help\" for more information.\n"), progname); fprintf(stderr, _("Try \"%s --help\" for more information.\n"), progname);
exit(1); exit(1);
...@@ -128,7 +133,7 @@ main(int argc, char *argv[]) ...@@ -128,7 +133,7 @@ main(int argc, char *argv[])
exit(1); exit(1);
} }
cluster_all_databases(host, port, username, password, cluster_all_databases(verbose, host, port, username, password,
progname, echo, quiet); progname, echo, quiet);
} }
else else
...@@ -143,7 +148,7 @@ main(int argc, char *argv[]) ...@@ -143,7 +148,7 @@ main(int argc, char *argv[])
dbname = get_user_name(progname); dbname = get_user_name(progname);
} }
cluster_one_database(dbname, table, cluster_one_database(dbname, verbose, table,
host, port, username, password, host, port, username, password,
progname, echo); progname, echo);
} }
...@@ -153,7 +158,7 @@ main(int argc, char *argv[]) ...@@ -153,7 +158,7 @@ main(int argc, char *argv[])
static void 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 *host, const char *port,
const char *username, bool password, const char *username, bool password,
const char *progname, bool echo) const char *progname, bool echo)
...@@ -165,6 +170,8 @@ cluster_one_database(const char *dbname, const char *table, ...@@ -165,6 +170,8 @@ cluster_one_database(const char *dbname, const char *table,
initPQExpBuffer(&sql); initPQExpBuffer(&sql);
appendPQExpBuffer(&sql, "CLUSTER"); appendPQExpBuffer(&sql, "CLUSTER");
if (verbose)
appendPQExpBuffer(&sql, " VERBOSE");
if (table) if (table)
appendPQExpBuffer(&sql, " %s", fmtId(table)); appendPQExpBuffer(&sql, " %s", fmtId(table));
appendPQExpBuffer(&sql, ";\n"); appendPQExpBuffer(&sql, ";\n");
...@@ -187,7 +194,7 @@ cluster_one_database(const char *dbname, const char *table, ...@@ -187,7 +194,7 @@ cluster_one_database(const char *dbname, const char *table,
static void 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 *username, bool password,
const char *progname, bool echo, bool quiet) const char *progname, bool echo, bool quiet)
{ {
...@@ -209,7 +216,7 @@ cluster_all_databases(const char *host, const char *port, ...@@ -209,7 +216,7 @@ cluster_all_databases(const char *host, const char *port,
fflush(stdout); fflush(stdout);
} }
cluster_one_database(dbname, NULL, cluster_one_database(dbname, verbose, NULL,
host, port, username, password, host, port, username, password,
progname, echo); progname, echo);
} }
...@@ -230,6 +237,7 @@ help(const char *progname) ...@@ -230,6 +237,7 @@ help(const char *progname)
printf(_(" -t, --table=TABLE cluster specific table only\n")); printf(_(" -t, --table=TABLE cluster specific table only\n"));
printf(_(" -e, --echo show the commands being sent to the server\n")); printf(_(" -e, --echo show the commands being sent to the server\n"));
printf(_(" -q, --quiet don't write any messages\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(_(" --help show this help, then exit\n"));
printf(_(" --version output version information, then exit\n")); printf(_(" --version output version information, then exit\n"));
printf(_("\nConnection options:\n")); printf(_("\nConnection options:\n"));
......
...@@ -13,7 +13,7 @@ ...@@ -13,7 +13,7 @@
* Portions Copyright (c) 1996-2008, PostgreSQL Global Development Group * Portions Copyright (c) 1996-2008, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* $PostgreSQL: pgsql/src/include/nodes/parsenodes.h,v 1.378 2008/11/15 19:43:46 tgl Exp $ * $PostgreSQL: pgsql/src/include/nodes/parsenodes.h,v 1.379 2008/11/24 08:46:04 petere Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -1949,6 +1949,7 @@ typedef struct ClusterStmt ...@@ -1949,6 +1949,7 @@ typedef struct ClusterStmt
NodeTag type; NodeTag type;
RangeVar *relation; /* relation being indexed, or NULL if all */ RangeVar *relation; /* relation being indexed, or NULL if all */
char *indexname; /* original index defined */ char *indexname; /* original index defined */
bool verbose; /* print progress info */
} ClusterStmt; } ClusterStmt;
/* ---------------------- /* ----------------------
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment