45 #define TEXT_DUMP_HEADER "--\n-- PostgreSQL database dump\n--\n\n"
46 #define TEXT_DUMPALL_HEADER "--\n-- PostgreSQL database cluster dump\n--\n\n"
107 void *callback_data);
111 void *callback_data);
144 opts->include_everything =
true;
240 AH =
_allocAH(FileSpec,
fmt, compression_spec,
true,
258 pg_fatal(
"could not close output file: %m");
266 if (dopt == NULL && ropt != NULL)
312 pg_fatal(
"unexpected section code %d",
349 pg_fatal(
"parallel restore is not supported with this archive file format");
353 pg_fatal(
"parallel restore is not supported with archives made by pre-8.0 pg_dump");
374 pg_fatal(
"cannot restore from compressed archive (%s)",
396 pg_fatal(
"direct database connections are not supported in pre-1.3 archives");
426 int impliedDataOnly = 1;
450 ahprintf(AH,
"--\n-- PostgreSQL database dump\n--\n\n");
453 ahprintf(AH,
"-- Dumped from database version %s\n",
456 ahprintf(AH,
"-- Dumped by pg_dump version %s\n",
497 if (strcmp(te->
desc,
"DATABASE") != 0 &&
498 strcmp(te->
desc,
"DATABASE PROPERTIES") != 0)
518 strncmp(te->
dropStmt,
"--", 2) == 0)
536 if (strncmp(te->
desc,
"BLOB", 4) == 0)
543 char *dropStmtOrig = dropStmt;
550 if (strncmp(dropStmt,
"ALTER TABLE", 11) == 0)
553 "ALTER TABLE IF EXISTS");
554 dropStmt = dropStmt + 11;
576 if (strcmp(te->
desc,
"DEFAULT") == 0 ||
577 strcmp(te->
desc,
"DATABASE PROPERTIES") == 0 ||
578 strncmp(dropStmt,
"CREATE OR REPLACE VIEW", 22) == 0)
585 if (strcmp(te->
desc,
"CONSTRAINT") == 0 ||
586 strcmp(te->
desc,
"CHECK CONSTRAINT") == 0 ||
587 strcmp(te->
desc,
"FK CONSTRAINT") == 0)
588 strcpy(buffer,
"DROP CONSTRAINT");
590 snprintf(buffer,
sizeof(buffer),
"DROP %s",
593 mark = strstr(dropStmt, buffer);
600 mark + strlen(buffer));
605 pg_log_warning(
"could not find where to insert IF EXISTS in statement \"%s\"",
671 bool haveACL =
false;
672 bool havePostACL =
false;
687 case RESTORE_PASS_POST_ACL:
725 ahprintf(AH,
"--\n-- PostgreSQL database dump complete\n--\n\n");
778 te->
desc, te->namespace, te->
tag);
786 if (strcmp(te->
desc,
"TABLE") == 0)
827 if (strcmp(te->
desc,
"DATABASE") == 0 ||
828 strcmp(te->
desc,
"DATABASE PROPERTIES") == 0)
854 if (strcmp(te->
desc,
"BLOBS") == 0 ||
855 strcmp(te->
desc,
"BLOB COMMENTS") == 0)
862 if (strcmp(te->
desc,
"BLOB COMMENTS") == 0)
880 te->namespace, te->
tag);
898 use_truncate = is_parallel && te->
created &&
913 ahprintf(AH,
"TRUNCATE TABLE ONLY %s;\n\n",
946 else if (!defnDumped)
976 opts->compression_spec.level = 0;
1003 ahprintf(AH,
"ALTER TABLE %s DISABLE TRIGGER ALL;\n\n",
1029 ahprintf(AH,
"ALTER TABLE %s ENABLE TRIGGER ALL;\n\n",
1048 strncmp(te->
defn,
"-- load via partition root ", 27) == 0)
1081 pg_fatal(
"internal error -- WriteData cannot be called outside the context of a DataDumper routine");
1128 if (
opts->nDeps > 0)
1163 const char *fmtName;
1175 strcpy(stamp_str,
"[unknown]");
1177 ahprintf(AH,
";\n; Archive created at %s\n", stamp_str);
1178 ahprintf(AH,
"; dbname: %s\n; TOC Entries: %d\n; Compression: %s\n",
1189 fmtName =
"DIRECTORY";
1195 fmtName =
"UNKNOWN";
1198 ahprintf(AH,
"; Dump Version: %d.%d-%d\n",
1200 ahprintf(AH,
"; Format: %s\n", fmtName);
1204 ahprintf(AH,
"; Dumped from database version: %s\n",
1207 ahprintf(AH,
"; Dumped by pg_dump version: %s\n",
1210 ahprintf(AH,
";\n;\n; Selected TOC Entries:\n;\n");
1220 char *sanitized_name;
1221 char *sanitized_schema;
1222 char *sanitized_owner;
1232 te->
desc, sanitized_schema, sanitized_name,
1235 free(sanitized_name);
1236 free(sanitized_schema);
1237 free(sanitized_owner);
1269 pg_fatal(
"large-object output not supported in chosen format");
1328 "restored %d large objects",
1348 pg_log_info(
"restoring large object with OID %u", oid);
1351 if (old_lo_style && drop)
1359 if (loOid == 0 || loOid != oid)
1360 pg_fatal(
"could not create large object %u: %s",
1365 pg_fatal(
"could not open large object %u: %s",
1371 ahprintf(AH,
"SELECT pg_catalog.lo_open(pg_catalog.lo_create('%u'), %d);\n",
1374 ahprintf(AH,
"SELECT pg_catalog.lo_open('%u', %d);\n",
1399 ahprintf(AH,
"SELECT pg_catalog.lo_close(0);\n\n");
1433 cmnt = strchr(linebuf.
data,
';');
1437 linebuf.
len = cmnt - linebuf.
data;
1441 if (strspn(linebuf.
data,
" \t\r\n") == linebuf.
len)
1445 id = strtol(linebuf.
data, &endptr, 10);
1446 if (endptr == linebuf.
data || id <= 0 || id > AH->
maxDumpId ||
1456 pg_fatal(
"could not find entry for ID %d",
1478 if (fclose(fh) != 0)
1479 pg_fatal(
"could not close TOC file: %m");
1498 int save_errno = errno;
1548 fn = fileno(AH->
FH);
1568 pg_fatal(
"could not open output file: %m");
1585 pg_fatal(
"could not close output file: %m");
1587 AH->
OF = savedOutput;
1598 int save_errno = errno;
1652 "wrote %zu bytes of large object data (result = %d)",
1665 (
const unsigned char *) AH->
lo_buf,
1671 ahprintf(AH,
"SELECT pg_catalog.lowrite(0, %s);\n",
buf->data);
1689 int bytes_written = 0;
1700 ptr = (
const void *) ((
const char *) ptr + avail);
1709 bytes_written = size * nmemb;
1712 bytes_written = AH->
CustomOutPtr(AH, ptr, size * nmemb);
1725 bytes_written = size * nmemb;
1728 if (bytes_written != size * nmemb)
1849 if (strcmp(te->
desc,
"TABLE DATA") == 0 && te->
nDeps > 0)
1858 if (tableId <= 0 || tableId > maxDumpId)
1859 pg_fatal(
"bad table dumpId for TABLE DATA item");
1873 if (
id > 0 && id <= AH->maxDumpId)
1899 for (off = 0; off <
sizeof(
pgoff_t); off++)
1951 pg_fatal(
"unexpected data offset flag %d", offsetFlg);
1957 for (off = 0; off < AH->
offSize; off++)
1964 pg_fatal(
"file offset in dump file is too large");
2019 res =
res + (bv << bitShift);
2036 int len = strlen(
c);
2075 pg_fatal(
"directory name too long: \"%s\"", dir);
2088 pg_log_debug(
"attempting to ascertain archive format");
2125 pg_fatal(
"directory \"%s\" does not appear to be a valid archive (\"toc.dat\" does not exist)",
2133 pg_fatal(
"could not open input file \"%s\": %m", AH->
fSpec);
2140 pg_fatal(
"could not open input file: %m");
2143 if ((cnt = fread(
sig, 1, 5, fh)) != 5)
2146 pg_fatal(
"could not read input file: %m");
2148 pg_fatal(
"input file is too short (read %lu, expected 5)",
2149 (
unsigned long) cnt);
2156 if (strncmp(
sig,
"PGDMP", 5) == 0)
2180 pg_fatal(
"input file appears to be a text format dump. Please use psql.");
2186 pg_fatal(
"input file does not appear to be a valid archive (too short?)");
2192 pg_fatal(
"input file does not appear to be a valid archive");
2200 if (fclose(fh) != 0)
2201 pg_fatal(
"could not close input file: %m");
2225 FileSpec ? FileSpec :
"(stdio)",
fmt);
2280 pg_fatal(
"could not open stdout for appending: %m");
2290 (AH->
fSpec == NULL || strcmp(AH->
fSpec,
"") == 0))
2293 _setmode(fileno(
stdout), O_BINARY);
2295 _setmode(fileno(stdin), O_BINARY);
2368 for (
int i = 0;
i < ntes;
i++)
2404 void *callback_data)
2410 pg_fatal(
"worker process failed: exit code %d",
2423 if (strcmp(te->
desc,
"BLOBS") == 0)
2434 if (startPtr != NULL)
2435 (*startPtr) (AH, te);
2531 pg_fatal(
"entry ID %d out of range -- perhaps a corrupt TOC",
2562 if (strcmp(te->
desc,
"COMMENT") == 0 ||
2563 strcmp(te->
desc,
"ACL") == 0 ||
2564 strcmp(te->
desc,
"ACL LANGUAGE") == 0)
2566 else if (strcmp(te->
desc,
"TABLE DATA") == 0 ||
2567 strcmp(te->
desc,
"BLOBS") == 0 ||
2568 strcmp(te->
desc,
"BLOB COMMENTS") == 0)
2570 else if (strcmp(te->
desc,
"CONSTRAINT") == 0 ||
2571 strcmp(te->
desc,
"CHECK CONSTRAINT") == 0 ||
2572 strcmp(te->
desc,
"FK CONSTRAINT") == 0 ||
2573 strcmp(te->
desc,
"INDEX") == 0 ||
2574 strcmp(te->
desc,
"RULE") == 0 ||
2575 strcmp(te->
desc,
"TRIGGER") == 0)
2597 is_supported =
true;
2599 is_supported =
false;
2604 if (strcmp(tmp,
"true") == 0)
2605 is_supported =
false;
2611 pg_log_warning(
"restoring tables WITH OIDS is not supported anymore");
2624 if (depIdx >= depSize)
2629 sscanf(tmp,
"%d", &deps[depIdx]);
2667 if (strcmp(te->
desc,
"ENCODING") == 0)
2669 else if (strcmp(te->
desc,
"STDSTRINGS") == 0)
2671 else if (strcmp(te->
desc,
"SEARCHPATH") == 0)
2685 ptr1 = strchr(defn,
'\'');
2687 ptr2 = strchr(++ptr1,
'\'');
2693 pg_fatal(
"unrecognized encoding \"%s\"",
2698 pg_fatal(
"invalid ENCODING item: %s",
2710 ptr1 = strchr(te->
defn,
'\'');
2711 if (ptr1 && strncmp(ptr1,
"'on'", 4) == 0)
2713 else if (ptr1 && strncmp(ptr1,
"'off'", 5) == 0)
2716 pg_fatal(
"invalid STDSTRINGS item: %s",
2733 const char *missing_name;
2740 if (missing_name != NULL)
2741 pg_fatal(
"schema \"%s\" not found", missing_name);
2747 if (missing_name != NULL)
2748 pg_fatal(
"table \"%s\" not found", missing_name);
2754 if (missing_name != NULL)
2755 pg_fatal(
"index \"%s\" not found", missing_name);
2761 if (missing_name != NULL)
2762 pg_fatal(
"function \"%s\" not found", missing_name);
2768 if (missing_name != NULL)
2769 pg_fatal(
"trigger \"%s\" not found", missing_name);
2787 if (strcmp(te->
desc,
"ENCODING") == 0 ||
2788 strcmp(te->
desc,
"STDSTRINGS") == 0 ||
2789 strcmp(te->
desc,
"SEARCHPATH") == 0)
2797 if (strcmp(te->
desc,
"DATABASE") == 0 ||
2798 strcmp(te->
desc,
"DATABASE PROPERTIES") == 0)
2823 (strcmp(te->
desc,
"PUBLICATION") == 0 ||
2824 strcmp(te->
desc,
"PUBLICATION TABLE") == 0 ||
2825 strcmp(te->
desc,
"PUBLICATION TABLES IN SCHEMA") == 0))
2863 if (strcmp(te->
desc,
"ACL") == 0 ||
2864 strcmp(te->
desc,
"COMMENT") == 0 ||
2865 strcmp(te->
desc,
"SECURITY LABEL") == 0)
2868 if (strncmp(te->
tag,
"DATABASE ", 9) == 0)
2893 if (te->
nDeps != 1 ||
2917 if (strcmp(te->
desc,
"TABLE") == 0 ||
2918 strcmp(te->
desc,
"TABLE DATA") == 0 ||
2919 strcmp(te->
desc,
"VIEW") == 0 ||
2920 strcmp(te->
desc,
"FOREIGN TABLE") == 0 ||
2921 strcmp(te->
desc,
"MATERIALIZED VIEW") == 0 ||
2922 strcmp(te->
desc,
"MATERIALIZED VIEW DATA") == 0 ||
2923 strcmp(te->
desc,
"SEQUENCE") == 0 ||
2924 strcmp(te->
desc,
"SEQUENCE SET") == 0)
2932 else if (strcmp(te->
desc,
"INDEX") == 0)
2940 else if (strcmp(te->
desc,
"FUNCTION") == 0 ||
2941 strcmp(te->
desc,
"AGGREGATE") == 0 ||
2942 strcmp(te->
desc,
"PROCEDURE") == 0)
2950 else if (strcmp(te->
desc,
"TRIGGER") == 0)
2978 if (strcmp(te->
desc,
"SEQUENCE SET") == 0 ||
2979 strcmp(te->
desc,
"BLOB") == 0 ||
2980 (strcmp(te->
desc,
"ACL") == 0 &&
2981 strncmp(te->
tag,
"LARGE OBJECT ", 13) == 0) ||
2982 (strcmp(te->
desc,
"COMMENT") == 0 &&
2983 strncmp(te->
tag,
"LARGE OBJECT ", 13) == 0) ||
2984 (strcmp(te->
desc,
"SECURITY LABEL") == 0 &&
2985 strncmp(te->
tag,
"LARGE OBJECT ", 13) == 0))
2996 strncmp(te->
defn,
"-- load via partition root ", 27) == 0)
3003 if ((strcmp(te->
desc,
"<Init>") == 0) && (strcmp(te->
tag,
"Max OID") == 0))
3019 (strcmp(te->
desc,
"BLOB") == 0 ||
3020 (strcmp(te->
desc,
"ACL") == 0 &&
3021 strncmp(te->
tag,
"LARGE OBJECT ", 13) == 0) ||
3022 (strcmp(te->
desc,
"COMMENT") == 0 &&
3023 strncmp(te->
tag,
"LARGE OBJECT ", 13) == 0) ||
3024 (strcmp(te->
desc,
"SECURITY LABEL") == 0 &&
3025 strncmp(te->
tag,
"LARGE OBJECT ", 13) == 0))))
3045 if (strcmp(te->
desc,
"ACL") == 0 ||
3046 strcmp(te->
desc,
"ACL LANGUAGE") == 0 ||
3047 strcmp(te->
desc,
"DEFAULT ACL") == 0)
3049 if (strcmp(te->
desc,
"EVENT TRIGGER") == 0 ||
3050 strcmp(te->
desc,
"MATERIALIZED VIEW DATA") == 0)
3051 return RESTORE_PASS_POST_ACL;
3059 if (strcmp(te->
desc,
"COMMENT") == 0 &&
3060 strncmp(te->
tag,
"EVENT TRIGGER ", 14) == 0)
3061 return RESTORE_PASS_POST_ACL;
3078 if (strcmp(te->
desc,
"ACL") == 0 ||
3079 strcmp(te->
desc,
"ACL LANGUAGE") == 0 ||
3080 strcmp(te->
desc,
"DEFAULT ACL") == 0)
3097 ahprintf(AH,
"SET statement_timeout = 0;\n");
3098 ahprintf(AH,
"SET lock_timeout = 0;\n");
3099 ahprintf(AH,
"SET idle_in_transaction_session_timeout = 0;\n");
3102 ahprintf(AH,
"SET client_encoding = '%s';\n",
3106 ahprintf(AH,
"SET standard_conforming_strings = %s;\n",
3118 ahprintf(AH,
"SET check_function_bodies = false;\n");
3121 ahprintf(AH,
"SET xmloption = content;\n");
3124 ahprintf(AH,
"SET client_min_messages = warning;\n");
3126 ahprintf(AH,
"SET escape_string_warning = off;\n");
3130 ahprintf(AH,
"SET row_security = on;\n");
3132 ahprintf(AH,
"SET row_security = off;\n");
3166 pg_fatal(
"could not set session user to \"%s\": %s",
3279 if (!schemaName || *schemaName ==
'\0' ||
3287 if (strcmp(schemaName,
"pg_catalog") != 0)
3298 "could not set search_path to \"%s\": %s",
3335 if (have && strcmp(want, have) == 0)
3340 if (strcmp(want,
"") == 0)
3359 "could not set default_tablespace to %s: %s",
3394 if (have && strcmp(want, have) == 0)
3408 "could not set default_table_access_method: %s",
3435 if (strcmp(
type,
"COLLATION") == 0 ||
3436 strcmp(
type,
"CONVERSION") == 0 ||
3437 strcmp(
type,
"DOMAIN") == 0 ||
3438 strcmp(
type,
"FOREIGN TABLE") == 0 ||
3439 strcmp(
type,
"MATERIALIZED VIEW") == 0 ||
3440 strcmp(
type,
"SEQUENCE") == 0 ||
3441 strcmp(
type,
"STATISTICS") == 0 ||
3442 strcmp(
type,
"TABLE") == 0 ||
3443 strcmp(
type,
"TEXT SEARCH DICTIONARY") == 0 ||
3444 strcmp(
type,
"TEXT SEARCH CONFIGURATION") == 0 ||
3445 strcmp(
type,
"TYPE") == 0 ||
3446 strcmp(
type,
"VIEW") == 0 ||
3448 strcmp(
type,
"DATABASE") == 0 ||
3449 strcmp(
type,
"PROCEDURAL LANGUAGE") == 0 ||
3450 strcmp(
type,
"SCHEMA") == 0 ||
3451 strcmp(
type,
"EVENT TRIGGER") == 0 ||
3452 strcmp(
type,
"FOREIGN DATA WRAPPER") == 0 ||
3453 strcmp(
type,
"SERVER") == 0 ||
3454 strcmp(
type,
"PUBLICATION") == 0 ||
3455 strcmp(
type,
"SUBSCRIPTION") == 0)
3458 if (te->namespace && *te->namespace)
3463 else if (strcmp(
type,
"BLOB") == 0)
3472 else if (strcmp(
type,
"AGGREGATE") == 0 ||
3473 strcmp(
type,
"FUNCTION") == 0 ||
3474 strcmp(
type,
"OPERATOR") == 0 ||
3475 strcmp(
type,
"OPERATOR CLASS") == 0 ||
3476 strcmp(
type,
"OPERATOR FAMILY") == 0 ||
3477 strcmp(
type,
"PROCEDURE") == 0)
3484 last = first + strlen(first) - 1;
3487 while (last >= first && (*last ==
'\n' || *last ==
';'))
3497 else if (strcmp(
type,
"CAST") == 0 ||
3498 strcmp(
type,
"CHECK CONSTRAINT") == 0 ||
3499 strcmp(
type,
"CONSTRAINT") == 0 ||
3500 strcmp(
type,
"DATABASE PROPERTIES") == 0 ||
3501 strcmp(
type,
"DEFAULT") == 0 ||
3502 strcmp(
type,
"FK CONSTRAINT") == 0 ||
3503 strcmp(
type,
"INDEX") == 0 ||
3504 strcmp(
type,
"RULE") == 0 ||
3505 strcmp(
type,
"TRIGGER") == 0 ||
3506 strcmp(
type,
"ROW SECURITY") == 0 ||
3507 strcmp(
type,
"POLICY") == 0 ||
3508 strcmp(
type,
"USER MAPPING") == 0)
3513 pg_fatal(
"don't know how to set owner for object type \"%s\"",
type);
3538 char *sanitized_name;
3539 char *sanitized_schema;
3540 char *sanitized_owner;
3550 ahprintf(AH,
"-- TOC entry %d (class %u OID %u)\n",
3567 ahprintf(AH,
"-- %sName: %s; Type: %s; Schema: %s; Owner: %s",
3568 pfx, sanitized_name, te->
desc, sanitized_schema,
3571 free(sanitized_name);
3572 free(sanitized_schema);
3573 free(sanitized_owner);
3577 char *sanitized_tablespace;
3580 ahprintf(AH,
"; Tablespace: %s", sanitized_tablespace);
3581 free(sanitized_tablespace);
3599 strcmp(te->
desc,
"SCHEMA") == 0 && strncmp(te->
defn,
"--", 2) != 0)
3605 if (te->
defn && strlen(te->
defn) > 0)
3618 (strcmp(te->
desc,
"SCHEMA") == 0 &&
3619 strncmp(te->
defn,
"--", 2) == 0)) &&
3671 return pg_strdup(want_hyphen ?
"-" :
"");
3675 for (s = result; *s !=
'\0'; s++)
3677 if (*s ==
'\n' || *s ==
'\r')
3734 if (strncmp(tmpMag,
"PGDMP", 5) != 0)
3735 pg_fatal(
"did not find magic string in file header");
3741 if (vmaj > 1 || (vmaj == 1 && vmin > 0))
3749 pg_fatal(
"unsupported version (%d.%d) in file header",
3754 pg_fatal(
"sanity check on integer size (%lu) failed",
3757 if (AH->
intSize >
sizeof(
int))
3758 pg_log_warning(
"archive was made on a machine with larger integers, some operations might fail");
3768 pg_fatal(
"expected format (%d) differs from format found in file (%d)",
3790 pg_log_warning(
"archive is compressed, but this installation does not support compression (%s) -- no data will be available",
3862 if (
fseeko(fp, tpos, SEEK_SET) != 0)
3922 skipped_some =
false;
3923 for (next_work_item = AH->
toc->
next; next_work_item != AH->
toc; next_work_item = next_work_item->
next)
3934 skipped_some =
true;
3962 next_work_item->
desc, next_work_item->
tag);
4043 if (next_work_item != NULL)
4050 next_work_item->
desc, next_work_item->
tag);
4059 next_work_item->
desc, next_work_item->
tag);
4165 for (k = 0; k < te2->
nDeps; k++)
4255 for (te = pending_list->
pending_next; te != pending_list; te = next_te)
4297 bool conflicts =
false;
4308 if (running_te == NULL)
4366 void *callback_data)
4382 else if (status != 0)
4383 pg_fatal(
"worker process failed: exit code %d",
4438 if (strcmp(te->
desc,
"BLOB COMMENTS") == 0 && te->
nDeps == 0)
4444 if (strcmp(te2->
desc,
"BLOBS") == 0)
4475 if (depid <= AH->maxDumpId && AH->
tocsByDumpId[depid] != NULL)
4503 if (depid <= AH->maxDumpId && AH->
tocsByDumpId[depid] != NULL)
4547 if (olddep <= AH->maxDumpId &&
4556 te->
dumpId, olddep, tabledataid);
4591 if (strcmp(te->
desc,
"INDEX") == 0)
4610 if (depid <= AH->maxDumpId && AH->
tocsByDumpId[depid] != NULL &&
4613 lockids[nlockids++] = depid;
4689 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)
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)
@ DATA_DIR_SYNC_METHOD_FSYNC
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 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 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
#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)
#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)
bool(* write_func)(const void *ptr, size_t size, struct CompressFileHandle *CFH)
bool(* open_func)(const char *path, int fd, const char *mode, CompressFileHandle *CFH)
SimpleStringListCell * head
DeClonePtrType DeClonePtr
DataDirSyncMethod sync_method
struct _tocEntry * lastErrorTE
ReadExtraTocPtrType ReadExtraTocPtr
char * archiveDumpVersion
struct _tocEntry * currentTE
CustomOutPtrType CustomOutPtr