Skip to content

Commit 5671aac

Browse files
committed
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
1 parent a5d489c commit 5671aac

File tree

4 files changed

+47
-10
lines changed

4 files changed

+47
-10
lines changed

doc/src/sgml/ref/pg_dump.sgml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -497,8 +497,10 @@ PostgreSQL documentation
497497
<term><option>--table=<replaceable class="parameter">table</replaceable></option></term>
498498
<listitem>
499499
<para>
500-
Dump only tables (or views or sequences or foreign tables) matching
501-
<replaceable class="parameter">table</replaceable>. Multiple tables
500+
Dump only tables with names matching
501+
<replaceable class="parameter">table</replaceable>.
502+
For this purpose, <quote>table</> includes views, materialized views,
503+
sequences, and foreign tables. Multiple tables
502504
can be selected by writing multiple <option>-t</> switches. Also, the
503505
<replaceable class="parameter">table</replaceable> parameter is
504506
interpreted as a pattern according to the same rules used by

doc/src/sgml/ref/pg_restore.sgml

Lines changed: 34 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -395,10 +395,39 @@
395395
<term><option>--table=<replaceable class="parameter">table</replaceable></option></term>
396396
<listitem>
397397
<para>
398-
Restore definition and/or data of named table only. Multiple tables
399-
may be specified with multiple <option>-t</> switches. This can be
400-
combined with the <option>-n</option> option to specify a schema.
401-
</para>
398+
Restore definition and/or data of only the named table.
399+
For this purpose, <quote>table</> includes views, materialized views,
400+
sequences, and foreign tables. Multiple tables
401+
can be selected by writing multiple <option>-t</> switches.
402+
This option can be combined with the <option>-n</option> option to
403+
specify table(s) in a particular schema.
404+
</para>
405+
406+
<note>
407+
<para>
408+
When <option>-t</option> is specified, <application>pg_restore</>
409+
makes no attempt to restore any other database objects that the
410+
selected table(s) might depend upon. Therefore, there is no
411+
guarantee that a specific-table restore into a clean database will
412+
succeed.
413+
</para>
414+
</note>
415+
416+
<note>
417+
<para>
418+
This flag does not behave identically to the <option>-t</option>
419+
flag of <application>pg_dump</application>. There is not currently
420+
any provision for wild-card matching in <application>pg_restore</>,
421+
nor can you include a schema name within its <option>-t</>.
422+
</para>
423+
</note>
424+
425+
<note>
426+
<para>
427+
In versions prior to <productname>PostgreSQL</> 9.6, this flag
428+
matched only tables, not any other type of relation.
429+
</para>
430+
</note>
402431
</listitem>
403432
</varlistentry>
404433

@@ -494,7 +523,7 @@
494523
fail if the user does not have the right to insert the rows from the
495524
dump into the table.
496525
</para>
497-
526+
498527
<para>
499528
Note that this option currently also requires the dump be in INSERT
500529
format as COPY TO does not support row security.

src/bin/pg_dump/pg_backup_archiver.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2663,7 +2663,13 @@ _tocEntryRequired(TocEntry *te, teSection curSection, RestoreOptions *ropt)
26632663
if (ropt->selTypes)
26642664
{
26652665
if (strcmp(te->desc, "TABLE") == 0 ||
2666-
strcmp(te->desc, "TABLE DATA") == 0)
2666+
strcmp(te->desc, "TABLE DATA") == 0 ||
2667+
strcmp(te->desc, "VIEW") == 0 ||
2668+
strcmp(te->desc, "FOREIGN TABLE") == 0 ||
2669+
strcmp(te->desc, "MATERIALIZED VIEW") == 0 ||
2670+
strcmp(te->desc, "MATERIALIZED VIEW DATA") == 0 ||
2671+
strcmp(te->desc, "SEQUENCE") == 0 ||
2672+
strcmp(te->desc, "SEQUENCE SET") == 0)
26672673
{
26682674
if (!ropt->selTable)
26692675
return 0;

src/bin/pg_dump/pg_restore.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ main(int argc, char **argv)
227227
if (strlen(optarg) != 0)
228228
opts->superuser = pg_strdup(optarg);
229229
break;
230-
case 't': /* Dump data for this table only */
230+
case 't': /* Dump specified table(s) only */
231231
opts->selTypes = 1;
232232
opts->selTable = 1;
233233
simple_string_list_append(&opts->tableNames, optarg);
@@ -455,7 +455,7 @@ usage(const char *progname)
455455
printf(_(" -P, --function=NAME(args) restore named function\n"));
456456
printf(_(" -s, --schema-only restore only the schema, no data\n"));
457457
printf(_(" -S, --superuser=NAME superuser user name to use for disabling triggers\n"));
458-
printf(_(" -t, --table=NAME restore named table\n"));
458+
printf(_(" -t, --table=NAME restore named relation (table, view, etc)\n"));
459459
printf(_(" -T, --trigger=NAME restore named trigger\n"));
460460
printf(_(" -x, --no-privileges skip restoration of access privileges (grant/revoke)\n"));
461461
printf(_(" -1, --single-transaction restore as a single transaction\n"));

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy