67 bool data_only =
false;
68 bool schema_only =
false;
70 static int enable_row_security = 0;
72 static int no_data_for_failed_tables = 0;
73 static int outputNoTableAm = 0;
74 static int outputNoTablespaces = 0;
88 struct option cmdopts[] = {
89 {
"clean", 0, NULL,
'c'},
90 {
"create", 0, NULL,
'C'},
91 {
"data-only", 0, NULL,
'a'},
92 {
"dbname", 1, NULL,
'd'},
93 {
"exit-on-error", 0, NULL,
'e'},
94 {
"exclude-schema", 1, NULL,
'N'},
95 {
"file", 1, NULL,
'f'},
96 {
"format", 1, NULL,
'F'},
97 {
"function", 1, NULL,
'P'},
98 {
"host", 1, NULL,
'h'},
99 {
"index", 1, NULL,
'I'},
100 {
"jobs", 1, NULL,
'j'},
101 {
"list", 0, NULL,
'l'},
102 {
"no-privileges", 0, NULL,
'x'},
103 {
"no-acl", 0, NULL,
'x'},
104 {
"no-owner", 0, NULL,
'O'},
105 {
"no-reconnect", 0, NULL,
'R'},
106 {
"port", 1, NULL,
'p'},
107 {
"no-password", 0, NULL,
'w'},
108 {
"password", 0, NULL,
'W'},
109 {
"schema", 1, NULL,
'n'},
110 {
"schema-only", 0, NULL,
's'},
111 {
"superuser", 1, NULL,
'S'},
112 {
"table", 1, NULL,
't'},
113 {
"trigger", 1, NULL,
'T'},
114 {
"use-list", 1, NULL,
'L'},
115 {
"username", 1, NULL,
'U'},
116 {
"verbose", 0, NULL,
'v'},
117 {
"single-transaction", 0, NULL,
'1'},
123 {
"enable-row-security",
no_argument, &enable_row_security, 1},
125 {
"no-data-for-failed-tables",
no_argument, &no_data_for_failed_tables, 1},
126 {
"no-table-access-method",
no_argument, &outputNoTableAm, 1},
127 {
"no-tablespaces",
no_argument, &outputNoTablespaces, 1},
161 if (strcmp(argv[1],
"--help") == 0 || strcmp(argv[1],
"-?") == 0)
166 if (strcmp(argv[1],
"--version") == 0 || strcmp(argv[1],
"-V") == 0)
168 puts(
"pg_restore (PostgreSQL) " PG_VERSION);
173 while ((
c =
getopt_long(argc, argv,
"acCd:ef:F:h:I:j:lL:n:N:Op:P:RsS:t:T:U:vwWx1",
174 cmdopts, NULL)) != -1)
182 opts->dropSchema = 1;
191 opts->exit_on_error =
true;
213 opts->tocSummary = 1;
241 opts->selFunction = 1;
251 opts->selTrigger = 1;
289 opts->single_txn =
true;
290 opts->exit_on_error =
true;
317 opts->exit_on_error =
true;
333 inputFileSpec = argv[
optind++];
335 inputFileSpec = NULL;
340 pg_log_error(
"too many command-line arguments (first is \"%s\")",
347 if (!
opts->cparams.dbname && !
opts->filename && !
opts->tocSummary)
348 pg_fatal(
"one of -d/--dbname and -f/--file must be specified");
351 if (
opts->cparams.dbname)
355 pg_log_error(
"options %s and %s cannot be used together",
356 "-d/--dbname",
"-f/--file");
361 if (
opts->restrict_key)
362 pg_fatal(
"options %s and %s cannot be used together",
363 "-d/--dbname",
"--restrict-key");
372 if (!
opts->restrict_key)
374 if (!
opts->restrict_key)
375 pg_fatal(
"could not generate restrict key");
381 if (data_only && schema_only)
382 pg_fatal(
"options %s and %s cannot be used together",
383 "-s/--schema-only",
"-a/--data-only");
385 pg_fatal(
"options %s and %s cannot be used together",
386 "-s/--schema-only",
"--statistics-only");
388 pg_fatal(
"options %s and %s cannot be used together",
389 "-a/--data-only",
"--statistics-only");
393 pg_fatal(
"options %s and %s cannot be used together",
394 "-a/--data-only",
"--no-data");
396 pg_fatal(
"options %s and %s cannot be used together",
397 "-s/--schema-only",
"--no-schema");
399 pg_fatal(
"options %s and %s cannot be used together",
400 "--statistics-only",
"--no-statistics");
404 pg_fatal(
"options %s and %s cannot be used together",
405 "--statistics",
"--no-statistics");
409 pg_fatal(
"options %s and %s cannot be used together",
410 "-a/--data-only",
"--statistics");
412 pg_fatal(
"options %s and %s cannot be used together",
413 "-s/--schema-only",
"--statistics");
415 if (data_only &&
opts->dropSchema)
416 pg_fatal(
"options %s and %s cannot be used together",
417 "-c/--clean",
"-a/--data-only");
419 if (
opts->single_txn &&
opts->txn_size > 0)
420 pg_fatal(
"options %s and %s cannot be used together",
421 "-1/--single-transaction",
"--transaction-size");
427 if (
opts->createDB &&
opts->single_txn)
428 pg_fatal(
"options %s and %s cannot be used together",
429 "-C/--create",
"-1/--single-transaction");
432 if (
opts->single_txn && numWorkers > 1)
433 pg_fatal(
"cannot specify both --single-transaction and multiple jobs");
444 opts->dumpStatistics = ((
opts->dumpStatistics && !schema_only && !data_only) ||
448 opts->enable_row_security = enable_row_security;
449 opts->noDataForFailedTables = no_data_for_failed_tables;
450 opts->noTableAm = outputNoTableAm;
451 opts->noTablespace = outputNoTablespaces;
460 pg_fatal(
"option %s requires option %s",
461 "--if-exists",
"-c/--clean");
465 if (
opts->formatName)
480 pg_fatal(
"archive format \"%s\" is not supported; please use psql",
484 pg_fatal(
"unrecognized archive format \"%s\"; please specify \"c\", \"d\", or \"t\"",
512 if (
opts->tocSummary)
535 printf(
_(
"%s restores a PostgreSQL database from an archive created by pg_dump.\n\n"),
progname);
539 printf(
_(
"\nGeneral options:\n"));
540 printf(
_(
" -d, --dbname=NAME connect to database name\n"));
541 printf(
_(
" -f, --file=FILENAME output file name (- for stdout)\n"));
542 printf(
_(
" -F, --format=c|d|t backup file format (should be automatic)\n"));
543 printf(
_(
" -l, --list print summarized TOC of the archive\n"));
544 printf(
_(
" -v, --verbose verbose mode\n"));
545 printf(
_(
" -V, --version output version information, then exit\n"));
546 printf(
_(
" -?, --help show this help, then exit\n"));
548 printf(
_(
"\nOptions controlling the restore:\n"));
549 printf(
_(
" -a, --data-only restore only the data, no schema\n"));
550 printf(
_(
" -c, --clean clean (drop) database objects before recreating\n"));
551 printf(
_(
" -C, --create create the target database\n"));
552 printf(
_(
" -e, --exit-on-error exit on error, default is to continue\n"));
553 printf(
_(
" -I, --index=NAME restore named index\n"));
554 printf(
_(
" -j, --jobs=NUM use this many parallel jobs to restore\n"));
555 printf(
_(
" -L, --use-list=FILENAME use table of contents from this file for\n"
556 " selecting/ordering output\n"));
557 printf(
_(
" -n, --schema=NAME restore only objects in this schema\n"));
558 printf(
_(
" -N, --exclude-schema=NAME do not restore objects in this schema\n"));
559 printf(
_(
" -O, --no-owner skip restoration of object ownership\n"));
560 printf(
_(
" -P, --function=NAME(args) restore named function\n"));
561 printf(
_(
" -s, --schema-only restore only the schema, no data\n"));
562 printf(
_(
" -S, --superuser=NAME superuser user name to use for disabling triggers\n"));
563 printf(
_(
" -t, --table=NAME restore named relation (table, view, etc.)\n"));
564 printf(
_(
" -T, --trigger=NAME restore named trigger\n"));
565 printf(
_(
" -x, --no-privileges skip restoration of access privileges (grant/revoke)\n"));
566 printf(
_(
" -1, --single-transaction restore as a single transaction\n"));
567 printf(
_(
" --disable-triggers disable triggers during data-only restore\n"));
568 printf(
_(
" --enable-row-security enable row security\n"));
569 printf(
_(
" --filter=FILENAME restore or skip objects based on expressions\n"
571 printf(
_(
" --if-exists use IF EXISTS when dropping objects\n"));
572 printf(
_(
" --no-comments do not restore comment commands\n"));
573 printf(
_(
" --no-data do not restore data\n"));
574 printf(
_(
" --no-data-for-failed-tables do not restore data of tables that could not be\n"
576 printf(
_(
" --no-policies do not restore row security policies\n"));
577 printf(
_(
" --no-publications do not restore publications\n"));
578 printf(
_(
" --no-schema do not restore schema\n"));
579 printf(
_(
" --no-security-labels do not restore security labels\n"));
580 printf(
_(
" --no-statistics do not restore statistics\n"));
581 printf(
_(
" --no-subscriptions do not restore subscriptions\n"));
582 printf(
_(
" --no-table-access-method do not restore table access methods\n"));
583 printf(
_(
" --no-tablespaces do not restore tablespace assignments\n"));
584 printf(
_(
" --restrict-key=RESTRICT_KEY use provided string as psql \\restrict key\n"));
585 printf(
_(
" --section=SECTION restore named section (pre-data, data, or post-data)\n"));
586 printf(
_(
" --statistics restore the statistics\n"));
587 printf(
_(
" --statistics-only restore only the statistics, not schema or data\n"));
588 printf(
_(
" --strict-names require table and/or schema include patterns to\n"
589 " match at least one entity each\n"));
590 printf(
_(
" --transaction-size=N commit after every N objects\n"));
591 printf(
_(
" --use-set-session-authorization\n"
592 " use SET SESSION AUTHORIZATION commands instead of\n"
593 " ALTER OWNER commands to set ownership\n"));
595 printf(
_(
"\nConnection options:\n"));
596 printf(
_(
" -h, --host=HOSTNAME database server host or socket directory\n"));
597 printf(
_(
" -p, --port=PORT database server port number\n"));
598 printf(
_(
" -U, --username=NAME connect as specified database user\n"));
599 printf(
_(
" -w, --no-password never prompt for password\n"));
600 printf(
_(
" -W, --password force password prompt (should happen automatically)\n"));
601 printf(
_(
" --role=ROLENAME do SET ROLE before restore\n"));
604 "The options -I, -n, -N, -P, -t, -T, and --section can be combined and specified\n"
605 "multiple times to select multiple objects.\n"));
606 printf(
_(
"\nIf no input file name is supplied, then standard input is used.\n\n"));
607 printf(
_(
"Report bugs to <%s>.\n"), PACKAGE_BUGREPORT);
608 printf(
_(
"%s home page: <%s>\n"), PACKAGE_NAME, PACKAGE_URL);
649 opts->selFunction = 1;
667 opts->selTrigger = 1;
void on_exit_close_archive(Archive *AHX)
void init_parallel_dump_utils(void)
#define PG_TEXTDOMAIN(domain)
void set_pglocale_pgservice(const char *argv0, const char *app)
char * generate_restrict_key(void)
bool valid_restrict_key(const char *restrict_key)
char * pg_strdup(const char *in)
void filter_init(FilterStateData *fstate, const char *filename, exit_function f_exit)
void filter_free(FilterStateData *fstate)
const char * filter_object_type_name(FilterObjectType fot)
bool filter_read_item(FilterStateData *fstate, char **objname, FilterCommandType *comtype, FilterObjectType *objtype)
void pg_log_filter_error(FilterStateData *fstate, const char *fmt,...)
@ FILTER_OBJECT_TYPE_TABLE_DATA_AND_CHILDREN
@ FILTER_OBJECT_TYPE_SCHEMA
@ FILTER_OBJECT_TYPE_INDEX
@ FILTER_OBJECT_TYPE_TRIGGER
@ FILTER_OBJECT_TYPE_FOREIGN_DATA
@ FILTER_OBJECT_TYPE_DATABASE
@ FILTER_OBJECT_TYPE_FUNCTION
@ FILTER_OBJECT_TYPE_TABLE_DATA
@ FILTER_OBJECT_TYPE_NONE
@ FILTER_OBJECT_TYPE_TABLE_AND_CHILDREN
@ FILTER_OBJECT_TYPE_EXTENSION
@ FILTER_OBJECT_TYPE_TABLE
@ FILTER_COMMAND_TYPE_NONE
@ FILTER_COMMAND_TYPE_EXCLUDE
@ FILTER_COMMAND_TYPE_INCLUDE
int getopt_long(int argc, char *const argv[], const char *optstring, const struct option *longopts, int *longindex)
#define required_argument
Assert(PointerIsAligned(start, uint64))
void pg_logging_increase_verbosity(void)
void pg_logging_init(const char *argv0)
void pg_logging_set_level(enum pg_log_level new_level)
#define pg_log_error(...)
#define pg_log_error_hint(...)
bool option_parse_int(const char *optarg, const char *optname, int min_range, int max_range, int *result)
static AmcheckOptions opts
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)
void exit_nicely(int code)
void set_dump_section(const char *arg, int *dumpSections)
static int statistics_only
static int disable_triggers
static int no_publications
static int no_security_labels
static int use_setsessauth
static int no_subscriptions
static int with_statistics
PGDLLIMPORT char * optarg
static void usage(const char *progname)
int main(int argc, char **argv)
static void read_restore_filters(const char *filename, RestoreOptions *opts)
#define pg_log_warning(...)
int pg_strcasecmp(const char *s1, const char *s2)
const char * get_progname(const char *argv0)
void simple_string_list_append(SimpleStringList *list, const char *val)