Commit 458a0770 authored by Fujii Masao's avatar Fujii Masao

Support --verbose option in reindexdb.

Sawada Masahiko, reviewed by Fabrízio Mello
parent 35fcb1b3
...@@ -23,7 +23,8 @@ PostgreSQL documentation ...@@ -23,7 +23,8 @@ PostgreSQL documentation
<cmdsynopsis> <cmdsynopsis>
<command>reindexdb</command> <command>reindexdb</command>
<arg rep="repeat"><replaceable>connection-option</replaceable></arg> <arg rep="repeat"><replaceable>connection-option</replaceable></arg>
<arg rep="repeat"><replaceable>option</replaceable></arg>
<arg choice="plain" rep="repeat"> <arg choice="plain" rep="repeat">
<arg choice="opt"> <arg choice="opt">
<group choice="plain"> <group choice="plain">
...@@ -60,6 +61,8 @@ PostgreSQL documentation ...@@ -60,6 +61,8 @@ PostgreSQL documentation
<cmdsynopsis> <cmdsynopsis>
<command>reindexdb</command> <command>reindexdb</command>
<arg rep="repeat"><replaceable>connection-option</replaceable></arg> <arg rep="repeat"><replaceable>connection-option</replaceable></arg>
<arg rep="repeat"><replaceable>option</replaceable></arg>
<group choice="plain"> <group choice="plain">
<arg choice="plain"><option>--all</option></arg> <arg choice="plain"><option>--all</option></arg>
<arg choice="plain"><option>-a</option></arg> <arg choice="plain"><option>-a</option></arg>
...@@ -69,6 +72,8 @@ PostgreSQL documentation ...@@ -69,6 +72,8 @@ PostgreSQL documentation
<cmdsynopsis> <cmdsynopsis>
<command>reindexdb</command> <command>reindexdb</command>
<arg rep="repeat"><replaceable>connection-option</replaceable></arg> <arg rep="repeat"><replaceable>connection-option</replaceable></arg>
<arg rep="repeat"><replaceable>option</replaceable></arg>
<group choice="plain"> <group choice="plain">
<arg choice="plain"><option>--system</option></arg> <arg choice="plain"><option>--system</option></arg>
<arg choice="plain"><option>-s</option></arg> <arg choice="plain"><option>-s</option></arg>
...@@ -195,6 +200,16 @@ PostgreSQL documentation ...@@ -195,6 +200,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>
<varlistentry> <varlistentry>
<term><option>-V</></term> <term><option>-V</></term>
<term><option>--version</></term> <term><option>--version</></term>
......
...@@ -18,16 +18,16 @@ static void reindex_one_database(const char *name, const char *dbname, ...@@ -18,16 +18,16 @@ static void reindex_one_database(const char *name, const char *dbname,
const char *type, const char *host, const char *type, const char *host,
const char *port, const char *username, const char *port, const char *username,
enum trivalue prompt_password, const char *progname, enum trivalue prompt_password, const char *progname,
bool echo); bool echo, bool verbose);
static void reindex_all_databases(const char *maintenance_db, static void reindex_all_databases(const char *maintenance_db,
const char *host, const char *port, const char *host, const char *port,
const char *username, enum trivalue prompt_password, const char *username, enum trivalue prompt_password,
const char *progname, bool echo, const char *progname, bool echo,
bool quiet); bool quiet, bool verbose);
static void reindex_system_catalogs(const char *dbname, static void reindex_system_catalogs(const char *dbname,
const char *host, const char *port, const char *host, const char *port,
const char *username, enum trivalue prompt_password, const char *username, enum trivalue prompt_password,
const char *progname, bool echo); const char *progname, bool echo, bool verbose);
static void help(const char *progname); static void help(const char *progname);
int int
...@@ -47,6 +47,7 @@ main(int argc, char *argv[]) ...@@ -47,6 +47,7 @@ main(int argc, char *argv[])
{"system", no_argument, NULL, 's'}, {"system", no_argument, NULL, 's'},
{"table", required_argument, NULL, 't'}, {"table", required_argument, NULL, 't'},
{"index", required_argument, NULL, 'i'}, {"index", required_argument, NULL, 'i'},
{"verbose", no_argument, NULL, 'v'},
{"maintenance-db", required_argument, NULL, 2}, {"maintenance-db", required_argument, NULL, 2},
{NULL, 0, NULL, 0} {NULL, 0, NULL, 0}
}; };
...@@ -65,6 +66,7 @@ main(int argc, char *argv[]) ...@@ -65,6 +66,7 @@ main(int argc, char *argv[])
bool alldb = false; bool alldb = false;
bool echo = false; bool echo = false;
bool quiet = false; bool quiet = false;
bool verbose = false;
SimpleStringList indexes = {NULL, NULL}; SimpleStringList indexes = {NULL, NULL};
SimpleStringList tables = {NULL, NULL}; SimpleStringList tables = {NULL, NULL};
SimpleStringList schemas = {NULL, NULL}; SimpleStringList schemas = {NULL, NULL};
...@@ -75,7 +77,7 @@ main(int argc, char *argv[]) ...@@ -75,7 +77,7 @@ main(int argc, char *argv[])
handle_help_version_opts(argc, argv, "reindexdb", help); handle_help_version_opts(argc, argv, "reindexdb", help);
/* process command-line options */ /* process command-line options */
while ((c = getopt_long(argc, argv, "h:p:U:wWeqS:d:ast:i:", long_options, &optindex)) != -1) while ((c = getopt_long(argc, argv, "h:p:U:wWeqS:d:ast:i:v", long_options, &optindex)) != -1)
{ {
switch (c) switch (c)
{ {
...@@ -118,6 +120,9 @@ main(int argc, char *argv[]) ...@@ -118,6 +120,9 @@ main(int argc, char *argv[])
case 'i': case 'i':
simple_string_list_append(&indexes, optarg); simple_string_list_append(&indexes, optarg);
break; break;
case 'v':
verbose = true;
break;
case 2: case 2:
maintenance_db = pg_strdup(optarg); maintenance_db = pg_strdup(optarg);
break; break;
...@@ -176,7 +181,7 @@ main(int argc, char *argv[]) ...@@ -176,7 +181,7 @@ main(int argc, char *argv[])
} }
reindex_all_databases(maintenance_db, host, port, username, reindex_all_databases(maintenance_db, host, port, username,
prompt_password, progname, echo, quiet); prompt_password, progname, echo, quiet, verbose);
} }
else if (syscatalog) else if (syscatalog)
{ {
...@@ -207,7 +212,7 @@ main(int argc, char *argv[]) ...@@ -207,7 +212,7 @@ main(int argc, char *argv[])
} }
reindex_system_catalogs(dbname, host, port, username, prompt_password, reindex_system_catalogs(dbname, host, port, username, prompt_password,
progname, echo); progname, echo, verbose);
} }
else else
{ {
...@@ -228,7 +233,7 @@ main(int argc, char *argv[]) ...@@ -228,7 +233,7 @@ main(int argc, char *argv[])
for (cell = schemas.head; cell; cell = cell->next) for (cell = schemas.head; cell; cell = cell->next)
{ {
reindex_one_database(cell->val, dbname, "SCHEMA", host, port, reindex_one_database(cell->val, dbname, "SCHEMA", host, port,
username, prompt_password, progname, echo); username, prompt_password, progname, echo, verbose);
} }
} }
...@@ -239,7 +244,7 @@ main(int argc, char *argv[]) ...@@ -239,7 +244,7 @@ main(int argc, char *argv[])
for (cell = indexes.head; cell; cell = cell->next) for (cell = indexes.head; cell; cell = cell->next)
{ {
reindex_one_database(cell->val, dbname, "INDEX", host, port, reindex_one_database(cell->val, dbname, "INDEX", host, port,
username, prompt_password, progname, echo); username, prompt_password, progname, echo, verbose);
} }
} }
if (tables.head != NULL) if (tables.head != NULL)
...@@ -249,13 +254,13 @@ main(int argc, char *argv[]) ...@@ -249,13 +254,13 @@ main(int argc, char *argv[])
for (cell = tables.head; cell; cell = cell->next) for (cell = tables.head; cell; cell = cell->next)
{ {
reindex_one_database(cell->val, dbname, "TABLE", host, port, reindex_one_database(cell->val, dbname, "TABLE", host, port,
username, prompt_password, progname, echo); username, prompt_password, progname, echo, verbose);
} }
} }
/* reindex database only if neither index nor table nor schema is specified */ /* reindex database only if neither index nor table nor schema is specified */
if (indexes.head == NULL && tables.head == NULL && schemas.head == NULL) if (indexes.head == NULL && tables.head == NULL && schemas.head == NULL)
reindex_one_database(dbname, dbname, "DATABASE", host, port, reindex_one_database(dbname, dbname, "DATABASE", host, port,
username, prompt_password, progname, echo); username, prompt_password, progname, echo, verbose);
} }
exit(0); exit(0);
...@@ -264,7 +269,8 @@ main(int argc, char *argv[]) ...@@ -264,7 +269,8 @@ main(int argc, char *argv[])
static void static void
reindex_one_database(const char *name, const char *dbname, const char *type, reindex_one_database(const char *name, const char *dbname, const char *type,
const char *host, const char *port, const char *username, const char *host, const char *port, const char *username,
enum trivalue prompt_password, const char *progname, bool echo) enum trivalue prompt_password, const char *progname, bool echo,
bool verbose)
{ {
PQExpBufferData sql; PQExpBufferData sql;
...@@ -273,6 +279,10 @@ reindex_one_database(const char *name, const char *dbname, const char *type, ...@@ -273,6 +279,10 @@ reindex_one_database(const char *name, const char *dbname, const char *type,
initPQExpBuffer(&sql); initPQExpBuffer(&sql);
appendPQExpBufferStr(&sql, "REINDEX"); appendPQExpBufferStr(&sql, "REINDEX");
if (verbose)
appendPQExpBufferStr(&sql, " (VERBOSE)");
if (strcmp(type, "TABLE") == 0) if (strcmp(type, "TABLE") == 0)
appendPQExpBuffer(&sql, " TABLE %s", name); appendPQExpBuffer(&sql, " TABLE %s", name);
else if (strcmp(type, "INDEX") == 0) else if (strcmp(type, "INDEX") == 0)
...@@ -312,7 +322,7 @@ static void ...@@ -312,7 +322,7 @@ static void
reindex_all_databases(const char *maintenance_db, reindex_all_databases(const char *maintenance_db,
const char *host, const char *port, const char *host, const char *port,
const char *username, enum trivalue prompt_password, const char *username, enum trivalue prompt_password,
const char *progname, bool echo, bool quiet) const char *progname, bool echo, bool quiet, bool verbose)
{ {
PGconn *conn; PGconn *conn;
PGresult *result; PGresult *result;
...@@ -334,7 +344,7 @@ reindex_all_databases(const char *maintenance_db, ...@@ -334,7 +344,7 @@ reindex_all_databases(const char *maintenance_db,
} }
reindex_one_database(dbname, dbname, "DATABASE", host, port, username, reindex_one_database(dbname, dbname, "DATABASE", host, port, username,
prompt_password, progname, echo); prompt_password, progname, echo, verbose);
} }
PQclear(result); PQclear(result);
...@@ -343,7 +353,7 @@ reindex_all_databases(const char *maintenance_db, ...@@ -343,7 +353,7 @@ reindex_all_databases(const char *maintenance_db,
static void static void
reindex_system_catalogs(const char *dbname, const char *host, const char *port, reindex_system_catalogs(const char *dbname, const char *host, const char *port,
const char *username, enum trivalue prompt_password, const char *username, enum trivalue prompt_password,
const char *progname, bool echo) const char *progname, bool echo, bool verbose)
{ {
PQExpBufferData sql; PQExpBufferData sql;
...@@ -351,7 +361,12 @@ reindex_system_catalogs(const char *dbname, const char *host, const char *port, ...@@ -351,7 +361,12 @@ reindex_system_catalogs(const char *dbname, const char *host, const char *port,
initPQExpBuffer(&sql); initPQExpBuffer(&sql);
appendPQExpBuffer(&sql, "REINDEX SYSTEM %s;", dbname); appendPQExpBuffer(&sql, "REINDEX");
if (verbose)
appendPQExpBuffer(&sql, " (VERBOSE)");
appendPQExpBuffer(&sql, " SYSTEM %s;", dbname);
conn = connectDatabase(dbname, host, port, username, prompt_password, conn = connectDatabase(dbname, host, port, username, prompt_password,
progname, false); progname, false);
...@@ -381,6 +396,7 @@ help(const char *progname) ...@@ -381,6 +396,7 @@ help(const char *progname)
printf(_(" -s, --system reindex system catalogs\n")); printf(_(" -s, --system reindex system catalogs\n"));
printf(_(" -S, --schema=SCHEMA recreate specific schema(s) only\n")); printf(_(" -S, --schema=SCHEMA recreate specific schema(s) only\n"));
printf(_(" -t, --table=TABLE reindex specific table(s) only\n")); printf(_(" -t, --table=TABLE reindex specific table(s) only\n"));
printf(_(" -v, --verbose write a lot of output\n"));
printf(_(" -V, --version output version information, then exit\n")); printf(_(" -V, --version output version information, then exit\n"));
printf(_(" -?, --help show this help, then exit\n")); printf(_(" -?, --help show this help, then exit\n"));
printf(_("\nConnection options:\n")); printf(_("\nConnection options:\n"));
......
use strict; use strict;
use warnings; use warnings;
use TestLib; use TestLib;
use Test::More tests => 18; use Test::More tests => 20;
program_help_ok('reindexdb'); program_help_ok('reindexdb');
program_version_ok('reindexdb'); program_version_ok('reindexdb');
...@@ -35,3 +35,7 @@ issues_sql_like( ...@@ -35,3 +35,7 @@ issues_sql_like(
[ 'reindexdb', '-s', 'postgres' ], [ 'reindexdb', '-s', 'postgres' ],
qr/statement: REINDEX SYSTEM postgres;/, qr/statement: REINDEX SYSTEM postgres;/,
'reindex system tables'); 'reindex system tables');
issues_sql_like(
[ 'reindexdb', '-v', '-t', 'test1', 'postgres' ],
qr/statement: REINDEX \(VERBOSE\) TABLE test1;/,
'reindex with verbose output');
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