PostgreSQL Source Code git master
Loading...
Searching...
No Matches
pg_restore.c File Reference
#include "postgres_fe.h"
#include <ctype.h>
#include <sys/stat.h>
#include "common/string.h"
#include "connectdb.h"
#include "dumputils.h"
#include "fe_utils/option_utils.h"
#include "fe_utils/string_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.

Data Structures

struct  DbOidName
 

Typedefs

typedef struct DbOidName DbOidName
 

Functions

static void usage (const char *progname)
 
static void read_restore_filters (const char *filename, RestoreOptions *opts)
 
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 restore_global_objects (const char *inputFileSpec, RestoreOptions *opts)
 
static int restore_all_databases (const char *inputFileSpec, SimpleStringList db_exclude_patterns, RestoreOptions *opts, int numWorkers)
 
static int get_dbnames_list_to_restore (PGconn *conn, SimplePtrList *dbname_oid_list, SimpleStringList db_exclude_patterns)
 
static int get_dbname_oid_list_from_mfile (const char *dumpdirpatharg, SimplePtrList *dbname_oid_list)
 
int main (int argc, char **argv)
 

Typedef Documentation

◆ DbOidName

Function Documentation

◆ file_exists_in_directory()

static bool file_exists_in_directory ( const char dir,
const char filename 
)
static

Definition at line 936 of file pg_restore.c.

937{
938 struct stat st;
939 char buf[MAXPGPATH];
940
941 if (snprintf(buf, MAXPGPATH, "%s/%s", dir, filename) >= MAXPGPATH)
942 pg_fatal("directory name too long: \"%s\"", dir);
943
944 return (stat(buf, &st) == 0 && S_ISREG(st.st_mode));
945}
#define pg_fatal(...)
#define MAXPGPATH
static char * filename
Definition pg_dumpall.c:133
static char buf[DEFAULT_XLOG_SEG_SIZE]
#define snprintf
Definition port.h:260
#define stat
Definition win32_port.h:74
#define S_ISREG(m)
Definition win32_port.h:318

References buf, filename, MAXPGPATH, pg_fatal, S_ISREG, snprintf, stat::st_mode, and stat.

Referenced by get_dbname_oid_list_from_mfile(), main(), and restore_all_databases().

◆ get_dbname_oid_list_from_mfile()

static int get_dbname_oid_list_from_mfile ( const char dumpdirpatharg,
SimplePtrList dbname_oid_list 
)
static

Definition at line 1054 of file pg_restore.c.

1055{
1057 FILE *pfile;
1059 int count = 0;
1060 int len;
1062
1063 /*
1064 * If there is no map.dat file in the dump, then return from here as there
1065 * is no database to restore.
1066 */
1067 if (!file_exists_in_directory(dumpdirpath, "map.dat"))
1068 {
1069 pg_log_info("database restoring is skipped because file \"%s\" does not exist in directory \"%s\"", "map.dat", dumpdirpath);
1070 return 0;
1071 }
1072
1074
1075 /* Trim slash from directory name. */
1076 while (len > 1 && dumpdirpath[len - 1] == '/')
1077 {
1078 dumpdirpath[len - 1] = '\0';
1079 len--;
1080 }
1081
1083
1084 /* Open map.dat file. */
1086
1087 if (pfile == NULL)
1088 pg_fatal("could not open file \"%s\": %m", map_file_path);
1089
1091
1092 /* Append all the dbname/db_oid combinations to the list. */
1093 while (pg_get_line_buf(pfile, &linebuf))
1094 {
1095 Oid db_oid = InvalidOid;
1096 char *dbname;
1098 int namelen;
1099 char *p = linebuf.data;
1100
1101 /* look for the dboid. */
1102 while (isdigit((unsigned char) *p))
1103 p++;
1104
1105 /* ignore lines that don't begin with a digit */
1106 if (p == linebuf.data)
1107 continue;
1108
1109 if (*p == ' ')
1110 {
1111 sscanf(linebuf.data, "%u", &db_oid);
1112 p++;
1113 }
1114
1115 /* dbname is the rest of the line */
1116 dbname = p;
1117 namelen = strlen(dbname);
1118
1119 /* Strip trailing newline */
1120 if (namelen > 0 && dbname[namelen - 1] == '\n')
1121 dbname[--namelen] = '\0';
1122
1123 /* Report error and exit if the file has any corrupted data. */
1124 if (!OidIsValid(db_oid) || namelen < 1)
1125 pg_fatal("invalid entry in file \"%s\" on line %d", map_file_path,
1126 count + 1);
1127
1128 dbidname = pg_malloc(offsetof(DbOidName, str) + namelen + 1);
1129 dbidname->oid = db_oid;
1130 strlcpy(dbidname->str, dbname, namelen + 1);
1131
1132 pg_log_info("found database \"%s\" (OID: %u) in file \"%s\"",
1133 dbidname->str, db_oid, map_file_path);
1134
1136 count++;
1137 }
1138
1139 /* Close map.dat file. */
1140 fclose(pfile);
1141
1142 pfree(linebuf.data);
1143
1144 return count;
1145}
#define PG_BINARY_R
Definition c.h:1348
#define OidIsValid(objectId)
Definition c.h:830
void * pg_malloc(size_t size)
Definition fe_memutils.c:47
const char * str
#define pg_log_info(...)
Definition logging.h:124
char * pstrdup(const char *in)
Definition mcxt.c:1781
void pfree(void *pointer)
Definition mcxt.c:1616
const void size_t len
bool pg_get_line_buf(FILE *stream, StringInfo buf)
Definition pg_get_line.c:95
static bool file_exists_in_directory(const char *dir, const char *filename)
Definition pg_restore.c:936
size_t strlcpy(char *dst, const char *src, size_t siz)
Definition strlcpy.c:45
#define InvalidOid
unsigned int Oid
static int fb(int x)
void simple_ptr_list_append(SimplePtrList *list, void *ptr)
char * dbname
Definition streamutil.c:49
void initStringInfo(StringInfo str)
Definition stringinfo.c:97

References dbname, fb(), file_exists_in_directory(), initStringInfo(), InvalidOid, len, MAXPGPATH, OidIsValid, pfree(), PG_BINARY_R, pg_fatal, pg_get_line_buf(), pg_log_info, pg_malloc(), pstrdup(), simple_ptr_list_append(), snprintf, str, and strlcpy().

Referenced by restore_all_databases().

◆ get_dbnames_list_to_restore()

static int get_dbnames_list_to_restore ( PGconn conn,
SimplePtrList dbname_oid_list,
SimpleStringList  db_exclude_patterns 
)
static

