Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 458a077

Browse files
committed
Support --verbose option in reindexdb.
Sawada Masahiko, reviewed by Fabrízio Mello
1 parent 35fcb1b commit 458a077

File tree

3 files changed

+52
-17
lines changed

3 files changed

+52
-17
lines changed

doc/src/sgml/ref/reindexdb.sgml

+16-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ PostgreSQL documentation
2323
<cmdsynopsis>
2424
<command>reindexdb</command>
2525
<arg rep="repeat"><replaceable>connection-option</replaceable></arg>
26-
26+
<arg rep="repeat"><replaceable>option</replaceable></arg>
27+
2728
<arg choice="plain" rep="repeat">
2829
<arg choice="opt">
2930
<group choice="plain">
@@ -60,6 +61,8 @@ PostgreSQL documentation
6061
<cmdsynopsis>
6162
<command>reindexdb</command>
6263
<arg rep="repeat"><replaceable>connection-option</replaceable></arg>
64+
<arg rep="repeat"><replaceable>option</replaceable></arg>
65+
6366
<group choice="plain">
6467
<arg choice="plain"><option>--all</option></arg>
6568
<arg choice="plain"><option>-a</option></arg>
@@ -69,6 +72,8 @@ PostgreSQL documentation
6972
<cmdsynopsis>
7073
<command>reindexdb</command>
7174
<arg rep="repeat"><replaceable>connection-option</replaceable></arg>
75+
<arg rep="repeat"><replaceable>option</replaceable></arg>
76+
7277
<group choice="plain">
7378
<arg choice="plain"><option>--system</option></arg>
7479
<arg choice="plain"><option>-s</option></arg>
@@ -195,6 +200,16 @@ PostgreSQL documentation
195200
</listitem>
196201
</varlistentry>
197202

203+
<varlistentry>
204+
<term><option>-v</></term>
205+
<term><option>--verbose</></term>
206+
<listitem>
207+
<para>
208+
Print detailed information during processing.
209+
</para>
210+
</listitem>
211+
</varlistentry>
212+
198213
<varlistentry>
199214
<term><option>-V</></term>
200215
<term><option>--version</></term>

src/bin/scripts/reindexdb.c

+31-15
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,16 @@ static void reindex_one_database(const char *name, const char *dbname,
1818
const char *type, const char *host,
1919
const char *port, const char *username,
2020
enum trivalue prompt_password, const char *progname,
21-
bool echo);
21+
bool echo, bool verbose);
2222
static void reindex_all_databases(const char *maintenance_db,
2323
const char *host, const char *port,
2424
const char *username, enum trivalue prompt_password,
2525
const char *progname, bool echo,
26-
bool quiet);
26+
bool quiet, bool verbose);
2727
static void reindex_system_catalogs(const char *dbname,
2828
const char *host, const char *port,
2929
const char *username, enum trivalue prompt_password,
30-
const char *progname, bool echo);
30+
const char *progname, bool echo, bool verbose);
3131
static void help(const char *progname);
3232

3333
int
@@ -47,6 +47,7 @@ main(int argc, char *argv[])
4747
{"system", no_argument, NULL, 's'},
4848
{"table", required_argument, NULL, 't'},
4949
{"index", required_argument, NULL, 'i'},
50+
{"verbose", no_argument, NULL, 'v'},
5051
{"maintenance-db", required_argument, NULL, 2},
5152
{NULL, 0, NULL, 0}
5253
};
@@ -65,6 +66,7 @@ main(int argc, char *argv[])
6566
bool alldb = false;
6667
bool echo = false;
6768
bool quiet = false;
69+
bool verbose = false;
6870
SimpleStringList indexes = {NULL, NULL};
6971
SimpleStringList tables = {NULL, NULL};
7072
SimpleStringList schemas = {NULL, NULL};
@@ -75,7 +77,7 @@ main(int argc, char *argv[])
7577
handle_help_version_opts(argc, argv, "reindexdb", help);
7678

7779
/* process command-line options */
78-
while ((c = getopt_long(argc, argv, "h:p:U:wWeqS:d:ast:i:", long_options, &optindex)) != -1)
80+
while ((c = getopt_long(argc, argv, "h:p:U:wWeqS:d:ast:i:v", long_options, &optindex)) != -1)
7981
{
8082
switch (c)
8183
{
@@ -118,6 +120,9 @@ main(int argc, char *argv[])
118120
case 'i':
119121
simple_string_list_append(&indexes, optarg);
120122
break;
123+
case 'v':
124+
verbose = true;
125+
break;
121126
case 2:
122127
maintenance_db = pg_strdup(optarg);
123128
break;
@@ -176,7 +181,7 @@ main(int argc, char *argv[])
176181
}
177182

178183
reindex_all_databases(maintenance_db, host, port, username,
179-
prompt_password, progname, echo, quiet);
184+
prompt_password, progname, echo, quiet, verbose);
180185
}
181186
else if (syscatalog)
182187
{
@@ -207,7 +212,7 @@ main(int argc, char *argv[])
207212
}
208213

209214
reindex_system_catalogs(dbname, host, port, username, prompt_password,
210-
progname, echo);
215+
progname, echo, verbose);
211216
}
212217
else
213218
{
@@ -228,7 +233,7 @@ main(int argc, char *argv[])
228233
for (cell = schemas.head; cell; cell = cell->next)
229234
{
230235
reindex_one_database(cell->val, dbname, "SCHEMA", host, port,
231-
username, prompt_password, progname, echo);
236+
username, prompt_password, progname, echo, verbose);
232237
}
233238
}
234239

