33 #include "catalog/pg_class_d.h"
46 #define TEXT_DUMP_HEADER "--\n-- PostgreSQL database dump\n--\n\n"
47 #define TEXT_DUMPALL_HEADER "--\n-- PostgreSQL database cluster dump\n--\n\n"
110 void *callback_data);
114 void *callback_data);
147 opts->include_everything =
true;
243 AH =
_allocAH(FileSpec,
fmt, compression_spec,
true,
261 pg_fatal(
"could not close output file: %m");
269 if (dopt == NULL && ropt != NULL)
315 pg_fatal(
"unexpected section code %d",
352 pg_fatal(
"parallel restore is not supported with this archive file format");
356 pg_fatal(
"parallel restore is not supported with archives made by pre-8.0 pg_dump");
377 pg_fatal(
"cannot restore from compressed archive (%s)",
399 pg_fatal(
"direct database connections are not supported in pre-1.3 archives");
429 int impliedDataOnly = 1;
453 ahprintf(AH,
"--\n-- PostgreSQL database dump\n--\n\n");
456 ahprintf(AH,
"-- Dumped from database version %s\n",
459 ahprintf(AH,
"-- Dumped by pg_dump version %s\n",
500 if (strcmp(te->
desc,
"DATABASE") != 0 &&
501 strcmp(te->
desc,
"DATABASE PROPERTIES") != 0)
508 bool not_allowed_in_txn =
false;
519 if (strcmp(te->
desc,
"DATABASE") == 0 ||
520 strcmp(te->
desc,
"DATABASE PROPERTIES") == 0)
522 not_allowed_in_txn =
true;
539 if (strcmp(te->
desc,
"BLOB METADATA") == 0)
544 "SELECT pg_catalog.lo_unlink(oid) "
545 "FROM pg_catalog.pg_largeobject_metadata "
546 "WHERE oid = '",
"'");
549 "SELECT pg_catalog.lo_unlink('",
555 strncmp(te->
dropStmt,
"--", 2) == 0)
573 if (strcmp(te->
desc,
"BLOB") == 0)
580 char *dropStmtOrig = dropStmt;
587 if (strncmp(dropStmt,
"ALTER TABLE", 11) == 0)
590 "ALTER TABLE IF EXISTS");
591 dropStmt = dropStmt + 11;
613 if (strcmp(te->
desc,
"DEFAULT") == 0 ||
614 strcmp(te->
desc,
"DATABASE PROPERTIES") == 0 ||
615 strncmp(dropStmt,
"CREATE OR REPLACE VIEW", 22) == 0)
622 if (strcmp(te->
desc,
"CONSTRAINT") == 0 ||
623 strcmp(te->
desc,
"CHECK CONSTRAINT") == 0 ||
624 strcmp(te->
desc,
"FK CONSTRAINT") == 0)
625 strcpy(buffer,
"DROP CONSTRAINT");
627 snprintf(buffer,
sizeof(buffer),
"DROP %s",
630 mark = strstr(dropStmt, buffer);
637 mark + strlen(buffer));
642 pg_log_warning(
"could not find where to insert IF EXISTS in statement \"%s\"",
662 if (not_allowed_in_txn)
735 bool haveACL =
false;
736 bool havePostACL =
false;
793 ahprintf(AH,
"--\n-- PostgreSQL database dump complete\n--\n\n");
843 bool object_is_db =
false;
849 if (strcmp(te->
desc,
"DATABASE") == 0 ||
850 strcmp(te->
desc,
"DATABASE PROPERTIES") == 0)
865 te->
desc, te->namespace, te->
tag);
873 if (strcmp(te->
desc,
"TABLE") == 0)
941 if (strcmp(te->
desc,
"BLOBS") == 0 ||
942 strcmp(te->
desc,
"BLOB COMMENTS") == 0)
949 if (strcmp(te->
desc,
"BLOB COMMENTS") == 0)
967 te->namespace, te->
tag);
985 use_truncate = is_parallel && te->
created &&
1000 ahprintf(AH,
"TRUNCATE TABLE ONLY %s;\n\n",
1033 else if (!defnDumped)
1055 ahprintf(AH,
"COMMIT;\nBEGIN;\n\n");
1082 opts->compression_spec.level = 0;
1109 ahprintf(AH,
"ALTER TABLE %s DISABLE TRIGGER ALL;\n\n",
1135 ahprintf(AH,
"ALTER TABLE %s ENABLE TRIGGER ALL;\n\n",
1154 strncmp(te->
defn,
"-- load via partition root ", 27) == 0)
1187 pg_fatal(
"internal error -- WriteData cannot be called outside the context of a DataDumper routine");
1235 if (
opts->nDeps > 0)
1270 const char *fmtName;
1282 strcpy(stamp_str,
"[unknown]");
1284 ahprintf(AH,
";\n; Archive created at %s\n", stamp_str);
1285 ahprintf(AH,
"; dbname: %s\n; TOC Entries: %d\n; Compression: %s\n",
1296 fmtName =
"DIRECTORY";
1302 fmtName =
"UNKNOWN";
1305 ahprintf(AH,
"; Dump Version: %d.%d-%d\n",
1307 ahprintf(AH,
"; Format: %s\n", fmtName);
1311 ahprintf(AH,
"; Dumped from database version: %s\n",
1314 ahprintf(AH,
"; Dumped by pg_dump version: %s\n",
1317 ahprintf(AH,
";\n;\n; Selected TOC Entries:\n;\n");
1330 char *sanitized_name;
1331 char *sanitized_schema;
1332 char *sanitized_owner;
1342 te->
desc, sanitized_schema, sanitized_name,
1345 free(sanitized_name);
1346 free(sanitized_schema);
1347 free(sanitized_owner);
1379 pg_fatal(
"large-object output not supported in chosen format");
1443 "restored %d large objects",
1469 pg_log_info(
"restoring large object with OID %u", oid);
1472 if (old_lo_style && drop)
1480 if (loOid == 0 || loOid != oid)
1481 pg_fatal(
"could not create large object %u: %s",
1486 pg_fatal(
"could not open large object %u: %s",
1492 ahprintf(AH,
"SELECT pg_catalog.lo_open(pg_catalog.lo_create('%u'), %d);\n",
1495 ahprintf(AH,
"SELECT pg_catalog.lo_open('%u', %d);\n",
1520 ahprintf(AH,
"SELECT pg_catalog.lo_close(0);\n\n");
1554 cmnt = strchr(linebuf.
data,
';');
1558 linebuf.
len = cmnt - linebuf.
data;
1562 if (strspn(linebuf.
data,
" \t\r\n") == linebuf.
len)
1566 id = strtol(linebuf.
data, &endptr, 10);
1567 if (endptr == linebuf.
data || id <= 0 || id > AH->
maxDumpId ||
1577 pg_fatal(
"could not find entry for ID %d",
1599 if (fclose(fh) != 0)
1600 pg_fatal(
"could not close TOC file: %m");
1619 int save_errno = errno;
1669 fn = fileno(AH->
FH);
1689 pg_fatal(
"could not open output file: %m");
1706 pg_fatal(
"could not close output file: %m");
1708 AH->
OF = savedOutput;
1719 int save_errno = errno;
1773 "wrote %zu bytes of large object data (result = %d)",
1786 (
const unsigned char *) AH->
lo_buf,
1792 ahprintf(AH,
"SELECT pg_catalog.lowrite(0, %s);\n",
buf->data);
1810 int bytes_written = 0;
1821 ptr = (
const void *) ((
const char *) ptr + avail);
1830 bytes_written =
size * nmemb;
1846 bytes_written =
size * nmemb;
1849 if (bytes_written !=
size * nmemb)
1970 if (strcmp(te->
desc,
"TABLE DATA") == 0 && te->
nDeps > 0)
1979 if (tableId <= 0 || tableId > maxDumpId)
1980 pg_fatal(
"bad table dumpId for TABLE DATA item");
1994 if (
id > 0 && id <= AH->maxDumpId)
2020 for (off = 0; off <
sizeof(
pgoff_t); off++)
2072 pg_fatal(
"unexpected data offset flag %d", offsetFlg);
2078 for (off = 0; off < AH->
offSize; off++)
2085 pg_fatal(
"file offset in dump file is too large");
2140 res =
res + (bv << bitShift);
2157 int len = strlen(
c);
2196 pg_fatal(
"directory name too long: \"%s\"", dir);
2209 pg_log_debug(
"attempting to ascertain archive format");
2246 pg_fatal(
"directory \"%s\" does not appear to be a valid archive (\"toc.dat\" does not exist)",
2254 pg_fatal(
"could not open input file \"%s\": %m", AH->
fSpec);
2261 pg_fatal(
"could not open input file: %m");
2264 if ((cnt = fread(
sig, 1, 5, fh)) != 5)
2267 pg_fatal(
"could not read input file: %m");
2269 pg_fatal(
"input file is too short (read %lu, expected 5)",
2270 (
unsigned long) cnt);
2277 if (strncmp(
sig,
"PGDMP", 5) == 0)
2301 pg_fatal(
"input file appears to be a text format dump. Please use psql.");
2307 pg_fatal(
"input file does not appear to be a valid archive (too short?)");
2313 pg_fatal(
"input file does not appear to be a valid archive");
2321 if (fclose(fh) != 0)
2322 pg_fatal(
"could not close input file: %m");
2346 FileSpec ? FileSpec :
"(stdio)",
fmt);
2401 pg_fatal(
"could not open stdout for appending: %m");
2411 (AH->
fSpec == NULL || strcmp(AH->
fSpec,
"") == 0))
2414 _setmode(fileno(
stdout), O_BINARY);
2416 _setmode(fileno(stdin), O_BINARY);
2489 for (
int i = 0;
i < ntes;
i++)
2525 void *callback_data)
2531 pg_fatal(
"worker process failed: exit code %d",
2544 if (strcmp(te->
desc,
"BLOBS") == 0)
2555 if (startPtr != NULL)
2556 (*startPtr) (AH, te);
2653 pg_fatal(
"entry ID %d out of range -- perhaps a corrupt TOC",
2684 if (strcmp(te->
desc,
"COMMENT") == 0 ||
2685 strcmp(te->
desc,
"ACL") == 0 ||
2686 strcmp(te->
desc,
"ACL LANGUAGE") == 0)
2688 else if (strcmp(te->
desc,
"TABLE DATA") == 0 ||
2689 strcmp(te->
desc,
"BLOBS") == 0 ||
2690 strcmp(te->
desc,
"BLOB COMMENTS") == 0)
2692 else if (strcmp(te->
desc,
"CONSTRAINT") == 0 ||
2693 strcmp(te->
desc,
"CHECK CONSTRAINT") == 0 ||
2694 strcmp(te->
desc,
"FK CONSTRAINT") == 0 ||
2695 strcmp(te->
desc,
"INDEX") == 0 ||
2696 strcmp(te->
desc,
"RULE") == 0 ||
2697 strcmp(te->
desc,
"TRIGGER") == 0)
2722 is_supported =
true;
2724 is_supported =
false;
2729 if (strcmp(tmp,
"true") == 0)
2730 is_supported =
false;
2736 pg_log_warning(
"restoring tables WITH OIDS is not supported anymore");
2749 if (depIdx >= depSize)
2754 sscanf(tmp,
"%d", &deps[depIdx]);
2792 if (strcmp(te->
desc,
"ENCODING") == 0)
2794 else if (strcmp(te->
desc,
"STDSTRINGS") == 0)
2796 else if (strcmp(te->
desc,
"SEARCHPATH") == 0)
2810 ptr1 = strchr(defn,
'\'');
2812 ptr2 = strchr(++ptr1,
'\'');
2818 pg_fatal(
"unrecognized encoding \"%s\"",
2823 pg_fatal(
"invalid ENCODING item: %s",
2835 ptr1 = strchr(te->
defn,
'\'');
2836 if (ptr1 && strncmp(ptr1,
"'on'", 4) == 0)
2838 else if (ptr1 && strncmp(ptr1,
"'off'", 5) == 0)
2841 pg_fatal(
"invalid STDSTRINGS item: %s",
2858 const char *missing_name;
2865 if (missing_name != NULL)
2866 pg_fatal(
"schema \"%s\" not found", missing_name);
2872 if (missing_name != NULL)
2873 pg_fatal(
"table \"%s\" not found", missing_name);
2879 if (missing_name != NULL)
2880 pg_fatal(
"index \"%s\" not found", missing_name);
2886 if (missing_name != NULL)
2887 pg_fatal(
"function \"%s\" not found", missing_name);
2893 if (missing_name != NULL)
2894 pg_fatal(
"trigger \"%s\" not found", missing_name);
2912 if (strcmp(te->
desc,
"ENCODING") == 0 ||
2913 strcmp(te->
desc,
"STDSTRINGS") == 0 ||
2914 strcmp(te->
desc,
"SEARCHPATH") == 0)
2922 if (strcmp(te->
desc,
"DATABASE") == 0 ||
2923 strcmp(te->
desc,
"DATABASE PROPERTIES") == 0)
2948 (strcmp(te->
desc,
"PUBLICATION") == 0 ||
2949 strcmp(te->
desc,
"PUBLICATION TABLE") == 0 ||
2950 strcmp(te->
desc,
"PUBLICATION TABLES IN SCHEMA") == 0))
2988 if (strcmp(te->
desc,
"ACL") == 0 ||
2989 strcmp(te->
desc,
"COMMENT") == 0 ||
2990 strcmp(te->
desc,
"SECURITY LABEL") == 0)
2993 if (strncmp(te->
tag,
"DATABASE ", 9) == 0)
3021 bool dumpthis =
false;
3023 for (
int i = 0;
i < te->
nDeps;
i++)
3029 if (strcmp(pte->
desc,
"ACL") == 0)
3060 if (strcmp(te->
desc,
"TABLE") == 0 ||
3061 strcmp(te->
desc,
"TABLE DATA") == 0 ||
3062 strcmp(te->
desc,
"VIEW") == 0 ||
3063 strcmp(te->
desc,
"FOREIGN TABLE") == 0 ||
3064 strcmp(te->
desc,
"MATERIALIZED VIEW") == 0 ||
3065 strcmp(te->
desc,
"MATERIALIZED VIEW DATA") == 0 ||
3066 strcmp(te->
desc,
"SEQUENCE") == 0 ||
3067 strcmp(te->
desc,
"SEQUENCE SET") == 0)
3075 else if (strcmp(te->
desc,
"INDEX") == 0)
3083 else if (strcmp(te->
desc,
"FUNCTION") == 0 ||
3084 strcmp(te->
desc,
"AGGREGATE") == 0 ||
3085 strcmp(te->
desc,
"PROCEDURE") == 0)
3093 else if (strcmp(te->
desc,
"TRIGGER") == 0)
3121 if (strcmp(te->
desc,
"SEQUENCE SET") == 0 ||
3122 strcmp(te->
desc,
"BLOB") == 0 ||
3123 strcmp(te->
desc,
"BLOB METADATA") == 0 ||
3124 (strcmp(te->
desc,
"ACL") == 0 &&
3125 strncmp(te->
tag,
"LARGE OBJECT", 12) == 0) ||
3126 (strcmp(te->
desc,
"COMMENT") == 0 &&
3127 strncmp(te->
tag,
"LARGE OBJECT", 12) == 0) ||
3128 (strcmp(te->
desc,
"SECURITY LABEL") == 0 &&
3129 strncmp(te->
tag,
"LARGE OBJECT", 12) == 0))
3140 strncmp(te->
defn,
"-- load via partition root ", 27) == 0)
3147 if ((strcmp(te->
desc,
"<Init>") == 0) && (strcmp(te->
tag,
"Max OID") == 0))
3163 (strcmp(te->
desc,
"BLOB") == 0 ||
3164 strcmp(te->
desc,
"BLOB METADATA") == 0 ||
3165 (strcmp(te->
desc,
"ACL") == 0 &&
3166 strncmp(te->
tag,
"LARGE OBJECT", 12) == 0) ||
3167 (strcmp(te->
desc,
"COMMENT") == 0 &&
3168 strncmp(te->
tag,
"LARGE OBJECT", 12) == 0) ||
3169 (strcmp(te->
desc,
"SECURITY LABEL") == 0 &&
3170 strncmp(te->
tag,
"LARGE OBJECT", 12) == 0))))
3190 if (strcmp(te->
desc,
"ACL") == 0 ||
3191 strcmp(te->
desc,
"ACL LANGUAGE") == 0 ||
3192 strcmp(te->
desc,
"DEFAULT ACL") == 0)
3194 if (strcmp(te->
desc,
"EVENT TRIGGER") == 0 ||
3195 strcmp(te->
desc,
"MATERIALIZED VIEW DATA") == 0)
3204 if (strcmp(te->
desc,
"COMMENT") == 0 &&
3205 strncmp(te->
tag,
"EVENT TRIGGER ", 14) == 0)
3223 if (strcmp(te->
desc,
"ACL") == 0 ||
3224 strcmp(te->
desc,
"ACL LANGUAGE") == 0 ||
3225 strcmp(te->
desc,
"DEFAULT ACL") == 0)
3242 ahprintf(AH,
"SET statement_timeout = 0;\n");
3243 ahprintf(AH,
"SET lock_timeout = 0;\n");
3244 ahprintf(AH,
"SET idle_in_transaction_session_timeout = 0;\n");
3245 ahprintf(AH,
"SET transaction_timeout = 0;\n");
3248 ahprintf(AH,
"SET client_encoding = '%s';\n",
3252 ahprintf(AH,
"SET standard_conforming_strings = %s;\n",
3264 ahprintf(AH,
"SET check_function_bodies = false;\n");
3267 ahprintf(AH,
"SET xmloption = content;\n");
3270 ahprintf(AH,
"SET client_min_messages = warning;\n");
3272 ahprintf(AH,
"SET escape_string_warning = off;\n");
3276 ahprintf(AH,
"SET row_security = on;\n");
3278 ahprintf(AH,
"SET row_security = off;\n");
3325 pg_fatal(
"could not set session user to \"%s\": %s",
3438 if (!schemaName || *schemaName ==
'\0' ||
3446 if (strcmp(schemaName,
"pg_catalog") != 0)
3457 "could not set \"search_path\" to \"%s\": %s",
3494 if (have && strcmp(want, have) == 0)
3499 if (strcmp(want,
"") == 0)
3518 "could not set \"default_tablespace\" to %s: %s",
3553 if (have && strcmp(want, have) == 0)
3567 "could not set \"default_table_access_method\": %s",
3589 const char *tableam = te->
tableam;
3616 "could not alter table access method: %s",
3639 if (strcmp(
type,
"COLLATION") == 0 ||
3640 strcmp(
type,
"CONVERSION") == 0 ||
3641 strcmp(
type,
"DOMAIN") == 0 ||
3642 strcmp(
type,
"FOREIGN TABLE") == 0 ||
3643 strcmp(
type,
"MATERIALIZED VIEW") == 0 ||
3644 strcmp(
type,
"SEQUENCE") == 0 ||
3645 strcmp(
type,
"STATISTICS") == 0 ||
3646 strcmp(
type,
"TABLE") == 0 ||
3647 strcmp(
type,
"TEXT SEARCH DICTIONARY") == 0 ||
3648 strcmp(
type,
"TEXT SEARCH CONFIGURATION") == 0 ||
3649 strcmp(
type,
"TYPE") == 0 ||
3650 strcmp(
type,
"VIEW") == 0 ||
3652 strcmp(
type,
"DATABASE") == 0 ||
3653 strcmp(
type,
"PROCEDURAL LANGUAGE") == 0 ||
3654 strcmp(
type,
"SCHEMA") == 0 ||
3655 strcmp(
type,
"EVENT TRIGGER") == 0 ||
3656 strcmp(
type,
"FOREIGN DATA WRAPPER") == 0 ||
3657 strcmp(
type,
"SERVER") == 0 ||
3658 strcmp(
type,
"PUBLICATION") == 0 ||
3659 strcmp(
type,
"SUBSCRIPTION") == 0)
3662 if (te->namespace && *te->namespace)
3667 else if (strcmp(
type,
"BLOB") == 0)
3676 else if (strcmp(
type,
"AGGREGATE") == 0 ||
3677 strcmp(
type,
"FUNCTION") == 0 ||
3678 strcmp(
type,
"OPERATOR") == 0 ||
3679 strcmp(
type,
"OPERATOR CLASS") == 0 ||
3680 strcmp(
type,
"OPERATOR FAMILY") == 0 ||
3681 strcmp(
type,
"PROCEDURE") == 0)
3688 last = first + strlen(first) - 1;
3691 while (last >= first && (*last ==
'\n' || *last ==
';'))
3701 else if (strcmp(
type,
"CAST") == 0 ||
3702 strcmp(
type,
"CHECK CONSTRAINT") == 0 ||
3703 strcmp(
type,
"CONSTRAINT") == 0 ||
3704 strcmp(
type,
"DATABASE PROPERTIES") == 0 ||
3705 strcmp(
type,
"DEFAULT") == 0 ||
3706 strcmp(
type,
"FK CONSTRAINT") == 0 ||
3707 strcmp(
type,
"INDEX") == 0 ||
3708 strcmp(
type,
"RULE") == 0 ||
3709 strcmp(
type,
"TRIGGER") == 0 ||
3710 strcmp(
type,
"ROW SECURITY") == 0 ||
3711 strcmp(
type,
"POLICY") == 0 ||
3712 strcmp(
type,
"USER MAPPING") == 0)
3717 pg_fatal(
"don't know how to set owner for object type \"%s\"",
type);
3741 if (te->
relkind != RELKIND_PARTITIONED_TABLE)
3748 char *sanitized_name;
3749 char *sanitized_schema;
3750 char *sanitized_owner;
3760 ahprintf(AH,
"-- TOC entry %d (class %u OID %u)\n",
3777 ahprintf(AH,
"-- %sName: %s; Type: %s; Schema: %s; Owner: %s",
3778 pfx, sanitized_name, te->
desc, sanitized_schema,
3781 free(sanitized_name);
3782 free(sanitized_schema);
3783 free(sanitized_owner);
3787 char *sanitized_tablespace;
3790 ahprintf(AH,
"; Tablespace: %s", sanitized_tablespace);
3791 free(sanitized_tablespace);
3817 strcmp(te->
desc,
"SCHEMA") == 0 && strncmp(te->
defn,
"--", 2) != 0)
3821 else if (strcmp(te->
desc,
"BLOB METADATA") == 0)
3825 else if (strcmp(te->
desc,
"ACL") == 0 &&
3826 strncmp(te->
tag,
"LARGE OBJECTS", 13) == 0)
3830 else if (te->
defn && strlen(te->
defn) > 0)
3842 strcmp(te->
desc,
"FUNCTION") != 0 &&
3843 strcmp(te->
desc,
"PROCEDURE") != 0)
3845 const char *p = te->
defn;
3848 while ((p = strchr(p,
';')) != NULL)
3867 (strcmp(te->
desc,
"SCHEMA") == 0 &&
3868 strncmp(te->
defn,
"--", 2) == 0)) &&
3872 if (strcmp(te->
desc,
"BLOB METADATA") == 0)
3893 ahprintf(AH,
"ALTER %s OWNER TO %s;\n\n",
3903 if (te->
relkind == RELKIND_PARTITIONED_TABLE)
3940 return pg_strdup(want_hyphen ?
"-" :
"");
3944 for (s = result; *s !=
'\0'; s++)
3946 if (*s ==
'\n' || *s ==
'\r')
4003 if (strncmp(tmpMag,
"PGDMP", 5) != 0)
4004 pg_fatal(
"did not find magic string in file header");
4010 if (vmaj > 1 || (vmaj == 1 && vmin > 0))
4018 pg_fatal(
"unsupported version (%d.%d) in file header",
4023 pg_fatal(
"sanity check on integer size (%lu) failed",
4026 if (AH->
intSize >
sizeof(
int))
4027 pg_log_warning(
"archive was made on a machine with larger integers, some operations might fail");
4037 pg_fatal(
"expected format (%d) differs from format found in file (%d)",
4059 pg_log_warning(
"archive is compressed, but this installation does not support compression (%s) -- no data will be available",
4131 if (
fseeko(fp, tpos, SEEK_SET) != 0)
4191 skipped_some =
false;
4192 for (next_work_item = AH->
toc->
next; next_work_item != AH->
toc; next_work_item = next_work_item->
next)
4203 skipped_some =
true;
4231 next_work_item->
desc, next_work_item->
tag);
4320 if (next_work_item != NULL)
4327 next_work_item->
desc, next_work_item->
tag);
4336 next_work_item->
desc, next_work_item->
tag);
4442 for (k = 0; k < te2->
nDeps; k++)
4532 for (te = pending_list->
pending_next; te != pending_list; te = next_te)
4574 bool conflicts =
false;
4585 if (running_te == NULL)
4643 void *callback_data)
4659 else if (status != 0)
4660 pg_fatal(
"worker process failed: exit code %d",
4715 if (strcmp(te->
desc,
"BLOB COMMENTS") == 0 && te->
nDeps == 0)
4721 if (strcmp(te2->
desc,
"BLOBS") == 0)
4752 if (depid <= AH->maxDumpId && AH->
tocsByDumpId[depid] != NULL)
4780 if (depid <= AH->maxDumpId && AH->
tocsByDumpId[depid] != NULL)
4824 if (olddep <= AH->maxDumpId &&
4833 te->
dumpId, olddep, tabledataid);
4868 if (strcmp(te->
desc,
"INDEX") == 0)
4887 if (depid <= AH->maxDumpId && AH->
tocsByDumpId[depid] != NULL &&
4890 lockids[nlockids++] = depid;
4966 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)
void binaryheap_remove_node(binaryheap *heap, int n)
void binaryheap_add(binaryheap *heap, bh_node_type d)
binaryheap * binaryheap_allocate(int capacity, binaryheap_comparator compare, void *arg)
void binaryheap_free(binaryheap *heap)
#define binaryheap_size(h)
#define binaryheap_empty(h)
#define binaryheap_get_node(h, n)
#define ngettext(s, p, n)
#define Assert(condition)
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,...)
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)
@ DATA_DIR_SYNC_METHOD_FSYNC
static DataDirSyncMethod sync_method
if(TABLE==NULL||TABLE_index==NULL)
static void const char * fmt
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 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)
TocEntry * getTocEntryByDumpId(ArchiveHandle *AH, DumpId id)
static void pending_list_append(TocEntry *l, TocEntry *te)
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 move_to_ready_heap(TocEntry *pending_list, binaryheap *ready_heap, RestorePass pass)
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 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)
Archive * CreateArchive(const char *FileSpec, const ArchiveFormat fmt, const pg_compress_specification compression_spec, bool dosync, ArchiveMode mode, SetupWorkerPtrType setupDumpWorker, DataDirSyncMethod sync_method)
static void _reconnectToDB(ArchiveHandle *AH, const char *dbname)
static int TocEntrySizeCompareQsort(const void *p1, const void *p2)
void StartRestoreLOs(ArchiveHandle *AH)
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 _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 _printTableAccessMethodNoStorage(ArchiveHandle *AH, TocEntry *te)
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 TocEntrySizeCompareBinaryheap(void *p1, void *p2, void *arg)
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 void reduce_dependencies(ArchiveHandle *AH, TocEntry *te, binaryheap *ready_heap)
static char * sanitize_line(const char *str, bool want_hyphen)
void EndRestoreLO(ArchiveHandle *AH, Oid oid)
static void _selectTablespace(ArchiveHandle *AH, const char *tablespace)
void RestoreArchive(Archive *AHX)
void WriteToc(ArchiveHandle *AH)
void archputs(const char *s, Archive *AH)
static bool _fileExistsInDirectory(const char *dir, const char *filename)
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)
static ArchiveHandle * _allocAH(const char *FileSpec, const ArchiveFormat fmt, const pg_compress_specification compression_spec, bool dosync, ArchiveMode mode, SetupWorkerPtrType setupWorkerPtr, DataDirSyncMethod sync_method)
DumpOptions * dumpOptionsFromRestoreOptions(RestoreOptions *ropt)
static void dump_lo_buf(ArchiveHandle *AH)
static TocEntry * pop_next_work_item(binaryheap *ready_heap, ParallelState *pstate)
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
void IssueACLPerBlob(ArchiveHandle *AH, TocEntry *te)
#define appendByteaLiteralAHX(buf, str, len, AH)