Definition at line 957 of file pg_restore.c.

960{
961 int count_db = 0;
962 PQExpBuffer query;
964 PGresult *res;
965
966 query = createPQExpBuffer();
968
969 /*
970 * Process one by one all dbnames and if specified to skip restoring, then
971 * remove dbname from list.
972 */
974 db_cell; db_cell = db_cell->next)
975 {
977 bool skip_db_restore = false;
978
979 resetPQExpBuffer(query);
981
983
985 {
986 /*
987 * If there is an exact match then we don't need to try a pattern
988 * match
989 */
990 if (pg_strcasecmp(dbidname->str, pat_cell->val) == 0)
991 skip_db_restore = true;
992 /* Otherwise, try a pattern match if there is a connection */
993 else
994 {
995 int dotcnt;
996
997 appendPQExpBufferStr(query, "SELECT 1 ");
998 processSQLNamePattern(conn, query, pat_cell->val, false,
999 false, NULL, db_lit->data,
1000 NULL, NULL, NULL, &dotcnt);
1001
1002 if (dotcnt > 0)
1003 {
1004 pg_log_error("improper qualified name (too many dotted names): %s",
1005 dbidname->str);
1006 PQfinish(conn);
1007 exit_nicely(1);
1008 }
1009
1010 res = executeQuery(conn, query->data);
1011
1012 if (PQntuples(res))
1013 {
1014 skip_db_restore = true;
1015 pg_log_info("database name \"%s\" matches --exclude-database pattern \"%s\"", dbidname->str, pat_cell->val);
1016 }
1017
1018 PQclear(res);
1019 resetPQExpBuffer(query);
1020 }
1021
1022 if (skip_db_restore)
1023 break;
1024 }
1025
1026 /*
1027 * Mark db to be skipped or increment the counter of dbs to be
1028 * restored
1029 */
1030 if (skip_db_restore)
1031 {
1032 pg_log_info("excluding database \"%s\"", dbidname->str);
1033 dbidname->oid = InvalidOid;
1034 }
1035 else
1036 count_db++;
1037 }
1038
1039 destroyPQExpBuffer(query);
1041
1042 return count_db;
1043}
PGresult * executeQuery(PGconn *conn, const char *query)
Definition connectdb.c:278
void PQfinish(PGconn *conn)
#define PQclear
#define PQntuples
#define pg_log_error(...)
Definition logging.h:106
void exit_nicely(int code)
int pg_strcasecmp(const char *s1, const char *s2)
PQExpBuffer createPQExpBuffer(void)
Definition pqexpbuffer.c:72
void resetPQExpBuffer(PQExpBuffer str)
void destroyPQExpBuffer(PQExpBuffer str)
void appendPQExpBufferStr(PQExpBuffer str, const char *data)
PGconn * conn
Definition streamutil.c:52
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)

References appendPQExpBufferStr(), appendStringLiteralConn(), conn, createPQExpBuffer(), PQExpBufferData::data, destroyPQExpBuffer(), executeQuery(), exit_nicely(), fb(), InvalidOid, pg_log_error, pg_log_info, pg_strcasecmp(), PQclear, PQfinish(), PQntuples, processSQLNamePattern(), and resetPQExpBuffer().

Referenced by restore_all_databases().

◆ main()

int main ( int  argc,
char **  argv 
)

Definition at line 85 of file pg_restore.c.

