From 5671aaca87c47128f6a1e0556ce9c7512096ad87 Mon Sep 17 00:00:00 2001 From: Tom Lane Date: Thu, 2 Jul 2015 18:13:34 -0400 Subject: [PATCH] Improve pg_restore's -t switch to match all types of relations. -t will now match views, foreign tables, materialized views, and sequences, not only plain tables. This is more useful, and also more consistent with the behavior of pg_dump's -t switch, which has always matched all relation types. We're still not there on matching pg_dump's behavior entirely, so mention that in the docs. Craig Ringer, reviewed by Pavel Stehule --- doc/src/sgml/ref/pg_dump.sgml | 6 +++-- doc/src/sgml/ref/pg_restore.sgml | 37 +++++++++++++++++++++++++--- src/bin/pg_dump/pg_backup_archiver.c | 8 +++++- src/bin/pg_dump/pg_restore.c | 4 +-- 4 files changed, 46 insertions(+), 9 deletions(-) diff --git a/doc/src/sgml/ref/pg_dump.sgml b/doc/src/sgml/ref/pg_dump.sgml index 7c28bd2876..7467e868e3 100644 --- a/doc/src/sgml/ref/pg_dump.sgml +++ b/doc/src/sgml/ref/pg_dump.sgml @@ -497,8 +497,10 @@ PostgreSQL documentation - Dump only tables (or views or sequences or foreign tables) matching - table. Multiple tables + Dump only tables with names matching + table. + For this purpose, table includes views, materialized views, + sequences, and foreign tables. Multiple tables can be selected by writing multiple - + Note that this option currently also requires the dump be in INSERT format as COPY TO does not support row security. diff --git a/src/bin/pg_dump/pg_backup_archiver.c b/src/bin/pg_dump/pg_backup_archiver.c index 0d52babc4f..8f1f6c1a24 100644 --- a/src/bin/pg_dump/pg_backup_archiver.c +++ b/src/bin/pg_dump/pg_backup_archiver.c @@ -2663,7 +2663,13 @@ _tocEntryRequired(TocEntry *te, teSection curSection, RestoreOptions *ropt) if (ropt->selTypes) { if (strcmp(te->desc, "TABLE") == 0 || - strcmp(te->desc, "TABLE DATA") == 0) + strcmp(te->desc, "TABLE DATA") == 0 || + strcmp(te->desc, "VIEW") == 0 || + strcmp(te->desc, "FOREIGN TABLE") == 0 || + strcmp(te->desc, "MATERIALIZED VIEW") == 0 || + strcmp(te->desc, "MATERIALIZED VIEW DATA") == 0 || + strcmp(te->desc, "SEQUENCE") == 0 || + strcmp(te->desc, "SEQUENCE SET") == 0) { if (!ropt->selTable) return 0; diff --git a/src/bin/pg_dump/pg_restore.c b/src/bin/pg_dump/pg_restore.c index ec82d0b98d..b12948823c 100644 --- a/src/bin/pg_dump/pg_restore.c +++ b/src/bin/pg_dump/pg_restore.c @@ -227,7 +227,7 @@ main(int argc, char **argv) if (strlen(optarg) != 0) opts->superuser = pg_strdup(optarg); break; - case 't': /* Dump data for this table only */ + case 't': /* Dump specified table(s) only */ opts->selTypes = 1; opts->selTable = 1; simple_string_list_append(&opts->tableNames, optarg); @@ -455,7 +455,7 @@ usage(const char *progname) printf(_(" -P, --function=NAME(args) restore named function\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(_(" -t, --table=NAME restore named table\n")); + printf(_(" -t, --table=NAME restore named relation (table, view, etc)\n")); printf(_(" -T, --trigger=NAME restore named trigger\n")); printf(_(" -x, --no-privileges skip restoration of access privileges (grant/revoke)\n")); printf(_(" -1, --single-transaction restore as a single transaction\n"));