Commit f3af5344 authored by Magnus Hagander's avatar Magnus Hagander

Support multiple -t/--table arguments for more commands

On top of the previous support in pg_dump, add support to specify
multiple tables (by using the -t option multiple times) to
pg_restore, clsuterdb, reindexdb and vacuumdb.

Josh Kupershmidt, reviewed by Karl O. Pinc
parent 36bdfa52
...@@ -24,7 +24,17 @@ PostgreSQL documentation ...@@ -24,7 +24,17 @@ PostgreSQL documentation
<command>clusterdb</command> <command>clusterdb</command>
<arg rep="repeat"><replaceable>connection-option</replaceable></arg> <arg rep="repeat"><replaceable>connection-option</replaceable></arg>
<group choice="opt"><arg choice="plain"><option>--verbose</option></arg><arg choice="plain"><option>-v</option></arg></group> <group choice="opt"><arg choice="plain"><option>--verbose</option></arg><arg choice="plain"><option>-v</option></arg></group>
<arg choice="opt"><group choice="plain"><arg choice="plain"><option>--table</option></arg><arg choice="plain"><option>-t</option></arg></group> <replaceable>table</replaceable> </arg>
<arg choice="plain" rep="repeat">
<arg choice="opt">
<group choice="plain">
<arg choice="plain"><option>--table</option></arg>
<arg choice="plain"><option>-t</option></arg>
</group>
<replaceable>table</replaceable>
</arg>
</arg>
<arg choice="opt"><replaceable>dbname</replaceable></arg> <arg choice="opt"><replaceable>dbname</replaceable></arg>
</cmdsynopsis> </cmdsynopsis>
...@@ -117,6 +127,8 @@ PostgreSQL documentation ...@@ -117,6 +127,8 @@ PostgreSQL documentation
<listitem> <listitem>
<para> <para>
Cluster <replaceable class="parameter">table</replaceable> only. Cluster <replaceable class="parameter">table</replaceable> only.
Multiple tables can be clustered by writing multiple
<option>-t</> switches.
</para> </para>
</listitem> </listitem>
</varlistentry> </varlistentry>
......
...@@ -400,7 +400,8 @@ ...@@ -400,7 +400,8 @@
<term><option>--table=<replaceable class="parameter">table</replaceable></option></term> <term><option>--table=<replaceable class="parameter">table</replaceable></option></term>
<listitem> <listitem>
<para> <para>
Restore definition and/or data of named table only. This can be Restore definition and/or data of named table only. Multiple tables
may be specified with multiple <option>-t</> switches. This can be
combined with the <option>-n</option> option to specify a schema. combined with the <option>-n</option> option to specify a schema.
</para> </para>
</listitem> </listitem>
......
...@@ -23,20 +23,27 @@ PostgreSQL documentation ...@@ -23,20 +23,27 @@ 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>
<group choice="opt">
<arg choice="plain" rep="repeat">
<arg choice="opt">
<group choice="plain"> <group choice="plain">
<arg choice="plain"><option>--table</option></arg> <arg choice="plain"><option>--table</option></arg>
<arg choice="plain"><option>-t</option></arg> <arg choice="plain"><option>-t</option></arg>
</group> </group>
<replaceable>table</replaceable> <replaceable>table</replaceable>
</group> </arg>
<group choice="opt"> </arg>
<arg choice="plain" rep="repeat">
<arg choice="opt">
<group choice="plain"> <group choice="plain">
<arg choice="plain"><option>--index</option></arg> <arg choice="plain"><option>--index</option></arg>
<arg choice="plain"><option>-i</option></arg> <arg choice="plain"><option>-i</option></arg>
</group> </group>
<replaceable>index</replaceable> <replaceable>index</replaceable>
</group> </arg>
</arg>
<arg choice="opt"><replaceable>dbname</replaceable></arg> <arg choice="opt"><replaceable>dbname</replaceable></arg>
</cmdsynopsis> </cmdsynopsis>
...@@ -128,6 +135,8 @@ PostgreSQL documentation ...@@ -128,6 +135,8 @@ PostgreSQL documentation
<listitem> <listitem>
<para> <para>
Recreate <replaceable class="parameter">index</replaceable> only. Recreate <replaceable class="parameter">index</replaceable> only.
Multiple indexes can be recreated by writing multiple
<option>-i</> switches.
</para> </para>
</listitem> </listitem>
</varlistentry> </varlistentry>
...@@ -158,6 +167,8 @@ PostgreSQL documentation ...@@ -158,6 +167,8 @@ PostgreSQL documentation
<listitem> <listitem>
<para> <para>
Reindex <replaceable class="parameter">table</replaceable> only. Reindex <replaceable class="parameter">table</replaceable> only.
Multiple tables can be reindexed by writing multiple
<option>-t</> switches.
</para> </para>
</listitem> </listitem>
</varlistentry> </varlistentry>
......
...@@ -24,6 +24,8 @@ PostgreSQL documentation ...@@ -24,6 +24,8 @@ PostgreSQL documentation
<command>vacuumdb</command> <command>vacuumdb</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 rep="repeat"><replaceable>option</replaceable></arg>
<arg choice="plain" rep="repeat">
<arg choice="opt"> <arg choice="opt">
<group choice="plain"> <group choice="plain">
<arg choice="plain"><option>--table</option></arg> <arg choice="plain"><option>--table</option></arg>
...@@ -32,6 +34,8 @@ PostgreSQL documentation ...@@ -32,6 +34,8 @@ PostgreSQL documentation
<replaceable>table</replaceable> <replaceable>table</replaceable>
<arg choice="opt">( <replaceable class="parameter">column</replaceable> [,...] )</arg> <arg choice="opt">( <replaceable class="parameter">column</replaceable> [,...] )</arg>
</arg> </arg>
</arg>
<arg choice="opt"><replaceable>dbname</replaceable></arg> <arg choice="opt"><replaceable>dbname</replaceable></arg>
</cmdsynopsis> </cmdsynopsis>
...@@ -147,6 +151,8 @@ PostgreSQL documentation ...@@ -147,6 +151,8 @@ PostgreSQL documentation
Clean or analyze <replaceable class="parameter">table</replaceable> only. Clean or analyze <replaceable class="parameter">table</replaceable> only.
Column names can be specified only in conjunction with Column names can be specified only in conjunction with
the <option>--analyze</option> or <option>--analyze-only</option> options. the <option>--analyze</option> or <option>--analyze-only</option> options.
Multiple tables can be vacuumed by writing multiple
<option>-t</> switches.
</para> </para>
<tip> <tip>
<para> <para>
......
...@@ -898,24 +898,6 @@ simple_oid_list_append(SimpleOidList *list, Oid val) ...@@ -898,24 +898,6 @@ simple_oid_list_append(SimpleOidList *list, Oid val)
list->tail = cell; list->tail = cell;
} }
void
simple_string_list_append(SimpleStringList *list, const char *val)
{
SimpleStringListCell *cell;
/* this calculation correctly accounts for the null trailing byte */
cell = (SimpleStringListCell *)
pg_malloc(sizeof(SimpleStringListCell) + strlen(val));
cell->next = NULL;
strcpy(cell->val, val);
if (list->tail)
list->tail->next = cell;
else
list->head = cell;
list->tail = cell;
}
bool bool
simple_oid_list_member(SimpleOidList *list, Oid val) simple_oid_list_member(SimpleOidList *list, Oid val)
{ {
...@@ -928,16 +910,3 @@ simple_oid_list_member(SimpleOidList *list, Oid val) ...@@ -928,16 +910,3 @@ simple_oid_list_member(SimpleOidList *list, Oid val)
} }
return false; return false;
} }
bool
simple_string_list_member(SimpleStringList *list, const char *val)
{
SimpleStringListCell *cell;
for (cell = list->head; cell; cell = cell->next)
{
if (strcmp(cell->val, val) == 0)
return true;
}
return false;
}
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
#include <ctype.h> #include <ctype.h>
#include "dumputils.h" #include "dumputils.h"
#include "dumpmem.h"
#include "parser/keywords.h" #include "parser/keywords.h"
...@@ -1352,3 +1353,35 @@ exit_nicely(int code) ...@@ -1352,3 +1353,35 @@ exit_nicely(int code)
exit(code); exit(code);
} }
void
simple_string_list_append(SimpleStringList *list, const char *val)
{
SimpleStringListCell *cell;
/* this calculation correctly accounts for the null trailing byte */
cell = (SimpleStringListCell *)
pg_malloc(sizeof(SimpleStringListCell) + strlen(val));
cell->next = NULL;
strcpy(cell->val, val);
if (list->tail)
list->tail->next = cell;
else
list->head = cell;
list->tail = cell;
}
bool
simple_string_list_member(SimpleStringList *list, const char *val)
{
SimpleStringListCell *cell;
for (cell = list->head; cell; cell = cell->next)
{
if (strcmp(cell->val, val) == 0)
return true;
}
return false;
}
...@@ -27,6 +27,19 @@ typedef enum /* bits returned by set_dump_section */ ...@@ -27,6 +27,19 @@ typedef enum /* bits returned by set_dump_section */
DUMP_UNSECTIONED = 0xff DUMP_UNSECTIONED = 0xff
} DumpSections; } DumpSections;
typedef struct SimpleStringListCell
{
struct SimpleStringListCell *next;
char val[1]; /* VARIABLE LENGTH FIELD */
} SimpleStringListCell;
typedef struct SimpleStringList
{
SimpleStringListCell *head;
SimpleStringListCell *tail;
} SimpleStringList;
typedef void (*on_exit_nicely_callback) (int code, void *arg); typedef void (*on_exit_nicely_callback) (int code, void *arg);
extern int quote_all_identifiers; extern int quote_all_identifiers;
...@@ -75,4 +88,8 @@ __attribute__((format(PG_PRINTF_ATTRIBUTE, 2, 3), noreturn)); ...@@ -75,4 +88,8 @@ __attribute__((format(PG_PRINTF_ATTRIBUTE, 2, 3), noreturn));
extern void on_exit_nicely(on_exit_nicely_callback function, void *arg); extern void on_exit_nicely(on_exit_nicely_callback function, void *arg);
extern void exit_nicely(int code) __attribute__((noreturn)); extern void exit_nicely(int code) __attribute__((noreturn));
extern void simple_string_list_append(SimpleStringList *list, const char *val);
extern bool simple_string_list_member(SimpleStringList *list, const char *val);
#endif /* DUMPUTILS_H */ #endif /* DUMPUTILS_H */
...@@ -26,6 +26,7 @@ ...@@ -26,6 +26,7 @@
#include "postgres_fe.h" #include "postgres_fe.h"
#include "pg_dump.h" #include "pg_dump.h"
#include "dumputils.h"
#include "libpq-fe.h" #include "libpq-fe.h"
...@@ -125,9 +126,9 @@ typedef struct _restoreOptions ...@@ -125,9 +126,9 @@ typedef struct _restoreOptions
int selTable; int selTable;
char *indexNames; char *indexNames;
char *functionNames; char *functionNames;
char *tableNames;
char *schemaNames; char *schemaNames;
char *triggerNames; char *triggerNames;
SimpleStringList tableNames;
int useDB; int useDB;
char *dbname; char *dbname;
......
...@@ -2493,7 +2493,7 @@ _tocEntryRequired(TocEntry *te, teSection curSection, RestoreOptions *ropt) ...@@ -2493,7 +2493,7 @@ _tocEntryRequired(TocEntry *te, teSection curSection, RestoreOptions *ropt)
{ {
if (!ropt->selTable) if (!ropt->selTable)
return 0; return 0;
if (ropt->tableNames && strcmp(ropt->tableNames, te->tag) != 0) if (ropt->tableNames.head != NULL && (!(simple_string_list_member(&ropt->tableNames, te->tag))))
return 0; return 0;
} }
else if (strcmp(te->desc, "INDEX") == 0) else if (strcmp(te->desc, "INDEX") == 0)
......
...@@ -58,17 +58,6 @@ typedef struct SimpleOidList ...@@ -58,17 +58,6 @@ typedef struct SimpleOidList
SimpleOidListCell *tail; SimpleOidListCell *tail;
} SimpleOidList; } SimpleOidList;
typedef struct SimpleStringListCell
{
struct SimpleStringListCell *next;
char val[1]; /* VARIABLE LENGTH FIELD */
} SimpleStringListCell;
typedef struct SimpleStringList
{
SimpleStringListCell *head;
SimpleStringListCell *tail;
} SimpleStringList;
/* /*
* The data structures used to store system catalog information. Every * The data structures used to store system catalog information. Every
...@@ -533,9 +522,7 @@ extern CollInfo *findCollationByOid(Oid oid); ...@@ -533,9 +522,7 @@ extern CollInfo *findCollationByOid(Oid oid);
extern NamespaceInfo *findNamespaceByOid(Oid oid); extern NamespaceInfo *findNamespaceByOid(Oid oid);
extern void simple_oid_list_append(SimpleOidList *list, Oid val); extern void simple_oid_list_append(SimpleOidList *list, Oid val);
extern void simple_string_list_append(SimpleStringList *list, const char *val);
extern bool simple_oid_list_member(SimpleOidList *list, Oid val); extern bool simple_oid_list_member(SimpleOidList *list, Oid val);
extern bool simple_string_list_member(SimpleStringList *list, const char *val);
extern void parseOidArray(const char *str, Oid *array, int arraysize); extern void parseOidArray(const char *str, Oid *array, int arraysize);
......
...@@ -234,7 +234,7 @@ main(int argc, char **argv) ...@@ -234,7 +234,7 @@ main(int argc, char **argv)
case 't': /* Dump data for this table only */ case 't': /* Dump data for this table only */
opts->selTypes = 1; opts->selTypes = 1;
opts->selTable = 1; opts->selTable = 1;
opts->tableNames = pg_strdup(optarg); simple_string_list_append(&opts->tableNames, optarg);
break; break;
case 'U': case 'U':
...@@ -424,7 +424,7 @@ usage(const char *progname) ...@@ -424,7 +424,7 @@ usage(const char *progname)
printf(_(" -P, --function=NAME(args) restore named function\n")); printf(_(" -P, --function=NAME(args) restore named function\n"));
printf(_(" -s, --schema-only restore only the schema, no data\n")); printf(_(" -s, --schema-only restore only the schema, no data\n"));
printf(_(" -S, --superuser=NAME superuser user name to use for disabling triggers\n")); printf(_(" -S, --superuser=NAME superuser user name to use for disabling triggers\n"));
printf(_(" -t, --table=NAME restore named table\n")); printf(_(" -t, --table=NAME restore named table(s)\n"));
printf(_(" -T, --trigger=NAME restore named trigger\n")); printf(_(" -T, --trigger=NAME restore named trigger\n"));
printf(_(" -x, --no-privileges skip restoration of access privileges (grant/revoke)\n")); printf(_(" -x, --no-privileges skip restoration of access privileges (grant/revoke)\n"));
printf(_(" -1, --single-transaction restore as a single transaction\n")); printf(_(" -1, --single-transaction restore as a single transaction\n"));
......
...@@ -32,7 +32,7 @@ dropdb: dropdb.o common.o dumputils.o kwlookup.o keywords.o | submake-libpq ...@@ -32,7 +32,7 @@ dropdb: dropdb.o common.o dumputils.o kwlookup.o keywords.o | submake-libpq
droplang: droplang.o common.o print.o mbprint.o | submake-libpq droplang: droplang.o common.o print.o mbprint.o | submake-libpq
dropuser: dropuser.o common.o dumputils.o kwlookup.o keywords.o | submake-libpq dropuser: dropuser.o common.o dumputils.o kwlookup.o keywords.o | submake-libpq
clusterdb: clusterdb.o common.o dumputils.o kwlookup.o keywords.o | submake-libpq clusterdb: clusterdb.o common.o dumputils.o kwlookup.o keywords.o | submake-libpq
vacuumdb: vacuumdb.o common.o | submake-libpq vacuumdb: vacuumdb.o common.o dumputils.o kwlookup.o keywords.o | submake-libpq
reindexdb: reindexdb.o common.o dumputils.o kwlookup.o keywords.o | submake-libpq reindexdb: reindexdb.o common.o dumputils.o kwlookup.o keywords.o | submake-libpq
dumputils.c keywords.c: % : $(top_srcdir)/src/bin/pg_dump/% dumputils.c keywords.c: % : $(top_srcdir)/src/bin/pg_dump/%
......
...@@ -58,8 +58,8 @@ main(int argc, char *argv[]) ...@@ -58,8 +58,8 @@ main(int argc, char *argv[])
bool echo = false; bool echo = false;
bool quiet = false; bool quiet = false;
bool alldb = false; bool alldb = false;
char *table = NULL;
bool verbose = false; bool verbose = false;
SimpleStringList tables = {NULL, NULL};
progname = get_progname(argv[0]); progname = get_progname(argv[0]);
set_pglocale_pgservice(argv[0], PG_TEXTDOMAIN("pgscripts")); set_pglocale_pgservice(argv[0], PG_TEXTDOMAIN("pgscripts"));
...@@ -98,7 +98,7 @@ main(int argc, char *argv[]) ...@@ -98,7 +98,7 @@ main(int argc, char *argv[])
alldb = true; alldb = true;
break; break;
case 't': case 't':
table = pg_strdup(optarg); simple_string_list_append(&tables, optarg);
break; break;
case 'v': case 'v':
verbose = true; verbose = true;
...@@ -140,9 +140,10 @@ main(int argc, char *argv[]) ...@@ -140,9 +140,10 @@ main(int argc, char *argv[])
progname); progname);
exit(1); exit(1);
} }
if (table)
if (tables.head != NULL)
{ {
fprintf(stderr, _("%s: cannot cluster a specific table in all databases\n"), fprintf(stderr, _("%s: cannot cluster specific table(s) in all databases\n"),
progname); progname);
exit(1); exit(1);
} }
...@@ -162,7 +163,19 @@ main(int argc, char *argv[]) ...@@ -162,7 +163,19 @@ main(int argc, char *argv[])
dbname = get_user_name(progname); dbname = get_user_name(progname);
} }
cluster_one_database(dbname, verbose, table, if (tables.head != NULL)
{
SimpleStringListCell *cell;
for (cell = tables.head; cell; cell = cell->next)
{
cluster_one_database(dbname, verbose, cell->val,
host, port, username, prompt_password,
progname, echo);
}
}
else
cluster_one_database(dbname, verbose, NULL,
host, port, username, prompt_password, host, port, username, prompt_password,
progname, echo); progname, echo);
} }
...@@ -253,7 +266,7 @@ help(const char *progname) ...@@ -253,7 +266,7 @@ help(const char *progname)
printf(_(" -d, --dbname=DBNAME database to cluster\n")); printf(_(" -d, --dbname=DBNAME database to cluster\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(_(" -t, --table=TABLE cluster specific table only\n")); printf(_(" -t, --table=TABLE cluster specific table(s) only\n"));
printf(_(" -v, --verbose write a lot of output\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"));
......
...@@ -64,8 +64,8 @@ main(int argc, char *argv[]) ...@@ -64,8 +64,8 @@ main(int argc, char *argv[])
bool alldb = false; bool alldb = false;
bool echo = false; bool echo = false;
bool quiet = false; bool quiet = false;
const char *table = NULL; SimpleStringList indexes = {NULL, NULL};
const char *index = NULL; SimpleStringList tables = {NULL, NULL};
progname = get_progname(argv[0]); progname = get_progname(argv[0]);
set_pglocale_pgservice(argv[0], PG_TEXTDOMAIN("pgscripts")); set_pglocale_pgservice(argv[0], PG_TEXTDOMAIN("pgscripts"));
...@@ -108,10 +108,10 @@ main(int argc, char *argv[]) ...@@ -108,10 +108,10 @@ main(int argc, char *argv[])
syscatalog = true; syscatalog = true;
break; break;
case 't': case 't':
table = pg_strdup(optarg); simple_string_list_append(&tables, optarg);
break; break;
case 'i': case 'i':
index = pg_strdup(optarg); simple_string_list_append(&indexes, optarg);
break; break;
case 2: case 2:
maintenance_db = pg_strdup(optarg); maintenance_db = pg_strdup(optarg);
...@@ -154,14 +154,14 @@ main(int argc, char *argv[]) ...@@ -154,14 +154,14 @@ main(int argc, char *argv[])
fprintf(stderr, _("%s: cannot reindex all databases and system catalogs at the same time\n"), progname); fprintf(stderr, _("%s: cannot reindex all databases and system catalogs at the same time\n"), progname);
exit(1); exit(1);
} }
if (table) if (tables.head != NULL)
{ {
fprintf(stderr, _("%s: cannot reindex a specific table in all databases\n"), progname); fprintf(stderr, _("%s: cannot reindex specific table(s) in all databases\n"), progname);
exit(1); exit(1);
} }
if (index) if (indexes.head != NULL)
{ {
fprintf(stderr, _("%s: cannot reindex a specific index in all databases\n"), progname); fprintf(stderr, _("%s: cannot reindex specific index(es) in all databases\n"), progname);
exit(1); exit(1);
} }
...@@ -170,14 +170,14 @@ main(int argc, char *argv[]) ...@@ -170,14 +170,14 @@ main(int argc, char *argv[])
} }
else if (syscatalog) else if (syscatalog)
{ {
if (table) if (tables.head != NULL)
{ {
fprintf(stderr, _("%s: cannot reindex a specific table and system catalogs at the same time\n"), progname); fprintf(stderr, _("%s: cannot reindex specific table(s) and system catalogs at the same time\n"), progname);
exit(1); exit(1);
} }
if (index) if (indexes.head != NULL)
{ {
fprintf(stderr, _("%s: cannot reindex a specific index and system catalogs at the same time\n"), progname); fprintf(stderr, _("%s: cannot reindex specific index(es) and system catalogs at the same time\n"), progname);
exit(1); exit(1);
} }
...@@ -206,14 +206,28 @@ main(int argc, char *argv[]) ...@@ -206,14 +206,28 @@ main(int argc, char *argv[])
dbname = get_user_name(progname); dbname = get_user_name(progname);
} }
if (index) if (indexes.head != NULL)
reindex_one_database(index, dbname, "INDEX", host, port, {
SimpleStringListCell *cell;
for (cell = indexes.head; cell; cell = cell->next)
{
reindex_one_database(cell->val, dbname, "INDEX", host, port,
username, prompt_password, progname, echo); username, prompt_password, progname, echo);
if (table) }
reindex_one_database(table, dbname, "TABLE", host, port, }
if (tables.head != NULL)
{
SimpleStringListCell *cell;
for (cell = tables.head; cell; cell = cell->next)
{
reindex_one_database(cell->val, dbname, "TABLE", host, port,
username, prompt_password, progname, echo); username, prompt_password, progname, echo);
/* reindex database only if index or table is not specified */ }
if (index == NULL && table == NULL) }
/* reindex database only if neither index nor table is specified */
if (indexes.head == NULL && tables.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);
} }
...@@ -331,10 +345,10 @@ help(const char *progname) ...@@ -331,10 +345,10 @@ help(const char *progname)
printf(_(" -a, --all reindex all databases\n")); printf(_(" -a, --all reindex all databases\n"));
printf(_(" -d, --dbname=DBNAME database to reindex\n")); printf(_(" -d, --dbname=DBNAME database to reindex\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(_(" -i, --index=INDEX recreate specific index only\n")); printf(_(" -i, --index=INDEX recreate specific index(es) only\n"));
printf(_(" -q, --quiet don't write any messages\n")); printf(_(" -q, --quiet don't write any messages\n"));
printf(_(" -s, --system reindex system catalogs\n")); printf(_(" -s, --system reindex system catalogs\n"));
printf(_(" -t, --table=TABLE reindex specific table only\n")); printf(_(" -t, --table=TABLE reindex specific table(s) only\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"));
......
...@@ -12,6 +12,7 @@ ...@@ -12,6 +12,7 @@
#include "postgres_fe.h" #include "postgres_fe.h"
#include "common.h" #include "common.h"
#include "dumputils.h"
static void vacuum_one_database(const char *dbname, bool full, bool verbose, static void vacuum_one_database(const char *dbname, bool full, bool verbose,
...@@ -68,9 +69,9 @@ main(int argc, char *argv[]) ...@@ -68,9 +69,9 @@ main(int argc, char *argv[])
bool analyze_only = false; bool analyze_only = false;
bool freeze = false; bool freeze = false;
bool alldb = false; bool alldb = false;
char *table = NULL;
bool full = false; bool full = false;
bool verbose = false; bool verbose = false;
SimpleStringList tables = {NULL, NULL};
progname = get_progname(argv[0]); progname = get_progname(argv[0]);
set_pglocale_pgservice(argv[0], PG_TEXTDOMAIN("pgscripts")); set_pglocale_pgservice(argv[0], PG_TEXTDOMAIN("pgscripts"));
...@@ -118,7 +119,7 @@ main(int argc, char *argv[]) ...@@ -118,7 +119,7 @@ main(int argc, char *argv[])
alldb = true; alldb = true;
break; break;
case 't': case 't':
table = pg_strdup(optarg); simple_string_list_append(&tables, optarg);
break; break;
case 'f': case 'f':
full = true; full = true;
...@@ -181,9 +182,9 @@ main(int argc, char *argv[]) ...@@ -181,9 +182,9 @@ main(int argc, char *argv[])
progname); progname);
exit(1); exit(1);
} }
if (table) if (tables.head != NULL)
{ {
fprintf(stderr, _("%s: cannot vacuum a specific table in all databases\n"), fprintf(stderr, _("%s: cannot vacuum specific table(s) in all databases\n"),
progname); progname);
exit(1); exit(1);
} }
...@@ -204,8 +205,23 @@ main(int argc, char *argv[]) ...@@ -204,8 +205,23 @@ main(int argc, char *argv[])
dbname = get_user_name(progname); dbname = get_user_name(progname);
} }
vacuum_one_database(dbname, full, verbose, and_analyze, analyze_only, if (tables.head != NULL)
freeze, table, {
SimpleStringListCell *cell;
for (cell = tables.head; cell; cell = cell->next)
{
vacuum_one_database(dbname, full, verbose, and_analyze,
analyze_only,
freeze, cell->val,
host, port, username, prompt_password,
progname, echo);
}
}
else
vacuum_one_database(dbname, full, verbose, and_analyze,
analyze_only,
freeze, NULL,
host, port, username, prompt_password, host, port, username, prompt_password,
progname, echo); progname, echo);
} }
...@@ -348,7 +364,7 @@ help(const char *progname) ...@@ -348,7 +364,7 @@ help(const char *progname)
printf(_(" -f, --full do full vacuuming\n")); printf(_(" -f, --full do full vacuuming\n"));
printf(_(" -F, --freeze freeze row transaction information\n")); printf(_(" -F, --freeze freeze row transaction information\n"));
printf(_(" -q, --quiet don't write any messages\n")); printf(_(" -q, --quiet don't write any messages\n"));
printf(_(" -t, --table='TABLE[(COLUMNS)]' vacuum specific table only\n")); printf(_(" -t, --table='TABLE[(COLUMNS)]' vacuum specific table(s) only\n"));
printf(_(" -v, --verbose write a lot of output\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(_(" -z, --analyze update optimizer statistics\n")); printf(_(" -z, --analyze update optimizer statistics\n"));
......
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