86{
88 int c;
89 int numWorkers = 1;
90 char *inputFileSpec;
91 bool data_only = false;
92 bool schema_only = false;
93 int n_errors = 0;
94 bool globals_only = false;
96 static int disable_triggers = 0;
97 static int enable_row_security = 0;
98 static int if_exists = 0;
99 static int no_data_for_failed_tables = 0;
100 static int outputNoTableAm = 0;
101 static int outputNoTablespaces = 0;
102 static int use_setsessauth = 0;
103 static int no_comments = 0;
104 static int no_data = 0;
105 static int no_policies = 0;
106 static int no_publications = 0;
107 static int no_schema = 0;
108 static int no_security_labels = 0;
109 static int no_statistics = 0;
110 static int no_globals = 0;
111 static int no_subscriptions = 0;
112 static int strict_names = 0;
113 static int statistics_only = 0;
114 static int with_statistics = 0;
115
116 struct option cmdopts[] = {
117 {"clean", 0, NULL, 'c'},
118 {"create", 0, NULL, 'C'},
119 {"data-only", 0, NULL, 'a'},
120 {"globals-only", 0, NULL, 'g'},
121 {"dbname", 1, NULL, 'd'},
122 {"exit-on-error", 0, NULL, 'e'},
123 {"exclude-schema", 1, NULL, 'N'},
124 {"file", 1, NULL, 'f'},
125 {"format", 1, NULL, 'F'},
126 {"function", 1, NULL, 'P'},
127 {"host", 1, NULL, 'h'},
128 {"index", 1, NULL, 'I'},
129 {"jobs", 1, NULL, 'j'},
130 {"list", 0, NULL, 'l'},
131 {"no-privileges", 0, NULL, 'x'},
132 {"no-acl", 0, NULL, 'x'},
133 {"no-owner", 0, NULL, 'O'},
134 {"no-reconnect", 0, NULL, 'R'},
135 {"port", 1, NULL, 'p'},
136 {"no-password", 0, NULL, 'w'},
137 {"password", 0, NULL, 'W'},
138 {"schema", 1, NULL, 'n'},
139 {"schema-only", 0, NULL, 's'},
140 {"superuser", 1, NULL, 'S'},
141 {"table", 1, NULL, 't'},
142 {"trigger", 1, NULL, 'T'},
143 {"use-list", 1, NULL, 'L'},
144 {"username", 1, NULL, 'U'},
145 {"verbose", 0, NULL, 'v'},
146 {"single-transaction", 0, NULL, '1'},
147
148 /*
149 * the following options don't have an equivalent short option letter
150 */
151 {"disable-triggers", no_argument, &disable_triggers, 1},
152 {"enable-row-security", no_argument, &enable_row_security, 1},
153 {"if-exists", no_argument, &if_exists, 1},
154 {"no-data-for-failed-tables", no_argument, &no_data_for_failed_tables, 1},
155 {"no-table-access-method", no_argument, &outputNoTableAm, 1},
156 {"no-tablespaces", no_argument, &outputNoTablespaces, 1},
157 {"role", required_argument, NULL, 2},
158 {"section", required_argument, NULL, 3},
159 {"strict-names", no_argument, &strict_names, 1},
160 {"transaction-size", required_argument, NULL, 5},
161 {"use-set-session-authorization", no_argument, &use_setsessauth, 1},
162 {"no-comments", no_argument, &no_comments, 1},
163 {"no-data", no_argument, &no_data, 1},
164 {"no-policies", no_argument, &no_policies, 1},
165 {"no-publications", no_argument, &no_publications, 1},
166 {"no-schema", no_argument, &no_schema, 1},
167 {"no-security-labels", no_argument, &no_security_labels, 1},
168 {"no-globals", no_argument, &no_globals, 1},
169 {"no-subscriptions", no_argument, &no_subscriptions, 1},
170 {"no-statistics", no_argument, &no_statistics, 1},
171 {"statistics", no_argument, &with_statistics, 1},
172 {"statistics-only", no_argument, &statistics_only, 1},
173 {"filter", required_argument, NULL, 4},
174 {"restrict-key", required_argument, NULL, 6},
175 {"exclude-database", required_argument, NULL, 7},
176
177 {NULL, 0, NULL, 0}
178 };
179
180 pg_logging_init(argv[0]);
182 set_pglocale_pgservice(argv[0], PG_TEXTDOMAIN("pg_dump"));
183
185
187
188 progname = get_progname(argv[0]);
189
190 if (argc > 1)
191 {
192 if (strcmp(argv[1], "--help") == 0 || strcmp(argv[1], "-?") == 0)
193 {
195 exit_nicely(0);
196 }
197 if (strcmp(argv[1], "--version") == 0 || strcmp(argv[1], "-V") == 0)
198 {
199 puts("pg_restore (PostgreSQL) " PG_VERSION);
200 exit_nicely(0);
201 }
202 }
203
204 while ((c = getopt_long(argc, argv, "acCd:ef:F:gh:I:j:lL:n:N:Op:P:RsS:t:T:U:vwWx1",
205 cmdopts, NULL)) != -1)
206 {
207 switch (c)
208 {
209 case 'a': /* Dump data only */
210 data_only = true;
211 break;
212 case 'c': /* clean (i.e., drop) schema prior to create */
213 opts->dropSchema = 1;
214 break;
215 case 'C':
216 opts->createDB = 1;
217 break;
218 case 'd':
219 opts->cparams.dbname = pg_strdup(optarg);
220 break;
221 case 'e':
222 opts->exit_on_error = true;
223 break;
224 case 'f': /* output file name */
225 opts->filename = pg_strdup(optarg);
226 break;
227 case 'F':
228 if (strlen(optarg) != 0)
229 opts->formatName = pg_strdup(optarg);
230 break;
231 case 'g':
232 /* restore only global sql commands. */
233 globals_only = true;
234 break;
235 case 'h':
236 if (strlen(optarg) != 0)
237 opts->cparams.pghost = pg_strdup(optarg);
238 break;
239 case 'j': /* number of restore jobs */
240 if (!option_parse_int(optarg, "-j/--jobs", 1,
242 &numWorkers))
243 exit(1);
244 break;
245
246 case 'l': /* Dump the TOC summary */
247 opts->tocSummary = 1;
248 break;
249
250 case 'L': /* input TOC summary file name */
251 opts->tocFile = pg_strdup(optarg);
252 break;
253
254 case 'n': /* Dump data for this schema only */
255 simple_string_list_append(&opts->schemaNames, optarg);
256 break;
257
258 case 'N': /* Do not dump data for this schema */
259 simple_string_list_append(&opts->schemaExcludeNames, optarg);
260 break;
261
262 case 'O':
263 opts->noOwner = 1;
264 break;
265
266 case 'p':
267 if (strlen(optarg) != 0)
268 opts->cparams.pgport = pg_strdup(optarg);
269 break;
270 case 'R':
271 /* no-op, still accepted for backwards compatibility */
272 break;
273 case 'P': /* Function */
274 opts->selTypes = 1;
275 opts->selFunction = 1;
276 simple_string_list_append(&opts->functionNames, optarg);
277 break;
278 case 'I': /* Index */
279 opts->selTypes = 1;
280 opts->selIndex = 1;
282 break;
283 case 'T': /* Trigger */
284 opts->selTypes = 1;
285 opts->selTrigger = 1;
286 simple_string_list_append(&opts->triggerNames, optarg);
287 break;
288 case 's': /* dump schema only */
289 schema_only = true;
290 break;
291 case 'S': /* Superuser username */
292 if (strlen(optarg) != 0)
293 opts->superuser = pg_strdup(optarg);
294 break;
295 case 't': /* Dump specified table(s) only */
296 opts->selTypes = 1;
297 opts->selTable = 1;
299 break;
300
301 case 'U':
302 opts->cparams.username = pg_strdup(optarg);
303 break;
304
305 case 'v': /* verbose */
306 opts->verbose = 1;
308 break;
309
310 case 'w':
311 opts->cparams.promptPassword = TRI_NO;
312 break;
313
314 case 'W':
315 opts->cparams.promptPassword = TRI_YES;
316 break;
317
318 case 'x': /* skip ACL dump */
319 opts->aclsSkip = 1;
320 break;
321
322 case '1': /* Restore data in a single transaction */
323 opts->single_txn = true;
324 opts->exit_on_error = true;
325 break;
326
327 case 0:
328
329 /*
330 * This covers the long options without a short equivalent.
331 */
332 break;
333
334 case 2: /* SET ROLE */
335 opts->use_role = pg_strdup(optarg);
336 break;
337
338 case 3: /* section */
339 set_dump_section(optarg, &(opts->dumpSections));
340 break;
341
342 case 4: /* filter */
344 break;
345
346 case 5: /* transaction-size */
347 if (!option_parse_int(optarg, "--transaction-size",
348 1, INT_MAX,
349 &opts->txn_size))
350 exit(1);
351 opts->exit_on_error = true;
352 break;
353
354 case 6:
355 opts->restrict_key = pg_strdup(optarg);
356 break;
357
358 case 7: /* database patterns to skip */
360 break;
361
362 default:
363 /* getopt_long already emitted a complaint */
364 pg_log_error_hint("Try \"%s --help\" for more information.", progname);
365 exit_nicely(1);
366 }
367 }
368
369 /* Get file name from command line */
370 if (optind < argc)
371 inputFileSpec = argv[optind++];
372 else
374
375 /* Complain if any arguments remain */
376 if (optind < argc)
377 {
378 pg_log_error("too many command-line arguments (first is \"%s\")",
379 argv[optind]);
380 pg_log_error_hint("Try \"%s --help\" for more information.", progname);
381 exit_nicely(1);
382 }
383
384 /* Complain if neither -f nor -d was specified (except if dumping TOC) */
385 if (!opts->cparams.dbname && !opts->filename && !opts->tocSummary)
386 pg_fatal("one of -d/--dbname and -f/--file must be specified");
387
388 /* --exclude-database and --globals-only are incompatible */
389 check_mut_excl_opts(db_exclude_patterns.head, "--exclude-database",
390 globals_only, "-g/--globals-only");
391
392 /* Should get at most one of -d and -f, else user is confused */
393 check_mut_excl_opts(opts->cparams.dbname, "-d/--dbname",
394 opts->filename, "-f/--file");
395
396 /* --dbname and --restrict-key are incompatible */
397 check_mut_excl_opts(opts->cparams.dbname, "-d/--dbname",
398 opts->restrict_key, "--restrict-key");
399
400 if (opts->cparams.dbname)
401 opts->useDB = 1;
402 else
403 {
404 /*
405 * If you don't provide a restrict key, one will be appointed for you.
406 */
407 if (!opts->restrict_key)
408 opts->restrict_key = generate_restrict_key();
409 if (!opts->restrict_key)
410 pg_fatal("could not generate restrict key");
411 if (!valid_restrict_key(opts->restrict_key))
412 pg_fatal("invalid restrict key");
413 }
414
415 /* *-only options are incompatible with each other */
416 check_mut_excl_opts(data_only, "-a/--data-only",
417 globals_only, "-g/--globals-only",
418 schema_only, "-s/--schema-only",
419 statistics_only, "--statistics-only");
420
421 /* --no-* and *-only for same thing are incompatible */
422 check_mut_excl_opts(data_only, "-a/--data-only",
423 no_data, "--no-data");
424 check_mut_excl_opts(globals_only, "-g/--globals-only",
425 no_globals, "--no-globals");
426 check_mut_excl_opts(schema_only, "-s/--schema-only",
427 no_schema, "--no-schema");
428 check_mut_excl_opts(statistics_only, "--statistics-only",
429 no_statistics, "--no-statistics");
430
431 /* --statistics and --no-statistics are incompatible */
432 check_mut_excl_opts(with_statistics, "--statistics",
433 no_statistics, "--no-statistics");
434
435 /* --statistics is incompatible with *-only (except --statistics-only) */
436 check_mut_excl_opts(with_statistics, "--statistics",
437 data_only, "-a/--data-only",
438 globals_only, "-g/--globals-only",
439 schema_only, "-s/--schema-only");
440
441 /* --clean and --data-only are incompatible */
442 check_mut_excl_opts(opts->dropSchema, "-c/--clean",
443 data_only, "-a/--data-only");
444
445 /*
446 * --globals-only, --single-transaction, and --transaction-size are
447 * incompatible.
448 */
449 check_mut_excl_opts(globals_only, "-g/--globals-only",
450 opts->single_txn, "-1/--single-transaction",
451 opts->txn_size, "--transaction-size");
452
453 /* --exit-on-error and --globals-only are incompatible */
454 check_mut_excl_opts(opts->exit_on_error, "--exit-on-error",
455 globals_only, "-g/--globals-only");
456
457 /*
458 * -C is not compatible with -1, because we can't create a database inside
459 * a transaction block.
460 */
461 check_mut_excl_opts(opts->createDB, "-C/--create",
462 opts->single_txn, "-1/--single-transaction");
463
464 /* Can't do single-txn mode with multiple connections */
465 if (opts->single_txn && numWorkers > 1)
466 pg_fatal("cannot specify both --single-transaction and multiple jobs");
467
468 /*
469 * Set derivative flags. Ambiguous or nonsensical combinations, e.g.
470 * "--schema-only --no-schema", will have already caused an error in one
471 * of the checks above.
472 */
473 opts->dumpData = ((opts->dumpData && !schema_only && !statistics_only) ||
474 data_only) && !no_data;
475 opts->dumpSchema = ((opts->dumpSchema && !data_only && !statistics_only) ||
477 opts->dumpStatistics = ((opts->dumpStatistics && !schema_only && !data_only) ||
479
480 opts->disable_triggers = disable_triggers;
481 opts->enable_row_security = enable_row_security;
482 opts->noDataForFailedTables = no_data_for_failed_tables;
483 opts->noTableAm = outputNoTableAm;
484 opts->noTablespace = outputNoTablespaces;
485 opts->use_setsessauth = use_setsessauth;
486 opts->no_comments = no_comments;
487 opts->no_policies = no_policies;
488 opts->no_publications = no_publications;
489 opts->no_security_labels = no_security_labels;
490 opts->no_subscriptions = no_subscriptions;
491
492 if (if_exists && !opts->dropSchema)
493 pg_fatal("option %s requires option %s",
494 "--if-exists", "-c/--clean");
495 opts->if_exists = if_exists;
497
498 if (opts->formatName)
499 {
500 if (pg_strcasecmp(opts->formatName, "c") == 0 ||
501 pg_strcasecmp(opts->formatName, "custom") == 0)
502 opts->format = archCustom;
503 else if (pg_strcasecmp(opts->formatName, "d") == 0 ||
504 pg_strcasecmp(opts->formatName, "directory") == 0)
505 opts->format = archDirectory;
506 else if (pg_strcasecmp(opts->formatName, "t") == 0 ||
507 pg_strcasecmp(opts->formatName, "tar") == 0)
508 opts->format = archTar;
509 else if (pg_strcasecmp(opts->formatName, "p") == 0 ||
510 pg_strcasecmp(opts->formatName, "plain") == 0)
511 {
512 /* recognize this for consistency with pg_dump */
513 pg_fatal("archive format \"%s\" is not supported; please use psql",
514 opts->formatName);
515 }
516 else
517 pg_fatal("unrecognized archive format \"%s\"; please specify \"c\", \"d\", or \"t\"",
518 opts->formatName);
519 }
520
521 /*
522 * If toc.glo file is present, then restore all the databases from
523 * map.dat, but skip restoring those matching --exclude-database patterns.
524 */
525 if (inputFileSpec != NULL &&
527 {
530
531 opts->format = archUnknown;
532
534
535 /*
536 * Can only use --list or --use-list options with a single database
537 * dump.
538 */
539 if (opts->tocSummary)
540 pg_fatal("option %s cannot be used when restoring an archive created by pg_dumpall",
541 "-l/--list");
542 if (opts->tocFile)
543 pg_fatal("option %s cannot be used when restoring an archive created by pg_dumpall",
544 "-L/--use-list");
545
546 if (opts->strict_names)
547 pg_fatal("option %s cannot be used when restoring an archive created by pg_dumpall",
548 "--strict-names");
549 if (globals_only && opts->dropSchema)
550 pg_fatal("options %s and %s cannot be used together when restoring an archive created by pg_dumpall",
551 "--clean", "-g/--globals-only");
552
553 /*
554 * For pg_dumpall archives, --clean implies --if-exists since global
555 * objects may not exist in the target cluster.
556 */
557 if (opts->dropSchema && !opts->if_exists)
558 {
559 opts->if_exists = 1;
560 pg_log_info("--if-exists is implied by --clean for pg_dumpall archives");
561 }
562
563 if (no_schema)
564 pg_fatal("option %s cannot be used when restoring an archive created by pg_dumpall",
565 "--no-schema");
566
567 if (data_only)
568 pg_fatal("option %s cannot be used when restoring an archive created by pg_dumpall",
569 "-a/--data-only");
570
571 if (statistics_only)
572 pg_fatal("option %s cannot be used when restoring an archive created by pg_dumpall",
573 "--statistics-only");
574
575 if (!(opts->dumpSections & DUMP_PRE_DATA))
576 pg_fatal("option %s cannot exclude %s when restoring a pg_dumpall archive",
577 "--section", "--pre-data");
578
579 /*
580 * To restore from a pg_dumpall archive, -C (create database) option
581 * must be specified unless we are only restoring globals or we are
582 * skipping globals.
583 */
584 if (!no_globals && !globals_only && opts->createDB != 1)
585 {
586 pg_log_error("option %s must be specified when restoring an archive created by pg_dumpall",
587 "-C/--create");
588 pg_log_error_hint("Try \"%s --help\" for more information.", progname);
589 pg_log_error_hint("Individual databases can be restored using their specific archives.");
590 exit_nicely(1);
591 }
592
593 /*
594 * Restore global objects, even if --exclude-database results in zero
595 * databases to process. If 'globals-only' is set, exit immediately.
596 */
598
599 if (!no_globals)
601 else
602 pg_log_info("skipping restore of global objects because %s was specified",
603 "--no-globals");
604
605 if (globals_only)
606 pg_log_info("database restoring skipped because option %s was specified",
607 "-g/--globals-only");
608 else
609 {
610 /* Now restore all the databases from map.dat */
612 opts, numWorkers);
613 }
614
615 /* Free db pattern list. */
617 }
618 else
619 {
620 if (db_exclude_patterns.head != NULL)
621 {
623 pg_fatal("option %s can be used only when restoring an archive created by pg_dumpall",
624 "--exclude-database");
625 }
626
627 if (globals_only)
628 pg_fatal("option %s can be used only when restoring an archive created by pg_dumpall",
629 "-g/--globals-only");
630
631 /* Process if toc.glo file does not exist. */
632 n_errors = restore_one_database(inputFileSpec, opts, numWorkers, false);
633 }
634
635 /* Done, print a summary of ignored errors during restore. */
636 if (n_errors)
637 {
638 pg_log_warning("errors ignored on restore: %d", n_errors);
639 return 1;
640 }
641
642 return 0;
643}
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:1275
void set_pglocale_pgservice(const char *argv0, const char *app)
Definition exec.c:430
char * generate_restrict_key(void)
Definition dumputils.c:973
bool valid_restrict_key(const char *restrict_key)
Definition dumputils.c:997
char * pg_strdup(const char *in)
Definition fe_memutils.c:85
#define pg_malloc0_object(type)
Definition fe_memutils.h:51
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_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)
#define check_mut_excl_opts(set, opt,...)
static AmcheckOptions opts
Definition pg_amcheck.c:112
static void usage(void)
RestoreOptions * NewRestoreOptions(void)
@ archUnknown
Definition pg_backup.h:41
@ 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 DUMP_PRE_DATA
static int strict_names
Definition pg_dump.c:157
static int if_exists
Definition pg_dumpall.c:105
static int statistics_only
Definition pg_dumpall.c:125
static int no_policies
Definition pg_dumpall.c:111
static int disable_triggers
Definition pg_dumpall.c:104
static int no_comments
Definition pg_dumpall.c:110
static int no_publications
Definition pg_dumpall.c:112
static int no_security_labels
Definition pg_dumpall.c:113
static int no_statistics
Definition pg_dumpall.c:116
static int use_setsessauth
Definition pg_dumpall.c:109
static int no_data
Definition pg_dumpall.c:114
static int no_schema
Definition pg_dumpall.c:115
static int no_subscriptions
Definition pg_dumpall.c:117
static int with_statistics
Definition pg_dumpall.c:121
PGDLLIMPORT int optind
Definition getopt.c:51
PGDLLIMPORT char * optarg
Definition getopt.c:53
static int restore_one_database(const char *inputFileSpec, RestoreOptions *opts, int numWorkers, bool append_data)
Definition pg_restore.c:696
static int restore_global_objects(const char *inputFileSpec, RestoreOptions *opts)
Definition pg_restore.c:651
static void read_restore_filters(const char *filename, RestoreOptions *opts)
Definition pg_restore.c:838
static int restore_all_databases(const char *inputFileSpec, SimpleStringList db_exclude_patterns, RestoreOptions *opts, int numWorkers)
#define pg_log_warning(...)
Definition pgfnames.c:24
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
void simple_string_list_destroy(SimpleStringList *list)
@ TRI_YES
Definition vacuumlo.c:38
@ TRI_NO
Definition vacuumlo.c:37

References archCustom, archDirectory, archTar, archUnknown, check_mut_excl_opts, disable_triggers, DUMP_PRE_DATA, exit_nicely(), fb(), file_exists_in_directory(), generate_restrict_key(), get_progname(), getopt_long(), if_exists, init_parallel_dump_utils(), MAXPGPATH, NewRestoreOptions(), no_argument, no_comments, no_data, no_policies, no_publications, no_schema, no_security_labels, no_statistics, no_subscriptions, optarg, optind, option_parse_int(), opts, pg_fatal, pg_log_error, pg_log_error_hint, pg_log_info, pg_log_warning, PG_LOG_WARNING, pg_logging_increase_verbosity(), pg_logging_init(), pg_logging_set_level(), pg_malloc0_object, PG_MAX_JOBS, pg_strcasecmp(), pg_strdup(), PG_TEXTDOMAIN, progname, read_restore_filters(), required_argument, restore_all_databases(), restore_global_objects(), restore_one_database(), set_dump_section(), set_pglocale_pgservice(), simple_string_list_append(), simple_string_list_destroy(), snprintf, statistics_only, AmcheckOptions::strict_names, strict_names, TRI_NO, TRI_YES, usage(), use_setsessauth, valid_restrict_key(), AmcheckOptions::verbose, and with_statistics.

◆ read_restore_filters()

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

Definition at line 838 of file pg_restore.c.

839{
841 char *objname;
843 FilterObjectType objtype;
844
846
847 while (filter_read_item(&fstate, &objname, &comtype, &objtype))
848 {
850 {
851 switch (objtype)
852 {
854 break;
861 pg_log_filter_error(&fstate, _("%s filter for \"%s\" is not allowed"),
862 "include",
863 filter_object_type_name(objtype));
864 exit_nicely(1);
865
867 opts->selTypes = 1;
868 opts->selFunction = 1;
869 simple_string_list_append(&opts->functionNames, objname);
870 break;
872 opts->selTypes = 1;
873 opts->selIndex = 1;
874 simple_string_list_append(&opts->indexNames, objname);
875 break;
877 simple_string_list_append(&opts->schemaNames, objname);
878 break;
880 opts->selTypes = 1;
881 opts->selTable = 1;
882 simple_string_list_append(&opts->tableNames, objname);
883 break;
885 opts->selTypes = 1;
886 opts->selTrigger = 1;
887 simple_string_list_append(&opts->triggerNames, objname);
888 break;
889 }
890 }
892 {
893 switch (objtype)
894 {
896 break;
907 pg_log_filter_error(&fstate, _("%s filter for \"%s\" is not allowed"),
908 "exclude",
909 filter_object_type_name(objtype));
910 exit_nicely(1);
911
913 simple_string_list_append(&opts->schemaExcludeNames, objname);
914 break;
915 }
916 }
917 else
918 {
921 }
922
923 if (objname)
924 free(objname);
925 }
926
928}
#define Assert(condition)
Definition c.h:915
#define _(x)
Definition elog.c:95
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:392
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
#define free(a)

References _, Assert, exit_nicely(), fb(), 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().

◆ restore_all_databases()

static int restore_all_databases ( const char inputFileSpec,
SimpleStringList  db_exclude_patterns,
RestoreOptions opts,
int  numWorkers 
)
static

Definition at line 1159 of file pg_restore.c.

1162{
1164 int num_db_restore = 0;
1165 int num_total_db;
1166 int n_errors_total = 0;
1167 char *connected_db = NULL;
1168 PGconn *conn = NULL;
1171
1173
1174 /* Save db name to reuse it for all the database. */
1175 if (opts->cparams.dbname)
1176 connected_db = opts->cparams.dbname;
1177
1179
1180 pg_log_info(ngettext("found %d database name in \"%s\"",
1181 "found %d database names in \"%s\"",
1182 num_total_db),
1183 num_total_db, "map.dat");
1184
1185 /*
1186 * If exclude-patterns is given, connect to the database to process them.
1187 */
1188 if (db_exclude_patterns.head != NULL)
1189 {
1190 if (opts->cparams.dbname)
1191 {
1192 conn = ConnectDatabase(opts->cparams.dbname, NULL, opts->cparams.pghost,
1193 opts->cparams.pgport, opts->cparams.username, TRI_DEFAULT,
1194 false, progname, NULL, NULL, NULL, NULL);
1195
1196 if (!conn)
1197 pg_fatal("could not connect to database \"%s\"", opts->cparams.dbname);
1198 }
1199
1200 if (!conn)
1201 {
1202 pg_log_info("trying to connect to database \"%s\"", "postgres");
1203
1204 conn = ConnectDatabase("postgres", NULL, opts->cparams.pghost,
1205 opts->cparams.pgport, opts->cparams.username, TRI_DEFAULT,
1206 false, progname, NULL, NULL, NULL, NULL);
1207
1208 /* Try with template1. */
1209 if (!conn)
1210 {
1211 pg_log_info("trying to connect to database \"%s\"", "template1");
1212
1213 conn = ConnectDatabase("template1", NULL, opts->cparams.pghost,
1214 opts->cparams.pgport, opts->cparams.username, TRI_DEFAULT,
1215 false, progname, NULL, NULL, NULL, NULL);
1216 if (!conn)
1217 {
1218 pg_log_error("could not connect to databases \"postgres\" or \"template1\"\n"
1219 "Please specify an alternative database.");
1220 pg_log_error_hint("Try \"%s --help\" for more information.", progname);
1221 exit_nicely(1);
1222 }
1223 }
1224 }
1225
1226 /* Filter the db list according to the exclude patterns. */
1229 PQfinish(conn);
1230 }
1231 else
1233
1234 /* Exit if no db needs to be restored. */
1235 if (num_db_restore == 0)
1236 {
1237 pg_log_info(ngettext("no database needs restoring out of %d database",
1238 "no database needs restoring out of %d databases", num_total_db),
1239 num_total_db);
1242 return 0;
1243 }
1244
1245 pg_log_info("need to restore %d databases out of %d databases", num_db_restore, num_total_db);
1246
1247 /*
1248 * We have a list of databases to restore after processing the
1249 * exclude-database switch(es). Now we can restore them one by one.
1250 */
1252 db_cell; db_cell = db_cell->next)
1253 {
1254 DbOidName *dbidname = (DbOidName *) db_cell->ptr;
1255 char subdirpath[MAXPGPATH];
1256 char subdirdbpath[MAXPGPATH];
1257 char dbfilename[MAXPGPATH];
1258 int n_errors;
1259
1260 /* ignore dbs marked for skipping */
1261 if (dbidname->oid == InvalidOid)
1262 continue;
1263
1264 /*
1265 * Since pg_backup_archiver.c may modify RestoreOptions during the
1266 * previous restore, we must provide a fresh copy of the original
1267 * "opts" for each call to restore_one_database.
1268 */
1270
1271 /*
1272 * We need to reset override_dbname so that objects can be restored
1273 * into an already created database. (used with -d/--dbname option)
1274 */
1275 if (tmpopts->cparams.override_dbname)
1276 {
1277 pfree(tmpopts->cparams.override_dbname);
1278 tmpopts->cparams.override_dbname = NULL;
1279 }
1280
1281 snprintf(subdirdbpath, MAXPGPATH, "%s/databases", inputFileSpec);
1282
1283 /*
1284 * Look for the database dump file/dir. If there is an {oid}.tar or
1285 * {oid}.dmp file, use it. Otherwise try to use a directory called
1286 * {oid}
1287 */
1288 snprintf(dbfilename, MAXPGPATH, "%u.tar", dbidname->oid);
1290 snprintf(subdirpath, MAXPGPATH, "%s/databases/%u.tar", inputFileSpec, dbidname->oid);
1291 else
1292 {
1293 snprintf(dbfilename, MAXPGPATH, "%u.dmp", dbidname->oid);
1294
1296 snprintf(subdirpath, MAXPGPATH, "%s/databases/%u.dmp", inputFileSpec, dbidname->oid);
1297 else
1298 snprintf(subdirpath, MAXPGPATH, "%s/databases/%u", inputFileSpec, dbidname->oid);
1299 }
1300
1301 pg_log_info("restoring database \"%s\"", dbidname->str);
1302
1303 /* If database is already created, then don't set createDB flag. */
1304 if (tmpopts->cparams.dbname)
1305 {
1307
1308 test_conn = ConnectDatabase(dbidname->str, NULL, tmpopts->cparams.pghost,
1309 tmpopts->cparams.pgport, tmpopts->cparams.username, TRI_DEFAULT,
1310 false, progname, NULL, NULL, NULL, NULL);
1311 if (test_conn)
1312 {
1314
1315 /* Use already created database for connection. */
1316 tmpopts->createDB = 0;
1317 tmpopts->cparams.dbname = dbidname->str;
1318 }
1319 else
1320 {
1321 if (!tmpopts->createDB)
1322 {
1323 pg_log_info("skipping restore of database \"%s\": database does not exist and %s was not specified",
1324 dbidname->str, "-C/--create");
1325 continue;
1326 }
1327
1328 /* We'll have to create it */
1329 tmpopts->createDB = 1;
1330 tmpopts->cparams.dbname = connected_db;
1331 }
1332 }
1333
1334 /* Restore the single database. */
1335 n_errors = restore_one_database(subdirpath, tmpopts, numWorkers, true);
1336
1337 n_errors_total += n_errors;
1338
1339 /* Print a summary of ignored errors during single database restore. */
1340 if (n_errors)
1341 pg_log_warning("errors ignored on database \"%s\" restore: %d", dbidname->str, n_errors);
1342 }
1343
1344 /* Log number of processed databases. */
1345 pg_log_info("number of restored databases is %d", num_db_restore);
1346
1347 /* Free dbname and dboid list. */
1349
1352
1353 return n_errors_total;
1354}
#define ngettext(s, p, n)
Definition c.h:1242
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)
Definition connectdb.c:40
void pg_free(void *ptr)
static int get_dbnames_list_to_restore(PGconn *conn, SimplePtrList *dbname_oid_list, SimpleStringList db_exclude_patterns)
Definition pg_restore.c:957
static int get_dbname_oid_list_from_mfile(const char *dumpdirpatharg, SimplePtrList *dbname_oid_list)
void simple_ptr_list_destroy(SimplePtrList *list)
@ TRI_DEFAULT
Definition vacuumlo.c:36

