97 static int enable_row_security = 0;
100 static int outputNoTableAm = 0;
101 static int outputNoTablespaces = 0;
116 {
"clean", 0,
NULL,
'c'},
117 {
"create", 0,
NULL,
'C'},
118 {
"data-only", 0,
NULL,
'a'},
119 {
"globals-only", 0,
NULL,
'g'},
120 {
"dbname", 1,
NULL,
'd'},
121 {
"exit-on-error", 0,
NULL,
'e'},
122 {
"exclude-schema", 1,
NULL,
'N'},
123 {
"file", 1,
NULL,
'f'},
124 {
"format", 1,
NULL,
'F'},
125 {
"function", 1,
NULL,
'P'},
126 {
"host", 1,
NULL,
'h'},
127 {
"index", 1,
NULL,
'I'},
128 {
"jobs", 1,
NULL,
'j'},
129 {
"list", 0,
NULL,
'l'},
130 {
"no-privileges", 0,
NULL,
'x'},
131 {
"no-acl", 0,
NULL,
'x'},
132 {
"no-owner", 0,
NULL,
'O'},
133 {
"no-reconnect", 0,
NULL,
'R'},
134 {
"port", 1,
NULL,
'p'},
135 {
"no-password", 0,
NULL,
'w'},
136 {
"password", 0,
NULL,
'W'},
137 {
"schema", 1,
NULL,
'n'},
138 {
"schema-only", 0,
NULL,
's'},
139 {
"superuser", 1,
NULL,
'S'},
140 {
"table", 1,
NULL,
't'},
141 {
"trigger", 1,
NULL,
'T'},
142 {
"use-list", 1,
NULL,
'L'},
143 {
"username", 1,
NULL,
'U'},
144 {
"verbose", 0,
NULL,
'v'},
145 {
"single-transaction", 0,
NULL,
'1'},
151 {
"enable-row-security",
no_argument, &enable_row_security, 1},
154 {
"no-table-access-method",
no_argument, &outputNoTableAm, 1},
155 {
"no-tablespaces",
no_argument, &outputNoTablespaces, 1},
190 if (
strcmp(argv[1],
"--help") == 0 ||
strcmp(argv[1],
"-?") == 0)
195 if (
strcmp(argv[1],
"--version") == 0 ||
strcmp(argv[1],
"-V") == 0)
202 while ((
c =
getopt_long(argc, argv,
"acCd:ef:F:gh:I:j:lL:n:N:Op:P:RsS:t:T:U:vwWx1",
211 opts->dropSchema = 1;
220 opts->exit_on_error =
true;
245 opts->tocSummary = 1;
273 opts->selFunction = 1;
283 opts->selTrigger = 1;
321 opts->single_txn =
true;
322 opts->exit_on_error =
true;
349 opts->exit_on_error =
true;
376 pg_log_error(
"too many command-line arguments (first is \"%s\")",
383 if (!
opts->cparams.dbname && !
opts->filename && !
opts->tocSummary)
384 pg_fatal(
"one of -d/--dbname and -f/--file must be specified");
388 pg_log_error(
"option %s cannot be used together with %s",
389 "--exclude-database",
"-g/--globals-only");
395 if (
opts->cparams.dbname)
399 pg_log_error(
"options %s and %s cannot be used together",
400 "-d/--dbname",
"-f/--file");
405 if (
opts->restrict_key)
406 pg_fatal(
"options %s and %s cannot be used together",
407 "-d/--dbname",
"--restrict-key");
416 if (!
opts->restrict_key)
418 if (!
opts->restrict_key)
419 pg_fatal(
"could not generate restrict key");
426 pg_fatal(
"options %s and %s cannot be used together",
427 "-s/--schema-only",
"-a/--data-only");
429 pg_fatal(
"options %s and %s cannot be used together",
430 "-s/--schema-only",
"--statistics-only");
432 pg_fatal(
"options %s and %s cannot be used together",
433 "-a/--data-only",
"--statistics-only");
437 pg_fatal(
"options %s and %s cannot be used together",
438 "-a/--data-only",
"--no-data");
440 pg_fatal(
"options %s and %s cannot be used together",
441 "-s/--schema-only",
"--no-schema");
443 pg_fatal(
"options %s and %s cannot be used together",
444 "--statistics-only",
"--no-statistics");
448 pg_fatal(
"options %s and %s cannot be used together",
449 "--statistics",
"--no-statistics");
453 pg_fatal(
"options %s and %s cannot be used together",
454 "-a/--data-only",
"--statistics");
456 pg_fatal(
"options %s and %s cannot be used together",
457 "-s/--schema-only",
"--statistics");
460 pg_fatal(
"options %s and %s cannot be used together",
461 "-c/--clean",
"-a/--data-only");
463 if (
opts->single_txn &&
opts->txn_size > 0)
464 pg_fatal(
"options %s and %s cannot be used together",
465 "-1/--single-transaction",
"--transaction-size");
468 pg_fatal(
"options %s and %s cannot be used together when restoring an archive created by pg_dumpall",
469 "--single-transaction",
"-g/--globals-only");
472 pg_fatal(
"options %s and %s cannot be used together when restoring an archive created by pg_dumpall",
473 "--transaction-size",
"-g/--globals-only");
476 pg_fatal(
"options %s and %s cannot be used together when restoring an archive created by pg_dumpall",
477 "--exit-on-error",
"-g/--globals-only");
480 pg_fatal(
"options %s and %s cannot be used together",
481 "-a/--data-only",
"-g/--globals-only");
483 pg_fatal(
"options %s and %s cannot be used together",
484 "-s/--schema-only",
"-g/--globals-only");
486 pg_fatal(
"options %s and %s cannot be used together",
487 "--statistics-only",
"-g/--globals-only");
489 pg_fatal(
"options %s and %s cannot be used together",
490 "--statistics",
"-g/--globals-only");
496 if (
opts->createDB &&
opts->single_txn)
497 pg_fatal(
"options %s and %s cannot be used together",
498 "-C/--create",
"-1/--single-transaction");
501 if (
opts->single_txn && numWorkers > 1)
502 pg_fatal(
"cannot specify both --single-transaction and multiple jobs");
517 opts->enable_row_security = enable_row_security;
519 opts->noTableAm = outputNoTableAm;
520 opts->noTablespace = outputNoTablespaces;
529 pg_fatal(
"option %s requires option %s",
530 "--if-exists",
"-c/--clean");
534 if (
opts->formatName)
549 pg_fatal(
"archive format \"%s\" is not supported; please use psql",
553 pg_fatal(
"unrecognized archive format \"%s\"; please specify \"c\", \"d\", or \"t\"",
575 if (
opts->tocSummary)
576 pg_fatal(
"option %s cannot be used when restoring an archive created by pg_dumpall",
579 pg_fatal(
"option %s cannot be used when restoring an archive created by pg_dumpall",
583 pg_fatal(
"option %s cannot be used when restoring an archive created by pg_dumpall",
586 pg_fatal(
"options %s and %s cannot be used together when restoring an archive created by pg_dumpall",
587 "--clean",
"-g/--globals-only");
593 if (
opts->dropSchema && !
opts->if_exists)
596 pg_log_info(
"--if-exists is implied by --clean for pg_dumpall archives");
600 pg_fatal(
"option %s cannot be used when restoring an archive created by pg_dumpall",
604 pg_fatal(
"option %s cannot be used when restoring an archive created by pg_dumpall",
608 pg_fatal(
"option %s cannot be used when restoring an archive created by pg_dumpall",
609 "--statistics-only");
612 pg_fatal(
"option %s cannot exclude %s when restoring a pg_dumpall archive",
613 "--section",
"--pre-data");
621 pg_log_error(
"option %s must be specified when restoring an archive created by pg_dumpall",
624 pg_log_error_hint(
"Individual databases can be restored using their specific archives.");
638 pg_log_info(
"database restoring skipped because option %s was specified",
639 "-g/--globals-only");
655 pg_fatal(
"option %s can be used only when restoring an archive created by pg_dumpall",
656 "--exclude-database");
660 pg_fatal(
"option %s can be used only when restoring an archive created by pg_dumpall",
661 "-g/--globals-only");
764 if (
opts->tocSummary)
783 printf(
_(
"%s restores PostgreSQL databases from archives created by pg_dump or pg_dumpall.\n\n"),
progname);
787 printf(
_(
"\nGeneral options:\n"));
788 printf(
_(
" -d, --dbname=NAME connect to database name\n"));
789 printf(
_(
" -f, --file=FILENAME output file name (- for stdout)\n"));
790 printf(
_(
" -F, --format=c|d|t backup file format (should be automatic)\n"));
791 printf(
_(
" -l, --list print summarized TOC of the archive\n"));
792 printf(
_(
" -v, --verbose verbose mode\n"));
793 printf(
_(
" -V, --version output version information, then exit\n"));
794 printf(
_(
" -?, --help show this help, then exit\n"));
796 printf(
_(
"\nOptions controlling the restore:\n"));
797 printf(
_(
" -a, --data-only restore only the data, no schema\n"));
798 printf(
_(
" -c, --clean clean (drop) database objects before recreating\n"));
799 printf(
_(
" -C, --create create the target database\n"));
800 printf(
_(
" -e, --exit-on-error exit on error, default is to continue\n"));
801 printf(
_(
" -g, --globals-only restore only global objects, no databases\n"));
802 printf(
_(
" -I, --index=NAME restore named index\n"));
803 printf(
_(
" -j, --jobs=NUM use this many parallel jobs to restore\n"));
804 printf(
_(
" -L, --use-list=FILENAME use table of contents from this file for\n"
805 " selecting/ordering output\n"));
806 printf(
_(
" -n, --schema=NAME restore only objects in this schema\n"));
807 printf(
_(
" -N, --exclude-schema=NAME do not restore objects in this schema\n"));
808 printf(
_(
" -O, --no-owner skip restoration of object ownership\n"));
809 printf(
_(
" -P, --function=NAME(args) restore named function\n"));
810 printf(
_(
" -s, --schema-only restore only the schema, no data\n"));
811 printf(
_(
" -S, --superuser=NAME superuser user name to use for disabling triggers\n"));
812 printf(
_(
" -t, --table=NAME restore named relation (table, view, etc.)\n"));
813 printf(
_(
" -T, --trigger=NAME restore named trigger\n"));
814 printf(
_(
" -x, --no-privileges skip restoration of access privileges (grant/revoke)\n"));
815 printf(
_(
" -1, --single-transaction restore as a single transaction\n"));
816 printf(
_(
" --disable-triggers disable triggers during data-only restore\n"));
817 printf(
_(
" --enable-row-security enable row security\n"));
818 printf(
_(
" --exclude-database=PATTERN do not restore the specified database(s)\n"));
819 printf(
_(
" --filter=FILENAME restore or skip objects based on expressions\n"
821 printf(
_(
" --if-exists use IF EXISTS when dropping objects\n"));
822 printf(
_(
" --no-comments do not restore comment commands\n"));
823 printf(
_(
" --no-data do not restore data\n"));
824 printf(
_(
" --no-data-for-failed-tables do not restore data of tables that could not be\n"
826 printf(
_(
" --no-policies do not restore row security policies\n"));
827 printf(
_(
" --no-publications do not restore publications\n"));
828 printf(
_(
" --no-schema do not restore schema\n"));
829 printf(
_(
" --no-security-labels do not restore security labels\n"));
830 printf(
_(
" --no-statistics do not restore statistics\n"));
831 printf(
_(
" --no-subscriptions do not restore subscriptions\n"));
832 printf(
_(
" --no-table-access-method do not restore table access methods\n"));
833 printf(
_(
" --no-tablespaces do not restore tablespace assignments\n"));
834 printf(
_(
" --restrict-key=RESTRICT_KEY use provided string as psql \\restrict key\n"));
835 printf(
_(
" --section=SECTION restore named section (pre-data, data, or post-data)\n"));
836 printf(
_(
" --statistics restore the statistics\n"));
837 printf(
_(
" --statistics-only restore only the statistics, not schema or data\n"));
838 printf(
_(
" --strict-names require table and/or schema include patterns to\n"
839 " match at least one entity each\n"));
840 printf(
_(
" --transaction-size=N commit after every N objects\n"));
841 printf(
_(
" --use-set-session-authorization\n"
842 " use SET SESSION AUTHORIZATION commands instead of\n"
843 " ALTER OWNER commands to set ownership\n"));
845 printf(
_(
"\nConnection options:\n"));
846 printf(
_(
" -h, --host=HOSTNAME database server host or socket directory\n"));
847 printf(
_(
" -p, --port=PORT database server port number\n"));
848 printf(
_(
" -U, --username=NAME connect as specified database user\n"));
849 printf(
_(
" -w, --no-password never prompt for password\n"));
850 printf(
_(
" -W, --password force password prompt (should happen automatically)\n"));
851 printf(
_(
" --role=ROLENAME do SET ROLE before restore\n"));
854 "The options -I, -n, -N, -P, -t, -T, --section, and --exclude-database can be\n"
855 "combined and specified multiple times to select multiple objects.\n"));
856 printf(
_(
"\nIf no input file name is supplied, then standard input is used.\n\n"));
899 opts->selFunction = 1;
917 opts->selTrigger = 1;
973 pg_fatal(
"directory name too long: \"%s\"", dir);
1035 pg_log_error(
"improper qualified name (too many dotted names): %s",
1100 pg_log_info(
"database restoring is skipped because file \"%s\" does not exist in directory \"%s\"",
"map.dat",
dumpdirpath);
1133 while (
isdigit((
unsigned char) *p))
1151 if (namelen > 0 &&
dbname[namelen - 1] ==
'\n')
1152 dbname[--namelen] =
'\0';
1163 pg_log_info(
"found database \"%s\" (OID: %u) in file \"%s\"",
1206 if (
opts->cparams.dbname)
1212 "found %d database names in \"%s\"",
1221 if (
opts->cparams.dbname)
1228 pg_fatal(
"could not connect to database \"%s\"",
opts->cparams.dbname);
1233 pg_log_info(
"trying to connect to database \"%s\"",
"postgres");
1242 pg_log_info(
"trying to connect to database \"%s\"",
"template1");
1249 pg_log_error(
"could not connect to databases \"postgres\" or \"template1\"\n"
1250 "Please specify an alternative database.");
1269 "no database needs restoring out of %d databases",
num_total_db),
1306 if (
tmpopts->cparams.override_dbname)
void replace_on_exit_close_archive(Archive *AHX)
void on_exit_close_archive(Archive *AHX)
void init_parallel_dump_utils(void)
#define ngettext(s, p, n)
#define Assert(condition)
#define PG_TEXTDOMAIN(domain)
#define FLEXIBLE_ARRAY_MEMBER
#define OidIsValid(objectId)
void set_pglocale_pgservice(const char *argv0, const char *app)
PGresult * executeQuery(PGconn *conn, const char *query)
PGconn * ConnectDatabase(const char *dbname, const char *connection_string, const char *pghost, const char *pgport, const char *pguser, trivalue prompt_password, bool fail_on_error, const char *progname, const char **connstr, int *server_version, char *password, char *override_dbname)
char * generate_restrict_key(void)
bool valid_restrict_key(const char *restrict_key)
void PQfinish(PGconn *conn)
void * pg_malloc(size_t size)
char * pg_strdup(const char *in)
#define pg_malloc0_object(type)
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
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(...)
void pfree(void *pointer)
static size_t append_data(char *buf, size_t size, size_t nmemb, void *userdata)
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 RestoreArchive(Archive *AHX, bool append_data)
void CloseArchive(Archive *AHX)
void SortTocFromFile(Archive *AHX)
void PrintTOCSummary(Archive *AHX)
void SetArchiveOptions(Archive *AH, DumpOptions *dopt, RestoreOptions *ropt)
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
bool pg_get_line_buf(FILE *stream, StringInfo buf)
PGDLLIMPORT char * optarg
static bool file_exists_in_directory(const char *dir, const char *filename)
static int restore_one_database(const char *inputFileSpec, RestoreOptions *opts, int numWorkers, bool append_data)
static int get_dbnames_list_to_restore(PGconn *conn, SimplePtrList *dbname_oid_list, SimpleStringList db_exclude_patterns)
static int restore_global_objects(const char *inputFileSpec, RestoreOptions *opts)
static void read_restore_filters(const char *filename, RestoreOptions *opts)
static int get_dbname_oid_list_from_mfile(char *dumpdirpath, SimplePtrList *dbname_oid_list)
static int restore_all_databases(const char *inputFileSpec, SimpleStringList db_exclude_patterns, RestoreOptions *opts, int numWorkers)
static char buf[DEFAULT_XLOG_SEG_SIZE]
#define pg_log_warning(...)
int pg_strcasecmp(const char *s1, const char *s2)
const char * get_progname(const char *argv0)
size_t strlcpy(char *dst, const char *src, size_t siz)
PQExpBuffer createPQExpBuffer(void)
void resetPQExpBuffer(PQExpBuffer str)
void destroyPQExpBuffer(PQExpBuffer str)
void appendPQExpBufferStr(PQExpBuffer str, const char *data)
void simple_ptr_list_destroy(SimplePtrList *list)
void simple_string_list_append(SimpleStringList *list, const char *val)
void simple_string_list_destroy(SimpleStringList *list)
void simple_ptr_list_append(SimplePtrList *list, void *ptr)
void appendStringLiteralConn(PQExpBuffer buf, const char *str, PGconn *conn)
bool processSQLNamePattern(PGconn *conn, PQExpBuffer buf, const char *pattern, bool have_where, bool force_escape, const char *schemavar, const char *namevar, const char *altnamevar, const char *visibilityrule, PQExpBuffer dbnamebuf, int *dotcnt)
void initStringInfo(StringInfo str)
char str[FLEXIBLE_ARRAY_MEMBER]