PostgreSQL Source Code git master
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
pg_restore.c File Reference
#include "postgres_fe.h"
#include <ctype.h>
#include "fe_utils/option_utils.h"
#include "filter.h"
#include "getopt_long.h"
#include "parallel.h"
#include "pg_backup_utils.h"
Include dependency graph for pg_restore.c:

Go to the source code of this file.

Functions

static void usage (const char *progname)
 
static void read_restore_filters (const char *filename, RestoreOptions *opts)
 
int main (int argc, char **argv)
 

Function Documentation

◆ main()

int main ( int  argc,
char **  argv 
)

Definition at line 58 of file pg_restore.c.

59{
61 int c;
62 int exit_code;
63 int numWorkers = 1;
64 Archive *AH;
65 char *inputFileSpec;
66 bool data_only = false;
67 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_policies = 0;
78 static int no_publications = 0;
79 static int no_schema = 0;
80 static int no_security_labels = 0;
81 static int no_statistics = 0;
82 static int no_subscriptions = 0;
83 static int strict_names = 0;
84 static int statistics_only = 0;
85 static int with_data = 0;
86 static int with_schema = 0;
87 static int with_statistics = 0;
88
89 struct option cmdopts[] = {
90 {"clean", 0, NULL, 'c'},
91 {"create", 0, NULL, 'C'},
92 {"data-only", 0, NULL, 'a'},
93 {"dbname", 1, NULL, 'd'},
94 {"exit-on-error", 0, NULL, 'e'},
95 {"exclude-schema", 1, NULL, 'N'},
96 {"file", 1, NULL, 'f'},
97 {"format", 1, NULL, 'F'},
98 {"function", 1, NULL, 'P'},
99 {"host", 1, NULL, 'h'},
100 {"index", 1, NULL, 'I'},
101 {"jobs", 1, NULL, 'j'},
102 {"list", 0, NULL, 'l'},
103 {"no-privileges", 0, NULL, 'x'},
104 {"no-acl", 0, NULL, 'x'},
105 {"no-owner", 0, NULL, 'O'},
106 {"no-reconnect", 0, NULL, 'R'},
107 {"port", 1, NULL, 'p'},
108 {"no-password", 0, NULL, 'w'},
109 {"password", 0, NULL, 'W'},
110 {"schema", 1, NULL, 'n'},
111 {"schema-only", 0, NULL, 's'},
112 {"superuser", 1, NULL, 'S'},
113 {"table", 1, NULL, 't'},
114 {"trigger", 1, NULL, 'T'},
115 {"use-list", 1, NULL, 'L'},
116 {"username", 1, NULL, 'U'},
117 {"verbose", 0, NULL, 'v'},
118 {"single-transaction", 0, NULL, '1'},
119
120 /*
121 * the following options don't have an equivalent short option letter
122 */
123 {"disable-triggers", no_argument, &disable_triggers, 1},
124 {"enable-row-security", no_argument, &enable_row_security, 1},
125 {"if-exists", no_argument, &if_exists, 1},
126 {"no-data-for-failed-tables", no_argument, &no_data_for_failed_tables, 1},
127 {"no-table-access-method", no_argument, &outputNoTableAm, 1},
128 {"no-tablespaces", no_argument, &outputNoTablespaces, 1},
129 {"role", required_argument, NULL, 2},
130 {"section", required_argument, NULL, 3},
131 {"strict-names", no_argument, &strict_names, 1},
132 {"transaction-size", required_argument, NULL, 5},
133 {"use-set-session-authorization", no_argument, &use_setsessauth, 1},
134 {"no-comments", no_argument, &no_comments, 1},
135 {"no-data", no_argument, &no_data, 1},
136 {"no-policies", no_argument, &no_policies, 1},
137 {"no-publications", no_argument, &no_publications, 1},
138 {"no-schema", no_argument, &no_schema, 1},
139 {"no-security-labels", no_argument, &no_security_labels, 1},
140 {"no-subscriptions", no_argument, &no_subscriptions, 1},
141 {"no-statistics", no_argument, &no_statistics, 1},
142 {"with-data", no_argument, &with_data, 1},
143 {"with-schema", no_argument, &with_schema, 1},
144 {"with-statistics", no_argument, &with_statistics, 1},
145 {"statistics-only", no_argument, &statistics_only, 1},
146 {"filter", required_argument, NULL, 4},
147
148 {NULL, 0, NULL, 0}
149 };
150
151 pg_logging_init(argv[0]);
153 set_pglocale_pgservice(argv[0], PG_TEXTDOMAIN("pg_dump"));
154
156
158
159 progname = get_progname(argv[0]);
160
161 if (argc > 1)
162 {
163 if (strcmp(argv[1], "--help") == 0 || strcmp(argv[1], "-?") == 0)
164 {
166 exit_nicely(0);
167 }
168 if (strcmp(argv[1], "--version") == 0 || strcmp(argv[1], "-V") == 0)
169 {
170 puts("pg_restore (PostgreSQL) " PG_VERSION);
171 exit_nicely(0);
172 }
173 }
174
175 while ((c = getopt_long(argc, argv, "acCd:ef:F:h:I:j:lL:n:N:Op:P:RsS:t:T:U:vwWx1",
176 cmdopts, NULL)) != -1)
177 {
178 switch (c)
179 {
180 case 'a': /* Dump data only */
181 data_only = true;
182 break;
183 case 'c': /* clean (i.e., drop) schema prior to create */
184 opts->dropSchema = 1;
185 break;
186 case 'C':
187 opts->createDB = 1;
188 break;
189 case 'd':
190 opts->cparams.dbname = pg_strdup(optarg);
191 break;
192 case 'e':
193 opts->exit_on_error = true;
194 break;
195 case 'f': /* output file name */
196 opts->filename = pg_strdup(optarg);
197 break;
198 case 'F':
199 if (strlen(optarg) != 0)
200 opts->formatName = pg_strdup(optarg);
201 break;
202 case 'h':
203 if (strlen(optarg) != 0)
204 opts->cparams.pghost = pg_strdup(optarg);
205 break;
206
207 case 'j': /* number of restore jobs */
208 if (!option_parse_int(optarg, "-j/--jobs", 1,
210 &numWorkers))
211 exit(1);
212 break;
213
214 case 'l': /* Dump the TOC summary */
215 opts->tocSummary = 1;
216 break;
217
218 case 'L': /* input TOC summary file name */
219 opts->tocFile = pg_strdup(optarg);
220 break;
221
222 case 'n': /* Dump data for this schema only */
223 simple_string_list_append(&opts->schemaNames, optarg);
224 break;
225
226 case 'N': /* Do not dump data for this schema */
227 simple_string_list_append(&opts->schemaExcludeNames, optarg);
228 break;
229
230 case 'O':
231 opts->noOwner = 1;
232 break;
233
234 case 'p':
235 if (strlen(optarg) != 0)
236 opts->cparams.pgport = pg_strdup(optarg);
237 break;
238 case 'R':
239 /* no-op, still accepted for backwards compatibility */
240 break;
241 case 'P': /* Function */
242 opts->selTypes = 1;
243 opts->selFunction = 1;
244 simple_string_list_append(&opts->functionNames, optarg);
245 break;
246 case 'I': /* Index */
247 opts->selTypes = 1;
248 opts->selIndex = 1;
250 break;
251 case 'T': /* Trigger */
252 opts->selTypes = 1;
253 opts->selTrigger = 1;
254 simple_string_list_append(&opts->triggerNames, optarg);
255 break;
256 case 's': /* dump schema only */
257 schema_only = true;
258 break;
259 case 'S': /* Superuser username */
260 if (strlen(optarg) != 0)
261 opts->superuser = pg_strdup(optarg);
262 break;
263 case 't': /* Dump specified table(s) only */
264 opts->selTypes = 1;
265 opts->selTable = 1;
267 break;
268
269 case 'U':
270 opts->cparams.username = pg_strdup(optarg);
271 break;
272
273 case 'v': /* verbose */
274 opts->verbose = 1;
276 break;
277
278 case 'w':
279 opts->cparams.promptPassword = TRI_NO;
280 break;
281
282 case 'W':
283 opts->cparams.promptPassword = TRI_YES;
284 break;
285
286 case 'x': /* skip ACL dump */
287 opts->aclsSkip = 1;
288 break;
289
290 case '1': /* Restore data in a single transaction */
291 opts->single_txn = true;
292 opts->exit_on_error = true;
293 break;
294
295 case 0:
296
297 /*
298 * This covers the long options without a short equivalent.
299 */
300 break;
301
302 case 2: /* SET ROLE */
303 opts->use_role = pg_strdup(optarg);
304 break;
305
306 case 3: /* section */
307 set_dump_section(optarg, &(opts->dumpSections));
308 break;
309
310 case 4: /* filter */
312 break;
313
314 case 5: /* transaction-size */
315 if (!option_parse_int(optarg, "--transaction-size",
316 1, INT_MAX,
317 &opts->txn_size))
318 exit(1);
319 opts->exit_on_error = true;
320 break;
321
322 default:
323 /* getopt_long already emitted a complaint */
324 pg_log_error_hint("Try \"%s --help\" for more information.", progname);
325 exit_nicely(1);
326 }
327 }
328
329 /* Get file name from command line */
330 if (optind < argc)
331 inputFileSpec = argv[optind++];
332 else
333 inputFileSpec = NULL;
334
335 /* Complain if any arguments remain */
336 if (optind < argc)
337 {
338 pg_log_error("too many command-line arguments (first is \"%s\")",
339 argv[optind]);
340 pg_log_error_hint("Try \"%s --help\" for more information.", progname);
341 exit_nicely(1);
342 }
343
344 /* Complain if neither -f nor -d was specified (except if dumping TOC) */
345 if (!opts->cparams.dbname && !opts->filename && !opts->tocSummary)
346 pg_fatal("one of -d/--dbname and -f/--file must be specified");
347
348 /* Should get at most one of -d and -f, else user is confused */
349 if (opts->cparams.dbname)
350 {
351 if (opts->filename)
352 {
353 pg_log_error("options -d/--dbname and -f/--file cannot be used together");
354 pg_log_error_hint("Try \"%s --help\" for more information.", progname);
355 exit_nicely(1);
356 }
357 opts->useDB = 1;
358 }
359
360 /* reject conflicting "-only" options */
361 if (data_only && schema_only)
362 pg_fatal("options -s/--schema-only and -a/--data-only cannot be used together");
363 if (schema_only && statistics_only)
364 pg_fatal("options -s/--schema-only and --statistics-only cannot be used together");
365 if (data_only && statistics_only)
366 pg_fatal("options -a/--data-only and --statistics-only cannot be used together");
367
368 /* reject conflicting "-only" and "no-" options */
369 if (data_only && no_data)
370 pg_fatal("options -a/--data-only and --no-data cannot be used together");
371 if (schema_only && no_schema)
372 pg_fatal("options -s/--schema-only and --no-schema cannot be used together");
374 pg_fatal("options --statistics-only and --no-statistics cannot be used together");
375
376 /* reject conflicting "with-" and "no-" options */
377 if (with_data && no_data)
378 pg_fatal("options --with-data and --no-data cannot be used together");
379 if (with_schema && no_schema)
380 pg_fatal("options --with-schema and --no-schema cannot be used together");
382 pg_fatal("options --with-statistics and --no-statistics cannot be used together");
383
384 if (data_only && opts->dropSchema)
385 pg_fatal("options -c/--clean and -a/--data-only cannot be used together");
386
387 if (opts->single_txn && opts->txn_size > 0)
388 pg_fatal("options -1/--single-transaction and --transaction-size cannot be used together");
389
390 /*
391 * -C is not compatible with -1, because we can't create a database inside
392 * a transaction block.
393 */
394 if (opts->createDB && opts->single_txn)
395 pg_fatal("options -C/--create and -1/--single-transaction cannot be used together");
396
397 /* Can't do single-txn mode with multiple connections */
398 if (opts->single_txn && numWorkers > 1)
399 pg_fatal("cannot specify both --single-transaction and multiple jobs");
400
401 /*
402 * Set derivative flags. An "-only" option may be overridden by an
403 * explicit "with-" option; e.g. "--schema-only --with-statistics" will
404 * include schema and statistics. Other ambiguous or nonsensical
405 * combinations, e.g. "--schema-only --no-schema", will have already
406 * caused an error in one of the checks above.
407 */
408 opts->dumpData = ((opts->dumpData && !schema_only && !statistics_only) ||
409 (data_only || with_data)) && !no_data;
410 opts->dumpSchema = ((opts->dumpSchema && !data_only && !statistics_only) ||
411 (schema_only || with_schema)) && !no_schema;
412 opts->dumpStatistics = ((opts->dumpStatistics && !schema_only && !data_only) ||
414
415 opts->disable_triggers = disable_triggers;
416 opts->enable_row_security = enable_row_security;
417 opts->noDataForFailedTables = no_data_for_failed_tables;
418 opts->noTableAm = outputNoTableAm;
419 opts->noTablespace = outputNoTablespaces;
420 opts->use_setsessauth = use_setsessauth;
421 opts->no_comments = no_comments;
422 opts->no_policies = no_policies;
423 opts->no_publications = no_publications;
424 opts->no_security_labels = no_security_labels;
425 opts->no_subscriptions = no_subscriptions;
426
427 if (if_exists && !opts->dropSchema)
428 pg_fatal("option --if-exists requires option -c/--clean");
429 opts->if_exists = if_exists;
431
432 if (opts->formatName)
433 {
434 if (pg_strcasecmp(opts->formatName, "c") == 0 ||
435 pg_strcasecmp(opts->formatName, "custom") == 0)
436 opts->format = archCustom;
437 else if (pg_strcasecmp(opts->formatName, "d") == 0 ||
438 pg_strcasecmp(opts->formatName, "directory") == 0)
439 opts->format = archDirectory;
440 else if (pg_strcasecmp(opts->formatName, "t") == 0 ||
441 pg_strcasecmp(opts->formatName, "tar") == 0)
442 opts->format = archTar;
443 else if (pg_strcasecmp(opts->formatName, "p") == 0 ||
444 pg_strcasecmp(opts->formatName, "plain") == 0)
445 {
446 /* recognize this for consistency with pg_dump */
447 pg_fatal("archive format \"%s\" is not supported; please use psql",
448 opts->formatName);
449 }
450 else
451 pg_fatal("unrecognized archive format \"%s\"; please specify \"c\", \"d\", or \"t\"",
452 opts->formatName);
453 }
454
455 AH = OpenArchive(inputFileSpec, opts->format);
456
457 SetArchiveOptions(AH, NULL, opts);
458
459 /*
460 * We don't have a connection yet but that doesn't matter. The connection
461 * is initialized to NULL and if we terminate through exit_nicely() while
462 * it's still NULL, the cleanup function will just be a no-op.
463 */
465
466 /* Let the archiver know how noisy to be */
467 AH->verbose = opts->verbose;
468
469 /*
470 * Whether to keep submitting sql commands as "pg_restore ... | psql ... "
471 */
472 AH->exit_on_error = opts->exit_on_error;
473
474 if (opts->tocFile)
475 SortTocFromFile(AH);
476
477 AH->numWorkers = numWorkers;
478
479 if (opts->tocSummary)
480 PrintTOCSummary(AH);
481 else
482 {
484 RestoreArchive(AH);
485 }
486
487 /* done, print a summary of ignored errors */
488 if (AH->n_errors)
489 pg_log_warning("errors ignored on restore: %d", AH->n_errors);
490
491 /* AH may be freed in CloseArchive? */
492 exit_code = AH->n_errors ? 1 : 0;
493
494 CloseArchive(AH);
495
496 return exit_code;
497}
void on_exit_close_archive(Archive *AHX)
Definition: parallel.c:330
void init_parallel_dump_utils(void)
Definition: parallel.c:238
#define PG_MAX_JOBS
Definition: parallel.h:48
#define PG_TEXTDOMAIN(domain)
Definition: c.h:1185
void set_pglocale_pgservice(const char *argv0, const char *app)
Definition: exec.c:429
char * pg_strdup(const char *in)
Definition: fe_memutils.c:85
int getopt_long(int argc, char *const argv[], const char *optstring, const struct option *longopts, int *longindex)
Definition: getopt_long.c:60
#define no_argument
Definition: getopt_long.h:25
#define required_argument
Definition: getopt_long.h:26
void pg_logging_increase_verbosity(void)
Definition: logging.c:185
void pg_logging_init(const char *argv0)
Definition: logging.c:83
void pg_logging_set_level(enum pg_log_level new_level)
Definition: logging.c:176
#define pg_log_error(...)
Definition: logging.h:106
#define pg_log_error_hint(...)
Definition: logging.h:112
@ PG_LOG_WARNING
Definition: logging.h:38
const char * progname
Definition: main.c:44
bool option_parse_int(const char *optarg, const char *optname, int min_range, int max_range, int *result)
Definition: option_utils.c:50
static AmcheckOptions opts
Definition: pg_amcheck.c:112
void ProcessArchiveRestoreOptions(Archive *AHX)
RestoreOptions * NewRestoreOptions(void)
Archive * OpenArchive(const char *FileSpec, const ArchiveFormat fmt)
void CloseArchive(Archive *AHX)
void SortTocFromFile(Archive *AHX)
void PrintTOCSummary(Archive *AHX)
void SetArchiveOptions(Archive *AH, DumpOptions *dopt, RestoreOptions *ropt)
void RestoreArchive(Archive *AHX)
@ archTar
Definition: pg_backup.h:43
@ archCustom
Definition: pg_backup.h:42
@ archDirectory
Definition: pg_backup.h:45
void set_dump_section(const char *arg, int *dumpSections)
#define pg_fatal(...)
static int strict_names
Definition: pg_dump.c:152
static int if_exists
Definition: pg_dumpall.c:98
static int statistics_only
Definition: pg_dumpall.c:120
static int no_policies
Definition: pg_dumpall.c:104
static int disable_triggers
Definition: pg_dumpall.c:97
static int with_data
Definition: pg_dumpall.c:114
#define exit_nicely(code)
Definition: pg_dumpall.c:132
static int no_comments
Definition: pg_dumpall.c:103
static int no_publications
Definition: pg_dumpall.c:105
static int with_schema
Definition: pg_dumpall.c:115
static int no_security_labels
Definition: pg_dumpall.c:106
static int no_statistics
Definition: pg_dumpall.c:109
static int use_setsessauth
Definition: pg_dumpall.c:102
static int no_data
Definition: pg_dumpall.c:107
static int no_schema
Definition: pg_dumpall.c:108
static int no_subscriptions
Definition: pg_dumpall.c:110
static int with_statistics
Definition: pg_dumpall.c:116
PGDLLIMPORT int optind
Definition: getopt.c:51
PGDLLIMPORT char * optarg
Definition: getopt.c:53
static void usage(const char *progname)
Definition: pg_restore.c:500
static void read_restore_filters(const char *filename, RestoreOptions *opts)
Definition: pg_restore.c:587
#define pg_log_warning(...)
Definition: pgfnames.c:24
int pg_strcasecmp(const char *s1, const char *s2)
Definition: pgstrcasecmp.c:36
const char * get_progname(const char *argv0)
Definition: path.c:652
char * c
void simple_string_list_append(SimpleStringList *list, const char *val)
Definition: simple_list.c:63
bool strict_names
Definition: pg_amcheck.c:61
bool exit_on_error
Definition: pg_backup.h:247
int n_errors
Definition: pg_backup.h:248
int numWorkers
Definition: pg_backup.h:235
int verbose
Definition: pg_backup.h:227
@ TRI_YES
Definition: vacuumlo.c:38
@ TRI_NO
Definition: vacuumlo.c:37

References archCustom, archDirectory, archTar, CloseArchive(), disable_triggers, exit_nicely, Archive::exit_on_error, get_progname(), getopt_long(), if_exists, init_parallel_dump_utils(), Archive::n_errors, NewRestoreOptions(), no_argument, no_comments, no_data, no_policies, no_publications, no_schema, no_security_labels, no_statistics, no_subscriptions, Archive::numWorkers, on_exit_close_archive(), OpenArchive(), optarg, optind, option_parse_int(), opts, pg_fatal, pg_log_error, pg_log_error_hint, pg_log_warning, PG_LOG_WARNING, pg_logging_increase_verbosity(), pg_logging_init(), pg_logging_set_level(), PG_MAX_JOBS, pg_strcasecmp(), pg_strdup(), PG_TEXTDOMAIN, PrintTOCSummary(), ProcessArchiveRestoreOptions(), progname, read_restore_filters(), required_argument, RestoreArchive(), set_dump_section(), set_pglocale_pgservice(), SetArchiveOptions(), simple_string_list_append(), SortTocFromFile(), statistics_only, AmcheckOptions::strict_names, strict_names, TRI_NO, TRI_YES, usage(), use_setsessauth, AmcheckOptions::verbose, Archive::verbose, with_data, with_schema, and with_statistics.

◆ read_restore_filters()

static void read_restore_filters ( const char *  filename,
RestoreOptions opts 
)
static

Definition at line 587 of file pg_restore.c.

588{
589 FilterStateData fstate;
590 char *objname;
591 FilterCommandType comtype;
592 FilterObjectType objtype;
593
595
596 while (filter_read_item(&fstate, &objname, &comtype, &objtype))
597 {
598 if (comtype == FILTER_COMMAND_TYPE_INCLUDE)
599 {
600 switch (objtype)
601 {
603 break;
610 pg_log_filter_error(&fstate, _("%s filter for \"%s\" is not allowed"),
611 "include",
612 filter_object_type_name(objtype));
613 exit_nicely(1);
614
616 opts->selTypes = 1;
617 opts->selFunction = 1;
618 simple_string_list_append(&opts->functionNames, objname);
619 break;
621 opts->selTypes = 1;
622 opts->selIndex = 1;
623 simple_string_list_append(&opts->indexNames, objname);
624 break;
626 simple_string_list_append(&opts->schemaNames, objname);
627 break;
629 opts->selTypes = 1;
630 opts->selTable = 1;
631 simple_string_list_append(&opts->tableNames, objname);
632 break;
634 opts->selTypes = 1;
635 opts->selTrigger = 1;
636 simple_string_list_append(&opts->triggerNames, objname);
637 break;
638 }
639 }
640 else if (comtype == FILTER_COMMAND_TYPE_EXCLUDE)
641 {
642 switch (objtype)
643 {
645 break;
656 pg_log_filter_error(&fstate, _("%s filter for \"%s\" is not allowed"),
657 "exclude",
658 filter_object_type_name(objtype));
659 exit_nicely(1);
660
662 simple_string_list_append(&opts->schemaExcludeNames, objname);
663 break;
664 }
665 }
666 else
667 {
670 }
671
672 if (objname)
673 free(objname);
674 }
675
676 filter_free(&fstate);
677}
#define _(x)
Definition: elog.c:90
void filter_init(FilterStateData *fstate, const char *filename, exit_function f_exit)
Definition: filter.c:36
void filter_free(FilterStateData *fstate)
Definition: filter.c:60
const char * filter_object_type_name(FilterObjectType fot)
Definition: filter.c:82
bool filter_read_item(FilterStateData *fstate, char **objname, FilterCommandType *comtype, FilterObjectType *objtype)
Definition: filter.c:389
void pg_log_filter_error(FilterStateData *fstate, const char *fmt,...)
Definition: filter.c:154
FilterObjectType
Definition: filter.h:48
@ FILTER_OBJECT_TYPE_TABLE_DATA_AND_CHILDREN
Definition: filter.h:51
@ FILTER_OBJECT_TYPE_SCHEMA
Definition: filter.h:57
@ FILTER_OBJECT_TYPE_INDEX
Definition: filter.h:56
@ FILTER_OBJECT_TYPE_TRIGGER
Definition: filter.h:60
@ FILTER_OBJECT_TYPE_FOREIGN_DATA
Definition: filter.h:54
@ FILTER_OBJECT_TYPE_DATABASE
Definition: filter.h:52
@ FILTER_OBJECT_TYPE_FUNCTION
Definition: filter.h:55
@ FILTER_OBJECT_TYPE_TABLE_DATA
Definition: filter.h:50
@ FILTER_OBJECT_TYPE_NONE
Definition: filter.h:49
@ FILTER_OBJECT_TYPE_TABLE_AND_CHILDREN
Definition: filter.h:59
@ FILTER_OBJECT_TYPE_EXTENSION
Definition: filter.h:53
@ FILTER_OBJECT_TYPE_TABLE
Definition: filter.h:58
FilterCommandType
Definition: filter.h:38
@ FILTER_COMMAND_TYPE_NONE
Definition: filter.h:39
@ FILTER_COMMAND_TYPE_EXCLUDE
Definition: filter.h:41
@ FILTER_COMMAND_TYPE_INCLUDE
Definition: filter.h:40
Assert(PointerIsAligned(start, uint64))
#define free(a)
Definition: header.h:65
static char * filename
Definition: pg_dumpall.c:127

References _, Assert(), exit_nicely, filename, FILTER_COMMAND_TYPE_EXCLUDE, FILTER_COMMAND_TYPE_INCLUDE, FILTER_COMMAND_TYPE_NONE, filter_free(), filter_init(), FILTER_OBJECT_TYPE_DATABASE, FILTER_OBJECT_TYPE_EXTENSION, FILTER_OBJECT_TYPE_FOREIGN_DATA, FILTER_OBJECT_TYPE_FUNCTION, FILTER_OBJECT_TYPE_INDEX, filter_object_type_name(), FILTER_OBJECT_TYPE_NONE, FILTER_OBJECT_TYPE_SCHEMA, FILTER_OBJECT_TYPE_TABLE, FILTER_OBJECT_TYPE_TABLE_AND_CHILDREN, FILTER_OBJECT_TYPE_TABLE_DATA, FILTER_OBJECT_TYPE_TABLE_DATA_AND_CHILDREN, FILTER_OBJECT_TYPE_TRIGGER, filter_read_item(), free, opts, pg_log_filter_error(), and simple_string_list_append().

Referenced by main().

◆ usage()

static void usage ( const char *  progname)
static

Definition at line 500 of file pg_restore.c.

501{
502 printf(_("%s restores a PostgreSQL database from an archive created by pg_dump.\n\n"), progname);
503 printf(_("Usage:\n"));
504 printf(_(" %s [OPTION]... [FILE]\n"), progname);
505
506 printf(_("\nGeneral options:\n"));
507 printf(_(" -d, --dbname=NAME connect to database name\n"));
508 printf(_(" -f, --file=FILENAME output file name (- for stdout)\n"));
509 printf(_(" -F, --format=c|d|t backup file format (should be automatic)\n"));
510 printf(_(" -l, --list print summarized TOC of the archive\n"));
511 printf(_(" -v, --verbose verbose mode\n"));
512 printf(_(" -V, --version output version information, then exit\n"));
513 printf(_(" -?, --help show this help, then exit\n"));
514
515 printf(_("\nOptions controlling the restore:\n"));
516 printf(_(" -a, --data-only restore only the data, no schema\n"));
517 printf(_(" -c, --clean clean (drop) database objects before recreating\n"));
518 printf(_(" -C, --create create the target database\n"));
519 printf(_(" -e, --exit-on-error exit on error, default is to continue\n"));
520 printf(_(" -I, --index=NAME restore named index\n"));
521 printf(_(" -j, --jobs=NUM use this many parallel jobs to restore\n"));
522 printf(_(" -L, --use-list=FILENAME use table of contents from this file for\n"
523 " selecting/ordering output\n"));
524 printf(_(" -n, --schema=NAME restore only objects in this schema\n"));
525 printf(_(" -N, --exclude-schema=NAME do not restore objects in this schema\n"));
526 printf(_(" -O, --no-owner skip restoration of object ownership\n"));
527 printf(_(" -P, --function=NAME(args) restore named function\n"));
528 printf(_(" -s, --schema-only restore only the schema, no data\n"));
529 printf(_(" -S, --superuser=NAME superuser user name to use for disabling triggers\n"));
530 printf(_(" -t, --table=NAME restore named relation (table, view, etc.)\n"));
531 printf(_(" -T, --trigger=NAME restore named trigger\n"));
532 printf(_(" -x, --no-privileges skip restoration of access privileges (grant/revoke)\n"));
533 printf(_(" -1, --single-transaction restore as a single transaction\n"));
534 printf(_(" --disable-triggers disable triggers during data-only restore\n"));
535 printf(_(" --enable-row-security enable row security\n"));
536 printf(_(" --filter=FILENAME restore or skip objects based on expressions\n"
537 " in FILENAME\n"));
538 printf(_(" --if-exists use IF EXISTS when dropping objects\n"));
539 printf(_(" --no-comments do not restore comment commands\n"));
540 printf(_(" --no-data do not restore data\n"));
541 printf(_(" --no-data-for-failed-tables do not restore data of tables that could not be\n"
542 " created\n"));
543 printf(_(" --no-policies do not restore row security policies\n"));
544 printf(_(" --no-publications do not restore publications\n"));
545 printf(_(" --no-schema do not restore schema\n"));
546 printf(_(" --no-security-labels do not restore security labels\n"));
547 printf(_(" --no-statistics do not restore statistics\n"));
548 printf(_(" --no-subscriptions do not restore subscriptions\n"));
549 printf(_(" --no-table-access-method do not restore table access methods\n"));
550 printf(_(" --no-tablespaces do not restore tablespace assignments\n"));
551 printf(_(" --section=SECTION restore named section (pre-data, data, or post-data)\n"));
552 printf(_(" --statistics-only restore only the statistics, not schema or data\n"));
553 printf(_(" --strict-names require table and/or schema include patterns to\n"
554 " match at least one entity each\n"));
555 printf(_(" --transaction-size=N commit after every N objects\n"));
556 printf(_(" --use-set-session-authorization\n"
557 " use SET SESSION AUTHORIZATION commands instead of\n"
558 " ALTER OWNER commands to set ownership\n"));
559 printf(_(" --with-data dump the data\n"));
560 printf(_(" --with-schema dump the schema\n"));
561 printf(_(" --with-statistics dump the statistics\n"));
562
563 printf(_("\nConnection options:\n"));
564 printf(_(" -h, --host=HOSTNAME database server host or socket directory\n"));
565 printf(_(" -p, --port=PORT database server port number\n"));
566 printf(_(" -U, --username=NAME connect as specified database user\n"));
567 printf(_(" -w, --no-password never prompt for password\n"));
568 printf(_(" -W, --password force password prompt (should happen automatically)\n"));
569 printf(_(" --role=ROLENAME do SET ROLE before restore\n"));
570
571 printf(_("\n"
572 "The options -I, -n, -N, -P, -t, -T, and --section can be combined and specified\n"
573 "multiple times to select multiple objects.\n"));
574 printf(_("\nIf no input file name is supplied, then standard input is used.\n\n"));
575 printf(_("Report bugs to <%s>.\n"), PACKAGE_BUGREPORT);
576 printf(_("%s home page: <%s>\n"), PACKAGE_NAME, PACKAGE_URL);
577}
#define printf(...)
Definition: port.h:245

References _, printf, and progname.

Referenced by main().