References conn, ConnectDatabase(), exit_nicely(), fb(), file_exists_in_directory(), get_dbname_oid_list_from_mfile(), get_dbnames_list_to_restore(), InvalidOid, MAXPGPATH, ngettext, opts, pfree(), pg_fatal, pg_free(), pg_log_error, pg_log_error_hint, pg_log_info, pg_log_warning, pg_malloc0_object, PQfinish(), progname, restore_one_database(), simple_ptr_list_destroy(), snprintf, and TRI_DEFAULT.

Referenced by main().

◆ restore_global_objects()

static int restore_global_objects ( const char inputFileSpec,
RestoreOptions opts 
)
static

Definition at line 651 of file pg_restore.c.

652{
653 Archive *AH;
654 int nerror = 0;
655
656 /* Set format as custom so that toc.glo file can be read. */
657 opts->format = archCustom;
658 opts->txn_size = 0;
659
660 AH = OpenArchive(inputFileSpec, opts->format);
661
663
665
666 /* Let the archiver know how noisy to be */
667 AH->verbose = opts->verbose;
668
669 /* Don't output TOC entry comments when restoring globals */
670 ((ArchiveHandle *) AH)->noTocComments = 1;
671
672 AH->exit_on_error = false;
673
674 /* Parallel execution is not supported for global object restoration. */
675 AH->numWorkers = 1;
676
678 RestoreArchive(AH, false);
679
680 nerror = AH->n_errors;
681
682 /* AH may be freed in CloseArchive? */
683 CloseArchive(AH);
684
685 return nerror;
686}
void on_exit_close_archive(Archive *AHX)
Definition parallel.c:330
void ProcessArchiveRestoreOptions(Archive *AHX)
Archive * OpenArchive(const char *FileSpec, const ArchiveFormat fmt)
void RestoreArchive(Archive *AHX, bool append_data)
void CloseArchive(Archive *AHX)
void SetArchiveOptions(Archive *AH, DumpOptions *dopt, RestoreOptions *ropt)
bool exit_on_error
Definition pg_backup.h:252
int n_errors
Definition pg_backup.h:253
int numWorkers
Definition pg_backup.h:240
int verbose
Definition pg_backup.h:232

