Skip to content

Commit 46b55e7

Browse files
committed
pg_restore: Add -N option to exclude schemas
This is similar to the -N option in pg_dump, except that it doesn't take a pattern, just like the existing -n option in pg_restore. From: Michael Banck <michael.banck@credativ.de>
1 parent 16d1adb commit 46b55e7

File tree

4 files changed

+30
-2
lines changed

4 files changed

+30
-2
lines changed

doc/src/sgml/ref/pg_restore.sgml

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,7 @@
302302
</varlistentry>
303303

304304
<varlistentry>
305-
<term><option>-n <replaceable class="parameter">namespace</replaceable></option></term>
305+
<term><option>-n <replaceable class="parameter">schema</replaceable></option></term>
306306
<term><option>--schema=<replaceable class="parameter">schema</replaceable></option></term>
307307
<listitem>
308308
<para>
@@ -314,6 +314,22 @@
314314
</listitem>
315315
</varlistentry>
316316

317+
<varlistentry>
318+
<term><option>-N <replaceable class="parameter">schema</replaceable></option></term>
319+
<term><option>--exclude-schema=<replaceable class="parameter">schema</replaceable></option></term>
320+
<listitem>
321+
<para>
322+
Do not restore objects that are in the named schema. Multiple schemas
323+
to be excluded may be specified with multiple <option>-N</> switches.
324+
</para>
325+
326+
<para>
327+
When both <option>-n</> and <option>-N</> are given for the same
328+
schema name, the <option>-N</> switch wins and the schema is excluded.
329+
</para>
330+
</listitem>
331+
</varlistentry>
332+
317333
<varlistentry>
318334
<term><option>-O</option></term>
319335
<term><option>--no-owner</option></term>

src/bin/pg_dump/pg_backup.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ typedef struct _restoreOptions
9999
SimpleStringList indexNames;
100100
SimpleStringList functionNames;
101101
SimpleStringList schemaNames;
102+
SimpleStringList schemaExcludeNames;
102103
SimpleStringList triggerNames;
103104
SimpleStringList tableNames;
104105

src/bin/pg_dump/pg_backup_archiver.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2751,6 +2751,11 @@ _tocEntryRequired(TocEntry *te, teSection curSection, RestoreOptions *ropt)
27512751
return 0;
27522752
}
27532753

2754+
if (ropt->schemaExcludeNames.head != NULL
2755+
&& te->namespace
2756+
&& simple_string_list_member(&ropt->schemaExcludeNames, te->namespace))
2757+
return 0;
2758+
27542759
if (ropt->selTypes)
27552760
{
27562761
if (strcmp(te->desc, "TABLE") == 0 ||

src/bin/pg_dump/pg_restore.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ main(int argc, char **argv)
8585
{"data-only", 0, NULL, 'a'},
8686
{"dbname", 1, NULL, 'd'},
8787
{"exit-on-error", 0, NULL, 'e'},
88+
{"exclude-schema", 1, NULL, 'N'},
8889
{"file", 1, NULL, 'f'},
8990
{"format", 1, NULL, 'F'},
9091
{"function", 1, NULL, 'P'},
@@ -148,7 +149,7 @@ main(int argc, char **argv)
148149
}
149150
}
150151

151-
while ((c = getopt_long(argc, argv, "acCd:ef:F:h:I:j:lL:n:Op:P:RsS:t:T:U:vwWx1",
152+
while ((c = getopt_long(argc, argv, "acCd:ef:F:h:I:j:lL:n:N:Op:P:RsS:t:T:U:vwWx1",
152153
cmdopts, NULL)) != -1)
153154
{
154155
switch (c)
@@ -196,6 +197,10 @@ main(int argc, char **argv)
196197
simple_string_list_append(&opts->schemaNames, optarg);
197198
break;
198199

200+
case 'N': /* Do not dump data for this schema */
201+
simple_string_list_append(&opts->schemaExcludeNames, optarg);
202+
break;
203+
199204
case 'O':
200205
opts->noOwner = 1;
201206
break;
@@ -456,6 +461,7 @@ usage(const char *progname)
456461
printf(_(" -L, --use-list=FILENAME use table of contents from this file for\n"
457462
" selecting/ordering output\n"));
458463
printf(_(" -n, --schema=NAME restore only objects in this schema\n"));
464+
printf(_(" -N, --exclude-schema=NAME do not restore objects in this schema\n"));
459465
printf(_(" -O, --no-owner skip restoration of object ownership\n"));
460466
printf(_(" -P, --function=NAME(args) restore named function\n"));
461467
printf(_(" -s, --schema-only restore only the schema, no data\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