33#include "catalog/pg_class_d.h"
34#include "catalog/pg_largeobject_metadata_d.h"
35#include "catalog/pg_shdepend_d.h"
49#define TEXT_DUMP_HEADER "--\n-- PostgreSQL database dump\n--\n\n"
50#define TEXT_DUMPALL_HEADER "--\n-- PostgreSQL database cluster dump\n--\n\n"
52#define TOC_PREFIX_NONE ""
53#define TOC_PREFIX_DATA "Data for "
54#define TOC_PREFIX_STATS "Statistics for "
115 void *callback_data);
119 void *callback_data);
152 opts->include_everything =
true;
155 opts->dumpSchema =
true;
156 opts->dumpData =
true;
157 opts->dumpStatistics =
false;
254 AH =
_allocAH(FileSpec, fmt, compression_spec,
true,
272 pg_fatal(
"could not close output file: %m");
280 if (dopt == NULL && ropt != NULL)
326 pg_fatal(
"unexpected section code %d",
368 pg_fatal(
"parallel restore is not supported with this archive file format");
372 pg_fatal(
"parallel restore is not supported with archives made by pre-8.0 pg_dump");
393 pg_fatal(
"cannot restore from compressed archive (%s)",
415 pg_fatal(
"direct database connections are not supported in pre-1.3 archives");
445 bool no_schema_found =
true;
451 no_schema_found =
false;
469 ahprintf(AH,
"--\n-- PostgreSQL database dump\n--\n\n");
483 ahprintf(AH,
"-- Dumped from database version %s\n",
486 ahprintf(AH,
"-- Dumped by pg_dump version %s\n",
527 if (strcmp(te->
desc,
"DATABASE") != 0 &&
528 strcmp(te->
desc,
"DATABASE PROPERTIES") != 0)
535 bool not_allowed_in_txn =
false;
546 if (strcmp(te->
desc,
"DATABASE") == 0 ||
547 strcmp(te->
desc,
"DATABASE PROPERTIES") == 0)
549 not_allowed_in_txn =
true;
566 if (strcmp(te->
desc,
"BLOB METADATA") == 0)
571 "SELECT pg_catalog.lo_unlink(oid) "
572 "FROM pg_catalog.pg_largeobject_metadata "
573 "WHERE oid = '",
"'");
576 "SELECT pg_catalog.lo_unlink('",
582 strncmp(te->
dropStmt,
"--", 2) == 0)
600 if (strcmp(te->
desc,
"BLOB") == 0)
607 char *dropStmtOrig = dropStmt;
614 if (strncmp(dropStmt,
"ALTER TABLE", 11) == 0)
617 "ALTER TABLE IF EXISTS");
618 dropStmt = dropStmt + 11;
640 if (strcmp(te->
desc,
"DEFAULT") == 0 ||
641 strcmp(te->
desc,
"DATABASE PROPERTIES") == 0 ||
642 strncmp(dropStmt,
"CREATE OR REPLACE VIEW", 22) == 0)
649 if (strcmp(te->
desc,
"CONSTRAINT") == 0 ||
650 strcmp(te->
desc,
"CHECK CONSTRAINT") == 0 ||
651 strcmp(te->
desc,
"FK CONSTRAINT") == 0)
652 strcpy(buffer,
"DROP CONSTRAINT");
654 snprintf(buffer,
sizeof(buffer),
"DROP %s",
657 mark = strstr(dropStmt, buffer);
664 mark + strlen(buffer));
669 pg_log_warning(
"could not find where to insert IF EXISTS in statement \"%s\"",
689 if (not_allowed_in_txn)
762 bool haveACL =
false;
763 bool havePostACL =
false;
772 (strcmp(te->
desc,
"TABLESPACE") == 0))
780 strcmp(te->
desc,
"DROP_GLOBAL") == 0)
833 ahprintf(AH,
"--\n-- PostgreSQL database dump complete\n--\n\n");
891 bool object_is_db =
false;
897 if (strcmp(te->
desc,
"DATABASE") == 0 ||
898 strcmp(te->
desc,
"DATABASE PROPERTIES") == 0)
913 te->
desc, te->namespace, te->
tag);
921 if (strcmp(te->
desc,
"TABLE") == 0)
989 if (strcmp(te->
desc,
"BLOBS") == 0 ||
990 strcmp(te->
desc,
"BLOB COMMENTS") == 0)
997 if (strcmp(te->
desc,
"BLOB COMMENTS") == 0)
1014 pg_log_info(
"processing data for table \"%s.%s\"",
1015 te->namespace, te->
tag);
1033 use_truncate = is_parallel && te->
created &&
1048 ahprintf(AH,
"TRUNCATE TABLE ONLY %s;\n\n",
1081 else if (!defnDumped)
1109 ahprintf(AH,
"COMMIT;\nBEGIN;\n\n");
1136 opts->compression_spec.level = 0;
1137 opts->dumpSchema =
true;
1138 opts->dumpData =
true;
1139 opts->dumpStatistics =
true;
1166 ahprintf(AH,
"ALTER TABLE %s DISABLE TRIGGER ALL;\n\n",
1192 ahprintf(AH,
"ALTER TABLE %s ENABLE TRIGGER ALL;\n\n",
1211 strncmp(te->
defn,
"-- load via partition root ", 27) == 0)
1244 pg_fatal(
"internal error -- WriteData cannot be called outside the context of a DataDumper routine");
1292 if (
opts->nDeps > 0)
1330 const char *fmtName;
1342 strcpy(stamp_str,
"[unknown]");
1344 ahprintf(AH,
";\n; Archive created at %s\n", stamp_str);
1345 ahprintf(AH,
"; dbname: %s\n; TOC Entries: %d\n; Compression: %s\n",
1356 fmtName =
"DIRECTORY";
1362 fmtName =
"UNKNOWN";
1365 ahprintf(AH,
"; Dump Version: %d.%d-%d\n",
1367 ahprintf(AH,
"; Format: %s\n", fmtName);
1371 ahprintf(AH,
"; Dumped from database version: %s\n",
1374 ahprintf(AH,
"; Dumped by pg_dump version: %s\n",
1377 ahprintf(AH,
";\n;\n; Selected TOC Entries:\n;\n");
1390 char *sanitized_name;
1391 char *sanitized_schema;
1392 char *sanitized_owner;
1402 te->
desc, sanitized_schema, sanitized_name,
1405 free(sanitized_name);
1406 free(sanitized_schema);
1407 free(sanitized_owner);
1439 pg_fatal(
"large-object output not supported in chosen format");
1503 "restored %d large objects",
1529 pg_log_info(
"restoring large object with OID %u", oid);
1532 if (old_lo_style && drop)
1540 if (loOid == 0 || loOid != oid)
1541 pg_fatal(
"could not create large object %u: %s",
1546 pg_fatal(
"could not open large object %u: %s",
1552 ahprintf(AH,
"SELECT pg_catalog.lo_open(pg_catalog.lo_create('%u'), %d);\n",
1555 ahprintf(AH,
"SELECT pg_catalog.lo_open('%u', %d);\n",
1580 ahprintf(AH,
"SELECT pg_catalog.lo_close(0);\n\n");
1614 cmnt = strchr(linebuf.
data,
';');
1618 linebuf.
len = cmnt - linebuf.
data;
1622 if (strspn(linebuf.
data,
" \t\r\n") == linebuf.
len)
1626 id = strtol(linebuf.
data, &endptr, 10);
1627 if (endptr == linebuf.
data || id <= 0 || id > AH->
maxDumpId ||
1637 pg_fatal(
"could not find entry for ID %d",
1659 if (fclose(fh) != 0)
1660 pg_fatal(
"could not close TOC file: %m");
1679 int save_errno = errno;
1693 va_start(args, fmt);
1730 fn = fileno(stdout);
1733 fn = fileno(AH->
FH);
1739 fn = fileno(stdout);
1753 pg_fatal(
"could not open output file: %m");
1770 pg_fatal(
"could not close output file: %m");
1772 AH->
OF = savedOutput;
1783 int save_errno = errno;
1797 va_start(args, fmt);
1837 "wrote %zu bytes of large object data (result = %d)",
1850 (
const unsigned char *) AH->
lo_buf,
1856 ahprintf(AH,
"SELECT pg_catalog.lowrite(0, %s);\n",
buf->data);
1874 int bytes_written = 0;
1885 ptr = (
const char *) ptr + avail;
1894 bytes_written = size * nmemb;
1897 bytes_written = AH->
CustomOutPtr(AH, ptr, size * nmemb);
1910 bytes_written = size * nmemb;
1913 if (bytes_written != size * nmemb)
2034 if (strcmp(te->
desc,
"TABLE DATA") == 0 && te->
nDeps > 0)
2043 if (tableId <= 0 || tableId > maxDumpId)
2044 pg_fatal(
"bad table dumpId for TABLE DATA item");
2058 if (
id > 0 && id <= AH->maxDumpId)
2084 for (off = 0; off <
sizeof(
pgoff_t); off++)
2136 pg_fatal(
"unexpected data offset flag %d", offsetFlg);
2142 for (off = 0; off < AH->
offSize; off++)
2149 pg_fatal(
"file offset in dump file is too large");
2204 res = res + (bv << bitShift);
2221 int len = strlen(
c);
2260 pg_fatal(
"directory name too long: \"%s\"", dir);
2273 pg_log_debug(
"attempting to ascertain archive format");
2310 pg_fatal(
"directory \"%s\" does not appear to be a valid archive (\"toc.dat\" does not exist)",
2318 pg_fatal(
"could not open input file \"%s\": %m", AH->
fSpec);
2325 pg_fatal(
"could not open input file: %m");
2328 if ((cnt = fread(
sig, 1, 5, fh)) != 5)
2331 pg_fatal(
"could not read input file: %m");
2333 pg_fatal(
"input file is too short (read %zu, expected 5)", cnt);
2340 if (strncmp(
sig,
"PGDMP", 5) == 0)
2364 pg_fatal(
"input file appears to be a text format dump. Please use psql.");
2370 pg_fatal(
"input file does not appear to be a valid archive (too short?)");
2376 pg_fatal(
"input file does not appear to be a valid tar archive");
2384 if (fclose(fh) != 0)
2385 pg_fatal(
"could not close input file: %m");
2409 FileSpec ? FileSpec :
"(stdio)", fmt);
2464 pg_fatal(
"could not open stdout for appending: %m");
2474 (AH->
fSpec == NULL || strcmp(AH->
fSpec,
"") == 0))
2477 _setmode(fileno(stdout), O_BINARY);
2479 _setmode(fileno(stdin), O_BINARY);
2552 for (
int i = 0;
i < ntes;
i++)
2588 void *callback_data)
2594 pg_fatal(
"worker process failed: exit code %d",
2607 if (strcmp(te->
desc,
"BLOBS") == 0)
2618 if (startPtr != NULL)
2619 (*startPtr) (AH, te);
2692 pg_fatal(
"unexpected TOC entry in WriteToc(): %d %s %s",
2696 pg_fatal(
"error during file seek: %m");
2754 pg_fatal(
"entry ID %d out of range -- perhaps a corrupt TOC",
2785 if (strcmp(te->
desc,
"COMMENT") == 0 ||
2786 strcmp(te->
desc,
"ACL") == 0 ||
2787 strcmp(te->
desc,
"ACL LANGUAGE") == 0)
2789 else if (strcmp(te->
desc,
"TABLE DATA") == 0 ||
2790 strcmp(te->
desc,
"BLOBS") == 0 ||
2791 strcmp(te->
desc,
"BLOB COMMENTS") == 0)
2793 else if (strcmp(te->
desc,
"CONSTRAINT") == 0 ||
2794 strcmp(te->
desc,
"CHECK CONSTRAINT") == 0 ||
2795 strcmp(te->
desc,
"FK CONSTRAINT") == 0 ||
2796 strcmp(te->
desc,
"INDEX") == 0 ||
2797 strcmp(te->
desc,
"RULE") == 0 ||
2798 strcmp(te->
desc,
"TRIGGER") == 0)
2823 is_supported =
true;
2825 is_supported =
false;
2830 if (strcmp(tmp,
"true") == 0)
2831 is_supported =
false;
2837 pg_log_warning(
"restoring tables WITH OIDS is not supported anymore");
2850 if (depIdx >= depSize)
2855 sscanf(tmp,
"%d", &deps[depIdx]);
2893 if (strcmp(te->
desc,
"ENCODING") == 0)
2895 else if (strcmp(te->
desc,
"STDSTRINGS") == 0)
2897 else if (strcmp(te->
desc,
"SEARCHPATH") == 0)
2911 ptr1 = strchr(defn,
'\'');
2913 ptr2 = strchr(++ptr1,
'\'');
2919 pg_fatal(
"unrecognized encoding \"%s\"",
2925 pg_fatal(
"invalid ENCODING item: %s",
2937 ptr1 = strchr(te->
defn,
'\'');
2938 if (ptr1 && strncmp(ptr1,
"'on'", 4) == 0)
2940 else if (ptr1 && strncmp(ptr1,
"'off'", 5) == 0)
2943 pg_fatal(
"invalid STDSTRINGS item: %s",
2960 const char *missing_name;
2967 if (missing_name != NULL)
2968 pg_fatal(
"schema \"%s\" not found", missing_name);
2974 if (missing_name != NULL)
2975 pg_fatal(
"table \"%s\" not found", missing_name);
2981 if (missing_name != NULL)
2982 pg_fatal(
"index \"%s\" not found", missing_name);
2988 if (missing_name != NULL)
2989 pg_fatal(
"function \"%s\" not found", missing_name);
2995 if (missing_name != NULL)
2996 pg_fatal(
"trigger \"%s\" not found", missing_name);
3025 if (strcmp(te->
desc,
"ENCODING") == 0 ||
3026 strcmp(te->
desc,
"STDSTRINGS") == 0 ||
3027 strcmp(te->
desc,
"SEARCHPATH") == 0)
3030 if ((strcmp(te->
desc,
"STATISTICS DATA") == 0) ||
3031 (strcmp(te->
desc,
"EXTENDED STATISTICS DATA") == 0))
3044 if (strcmp(te->
desc,
"DATABASE") == 0 ||
3045 strcmp(te->
desc,
"DATABASE PROPERTIES") == 0)
3057 if (strcmp(te->
desc,
"ROLE") == 0 ||
3058 strcmp(te->
desc,
"ROLE PROPERTIES") == 0 ||
3059 strcmp(te->
desc,
"TABLESPACE") == 0 ||
3060 strcmp(te->
desc,
"DROP_GLOBAL") == 0)
3077 (strcmp(te->
desc,
"POLICY") == 0 ||
3078 strcmp(te->
desc,
"ROW SECURITY") == 0))
3085 if (strcmp(te->
desc,
"COMMENT") == 0)
3088 strncmp(te->
tag,
"POLICY", strlen(
"POLICY")) == 0)
3092 strncmp(te->
tag,
"PUBLICATION", strlen(
"PUBLICATION")) == 0)
3096 strncmp(te->
tag,
"SUBSCRIPTION", strlen(
"SUBSCRIPTION")) == 0)
3103 if (strncmp(te->
tag,
"ROLE", strlen(
"ROLE")) == 0 ||
3104 strncmp(te->
tag,
"TABLESPACE", strlen(
"TABLESPACE")) == 0)
3113 (strcmp(te->
desc,
"PUBLICATION") == 0 ||
3114 strcmp(te->
desc,
"PUBLICATION TABLE") == 0 ||
3115 strcmp(te->
desc,
"PUBLICATION TABLES IN SCHEMA") == 0))
3126 if (strcmp(te->
desc,
"SECURITY LABEL") == 0)
3129 strncmp(te->
tag,
"PUBLICATION", strlen(
"PUBLICATION")) == 0)
3133 strncmp(te->
tag,
"SUBSCRIPTION", strlen(
"SUBSCRIPTION")) == 0)
3140 if (strncmp(te->
tag,
"ROLE", strlen(
"ROLE")) == 0 ||
3141 strncmp(te->
tag,
"TABLESPACE", strlen(
"TABLESPACE")) == 0)
3176 if (strcmp(te->
desc,
"ACL") == 0 ||
3177 strcmp(te->
desc,
"COMMENT") == 0 ||
3178 strcmp(te->
desc,
"STATISTICS DATA") == 0 ||
3179 strcmp(te->
desc,
"SECURITY LABEL") == 0)
3182 if (strncmp(te->
tag,
"DATABASE ", 9) == 0)
3210 bool dumpthis =
false;
3212 for (
int i = 0;
i < te->
nDeps;
i++)
3218 if (strcmp(pte->
desc,
"ACL") == 0)
3249 if (strcmp(te->
desc,
"TABLE") == 0 ||
3250 strcmp(te->
desc,
"TABLE DATA") == 0 ||
3251 strcmp(te->
desc,
"VIEW") == 0 ||
3252 strcmp(te->
desc,
"FOREIGN TABLE") == 0 ||
3253 strcmp(te->
desc,
"MATERIALIZED VIEW") == 0 ||
3254 strcmp(te->
desc,
"MATERIALIZED VIEW DATA") == 0 ||
3255 strcmp(te->
desc,
"SEQUENCE") == 0 ||
3256 strcmp(te->
desc,
"SEQUENCE SET") == 0)
3264 else if (strcmp(te->
desc,
"INDEX") == 0)
3272 else if (strcmp(te->
desc,
"FUNCTION") == 0 ||
3273 strcmp(te->
desc,
"AGGREGATE") == 0 ||
3274 strcmp(te->
desc,
"PROCEDURE") == 0)
3282 else if (strcmp(te->
desc,
"TRIGGER") == 0)
3311 if (strcmp(te->
desc,
"SEQUENCE SET") == 0 ||
3312 strcmp(te->
desc,
"BLOB") == 0 ||
3313 strcmp(te->
desc,
"BLOB METADATA") == 0 ||
3314 (strcmp(te->
desc,
"ACL") == 0 &&
3315 strncmp(te->
tag,
"LARGE OBJECT", 12) == 0) ||
3316 (strcmp(te->
desc,
"COMMENT") == 0 &&
3317 strncmp(te->
tag,
"LARGE OBJECT", 12) == 0) ||
3318 (strcmp(te->
desc,
"SECURITY LABEL") == 0 &&
3319 strncmp(te->
tag,
"LARGE OBJECT", 12) == 0))
3322 res = res & ~REQ_DATA;
3330 strncmp(te->
defn,
"-- load via partition root ", 27) == 0)
3331 res = res & ~REQ_SCHEMA;
3337 if ((strcmp(te->
desc,
"<Init>") == 0) && (strcmp(te->
tag,
"Max OID") == 0))
3353 (strcmp(te->
desc,
"BLOB") == 0 ||
3354 strcmp(te->
desc,
"BLOB METADATA") == 0 ||
3355 (strcmp(te->
desc,
"ACL") == 0 &&
3356 strncmp(te->
tag,
"LARGE OBJECT", 12) == 0) ||
3357 (strcmp(te->
desc,
"COMMENT") == 0 &&
3358 strncmp(te->
tag,
"LARGE OBJECT", 12) == 0) ||
3359 (strcmp(te->
desc,
"SECURITY LABEL") == 0 &&
3360 strncmp(te->
tag,
"LARGE OBJECT", 12) == 0))))
3380 if (strcmp(te->
desc,
"ACL") == 0 ||
3381 strcmp(te->
desc,
"ACL LANGUAGE") == 0 ||
3382 strcmp(te->
desc,
"DEFAULT ACL") == 0)
3384 if (strcmp(te->
desc,
"EVENT TRIGGER") == 0 ||
3385 strcmp(te->
desc,
"MATERIALIZED VIEW DATA") == 0)
3395 if ((strcmp(te->
desc,
"COMMENT") == 0 ||
3396 strcmp(te->
desc,
"SECURITY LABEL") == 0) &&
3397 strncmp(te->
tag,
"EVENT TRIGGER ", 14) == 0)
3409 if (strcmp(te->
desc,
"STATISTICS DATA") == 0 &&
3428 if (strcmp(te->
desc,
"ACL") == 0 ||
3429 strcmp(te->
desc,
"ACL LANGUAGE") == 0 ||
3430 strcmp(te->
desc,
"DEFAULT ACL") == 0)
3447 ahprintf(AH,
"SET statement_timeout = 0;\n");
3448 ahprintf(AH,
"SET lock_timeout = 0;\n");
3449 ahprintf(AH,
"SET idle_in_transaction_session_timeout = 0;\n");
3450 ahprintf(AH,
"SET transaction_timeout = 0;\n");
3453 ahprintf(AH,
"SET client_encoding = '%s';\n",
3457 ahprintf(AH,
"SET standard_conforming_strings = %s;\n",
3469 ahprintf(AH,
"SET check_function_bodies = false;\n");
3472 ahprintf(AH,
"SET xmloption = content;\n");
3475 ahprintf(AH,
"SET client_min_messages = warning;\n");
3479 ahprintf(AH,
"SET row_security = on;\n");
3481 ahprintf(AH,
"SET row_security = off;\n");
3528 pg_fatal(
"could not set session user to \"%s\": %s",
3651 if (!schemaName || *schemaName ==
'\0' ||
3659 if (strcmp(schemaName,
"pg_catalog") != 0)
3670 "could not set \"search_path\" to \"%s\": %s",
3707 if (have && strcmp(want, have) == 0)
3712 if (strcmp(want,
"") == 0)
3731 "could not set \"default_tablespace\" to %s: %s",
3766 if (have && strcmp(want, have) == 0)
3780 "could not set \"default_table_access_method\": %s",
3802 const char *tableam = te->
tableam;
3829 "could not alter table access method: %s",
3852 if (strcmp(
type,
"COLLATION") == 0 ||
3853 strcmp(
type,
"CONVERSION") == 0 ||
3854 strcmp(
type,
"DOMAIN") == 0 ||
3855 strcmp(
type,
"FOREIGN TABLE") == 0 ||
3856 strcmp(
type,
"MATERIALIZED VIEW") == 0 ||
3857 strcmp(
type,
"PROPERTY GRAPH") == 0 ||
3858 strcmp(
type,
"SEQUENCE") == 0 ||
3859 strcmp(
type,
"STATISTICS") == 0 ||
3860 strcmp(
type,
"TABLE") == 0 ||
3861 strcmp(
type,
"TEXT SEARCH DICTIONARY") == 0 ||
3862 strcmp(
type,
"TEXT SEARCH CONFIGURATION") == 0 ||
3863 strcmp(
type,
"TYPE") == 0 ||
3864 strcmp(
type,
"VIEW") == 0 ||
3866 strcmp(
type,
"DATABASE") == 0 ||
3867 strcmp(
type,
"PROCEDURAL LANGUAGE") == 0 ||
3868 strcmp(
type,
"SCHEMA") == 0 ||
3869 strcmp(
type,
"EVENT TRIGGER") == 0 ||
3870 strcmp(
type,
"FOREIGN DATA WRAPPER") == 0 ||
3871 strcmp(
type,
"SERVER") == 0 ||
3872 strcmp(
type,
"PUBLICATION") == 0 ||
3873 strcmp(
type,
"SUBSCRIPTION") == 0)
3876 if (te->namespace && *te->namespace)
3881 else if (strcmp(
type,
"BLOB") == 0)
3890 else if (strcmp(
type,
"AGGREGATE") == 0 ||
3891 strcmp(
type,
"FUNCTION") == 0 ||
3892 strcmp(
type,
"OPERATOR") == 0 ||
3893 strcmp(
type,
"OPERATOR CLASS") == 0 ||
3894 strcmp(
type,
"OPERATOR FAMILY") == 0 ||
3895 strcmp(
type,
"PROCEDURE") == 0)
3902 last = first + strlen(first) - 1;
3905 while (last >= first && (*last ==
'\n' || *last ==
';'))
3915 else if (strcmp(
type,
"CAST") == 0 ||
3916 strcmp(
type,
"CHECK CONSTRAINT") == 0 ||
3917 strcmp(
type,
"CONSTRAINT") == 0 ||
3918 strcmp(
type,
"DROP_GLOBAL") == 0 ||
3919 strcmp(
type,
"ROLE PROPERTIES") == 0 ||
3920 strcmp(
type,
"ROLE") == 0 ||
3921 strcmp(
type,
"DATABASE PROPERTIES") == 0 ||
3922 strcmp(
type,
"DEFAULT") == 0 ||
3923 strcmp(
type,
"FK CONSTRAINT") == 0 ||
3924 strcmp(
type,
"INDEX") == 0 ||
3925 strcmp(
type,
"RULE") == 0 ||
3926 strcmp(
type,
"TRIGGER") == 0 ||
3927 strcmp(
type,
"ROW SECURITY") == 0 ||
3928 strcmp(
type,
"POLICY") == 0 ||
3929 strcmp(
type,
"USER MAPPING") == 0)
3934 pg_fatal(
"don't know how to set owner for object type \"%s\"",
type);
3958 if (te->
relkind != RELKIND_PARTITIONED_TABLE)
3964 char *sanitized_name;
3965 char *sanitized_schema;
3966 char *sanitized_owner;
3971 ahprintf(AH,
"-- TOC entry %d (class %u OID %u)\n",
3988 ahprintf(AH,
"-- %sName: %s; Type: %s; Schema: %s; Owner: %s",
3989 pfx, sanitized_name, te->
desc, sanitized_schema,
3992 free(sanitized_name);
3993 free(sanitized_schema);
3994 free(sanitized_owner);
3998 char *sanitized_tablespace;
4001 ahprintf(AH,
"; Tablespace: %s", sanitized_tablespace);
4002 free(sanitized_tablespace);
4033 strcmp(te->
desc,
"SCHEMA") == 0 && strncmp(te->
defn,
"--", 2) != 0)
4037 else if (strcmp(te->
desc,
"BLOB METADATA") == 0)
4041 else if (strcmp(te->
desc,
"ACL") == 0 &&
4042 strncmp(te->
tag,
"LARGE OBJECTS", 13) == 0)
4069 pg_fatal(
"unexpected TOC entry in _printTocEntry(): %d %s %s",
4079 else if (te->
defn && strlen(te->
defn) > 0)
4091 strcmp(te->
desc,
"FUNCTION") != 0 &&
4092 strcmp(te->
desc,
"PROCEDURE") != 0)
4094 const char *p = te->
defn;
4097 while ((p = strchr(p,
';')) != NULL)
4116 (strcmp(te->
desc,
"SCHEMA") == 0 &&
4117 strncmp(te->
defn,
"--", 2) == 0)) &&
4121 if (strcmp(te->
desc,
"BLOB METADATA") == 0)
4142 ahprintf(AH,
"ALTER %s OWNER TO %s;\n\n",
4152 if (te->
relkind == RELKIND_PARTITIONED_TABLE)
4216 if (strncmp(tmpMag,
"PGDMP", 5) != 0)
4217 pg_fatal(
"did not find magic string in file header");
4223 if (vmaj > 1 || (vmaj == 1 && vmin > 0))
4231 pg_fatal(
"unsupported version (%d.%d) in file header",
4238 if (AH->
intSize >
sizeof(
int))
4239 pg_log_warning(
"archive was made on a machine with larger integers, some operations might fail");
4249 pg_fatal(
"expected format (%d) differs from format found in file (%d)",
4271 pg_log_warning(
"archive is compressed, but this installation does not support compression (%s) -- no data will be available",
4343 if (
fseeko(fp, tpos, SEEK_SET) != 0)
4403 skipped_some =
false;
4404 for (next_work_item = AH->
toc->
next; next_work_item != AH->
toc; next_work_item = next_work_item->
next)
4415 skipped_some =
true;
4443 next_work_item->
desc, next_work_item->
tag);
4532 if (next_work_item != NULL)
4539 next_work_item->
desc, next_work_item->
tag);
4548 next_work_item->
desc, next_work_item->
tag);
4654 for (k = 0; k < te2->
nDeps; k++)
4744 for (te = pending_list->
pending_next; te != pending_list; te = next_te)
4786 bool conflicts =
false;
4797 if (running_te == NULL)
4855 void *callback_data)
4871 else if (status != 0)
4872 pg_fatal(
"worker process failed: exit code %d",
4927 if (strcmp(te->
desc,
"BLOB COMMENTS") == 0 && te->
nDeps == 0)
4933 if (strcmp(te2->
desc,
"BLOBS") == 0)
4964 if (depid <= AH->maxDumpId && AH->
tocsByDumpId[depid] != NULL)
4992 if (depid <= AH->maxDumpId && AH->
tocsByDumpId[depid] != NULL)
5036 if (olddep <= AH->maxDumpId &&
5045 te->
dumpId, olddep, tabledataid);
5080 if (strcmp(te->
desc,
"INDEX") == 0)
5099 if (depid <= AH->maxDumpId && AH->
tocsByDumpId[depid] != NULL &&
5102 lockids[nlockids++] = depid;
5178 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)
ParallelState * ParallelBackupStart(ArchiveHandle *AH)
void DispatchJobForTocEntry(ArchiveHandle *AH, ParallelState *pstate, TocEntry *te, T_Action act, ParallelCompletionPtr callback, void *callback_data)
bool IsEveryWorkerIdle(ParallelState *pstate)
void binaryheap_remove_node(binaryheap *heap, int n)
void binaryheap_add(binaryheap *heap, bh_node_type d)
void binaryheap_free(binaryheap *heap)
binaryheap * binaryheap_allocate(int capacity, binaryheap_comparator compare, void *arg)
#define binaryheap_size(h)
#define binaryheap_empty(h)
#define binaryheap_get_node(h, n)
#define ngettext(s, p, n)
#define Assert(condition)
memcpy(sums, checksumBaseOffsets, sizeof(checksumBaseOffsets))
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)
char * sanitize_line(const char *str, bool want_hyphen)
#define PGDUMP_STRFTIME_FMT
char * PQdb(const PGconn *conn)
char * PQerrorMessage(const PGconn *conn)
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_malloc(size_t size)
char * pg_strdup(const char *in)
void * pg_malloc0(size_t size)
#define pg_realloc_array(pointer, type, count)
#define pg_malloc_array(type, count)
#define pg_malloc0_object(type)
#define pg_malloc_object(type)
#define pg_malloc0_array(type, count)
@ DATA_DIR_SYNC_METHOD_FSYNC
static DataDirSyncMethod sync_method
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 size_t append_data(char *buf, size_t size, size_t nmemb, void *userdata)
static AmcheckOptions opts
void(* SetupWorkerPtrType)(Archive *AH)
enum _archiveFormat ArchiveFormat
void ConnectDatabaseAhx(Archive *AHX, const ConnParams *cparams, bool isReconnect)
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)
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)
RestoreOptions * NewRestoreOptions(void)
static bool _tocEntryIsACL(TocEntry *te)
static void move_to_ready_heap(TocEntry *pending_list, binaryheap *ready_heap, RestorePass pass)
char * ReadStr(ArchiveHandle *AH)
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)
size_t WriteOffset(ArchiveHandle *AH, pgoff_t o, int wasSet)
static RestorePass _tocEntryRestorePass(TocEntry *te)
TocEntry * ArchiveEntry(Archive *AHX, CatalogId catalogId, DumpId dumpId, ArchiveOpts *opts)
int StartLO(Archive *AHX, Oid oid)
static void _printTocEntry(ArchiveHandle *AH, TocEntry *te, const char *pfx)
ArchiveHandle * CloneArchive(ArchiveHandle *AH)
static void setupRestoreWorker(Archive *AHX)
static void _reconnectToDB(ArchiveHandle *AH, const char *dbname)
static int TocEntrySizeCompareQsort(const void *p1, const void *p2)
Archive * OpenArchive(const char *FileSpec, const ArchiveFormat fmt)
void StartRestoreLOs(ArchiveHandle *AH)
void RestoreArchive(Archive *AHX, bool append_data)
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)
TocEntry * getTocEntryByDumpId(ArchiveHandle *AH, DumpId id)
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)
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 _enableTriggersIfNecessary(ArchiveHandle *AH, TocEntry *te)
DumpOptions * NewDumpOptions(void)
void SortTocFromFile(Archive *AHX)
int ReadOffset(ArchiveHandle *AH, pgoff_t *o)
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)
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)
void ReadToc(ArchiveHandle *AH)
static void reduce_dependencies(ArchiveHandle *AH, TocEntry *te, binaryheap *ready_heap)
void EndRestoreLO(ArchiveHandle *AH, Oid oid)
static void _selectTablespace(ArchiveHandle *AH, const char *tablespace)
void WriteToc(ArchiveHandle *AH)
void archputs(const char *s, Archive *AH)
static bool _fileExistsInDirectory(const char *dir, const char *filename)
static void SetOutput(ArchiveHandle *AH, const char *filename, const pg_compress_specification compression_spec, bool append_data)
DumpOptions * dumpOptionsFromRestoreOptions(RestoreOptions *ropt)
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)
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)
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)
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)
#define WORKER_IGNORED_ERRORS
void IssueCommandPerBlob(ArchiveHandle *AH, TocEntry *te, const char *cmdBegin, const char *cmdEnd)
#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)
void exit_nicely(int code)
static PgChecksumMode mode
static void setupDumpWorker(Archive *AH)
bool pg_get_line_buf(FILE *stream, StringInfo buf)
static char buf[DEFAULT_XLOG_SEG_SIZE]
#define pg_encoding_to_char
#define pg_char_to_encoding
#define pg_log_warning(...)
bool isValidTarHeader(const char *header)
#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)
char * psprintf(const char *fmt,...)
const char * simple_string_list_not_touched(SimpleStringList *list)
bool simple_string_list_member(SimpleStringList *list, const char *val)
const char * fmtQualifiedId(const char *schema, const char *id)
const char * fmtId(const char *rawid)
void setFmtEncoding(int encoding)
void appendPsqlMetaConnect(PQExpBuffer buf, const char *dbname)
void initStringInfo(StringInfo str)
bool(* open_func)(const char *path, int fd, const char *mode, CompressFileHandle *CFH)
void(* write_func)(const void *ptr, size_t size, CompressFileHandle *CFH)
SimpleStringListCell * head
DeClonePtrType DeClonePtr
DataDirSyncMethod sync_method
struct _tocEntry * lastErrorTE
ReadExtraTocPtrType ReadExtraTocPtr
char * archiveDumpVersion
struct _tocEntry * currentTE
CustomOutPtrType CustomOutPtr
PGcancel *volatile connCancel
StartLOsPtrType StartLOsPtr
ArchiveEntryPtrType ArchiveEntryPtr
pg_compress_specification compression_spec
WriteDataPtrType WriteDataPtr
StartLOPtrType StartLOPtr
struct _tocEntry ** tocsByDumpId
WriteBufPtrType WriteBufPtr
PrepParallelRestorePtrType PrepParallelRestorePtr
WriteExtraTocPtrType WriteExtraTocPtr
ReadBytePtrType ReadBytePtr
PrintTocDataPtrType PrintTocDataPtr
struct _tocEntry * currToc
WriteBytePtrType WriteBytePtr
ReadBufPtrType ReadBufPtr
PrintExtraTocPtrType PrintExtraTocPtr
ArchiverStage lastErrorStage
StartDataPtrType StartDataPtr
ArchiverOutput outputKind
EndDataPtrType EndDataPtr
char * archiveRemoteVersion
SetupWorkerPtrType SetupWorkerPtr
int disable_dollar_quoting
const char * lockWaitTimeout
SimpleStringList schemaExcludeNames
SimpleStringList functionNames
SimpleStringList tableNames
SimpleStringList indexNames
pg_compress_specification compression_spec
SimpleStringList triggerNames
int disable_dollar_quoting
SimpleStringList schemaNames
const char * lockWaitTimeout
int noDataForFailedTables
struct _tocEntry * pending_next
struct _tocEntry * pending_prev
const void * dataDumperArg
const void * defnDumperArg
pg_compress_algorithm algorithm
static void * fn(void *arg)
#define fseeko(stream, offset, origin)
static void StartTransaction(void)
static void CommitTransaction(void)