References archCustom, CloseArchive(), Archive::exit_on_error, fb(), Archive::n_errors, Archive::numWorkers, on_exit_close_archive(), OpenArchive(), opts, ProcessArchiveRestoreOptions(), RestoreArchive(), SetArchiveOptions(), AmcheckOptions::verbose, and Archive::verbose.

Referenced by main().

◆ restore_one_database()

static int restore_one_database ( const char inputFileSpec,
RestoreOptions opts,
int  numWorkers,
bool  append_data 
)
static

Definition at line 696 of file pg_restore.c.

698{
699 Archive *AH;
700 int n_errors;
701
702 AH = OpenArchive(inputFileSpec, opts->format);
703
705
706 /*
707 * We don't have a connection yet but that doesn't matter. The connection
708 * is initialized to NULL and if we terminate through exit_nicely() while
709 * it's still NULL, the cleanup function will just be a no-op. If we are
710 * restoring multiple databases, then only update AX handle for cleanup as
711 * the previous entry was already in the array and we had closed previous
712 * connection, so we can use the same array slot.
713 */
714 if (!append_data)
716 else
718
719 /* Let the archiver know how noisy to be */
720 AH->verbose = opts->verbose;
721
722 /*
723 * Whether to keep submitting sql commands as "pg_restore ... | psql ... "
724 */
725 AH->exit_on_error = opts->exit_on_error;
726
727 if (opts->tocFile)
728 SortTocFromFile(AH);
729
730 AH->numWorkers = numWorkers;
731
732 if (opts->tocSummary)
733 PrintTOCSummary(AH);
734 else
735 {
738 }
739
740 n_errors = AH->n_errors;
741
742 /* AH may be freed in CloseArchive? */
743 CloseArchive(AH);
744
745 return n_errors;
746}
void replace_on_exit_close_archive(Archive *AHX)
Definition parallel.c:345
static size_t append_data(char *buf, size_t size, size_t nmemb, void *userdata)
void SortTocFromFile(Archive *AHX)
void PrintTOCSummary(Archive *AHX)

