44 #define TEXT_DUMP_HEADER "--\n-- PostgreSQL database dump\n--\n\n"
45 #define TEXT_DUMPALL_HEADER "--\n-- PostgreSQL database cluster dump\n--\n\n"
127 void *callback_data);
131 void *callback_data);
164 opts->include_everything =
true;
259 AH =
_allocAH(FileSpec,
fmt, compression_spec,
true,
276 pg_fatal(
"could not close output file: %m");
284 if (dopt == NULL && ropt != NULL)
330 pg_fatal(
"unexpected section code %d",
367 pg_fatal(
"parallel restore is not supported with this archive file format");
371 pg_fatal(
"parallel restore is not supported with archives made by pre-8.0 pg_dump");
391 pg_fatal(
"cannot restore from compressed archive (%s)",
413 pg_fatal(
"direct database connections are not supported in pre-1.3 archives");
443 int impliedDataOnly = 1;
467 ahprintf(AH,
"--\n-- PostgreSQL database dump\n--\n\n");
470 ahprintf(AH,
"-- Dumped from database version %s\n",
473 ahprintf(AH,
"-- Dumped by pg_dump version %s\n",
514 if (strcmp(te->
desc,
"DATABASE") != 0 &&
515 strcmp(te->
desc,
"DATABASE PROPERTIES") != 0)
535 strncmp(te->
dropStmt,
"--", 2) == 0)
553 if (strncmp(te->
desc,
"BLOB", 4) == 0)
560 char *dropStmtOrig = dropStmt;
567 if (strncmp(dropStmt,
"ALTER TABLE", 11) == 0)
570 "ALTER TABLE IF EXISTS");
571 dropStmt = dropStmt + 11;
593 if (strcmp(te->
desc,
"DEFAULT") == 0 ||
594 strcmp(te->
desc,
"DATABASE PROPERTIES") == 0 ||
595 strncmp(dropStmt,
"CREATE OR REPLACE VIEW", 22) == 0)
602 if (strcmp(te->
desc,
"CONSTRAINT") == 0 ||
603 strcmp(te->
desc,
"CHECK CONSTRAINT") == 0 ||
604 strcmp(te->
desc,
"FK CONSTRAINT") == 0)
605 strcpy(buffer,
"DROP CONSTRAINT");
607 snprintf(buffer,
sizeof(buffer),
"DROP %s",
610 mark = strstr(dropStmt, buffer);
617 mark + strlen(buffer));
622 pg_log_warning(
"could not find where to insert IF EXISTS in statement \"%s\"",
688 bool haveACL =
false;
689 bool havePostACL =
false;
704 case RESTORE_PASS_POST_ACL:
742 ahprintf(AH,
"--\n-- PostgreSQL database dump complete\n--\n\n");
795 te->
desc, te->namespace, te->
tag);
803 if (strcmp(te->
desc,
"TABLE") == 0)
844 if (strcmp(te->
desc,
"DATABASE") == 0 ||
845 strcmp(te->
desc,
"DATABASE PROPERTIES") == 0)
871 if (strcmp(te->
desc,
"BLOBS") == 0 ||
872 strcmp(te->
desc,
"BLOB COMMENTS") == 0)
879 if (strcmp(te->
desc,
"BLOB COMMENTS") == 0)
897 te->namespace, te->
tag);
915 use_truncate = is_parallel && te->
created &&
930 ahprintf(AH,
"TRUNCATE TABLE ONLY %s;\n\n",
963 else if (!defnDumped)
993 opts->compression_spec.level = 0;
1020 ahprintf(AH,
"ALTER TABLE %s DISABLE TRIGGER ALL;\n\n",
1046 ahprintf(AH,
"ALTER TABLE %s ENABLE TRIGGER ALL;\n\n",
1065 strncmp(te->
defn,
"-- load via partition root ", 27) == 0)
1098 pg_fatal(
"internal error -- WriteData cannot be called outside the context of a DataDumper routine");
1145 if (
opts->nDeps > 0)
1180 const char *fmtName;
1192 strcpy(stamp_str,
"[unknown]");
1194 ahprintf(AH,
";\n; Archive created at %s\n", stamp_str);
1195 ahprintf(AH,
"; dbname: %s\n; TOC Entries: %d\n; Compression: %s\n",
1206 fmtName =
"DIRECTORY";
1212 fmtName =
"UNKNOWN";
1215 ahprintf(AH,
"; Dump Version: %d.%d-%d\n",
1217 ahprintf(AH,
"; Format: %s\n", fmtName);
1221 ahprintf(AH,
"; Dumped from database version: %s\n",
1224 ahprintf(AH,
"; Dumped by pg_dump version: %s\n",
1227 ahprintf(AH,
";\n;\n; Selected TOC Entries:\n;\n");
1237 char *sanitized_name;
1238 char *sanitized_schema;
1239 char *sanitized_owner;
1249 te->
desc, sanitized_schema, sanitized_name,
1252 free(sanitized_name);
1253 free(sanitized_schema);
1254 free(sanitized_owner);
1286 pg_fatal(
"large-object output not supported in chosen format");
1345 "restored %d large objects",
1365 pg_log_info(
"restoring large object with OID %u", oid);
1368 if (old_lo_style && drop)
1376 if (loOid == 0 || loOid != oid)
1377 pg_fatal(
"could not create large object %u: %s",
1382 pg_fatal(
"could not open large object %u: %s",
1388 ahprintf(AH,
"SELECT pg_catalog.lo_open(pg_catalog.lo_create('%u'), %d);\n",
1391 ahprintf(AH,
"SELECT pg_catalog.lo_open('%u', %d);\n",
1416 ahprintf(AH,
"SELECT pg_catalog.lo_close(0);\n\n");
1450 cmnt = strchr(linebuf.
data,
';');
1454 linebuf.
len = cmnt - linebuf.
data;
1458 if (strspn(linebuf.
data,
" \t\r\n") == linebuf.
len)
1462 id = strtol(linebuf.
data, &endptr, 10);
1463 if (endptr == linebuf.
data || id <= 0 || id > AH->
maxDumpId ||
1473 pg_fatal(
"could not find entry for ID %d",
1495 if (fclose(fh) != 0)
1496 pg_fatal(
"could not close TOC file: %m");
1515 int save_errno = errno;
1565 fn = fileno(AH->
FH);
1585 pg_fatal(
"could not open output file: %m");
1602 pg_fatal(
"could not close output file: %m");
1604 AH->
OF = savedOutput;
1615 int save_errno = errno;
1669 "wrote %zu bytes of large object data (result = %d)",
1682 (
const unsigned char *) AH->
lo_buf,
1688 ahprintf(AH,
"SELECT pg_catalog.lowrite(0, %s);\n",
buf->data);
1706 int bytes_written = 0;
1717 ptr = (
const void *) ((
const char *) ptr + avail);
1726 bytes_written = size * nmemb;
1729 bytes_written = AH->
CustomOutPtr(AH, ptr, size * nmemb);
1742 bytes_written = size * nmemb;
1745 if (bytes_written != size * nmemb)
1866 if (strcmp(te->
desc,
"TABLE DATA") == 0 && te->
nDeps > 0)
1875 if (tableId <= 0 || tableId > maxDumpId)
1876 pg_fatal(
"bad table dumpId for TABLE DATA item");
1890 if (
id > 0 && id <= AH->maxDumpId)
1916 for (off = 0; off <
sizeof(
pgoff_t); off++)
1968 pg_fatal(
"unexpected data offset flag %d", offsetFlg);
1974 for (off = 0; off < AH->
offSize; off++)
1981 pg_fatal(
"file offset in dump file is too large");
2036 res =
res + (bv << bitShift);
2053 int len = strlen(
c);
2092 pg_fatal(
"directory name too long: \"%s\"", dir);
2105 pg_log_debug(
"attempting to ascertain archive format");
2138 pg_fatal(
"directory \"%s\" does not appear to be a valid archive (\"toc.dat\" does not exist)",
2146 pg_fatal(
"could not open input file \"%s\": %m", AH->
fSpec);
2153 pg_fatal(
"could not open input file: %m");
2156 if ((cnt = fread(
sig, 1, 5, fh)) != 5)
2159 pg_fatal(
"could not read input file: %m");
2161 pg_fatal(
"input file is too short (read %lu, expected 5)",
2162 (
unsigned long) cnt);
2169 if (strncmp(
sig,
"PGDMP", 5) == 0)
2193 pg_fatal(
"input file appears to be a text format dump. Please use psql.");
2199 pg_fatal(
"input file does not appear to be a valid archive (too short?)");
2205 pg_fatal(
"input file does not appear to be a valid archive");
2213 if (fclose(fh) != 0)
2214 pg_fatal(
"could not close input file: %m");
2238 FileSpec ? FileSpec :
"(stdio)",
fmt);
2292 pg_fatal(
"could not open stdout for appending: %m");
2302 (AH->
fSpec == NULL || strcmp(AH->
fSpec,
"") == 0))
2305 _setmode(fileno(
stdout), O_BINARY);
2307 _setmode(fileno(stdin), O_BINARY);
2380 for (
int i = 0;
i < ntes;
i++)
2416 void *callback_data)
2422 pg_fatal(
"worker process failed: exit code %d",
2435 if (strcmp(te->
desc,
"BLOBS") == 0)
2446 if (startPtr != NULL)
2447 (*startPtr) (AH, te);
2543 pg_fatal(
"entry ID %d out of range -- perhaps a corrupt TOC",
2574 if (strcmp(te->
desc,
"COMMENT") == 0 ||
2575 strcmp(te->
desc,
"ACL") == 0 ||
2576 strcmp(te->
desc,
"ACL LANGUAGE") == 0)
2578 else if (strcmp(te->
desc,
"TABLE DATA") == 0 ||
2579 strcmp(te->
desc,
"BLOBS") == 0 ||
2580 strcmp(te->
desc,
"BLOB COMMENTS") == 0)
2582 else if (strcmp(te->
desc,
"CONSTRAINT") == 0 ||
2583 strcmp(te->
desc,
"CHECK CONSTRAINT") == 0 ||
2584 strcmp(te->
desc,
"FK CONSTRAINT") == 0 ||
2585 strcmp(te->
desc,
"INDEX") == 0 ||
2586 strcmp(te->
desc,
"RULE") == 0 ||
2587 strcmp(te->
desc,
"TRIGGER") == 0)
2609 is_supported =
true;
2611 is_supported =
false;
2616 if (strcmp(tmp,
"true") == 0)
2617 is_supported =
false;
2623 pg_log_warning(
"restoring tables WITH OIDS is not supported anymore");
2636 if (depIdx >= depSize)
2641 sscanf(tmp,
"%d", &deps[depIdx]);
2679 if (strcmp(te->
desc,
"ENCODING") == 0)
2681 else if (strcmp(te->
desc,
"STDSTRINGS") == 0)
2683 else if (strcmp(te->
desc,
"SEARCHPATH") == 0)
2697 ptr1 = strchr(defn,
'\'');
2699 ptr2 = strchr(++ptr1,
'\'');
2705 pg_fatal(
"unrecognized encoding \"%s\"",
2710 pg_fatal(
"invalid ENCODING item: %s",
2722 ptr1 = strchr(te->
defn,
'\'');
2723 if (ptr1 && strncmp(ptr1,
"'on'", 4) == 0)
2725 else if (ptr1 && strncmp(ptr1,
"'off'", 5) == 0)
2728 pg_fatal(
"invalid STDSTRINGS item: %s",
2745 const char *missing_name;
2752 if (missing_name != NULL)
2753 pg_fatal(
"schema \"%s\" not found", missing_name);
2759 if (missing_name != NULL)
2760 pg_fatal(
"table \"%s\" not found", missing_name);
2766 if (missing_name != NULL)
2767 pg_fatal(
"index \"%s\" not found", missing_name);
2773 if (missing_name != NULL)
2774 pg_fatal(
"function \"%s\" not found", missing_name);
2780 if (missing_name != NULL)
2781 pg_fatal(
"trigger \"%s\" not found", missing_name);
2799 if (strcmp(te->
desc,
"ENCODING") == 0 ||
2800 strcmp(te->
desc,
"STDSTRINGS") == 0 ||
2801 strcmp(te->
desc,
"SEARCHPATH") == 0)
2809 if (strcmp(te->
desc,
"DATABASE") == 0 ||
2810 strcmp(te->
desc,
"DATABASE PROPERTIES") == 0)
2835 (strcmp(te->
desc,
"PUBLICATION") == 0 ||
2836 strcmp(te->
desc,
"PUBLICATION TABLE") == 0 ||
2837 strcmp(te->
desc,
"PUBLICATION TABLES IN SCHEMA") == 0))
2875 if (strcmp(te->
desc,
"ACL") == 0 ||
2876 strcmp(te->
desc,
"COMMENT") == 0 ||
2877 strcmp(te->
desc,
"SECURITY LABEL") == 0)
2880 if (strncmp(te->
tag,
"DATABASE ", 9) == 0)
2905 if (te->
nDeps != 1 ||
2929 if (strcmp(te->
desc,
"TABLE") == 0 ||
2930 strcmp(te->
desc,
"TABLE DATA") == 0 ||
2931 strcmp(te->
desc,
"VIEW") == 0 ||
2932 strcmp(te->
desc,
"FOREIGN TABLE") == 0 ||
2933 strcmp(te->
desc,
"MATERIALIZED VIEW") == 0 ||
2934 strcmp(te->
desc,
"MATERIALIZED VIEW DATA") == 0 ||
2935 strcmp(te->
desc,
"SEQUENCE") == 0 ||
2936 strcmp(te->
desc,
"SEQUENCE SET") == 0)
2944 else if (strcmp(te->
desc,
"INDEX") == 0)
2952 else if (strcmp(te->
desc,
"FUNCTION") == 0 ||
2953 strcmp(te->
desc,
"AGGREGATE") == 0 ||
2954 strcmp(te->
desc,
"PROCEDURE") == 0)
2962 else if (strcmp(te->
desc,
"TRIGGER") == 0)
2990 if (strcmp(te->
desc,
"SEQUENCE SET") == 0 ||
2991 strcmp(te->
desc,
"BLOB") == 0 ||
2992 (strcmp(te->
desc,
"ACL") == 0 &&
2993 strncmp(te->
tag,
"LARGE OBJECT ", 13) == 0) ||
2994 (strcmp(te->
desc,
"COMMENT") == 0 &&
2995 strncmp(te->
tag,
"LARGE OBJECT ", 13) == 0) ||
2996 (strcmp(te->
desc,
"SECURITY LABEL") == 0 &&
2997 strncmp(te->
tag,
"LARGE OBJECT ", 13) == 0))
3008 strncmp(te->
defn,
"-- load via partition root ", 27) == 0)
3015 if ((strcmp(te->
desc,
"<Init>") == 0) && (strcmp(te->
tag,
"Max OID") == 0))
3031 (strcmp(te->
desc,
"BLOB") == 0 ||
3032 (strcmp(te->
desc,
"ACL") == 0 &&
3033 strncmp(te->
tag,
"LARGE OBJECT ", 13) == 0) ||
3034 (strcmp(te->
desc,
"COMMENT") == 0 &&
3035 strncmp(te->
tag,
"LARGE OBJECT ", 13) == 0) ||
3036 (strcmp(te->
desc,
"SECURITY LABEL") == 0 &&
3037 strncmp(te->
tag,
"LARGE OBJECT ", 13) == 0))))
3057 if (strcmp(te->
desc,
"ACL") == 0 ||
3058 strcmp(te->
desc,
"ACL LANGUAGE") == 0 ||
3059 strcmp(te->
desc,
"DEFAULT ACL") == 0)
3061 if (strcmp(te->
desc,
"EVENT TRIGGER") == 0 ||
3062 strcmp(te->
desc,
"MATERIALIZED VIEW DATA") == 0)
3063 return RESTORE_PASS_POST_ACL;
3071 if (strcmp(te->
desc,
"COMMENT") == 0 &&
3072 strncmp(te->
tag,
"EVENT TRIGGER ", 14) == 0)
3073 return RESTORE_PASS_POST_ACL;
3090 if (strcmp(te->
desc,
"ACL") == 0 ||
3091 strcmp(te->
desc,
"ACL LANGUAGE") == 0 ||
3092 strcmp(te->
desc,
"DEFAULT ACL") == 0)
3109 ahprintf(AH,
"SET statement_timeout = 0;\n");
3110 ahprintf(AH,
"SET lock_timeout = 0;\n");
3111 ahprintf(AH,
"SET idle_in_transaction_session_timeout = 0;\n");
3114 ahprintf(AH,
"SET client_encoding = '%s';\n",
3118 ahprintf(AH,
"SET standard_conforming_strings = %s;\n",
3130 ahprintf(AH,
"SET check_function_bodies = false;\n");
3133 ahprintf(AH,
"SET xmloption = content;\n");
3136 ahprintf(AH,
"SET client_min_messages = warning;\n");
3138 ahprintf(AH,
"SET escape_string_warning = off;\n");
3142 ahprintf(AH,
"SET row_security = on;\n");
3144 ahprintf(AH,
"SET row_security = off;\n");
3178 pg_fatal(
"could not set session user to \"%s\": %s",
3291 if (!schemaName || *schemaName ==
'\0' ||
3299 if (strcmp(schemaName,
"pg_catalog") != 0)
3310 "could not set search_path to \"%s\": %s",
3347 if (have && strcmp(want, have) == 0)
3352 if (strcmp(want,
"") == 0)
3371 "could not set default_tablespace to %s: %s",
3406 if (have && strcmp(want, have) == 0)
3420 "could not set default_table_access_method: %s",
3447 if (strcmp(
type,
"COLLATION") == 0 ||
3448 strcmp(
type,
"CONVERSION") == 0 ||
3449 strcmp(
type,
"DOMAIN") == 0 ||
3450 strcmp(
type,
"FOREIGN TABLE") == 0 ||
3451 strcmp(
type,
"MATERIALIZED VIEW") == 0 ||
3452 strcmp(
type,
"SEQUENCE") == 0 ||
3453 strcmp(
type,
"STATISTICS") == 0 ||
3454 strcmp(
type,
"TABLE") == 0 ||
3455 strcmp(
type,
"TEXT SEARCH DICTIONARY") == 0 ||
3456 strcmp(
type,
"TEXT SEARCH CONFIGURATION") == 0 ||
3457 strcmp(
type,
"TYPE") == 0 ||
3458 strcmp(
type,
"VIEW") == 0 ||
3460 strcmp(
type,
"DATABASE") == 0 ||
3461 strcmp(
type,
"PROCEDURAL LANGUAGE") == 0 ||
3462 strcmp(
type,
"SCHEMA") == 0 ||
3463 strcmp(
type,
"EVENT TRIGGER") == 0 ||
3464 strcmp(
type,
"FOREIGN DATA WRAPPER") == 0 ||
3465 strcmp(
type,
"SERVER") == 0 ||
3466 strcmp(
type,
"PUBLICATION") == 0 ||
3467 strcmp(
type,
"SUBSCRIPTION") == 0)
3470 if (te->namespace && *te->namespace)
3475 else if (strcmp(
type,
"BLOB") == 0)
3483 else if (strcmp(
type,
"AGGREGATE") == 0 ||
3484 strcmp(
type,
"FUNCTION") == 0 ||
3485 strcmp(
type,
"OPERATOR") == 0 ||
3486 strcmp(
type,
"OPERATOR CLASS") == 0 ||
3487 strcmp(
type,
"OPERATOR FAMILY") == 0 ||
3488 strcmp(
type,
"PROCEDURE") == 0)
3495 last = first + strlen(first) - 1;
3498 while (last >= first && (*last ==
'\n' || *last ==
';'))
3508 else if (strcmp(
type,
"CAST") == 0 ||
3509 strcmp(
type,
"CHECK CONSTRAINT") == 0 ||
3510 strcmp(
type,
"CONSTRAINT") == 0 ||
3511 strcmp(
type,
"DATABASE PROPERTIES") == 0 ||
3512 strcmp(
type,
"DEFAULT") == 0 ||
3513 strcmp(
type,
"FK CONSTRAINT") == 0 ||
3514 strcmp(
type,
"INDEX") == 0 ||
3515 strcmp(
type,
"RULE") == 0 ||
3516 strcmp(
type,
"TRIGGER") == 0 ||
3517 strcmp(
type,
"ROW SECURITY") == 0 ||
3518 strcmp(
type,
"POLICY") == 0 ||
3519 strcmp(
type,
"USER MAPPING") == 0)
3524 pg_fatal(
"don't know how to set owner for object type \"%s\"",
type);
3549 char *sanitized_name;
3550 char *sanitized_schema;
3551 char *sanitized_owner;
3561 ahprintf(AH,
"-- TOC entry %d (class %u OID %u)\n",
3578 ahprintf(AH,
"-- %sName: %s; Type: %s; Schema: %s; Owner: %s",
3579 pfx, sanitized_name, te->
desc, sanitized_schema,
3582 free(sanitized_name);
3583 free(sanitized_schema);
3584 free(sanitized_owner);
3588 char *sanitized_tablespace;
3591 ahprintf(AH,
"; Tablespace: %s", sanitized_tablespace);
3592 free(sanitized_tablespace);
3610 strcmp(te->
desc,
"SCHEMA") == 0 && strncmp(te->
defn,
"--", 2) != 0)
3616 if (te->
defn && strlen(te->
defn) > 0)
3629 (strcmp(te->
desc,
"SCHEMA") == 0 &&
3630 strncmp(te->
defn,
"--", 2) == 0)) &&
3681 return pg_strdup(want_hyphen ?
"-" :
"");
3685 for (s = result; *s !=
'\0'; s++)
3687 if (*s ==
'\n' || *s ==
'\r')
3744 if (strncmp(tmpMag,
"PGDMP", 5) != 0)
3745 pg_fatal(
"did not find magic string in file header");
3751 if (vmaj > 1 || (vmaj == 1 && vmin > 0))
3759 pg_fatal(
"unsupported version (%d.%d) in file header",
3764 pg_fatal(
"sanity check on integer size (%lu) failed",
3767 if (AH->
intSize >
sizeof(
int))
3768 pg_log_warning(
"archive was made on a machine with larger integers, some operations might fail");
3778 pg_fatal(
"expected format (%d) differs from format found in file (%d)",
3800 pg_log_warning(
"archive is compressed, but this installation does not support compression (%s) -- no data will be available",
3872 if (
fseeko(fp, tpos, SEEK_SET) != 0)
3932 skipped_some =
false;
3933 for (next_work_item = AH->
toc->
next; next_work_item != AH->
toc; next_work_item = next_work_item->
next)
3944 skipped_some =
true;
3972 next_work_item->
desc, next_work_item->
tag);
4051 if (next_work_item != NULL)
4058 next_work_item->
desc, next_work_item->
tag);
4067 next_work_item->
desc, next_work_item->
tag);
4173 for (k = 0; k < te2->
nDeps; k++)
4227 ready_list->
sorted =
false;
4245 ready_list->
sorted =
false;
4254 Assert(
i >= f && i <= ready_list->last_te);
4267 memmove(first_te_ptr + 1, first_te_ptr, (
i - f) *
sizeof(
TocEntry *));
4284 ready_list->
sorted =
true;
4326 for (te = pending_list->
pending_next; te != pending_list; te = next_te)
4365 for (
int i = ready_list->
first_te; i <= ready_list->last_te;
i++)
4368 bool conflicts =
false;
4379 if (running_te == NULL)
4437 void *callback_data)
4454 pg_fatal(
"worker process failed: exit code %d",
4509 if (strcmp(te->
desc,
"BLOB COMMENTS") == 0 && te->
nDeps == 0)
4515 if (strcmp(te2->
desc,
"BLOBS") == 0)
4546 if (depid <= AH->maxDumpId && AH->
tocsByDumpId[depid] != NULL)
4574 if (depid <= AH->maxDumpId && AH->
tocsByDumpId[depid] != NULL)
4618 if (olddep <= AH->maxDumpId &&
4627 te->
dumpId, olddep, tabledataid);
4662 if (strcmp(te->
desc,
"INDEX") == 0)
4681 if (depid <= AH->maxDumpId && AH->
tocsByDumpId[depid] != NULL &&
4684 lockids[nlockids++] = depid;
4760 pg_log_info(
"table \"%s\" could not be created, will not restore its data",
int lo_write(int fd, const char *buf, int len)
void ParallelBackupEnd(ArchiveHandle *AH, ParallelState *pstate)
void WaitForWorkers(ArchiveHandle *AH, ParallelState *pstate, WFW_WaitOption mode)
void DispatchJobForTocEntry(ArchiveHandle *AH, ParallelState *pstate, TocEntry *te, T_Action act, ParallelCompletionPtr callback, void *callback_data)
bool IsEveryWorkerIdle(ParallelState *pstate)
ParallelState * ParallelBackupStart(ArchiveHandle *AH)
#define ngettext(s, p, n)
bool EndCompressFileHandle(CompressFileHandle *CFH)
char * supports_compression(const pg_compress_specification compression_spec)
CompressFileHandle * InitCompressFileHandle(const pg_compress_specification compression_spec)
const char * get_compress_algorithm_name(pg_compress_algorithm algorithm)
static void PGresult const char * p2
static void PGresult * res
#define PGDUMP_STRFTIME_FMT
int errmsg(const char *fmt,...)
int pg_char_to_encoding(const char *name)
const char * pg_encoding_to_char(int encoding)
char * PQdb(const PGconn *conn)
char * PQerrorMessage(const PGconn *conn)
ExecStatusType PQresultStatus(const PGresult *res)
PGresult * PQexec(PGconn *conn, const char *query)
int lo_close(PGconn *conn, int fd)
int lo_open(PGconn *conn, Oid lobjId, int mode)
Oid lo_create(PGconn *conn, Oid lobjId)
void * pg_realloc(void *ptr, size_t size)
void * pg_malloc0(size_t size)
char * pg_strdup(const char *in)
void * pg_malloc(size_t size)
if(TABLE==NULL||TABLE_index==NULL)
static void const char * fmt
Assert(fmt[strlen(fmt) - 1] !='\n')
void pg_log_generic_v(enum pg_log_level level, enum pg_log_part part, const char *pg_restrict fmt, va_list ap)
#define pg_log_debug(...)
static AmcheckOptions opts
void ConnectDatabase(Archive *AHX, const ConnParams *cparams, bool isReconnect)
void(* SetupWorkerPtrType)(Archive *AH)
enum _archiveFormat ArchiveFormat
void DisconnectDatabase(Archive *AHX)
enum _teSection teSection
static void fix_dependencies(ArchiveHandle *AH)
static void ready_list_insert(ParallelReadyList *ready_list, TocEntry *te)
static void repoint_table_dependencies(ArchiveHandle *AH)
void DeCloneArchive(ArchiveHandle *AH)
static int _discoverArchiveFormat(ArchiveHandle *AH)
#define TEXT_DUMPALL_HEADER
int TocIDRequired(ArchiveHandle *AH, DumpId id)
void ahwrite(const void *ptr, size_t size, size_t nmemb, ArchiveHandle *AH)
void warn_or_exit_horribly(ArchiveHandle *AH, const char *fmt,...)
void WriteDataChunksForTocEntry(ArchiveHandle *AH, TocEntry *te)
static void _becomeOwner(ArchiveHandle *AH, TocEntry *te)
void WriteHead(ArchiveHandle *AH)
int EndLO(Archive *AHX, Oid oid)
static CompressFileHandle * SaveOutput(ArchiveHandle *AH)
static void _becomeUser(ArchiveHandle *AH, const char *user)
static void ready_list_free(ParallelReadyList *ready_list)
TocEntry * getTocEntryByDumpId(ArchiveHandle *AH, DumpId id)
static void pending_list_append(TocEntry *l, TocEntry *te)
static void ready_list_sort(ParallelReadyList *ready_list)
size_t WriteInt(ArchiveHandle *AH, int i)
void ProcessArchiveRestoreOptions(Archive *AHX)
static int restore_toc_entry(ArchiveHandle *AH, TocEntry *te, bool is_parallel)
static void _moveBefore(TocEntry *pos, TocEntry *te)
static bool _tocEntryIsACL(TocEntry *te)
static void _getObjectDescription(PQExpBuffer buf, const TocEntry *te)
static void buildTocEntryArrays(ArchiveHandle *AH)
static void identify_locking_dependencies(ArchiveHandle *AH, TocEntry *te)
static void processEncodingEntry(ArchiveHandle *AH, TocEntry *te)
static void processSearchPathEntry(ArchiveHandle *AH, TocEntry *te)
int archprintf(Archive *AH, const char *fmt,...)
static void ready_list_remove(ParallelReadyList *ready_list, int i)
static void StrictNamesCheck(RestoreOptions *ropt)
static void mark_restore_job_done(ArchiveHandle *AH, TocEntry *te, int status, void *callback_data)
ArchiveHandle * CloneArchive(ArchiveHandle *AH)
size_t WriteOffset(ArchiveHandle *AH, pgoff_t o, int wasSet)
RestoreOptions * NewRestoreOptions(void)
static RestorePass _tocEntryRestorePass(TocEntry *te)
int StartLO(Archive *AHX, Oid oid)
static void setupRestoreWorker(Archive *AHX)
static void _reconnectToDB(ArchiveHandle *AH, const char *dbname)
void StartRestoreLOs(ArchiveHandle *AH)
Archive * CreateArchive(const char *FileSpec, const ArchiveFormat fmt, const pg_compress_specification compression_spec, bool dosync, ArchiveMode mode, SetupWorkerPtrType setupDumpWorker)
void CloseArchive(Archive *AHX)
static void pending_list_header_init(TocEntry *l)
static void restore_toc_entries_parallel(ArchiveHandle *AH, ParallelState *pstate, TocEntry *pending_list)
static void SetOutput(ArchiveHandle *AH, const char *filename, const pg_compress_specification compression_spec)
static void mark_create_done(ArchiveHandle *AH, TocEntry *te)
static void _selectTableAccessMethod(ArchiveHandle *AH, const char *tableam)
void WriteDataChunks(ArchiveHandle *AH, ParallelState *pstate)
static void dumpTimestamp(ArchiveHandle *AH, const char *msg, time_t tim)
int ahprintf(ArchiveHandle *AH, const char *fmt,...)
static void reduce_dependencies(ArchiveHandle *AH, TocEntry *te, ParallelReadyList *ready_list)
static void _selectOutputSchema(ArchiveHandle *AH, const char *schemaName)
static void mark_dump_job_done(ArchiveHandle *AH, TocEntry *te, int status, void *callback_data)
static bool is_load_via_partition_root(TocEntry *te)
static void _enableTriggersIfNecessary(ArchiveHandle *AH, TocEntry *te)
void SortTocFromFile(Archive *AHX)
int ReadOffset(ArchiveHandle *AH, pgoff_t *o)
char * ReadStr(ArchiveHandle *AH)
static void _printTocEntry(ArchiveHandle *AH, TocEntry *te, bool isData)
static void inhibit_data_for_failed_table(ArchiveHandle *AH, TocEntry *te)
int ReadInt(ArchiveHandle *AH)
static void restore_toc_entries_prefork(ArchiveHandle *AH, TocEntry *pending_list)
static void restore_toc_entries_postfork(ArchiveHandle *AH, TocEntry *pending_list)
static void RestoreOutput(ArchiveHandle *AH, CompressFileHandle *savedOutput)
TocEntry * ArchiveEntry(Archive *AHX, CatalogId catalogId, DumpId dumpId, ArchiveOpts *opts)
static void _doSetFixedOutputState(ArchiveHandle *AH)
void PrintTOCSummary(Archive *AHX)
static void processStdStringsEntry(ArchiveHandle *AH, TocEntry *te)
static int RestoringToDB(ArchiveHandle *AH)
void ReadHead(ArchiveHandle *AH)
void SetArchiveOptions(Archive *AH, DumpOptions *dopt, RestoreOptions *ropt)
static void pending_list_remove(TocEntry *te)
static bool has_lock_conflicts(TocEntry *te1, TocEntry *te2)
DumpOptions * NewDumpOptions(void)
void ReadToc(ArchiveHandle *AH)
static ArchiveHandle * _allocAH(const char *FileSpec, const ArchiveFormat fmt, const pg_compress_specification compression_spec, bool dosync, ArchiveMode mode, SetupWorkerPtrType setupWorkerPtr)
static char * sanitize_line(const char *str, bool want_hyphen)
void EndRestoreLO(ArchiveHandle *AH, Oid oid)
static void _selectTablespace(ArchiveHandle *AH, const char *tablespace)
static int TocEntrySizeCompare(const void *p1, const void *p2)
void RestoreArchive(Archive *AHX)
static void ready_list_init(ParallelReadyList *ready_list, int tocCount)
void WriteToc(ArchiveHandle *AH)
void archputs(const char *s, Archive *AH)
static void move_to_ready_list(TocEntry *pending_list, ParallelReadyList *ready_list, RestorePass pass)
static bool _fileExistsInDirectory(const char *dir, const char *filename)
struct _parallelReadyList ParallelReadyList
static TocEntry * pop_next_work_item(ParallelReadyList *ready_list, ParallelState *pstate)
static int _tocEntryRequired(TocEntry *te, teSection curSection, ArchiveHandle *AH)
static void _doSetSessionAuth(ArchiveHandle *AH, const char *user)
void EndRestoreLOs(ArchiveHandle *AH)
void StartRestoreLO(ArchiveHandle *AH, Oid oid, bool drop)
Archive * OpenArchive(const char *FileSpec, const ArchiveFormat fmt)
void InitDumpOptions(DumpOptions *opts)
DumpOptions * dumpOptionsFromRestoreOptions(RestoreOptions *ropt)
static void dump_lo_buf(ArchiveHandle *AH)
void WriteData(Archive *AHX, const void *data, size_t dLen)
int parallel_restore(ArchiveHandle *AH, TocEntry *te)
size_t WriteStr(ArchiveHandle *AH, const char *c)
static void _disableTriggersIfNecessary(ArchiveHandle *AH, TocEntry *te)
void InitArchiveFmt_Null(ArchiveHandle *AH)
#define WORKER_CREATE_DONE
#define appendByteaLiteralAHX(buf, str, len, AH)
void struct _archiveOpts ArchiveOpts
void(* EndDataPtrType)(ArchiveHandle *AH, TocEntry *te)
void(* StartDataPtrType)(ArchiveHandle *AH, TocEntry *te)
#define ARCHIVE_MAJOR(version)
#define ARCHIVE_MINOR(version)
#define RESTORE_PASS_LAST
void InitArchiveFmt_Custom(ArchiveHandle *AH)
void InitArchiveFmt_Tar(ArchiveHandle *AH)
#define appendStringLiteralAHX(buf, str, AH)
void DropLOIfExists(ArchiveHandle *AH, Oid oid)
#define MAKE_ARCHIVE_VERSION(major, minor, rev)
void ReconnectToServer(ArchiveHandle *AH, const char *dbname)
#define ARCHIVE_REV(version)
bool isValidTarHeader(char *header)
#define WORKER_IGNORED_ERRORS
#define K_OFFSET_POS_NOT_SET
#define READ_ERROR_EXIT(fd)
void InitArchiveFmt_Directory(ArchiveHandle *AH)
#define WORKER_INHIBIT_DATA
void EndDBCopyMode(Archive *AHX, const char *tocEntryTag)
int ExecuteSqlCommandBuf(Archive *AHX, const char *buf, size_t bufLen)
static PgChecksumMode mode
static void setupDumpWorker(Archive *AH)
#define exit_nicely(code)
bool pg_get_line_buf(FILE *stream, StringInfo buf)
static void static void status(const char *fmt,...) pg_attribute_printf(1
#define pg_log_warning(...)
#define qsort(a, b, c, d)
PQExpBuffer createPQExpBuffer(void)
void initPQExpBuffer(PQExpBuffer str)
void appendPQExpBuffer(PQExpBuffer str, const char *fmt,...)
void destroyPQExpBuffer(PQExpBuffer str)
void appendPQExpBufferChar(PQExpBuffer str, char ch)
void appendPQExpBufferStr(PQExpBuffer str, const char *data)
void termPQExpBuffer(PQExpBuffer str)
size_t pvsnprintf(char *buf, size_t len, const char *fmt, va_list args)
bool simple_string_list_member(SimpleStringList *list, const char *val)
const char * simple_string_list_not_touched(SimpleStringList *list)
void appendPsqlMetaConnect(PQExpBuffer buf, const char *dbname)
const char * fmtId(const char *rawid)
const char * fmtQualifiedId(const char *schema, const char *id)
void initStringInfo(StringInfo str)