@@ -239,7 +244,7 @@ main(int argc, char *argv[])
239244
for (cell = indexes.head; cell; cell = cell->next)
240245
{
241246
reindex_one_database(cell->val, dbname, "INDEX", host, port,
242-
username, prompt_password, progname, echo);
247+
username, prompt_password, progname, echo, verbose);
243248
}
244249
}
245250
if (tables.head != NULL)
@@ -249,13 +254,13 @@ main(int argc, char *argv[])
249254
for (cell = tables.head; cell; cell = cell->next)
250255
{
251256
reindex_one_database(cell->val, dbname, "TABLE", host, port,
252-
username, prompt_password, progname, echo);
257+
username, prompt_password, progname, echo, verbose);
253258
}
254259
}
255260
/* reindex database only if neither index nor table nor schema is specified */
256261
if (indexes.head == NULL && tables.head == NULL && schemas.head == NULL)
257262
reindex_one_database(dbname, dbname, "DATABASE", host, port,
258-
username, prompt_password, progname, echo);
263+
username, prompt_password, progname, echo, verbose);
259264
}
260265

261266
exit(0);
@@ -264,7 +269,8 @@ main(int argc, char *argv[])
264269
static void
265270
reindex_one_database(const char *name, const char *dbname, const char *type,
266271
const char *host, const char *port, const char *username,
267-
enum trivalue prompt_password, const char *progname, bool echo)
272+
enum trivalue prompt_password, const char *progname, bool echo,
273+
bool verbose)
268274
{
269275
PQExpBufferData sql;
270276

@@ -273,6 +279,10 @@ reindex_one_database(const char *name, const char *dbname, const char *type,
273279
initPQExpBuffer(&sql);
274280

275281
appendPQExpBufferStr(&sql, "REINDEX");
282+
283+
if (verbose)
284+
appendPQExpBufferStr(&sql, " (VERBOSE)");
285+
276286
if (strcmp(type, "TABLE") == 0)
277287
appendPQExpBuffer(&sql, " TABLE %s", name);
278288
else if (strcmp(type, "INDEX") == 0)
@@ -312,7 +322,7 @@ static void
312322
reindex_all_databases(const char *maintenance_db,
313323
const char *host, const char *port,
314324
const char *username, enum trivalue prompt_password,
315-
const char *progname, bool echo, bool quiet)
325+
const char *progname, bool echo, bool quiet, bool verbose)
316326
{
317327
PGconn *conn;
318328
PGresult *result;
@@ -334,7 +344,7 @@ reindex_all_databases(const char *maintenance_db,
334344
}
335345

336346
reindex_one_database(dbname, dbname, "DATABASE", host, port, username,
337-
prompt_password, progname, echo);
347+
prompt_password, progname, echo, verbose);
338348
}
339349

340350
PQclear(result);
@@ -343,15 +353,20 @@ reindex_all_databases(const char *maintenance_db,
343353
static void
344354
reindex_system_catalogs(const char *dbname, const char *host, const char *port,
345355
const char *username, enum trivalue prompt_password,
346-
const char *progname, bool echo)
356+
const char *progname, bool echo, bool verbose)
347357
{
348358
PQExpBufferData sql;
349359

350360
PGconn *conn;
351361

352362
initPQExpBuffer(&sql);
353363

354-
appendPQExpBuffer(&sql, "REINDEX SYSTEM %s;", dbname);
364+
appendPQExpBuffer(&sql, "REINDEX");
365+
366+
if (verbose)
367+
appendPQExpBuffer(&sql, " (VERBOSE)");
368+
369+
appendPQExpBuffer(&sql, " SYSTEM %s;", dbname);
355370

356371
conn = connectDatabase(dbname, host, port, username, prompt_password,
357372
progname, false);
@@ -381,6 +396,7 @@ help(const char *progname)
381396
printf(_(" -s, --system reindex system catalogs\n"));
382397
printf(_(" -S, --schema=SCHEMA recreate specific schema(s) only\n"));
383398
printf(_(" -t, --table=TABLE reindex specific table(s) only\n"));
399+
printf(_(" -v, --verbose write a lot of output\n"));
384400
printf(_(" -V, --version output version information, then exit\n"));
385401
printf(_(" -?, --help show this help, then exit\n"));
386402
printf(_("\nConnection options:\n"));

src/bin/scripts/t/090_reindexdb.pl

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use strict;
22
use warnings;
33
use TestLib;
4-
use Test::More tests => 18;
4+
use Test::More tests => 20;
55

66
program_help_ok('reindexdb');
77
program_version_ok('reindexdb');
@@ -35,3 +35,7 @@
3535
[ 'reindexdb', '-s', 'postgres' ],
3636
qr/statement: REINDEX SYSTEM postgres;/,
3737
'reindex system tables');
38+
issues_sql_like(
39+
[ 'reindexdb', '-v', '-t', 'test1', 'postgres' ],
40+
qr/statement: REINDEX \(VERBOSE\) TABLE test1;/,
41+
'reindex with verbose output');

0 commit comments

Comments
 (0)