References append_data(), CloseArchive(), Archive::exit_on_error, fb(), Archive::n_errors, Archive::numWorkers, on_exit_close_archive(), OpenArchive(), opts, PrintTOCSummary(), ProcessArchiveRestoreOptions(), replace_on_exit_close_archive(), RestoreArchive(), SetArchiveOptions(), SortTocFromFile(), AmcheckOptions::verbose, and Archive::verbose.

Referenced by main(), and restore_all_databases().

◆ usage()

static void usage ( const char progname)
static

Definition at line 749 of file pg_restore.c.

750{
751 printf(_("%s restores PostgreSQL databases from archives created by pg_dump or pg_dumpall.\n\n"), progname);
752 printf(_("Usage:\n"));
753 printf(_(" %s [OPTION]... [FILE]\n"), progname);
754
755 printf(_("\nGeneral options:\n"));
756 printf(_(" -d, --dbname=NAME connect to database name\n"));
757 printf(_(" -f, --file=FILENAME output file name (- for stdout)\n"));
758 printf(_(" -F, --format=c|d|t backup file format (should be automatic)\n"));
759 printf(_(" -l, --list print summarized TOC of the archive\n"));
760 printf(_(" -v, --verbose verbose mode\n"));
761 printf(_(" -V, --version output version information, then exit\n"));
762 printf(_(" -?, --help show this help, then exit\n"));
763
764 printf(_("\nOptions controlling the restore:\n"));
765 printf(_(" -a, --data-only restore only the data, no schema\n"));
766 printf(_(" -c, --clean clean (drop) database objects before recreating\n"));
767 printf(_(" -C, --create create the target database\n"));
768 printf(_(" -e, --exit-on-error exit on error, default is to continue\n"));
769 printf(_(" -g, --globals-only restore only global objects, no databases\n"));
770 printf(_(" -I, --index=NAME restore named index\n"));
771 printf(_(" -j, --jobs=NUM use this many parallel jobs to restore\n"));
772 printf(_(" -L, --use-list=FILENAME use table of contents from this file for\n"
773 " selecting/ordering output\n"));
774 printf(_(" -n, --schema=NAME restore only objects in this schema\n"));
775 printf(_(" -N, --exclude-schema=NAME do not restore objects in this schema\n"));
776 printf(_(" -O, --no-owner skip restoration of object ownership\n"));
777 printf(_(" -P, --function=NAME(args) restore named function\n"));
778 printf(_(" -s, --schema-only restore only the schema, no data\n"));
779 printf(_(" -S, --superuser=NAME superuser user name to use for disabling triggers\n"));
780 printf(_(" -t, --table=NAME restore named relation (table, view, etc.)\n"));
781 printf(_(" -T, --trigger=NAME restore named trigger\n"));
782 printf(_(" -x, --no-privileges skip restoration of access privileges (grant/revoke)\n"));
783 printf(_(" -1, --single-transaction restore as a single transaction\n"));
784 printf(_(" --disable-triggers disable triggers during data-only restore\n"));
785 printf(_(" --enable-row-security enable row security\n"));
786 printf(_(" --exclude-database=PATTERN do not restore the specified database(s)\n"));
787 printf(_(" --filter=FILENAME restore or skip objects based on expressions\n"
788 " in FILENAME\n"));
789 printf(_(" --if-exists use IF EXISTS when dropping objects\n"));
790 printf(_(" --no-comments do not restore comment commands\n"));
791 printf(_(" --no-data do not restore data\n"));
792 printf(_(" --no-data-for-failed-tables do not restore data of tables that could not be\n"
793 " created\n"));
794 printf(_(" --no-policies do not restore row security policies\n"));
795 printf(_(" --no-publications do not restore publications\n"));
796 printf(_(" --no-schema do not restore schema\n"));
797 printf(_(" --no-security-labels do not restore security labels\n"));
798 printf(_(" --no-statistics do not restore statistics\n"));
799 printf(_(" --no-subscriptions do not restore subscriptions\n"));
800 printf(_(" --no-globals do not restore global objects (roles and tablespaces)\n"));
801 printf(_(" --no-table-access-method do not restore table access methods\n"));
802 printf(_(" --no-tablespaces do not restore tablespace assignments\n"));
803 printf(_(" --restrict-key=RESTRICT_KEY use provided string as psql \\restrict key\n"));
804 printf(_(" --section=SECTION restore named section (pre-data, data, or post-data)\n"));
805 printf(_(" --statistics restore the statistics\n"));
806 printf(_(" --statistics-only restore only the statistics, not schema or data\n"));
807 printf(_(" --strict-names require table and/or schema include patterns to\n"
808 " match at least one entity each\n"));
809 printf(_(" --transaction-size=N commit after every N objects\n"));
810 printf(_(" --use-set-session-authorization\n"
811 " use SET SESSION AUTHORIZATION commands instead of\n"
812 " ALTER OWNER commands to set ownership\n"));
813
814 printf(_("\nConnection options:\n"));
815 printf(_(" -h, --host=HOSTNAME database server host or socket directory\n"));
816 printf(_(" -p, --port=PORT database server port number\n"));
817 printf(_(" -U, --username=NAME connect as specified database user\n"));
818 printf(_(" -w, --no-password never prompt for password\n"));
819 printf(_(" -W, --password force password prompt (should happen automatically)\n"));
820 printf(_(" --role=ROLENAME do SET ROLE before restore\n"));
821
822 printf(_("\n"
823 "The options -I, -n, -N, -P, -t, -T, --section, and --exclude-database can be\n"
824 "combined and specified multiple times to select multiple objects.\n"));
825 printf(_("\nIf no input file name is supplied, then standard input is used.\n\n"));
826 printf(_("Report bugs to <%s>.\n"), PACKAGE_BUGREPORT);
827 printf(_("%s home page: <%s>\n"), PACKAGE_NAME, PACKAGE_URL);
828}
#define printf(...)
Definition port.h:266

References _, fb(), printf, and progname.