Line data Source code
1 : /*-------------------------------------------------------------------------
2 : *
3 : * pg_restore.c
4 : * pg_restore is an utility extracting postgres database definitions
5 : * from a backup archive created by pg_dump using the archiver
6 : * interface.
7 : *
8 : * pg_restore will read the backup archive and
9 : * dump out a script that reproduces
10 : * the schema of the database in terms of
11 : * user-defined types
12 : * user-defined functions
13 : * tables
14 : * indexes
15 : * aggregates
16 : * operators
17 : * ACL - grant/revoke
18 : *
19 : * the output script is SQL that is understood by PostgreSQL
20 : *
21 : * Basic process in a restore operation is:
22 : *
23 : * Open the Archive and read the TOC.
24 : * Set flags in TOC entries, and *maybe* reorder them.
25 : * Generate script to stdout
26 : * Exit
27 : *
28 : * Copyright (c) 2000, Philip Warner
29 : * Rights are granted to use this software in any way so long
30 : * as this notice is not removed.
31 : *
32 : * The author is not responsible for loss or damages that may
33 : * result from its use.
34 : *
35 : *
36 : * IDENTIFICATION
37 : * src/bin/pg_dump/pg_restore.c
38 : *
39 : *-------------------------------------------------------------------------
40 : */
41 : #include "postgres_fe.h"
42 :
43 : #include <ctype.h>
44 : #ifdef HAVE_TERMIOS_H
45 : #include <termios.h>
46 : #endif
47 :
48 : #include "fe_utils/option_utils.h"
49 : #include "filter.h"
50 : #include "getopt_long.h"
51 : #include "parallel.h"
52 : #include "pg_backup_utils.h"
53 :
54 : static void usage(const char *progname);
55 : static void read_restore_filters(const char *filename, RestoreOptions *opts);
56 :
57 : int
58 134 : main(int argc, char **argv)
59 : {
60 : RestoreOptions *opts;
61 : int c;
62 : int exit_code;
63 134 : int numWorkers = 1;
64 : Archive *AH;
65 : char *inputFileSpec;
66 134 : bool data_only = false;
67 134 : bool schema_only = false;
68 : static int disable_triggers = 0;
69 : static int enable_row_security = 0;
70 : static int if_exists = 0;
71 : static int no_data_for_failed_tables = 0;
72 : static int outputNoTableAm = 0;
73 : static int outputNoTablespaces = 0;
74 : static int use_setsessauth = 0;
75 : static int no_comments = 0;
76 : static int no_data = 0;
77 : static int no_publications = 0;
78 : static int no_schema = 0;
79 : static int no_security_labels = 0;
80 : static int no_statistics = 0;
81 : static int no_subscriptions = 0;
82 : static int strict_names = 0;
83 : static int statistics_only = 0;
84 :
85 134 : struct option cmdopts[] = {
86 : {"clean", 0, NULL, 'c'},
87 : {"create", 0, NULL, 'C'},
88 : {"data-only", 0, NULL, 'a'},
89 : {"dbname", 1, NULL, 'd'},
90 : {"exit-on-error", 0, NULL, 'e'},
91 : {"exclude-schema", 1, NULL, 'N'},
92 : {"file", 1, NULL, 'f'},
93 : {"format", 1, NULL, 'F'},
94 : {"function", 1, NULL, 'P'},
95 : {"host", 1, NULL, 'h'},
96 : {"index", 1, NULL, 'I'},
97 : {"jobs", 1, NULL, 'j'},
98 : {"list", 0, NULL, 'l'},
99 : {"no-privileges", 0, NULL, 'x'},
100 : {"no-acl", 0, NULL, 'x'},
101 : {"no-owner", 0, NULL, 'O'},
102 : {"no-reconnect", 0, NULL, 'R'},
103 : {"port", 1, NULL, 'p'},
104 : {"no-password", 0, NULL, 'w'},
105 : {"password", 0, NULL, 'W'},
106 : {"schema", 1, NULL, 'n'},
107 : {"schema-only", 0, NULL, 's'},
108 : {"superuser", 1, NULL, 'S'},
109 : {"table", 1, NULL, 't'},
110 : {"trigger", 1, NULL, 'T'},
111 : {"use-list", 1, NULL, 'L'},
112 : {"username", 1, NULL, 'U'},
113 : {"verbose", 0, NULL, 'v'},
114 : {"single-transaction", 0, NULL, '1'},
115 :
116 : /*
117 : * the following options don't have an equivalent short option letter
118 : */
119 : {"disable-triggers", no_argument, &disable_triggers, 1},
120 : {"enable-row-security", no_argument, &enable_row_security, 1},
121 : {"if-exists", no_argument, &if_exists, 1},
122 : {"no-data-for-failed-tables", no_argument, &no_data_for_failed_tables, 1},
123 : {"no-table-access-method", no_argument, &outputNoTableAm, 1},
124 : {"no-tablespaces", no_argument, &outputNoTablespaces, 1},
125 : {"role", required_argument, NULL, 2},
126 : {"section", required_argument, NULL, 3},
127 : {"strict-names", no_argument, &strict_names, 1},
128 : {"transaction-size", required_argument, NULL, 5},
129 : {"use-set-session-authorization", no_argument, &use_setsessauth, 1},
130 : {"no-comments", no_argument, &no_comments, 1},
131 : {"no-data", no_argument, &no_data, 1},
132 : {"no-publications", no_argument, &no_publications, 1},
133 : {"no-schema", no_argument, &no_schema, 1},
134 : {"no-security-labels", no_argument, &no_security_labels, 1},
135 : {"no-subscriptions", no_argument, &no_subscriptions, 1},
136 : {"no-statistics", no_argument, &no_statistics, 1},
137 : {"statistics-only", no_argument, &statistics_only, 1},
138 : {"filter", required_argument, NULL, 4},
139 :
140 : {NULL, 0, NULL, 0}
141 : };
142 :
143 134 : pg_logging_init(argv[0]);
144 134 : pg_logging_set_level(PG_LOG_WARNING);
145 134 : set_pglocale_pgservice(argv[0], PG_TEXTDOMAIN("pg_dump"));
146 :
147 134 : init_parallel_dump_utils();
148 :
149 134 : opts = NewRestoreOptions();
150 :
151 134 : progname = get_progname(argv[0]);
152 :
153 134 : if (argc > 1)
154 : {
155 132 : if (strcmp(argv[1], "--help") == 0 || strcmp(argv[1], "-?") == 0)
156 : {
157 2 : usage(progname);
158 2 : exit_nicely(0);
159 : }
160 130 : if (strcmp(argv[1], "--version") == 0 || strcmp(argv[1], "-V") == 0)
161 : {
162 22 : puts("pg_restore (PostgreSQL) " PG_VERSION);
163 22 : exit_nicely(0);
164 : }
165 : }
166 :
167 498 : while ((c = getopt_long(argc, argv, "acCd:ef:F:h:I:j:lL:n:N:Op:P:RsS:t:T:U:vwWx1",
168 : cmdopts, NULL)) != -1)
169 : {
170 400 : switch (c)
171 : {
172 4 : case 'a': /* Dump data only */
173 4 : data_only = true;
174 4 : break;
175 18 : case 'c': /* clean (i.e., drop) schema prior to create */
176 18 : opts->dropSchema = 1;
177 18 : break;
178 28 : case 'C':
179 28 : opts->createDB = 1;
180 28 : break;
181 34 : case 'd':
182 34 : opts->cparams.dbname = pg_strdup(optarg);
183 34 : break;
184 24 : case 'e':
185 24 : opts->exit_on_error = true;
186 24 : break;
187 62 : case 'f': /* output file name */
188 62 : opts->filename = pg_strdup(optarg);
189 62 : break;
190 22 : case 'F':
191 22 : if (strlen(optarg) != 0)
192 22 : opts->formatName = pg_strdup(optarg);
193 22 : break;
194 24 : case 'h':
195 24 : if (strlen(optarg) != 0)
196 24 : opts->cparams.pghost = pg_strdup(optarg);
197 24 : break;
198 :
199 16 : case 'j': /* number of restore jobs */
200 16 : if (!option_parse_int(optarg, "-j/--jobs", 1,
201 : PG_MAX_JOBS,
202 : &numWorkers))
203 2 : exit(1);
204 14 : break;
205 :
206 8 : case 'l': /* Dump the TOC summary */
207 8 : opts->tocSummary = 1;
208 8 : break;
209 :
210 0 : case 'L': /* input TOC summary file name */
211 0 : opts->tocFile = pg_strdup(optarg);
212 0 : break;
213 :
214 0 : case 'n': /* Dump data for this schema only */
215 0 : simple_string_list_append(&opts->schemaNames, optarg);
216 0 : break;
217 :
218 0 : case 'N': /* Do not dump data for this schema */
219 0 : simple_string_list_append(&opts->schemaExcludeNames, optarg);
220 0 : break;
221 :
222 0 : case 'O':
223 0 : opts->noOwner = 1;
224 0 : break;
225 :
226 44 : case 'p':
227 44 : if (strlen(optarg) != 0)
228 44 : opts->cparams.pgport = pg_strdup(optarg);
229 44 : break;
230 0 : case 'R':
231 : /* no-op, still accepted for backwards compatibility */
232 0 : break;
233 0 : case 'P': /* Function */
234 0 : opts->selTypes = 1;
235 0 : opts->selFunction = 1;
236 0 : simple_string_list_append(&opts->functionNames, optarg);
237 0 : break;
238 0 : case 'I': /* Index */
239 0 : opts->selTypes = 1;
240 0 : opts->selIndex = 1;
241 0 : simple_string_list_append(&opts->indexNames, optarg);
242 0 : break;
243 0 : case 'T': /* Trigger */
244 0 : opts->selTypes = 1;
245 0 : opts->selTrigger = 1;
246 0 : simple_string_list_append(&opts->triggerNames, optarg);
247 0 : break;
248 2 : case 's': /* dump schema only */
249 2 : schema_only = true;
250 2 : break;
251 0 : case 'S': /* Superuser username */
252 0 : if (strlen(optarg) != 0)
253 0 : opts->superuser = pg_strdup(optarg);
254 0 : break;
255 0 : case 't': /* Dump specified table(s) only */
256 0 : opts->selTypes = 1;
257 0 : opts->selTable = 1;
258 0 : simple_string_list_append(&opts->tableNames, optarg);
259 0 : break;
260 :
261 28 : case 'U':
262 28 : opts->cparams.username = pg_strdup(optarg);
263 28 : break;
264 :
265 34 : case 'v': /* verbose */
266 34 : opts->verbose = 1;
267 34 : pg_logging_increase_verbosity();
268 34 : break;
269 :
270 0 : case 'w':
271 0 : opts->cparams.promptPassword = TRI_NO;
272 0 : break;
273 :
274 0 : case 'W':
275 0 : opts->cparams.promptPassword = TRI_YES;
276 0 : break;
277 :
278 0 : case 'x': /* skip ACL dump */
279 0 : opts->aclsSkip = 1;
280 0 : break;
281 :
282 4 : case '1': /* Restore data in a single transaction */
283 4 : opts->single_txn = true;
284 4 : opts->exit_on_error = true;
285 4 : break;
286 :
287 2 : case 0:
288 :
289 : /*
290 : * This covers the long options without a short equivalent.
291 : */
292 2 : break;
293 :
294 0 : case 2: /* SET ROLE */
295 0 : opts->use_role = pg_strdup(optarg);
296 0 : break;
297 :
298 0 : case 3: /* section */
299 0 : set_dump_section(optarg, &(opts->dumpSections));
300 0 : break;
301 :
302 20 : case 4: /* filter */
303 20 : read_restore_filters(optarg, opts);
304 12 : break;
305 :
306 24 : case 5: /* transaction-size */
307 24 : if (!option_parse_int(optarg, "--transaction-size",
308 : 1, INT_MAX,
309 : &opts->txn_size))
310 0 : exit(1);
311 24 : opts->exit_on_error = true;
312 24 : break;
313 :
314 2 : default:
315 : /* getopt_long already emitted a complaint */
316 2 : pg_log_error_hint("Try \"%s --help\" for more information.", progname);
317 2 : exit_nicely(1);
318 : }
319 : }
320 :
321 : /* Get file name from command line */
322 98 : if (optind < argc)
323 82 : inputFileSpec = argv[optind++];
324 : else
325 16 : inputFileSpec = NULL;
326 :
327 : /* Complain if any arguments remain */
328 98 : if (optind < argc)
329 : {
330 2 : pg_log_error("too many command-line arguments (first is \"%s\")",
331 : argv[optind]);
332 2 : pg_log_error_hint("Try \"%s --help\" for more information.", progname);
333 2 : exit_nicely(1);
334 : }
335 :
336 : /* Complain if neither -f nor -d was specified (except if dumping TOC) */
337 96 : if (!opts->cparams.dbname && !opts->filename && !opts->tocSummary)
338 2 : pg_fatal("one of -d/--dbname and -f/--file must be specified");
339 :
340 : /* Should get at most one of -d and -f, else user is confused */
341 94 : if (opts->cparams.dbname)
342 : {
343 34 : if (opts->filename)
344 : {
345 2 : pg_log_error("options -d/--dbname and -f/--file cannot be used together");
346 2 : pg_log_error_hint("Try \"%s --help\" for more information.", progname);
347 2 : exit_nicely(1);
348 : }
349 32 : opts->useDB = 1;
350 : }
351 :
352 92 : if (data_only && schema_only)
353 2 : pg_fatal("options -s/--schema-only and -a/--data-only cannot be used together");
354 90 : if (data_only && statistics_only)
355 0 : pg_fatal("options -a/--data-only and --statistics-only cannot be used together");
356 90 : if (schema_only && statistics_only)
357 0 : pg_fatal("options -s/--schema-only and --statistics-only cannot be used together");
358 :
359 90 : if (data_only && opts->dropSchema)
360 2 : pg_fatal("options -c/--clean and -a/--data-only cannot be used together");
361 :
362 88 : if (opts->single_txn && opts->txn_size > 0)
363 0 : pg_fatal("options -1/--single-transaction and --transaction-size cannot be used together");
364 :
365 : /*
366 : * -C is not compatible with -1, because we can't create a database inside
367 : * a transaction block.
368 : */
369 88 : if (opts->createDB && opts->single_txn)
370 2 : pg_fatal("options -C/--create and -1/--single-transaction cannot be used together");
371 :
372 : /* Can't do single-txn mode with multiple connections */
373 86 : if (opts->single_txn && numWorkers > 1)
374 2 : pg_fatal("cannot specify both --single-transaction and multiple jobs");
375 :
376 : /* set derivative flags */
377 84 : opts->dumpData = data_only || (!no_data && !schema_only && !statistics_only);
378 84 : opts->dumpSchema = schema_only || (!no_schema && !data_only && !statistics_only);
379 84 : opts->dumpStatistics = statistics_only || (!no_statistics && !data_only && !schema_only);
380 :
381 84 : opts->disable_triggers = disable_triggers;
382 84 : opts->enable_row_security = enable_row_security;
383 84 : opts->noDataForFailedTables = no_data_for_failed_tables;
384 84 : opts->noTableAm = outputNoTableAm;
385 84 : opts->noTablespace = outputNoTablespaces;
386 84 : opts->use_setsessauth = use_setsessauth;
387 84 : opts->no_comments = no_comments;
388 84 : opts->no_publications = no_publications;
389 84 : opts->no_security_labels = no_security_labels;
390 84 : opts->no_subscriptions = no_subscriptions;
391 :
392 84 : if (if_exists && !opts->dropSchema)
393 2 : pg_fatal("option --if-exists requires option -c/--clean");
394 82 : opts->if_exists = if_exists;
395 82 : opts->strict_names = strict_names;
396 :
397 82 : if (opts->formatName)
398 : {
399 44 : if (pg_strcasecmp(opts->formatName, "c") == 0 ||
400 22 : pg_strcasecmp(opts->formatName, "custom") == 0)
401 16 : opts->format = archCustom;
402 12 : else if (pg_strcasecmp(opts->formatName, "d") == 0 ||
403 6 : pg_strcasecmp(opts->formatName, "directory") == 0)
404 2 : opts->format = archDirectory;
405 8 : else if (pg_strcasecmp(opts->formatName, "t") == 0 ||
406 4 : pg_strcasecmp(opts->formatName, "tar") == 0)
407 2 : opts->format = archTar;
408 4 : else if (pg_strcasecmp(opts->formatName, "p") == 0 ||
409 2 : pg_strcasecmp(opts->formatName, "plain") == 0)
410 : {
411 : /* recognize this for consistency with pg_dump */
412 0 : pg_fatal("archive format \"%s\" is not supported; please use psql",
413 : opts->formatName);
414 : }
415 : else
416 2 : pg_fatal("unrecognized archive format \"%s\"; please specify \"c\", \"d\", or \"t\"",
417 : opts->formatName);
418 : }
419 :
420 80 : AH = OpenArchive(inputFileSpec, opts->format);
421 :
422 80 : SetArchiveOptions(AH, NULL, opts);
423 :
424 : /*
425 : * We don't have a connection yet but that doesn't matter. The connection
426 : * is initialized to NULL and if we terminate through exit_nicely() while
427 : * it's still NULL, the cleanup function will just be a no-op.
428 : */
429 80 : on_exit_close_archive(AH);
430 :
431 : /* Let the archiver know how noisy to be */
432 80 : AH->verbose = opts->verbose;
433 :
434 : /*
435 : * Whether to keep submitting sql commands as "pg_restore ... | psql ... "
436 : */
437 80 : AH->exit_on_error = opts->exit_on_error;
438 :
439 80 : if (opts->tocFile)
440 0 : SortTocFromFile(AH);
441 :
442 80 : AH->numWorkers = numWorkers;
443 :
444 80 : if (opts->tocSummary)
445 8 : PrintTOCSummary(AH);
446 : else
447 : {
448 72 : ProcessArchiveRestoreOptions(AH);
449 72 : RestoreArchive(AH);
450 : }
451 :
452 : /* done, print a summary of ignored errors */
453 80 : if (AH->n_errors)
454 0 : pg_log_warning("errors ignored on restore: %d", AH->n_errors);
455 :
456 : /* AH may be freed in CloseArchive? */
457 80 : exit_code = AH->n_errors ? 1 : 0;
458 :
459 80 : CloseArchive(AH);
460 :
461 80 : return exit_code;
462 : }
463 :
464 : static void
465 2 : usage(const char *progname)
466 : {
467 2 : printf(_("%s restores a PostgreSQL database from an archive created by pg_dump.\n\n"), progname);
468 2 : printf(_("Usage:\n"));
469 2 : printf(_(" %s [OPTION]... [FILE]\n"), progname);
470 :
471 2 : printf(_("\nGeneral options:\n"));
472 2 : printf(_(" -d, --dbname=NAME connect to database name\n"));
473 2 : printf(_(" -f, --file=FILENAME output file name (- for stdout)\n"));
474 2 : printf(_(" -F, --format=c|d|t backup file format (should be automatic)\n"));
475 2 : printf(_(" -l, --list print summarized TOC of the archive\n"));
476 2 : printf(_(" -v, --verbose verbose mode\n"));
477 2 : printf(_(" -V, --version output version information, then exit\n"));
478 2 : printf(_(" -?, --help show this help, then exit\n"));
479 :
480 2 : printf(_("\nOptions controlling the restore:\n"));
481 2 : printf(_(" -a, --data-only restore only the data, no schema\n"));
482 2 : printf(_(" -c, --clean clean (drop) database objects before recreating\n"));
483 2 : printf(_(" -C, --create create the target database\n"));
484 2 : printf(_(" -e, --exit-on-error exit on error, default is to continue\n"));
485 2 : printf(_(" -I, --index=NAME restore named index\n"));
486 2 : printf(_(" -j, --jobs=NUM use this many parallel jobs to restore\n"));
487 2 : printf(_(" -L, --use-list=FILENAME use table of contents from this file for\n"
488 : " selecting/ordering output\n"));
489 2 : printf(_(" -n, --schema=NAME restore only objects in this schema\n"));
490 2 : printf(_(" -N, --exclude-schema=NAME do not restore objects in this schema\n"));
491 2 : printf(_(" -O, --no-owner skip restoration of object ownership\n"));
492 2 : printf(_(" -P, --function=NAME(args) restore named function\n"));
493 2 : printf(_(" -s, --schema-only restore only the schema, no data\n"));
494 2 : printf(_(" -S, --superuser=NAME superuser user name to use for disabling triggers\n"));
495 2 : printf(_(" -t, --table=NAME restore named relation (table, view, etc.)\n"));
496 2 : printf(_(" -T, --trigger=NAME restore named trigger\n"));
497 2 : printf(_(" -x, --no-privileges skip restoration of access privileges (grant/revoke)\n"));
498 2 : printf(_(" -1, --single-transaction restore as a single transaction\n"));
499 2 : printf(_(" --disable-triggers disable triggers during data-only restore\n"));
500 2 : printf(_(" --enable-row-security enable row security\n"));
501 2 : printf(_(" --filter=FILENAME restore or skip objects based on expressions\n"
502 : " in FILENAME\n"));
503 2 : printf(_(" --if-exists use IF EXISTS when dropping objects\n"));
504 2 : printf(_(" --no-comments do not restore comment commands\n"));
505 2 : printf(_(" --no-data do not restore data\n"));
506 2 : printf(_(" --no-data-for-failed-tables do not restore data of tables that could not be\n"
507 : " created\n"));
508 2 : printf(_(" --no-publications do not restore publications\n"));
509 2 : printf(_(" --no-schema do not restore schema\n"));
510 2 : printf(_(" --no-security-labels do not restore security labels\n"));
511 2 : printf(_(" --no-statistics do not restore statistics\n"));
512 2 : printf(_(" --no-subscriptions do not restore subscriptions\n"));
513 2 : printf(_(" --no-table-access-method do not restore table access methods\n"));
514 2 : printf(_(" --no-tablespaces do not restore tablespace assignments\n"));
515 2 : printf(_(" --section=SECTION restore named section (pre-data, data, or post-data)\n"));
516 2 : printf(_(" --statistics-only restore only the statistics, not schema or data\n"));
517 2 : printf(_(" --strict-names require table and/or schema include patterns to\n"
518 : " match at least one entity each\n"));
519 2 : printf(_(" --transaction-size=N commit after every N objects\n"));
520 2 : printf(_(" --use-set-session-authorization\n"
521 : " use SET SESSION AUTHORIZATION commands instead of\n"
522 : " ALTER OWNER commands to set ownership\n"));
523 :
524 2 : printf(_("\nConnection options:\n"));
525 2 : printf(_(" -h, --host=HOSTNAME database server host or socket directory\n"));
526 2 : printf(_(" -p, --port=PORT database server port number\n"));
527 2 : printf(_(" -U, --username=NAME connect as specified database user\n"));
528 2 : printf(_(" -w, --no-password never prompt for password\n"));
529 2 : printf(_(" -W, --password force password prompt (should happen automatically)\n"));
530 2 : printf(_(" --role=ROLENAME do SET ROLE before restore\n"));
531 :
532 2 : printf(_("\n"
533 : "The options -I, -n, -N, -P, -t, -T, and --section can be combined and specified\n"
534 : "multiple times to select multiple objects.\n"));
535 2 : printf(_("\nIf no input file name is supplied, then standard input is used.\n\n"));
536 2 : printf(_("Report bugs to <%s>.\n"), PACKAGE_BUGREPORT);
537 2 : printf(_("%s home page: <%s>\n"), PACKAGE_NAME, PACKAGE_URL);
538 2 : }
539 :
540 : /*
541 : * read_restore_filters - retrieve object identifier patterns from file
542 : *
543 : * Parse the specified filter file for include and exclude patterns, and add
544 : * them to the relevant lists. If the filename is "-" then filters will be
545 : * read from STDIN rather than a file.
546 : */
547 : static void
548 20 : read_restore_filters(const char *filename, RestoreOptions *opts)
549 : {
550 : FilterStateData fstate;
551 : char *objname;
552 : FilterCommandType comtype;
553 : FilterObjectType objtype;
554 :
555 20 : filter_init(&fstate, filename, exit_nicely);
556 :
557 34 : while (filter_read_item(&fstate, &objname, &comtype, &objtype))
558 : {
559 22 : if (comtype == FILTER_COMMAND_TYPE_INCLUDE)
560 : {
561 16 : switch (objtype)
562 : {
563 0 : case FILTER_OBJECT_TYPE_NONE:
564 0 : break;
565 4 : case FILTER_OBJECT_TYPE_TABLE_DATA:
566 : case FILTER_OBJECT_TYPE_TABLE_DATA_AND_CHILDREN:
567 : case FILTER_OBJECT_TYPE_TABLE_AND_CHILDREN:
568 : case FILTER_OBJECT_TYPE_DATABASE:
569 : case FILTER_OBJECT_TYPE_EXTENSION:
570 : case FILTER_OBJECT_TYPE_FOREIGN_DATA:
571 4 : pg_log_filter_error(&fstate, _("%s filter for \"%s\" is not allowed"),
572 : "include",
573 : filter_object_type_name(objtype));
574 4 : exit_nicely(1);
575 :
576 4 : case FILTER_OBJECT_TYPE_FUNCTION:
577 4 : opts->selTypes = 1;
578 4 : opts->selFunction = 1;
579 4 : simple_string_list_append(&opts->functionNames, objname);
580 4 : break;
581 2 : case FILTER_OBJECT_TYPE_INDEX:
582 2 : opts->selTypes = 1;
583 2 : opts->selIndex = 1;
584 2 : simple_string_list_append(&opts->indexNames, objname);
585 2 : break;
586 2 : case FILTER_OBJECT_TYPE_SCHEMA:
587 2 : simple_string_list_append(&opts->schemaNames, objname);
588 2 : break;
589 2 : case FILTER_OBJECT_TYPE_TABLE:
590 2 : opts->selTypes = 1;
591 2 : opts->selTable = 1;
592 2 : simple_string_list_append(&opts->tableNames, objname);
593 2 : break;
594 2 : case FILTER_OBJECT_TYPE_TRIGGER:
595 2 : opts->selTypes = 1;
596 2 : opts->selTrigger = 1;
597 2 : simple_string_list_append(&opts->triggerNames, objname);
598 2 : break;
599 : }
600 12 : }
601 6 : else if (comtype == FILTER_COMMAND_TYPE_EXCLUDE)
602 : {
603 6 : switch (objtype)
604 : {
605 0 : case FILTER_OBJECT_TYPE_NONE:
606 0 : break;
607 4 : case FILTER_OBJECT_TYPE_TABLE_DATA:
608 : case FILTER_OBJECT_TYPE_TABLE_DATA_AND_CHILDREN:
609 : case FILTER_OBJECT_TYPE_DATABASE:
610 : case FILTER_OBJECT_TYPE_EXTENSION:
611 : case FILTER_OBJECT_TYPE_FOREIGN_DATA:
612 : case FILTER_OBJECT_TYPE_FUNCTION:
613 : case FILTER_OBJECT_TYPE_INDEX:
614 : case FILTER_OBJECT_TYPE_TABLE:
615 : case FILTER_OBJECT_TYPE_TABLE_AND_CHILDREN:
616 : case FILTER_OBJECT_TYPE_TRIGGER:
617 4 : pg_log_filter_error(&fstate, _("%s filter for \"%s\" is not allowed"),
618 : "exclude",
619 : filter_object_type_name(objtype));
620 4 : exit_nicely(1);
621 :
622 2 : case FILTER_OBJECT_TYPE_SCHEMA:
623 2 : simple_string_list_append(&opts->schemaExcludeNames, objname);
624 2 : break;
625 : }
626 2 : }
627 : else
628 : {
629 : Assert(comtype == FILTER_COMMAND_TYPE_NONE);
630 : Assert(objtype == FILTER_OBJECT_TYPE_NONE);
631 : }
632 :
633 14 : if (objname)
634 14 : free(objname);
635 : }
636 :
637 12 : filter_free(&fstate);
638 12 : }
|