44 #include "catalog/pg_aggregate_d.h"
45 #include "catalog/pg_am_d.h"
46 #include "catalog/pg_attribute_d.h"
47 #include "catalog/pg_authid_d.h"
48 #include "catalog/pg_cast_d.h"
49 #include "catalog/pg_class_d.h"
50 #include "catalog/pg_default_acl_d.h"
51 #include "catalog/pg_largeobject_d.h"
52 #include "catalog/pg_largeobject_metadata_d.h"
53 #include "catalog/pg_proc_d.h"
55 #include "catalog/pg_trigger_d.h"
56 #include "catalog/pg_type_d.h"
152 #define DUMP_DEFAULT_ROWS_PER_INSERT 1
157 #define fmtQualifiedDumpable(obj) \
158 fmtQualifiedId((obj)->dobj.namespace->dobj.name, \
163 const char *dumpencoding,
const char *dumpsnapshot,
182 const char *pattern);
187 static const char *
getRoleName(
const char *roleoid_str);
191 const char *
name,
const char *
namespace,
194 const char *initdb_comment);
196 const char *
name,
const char *
namespace,
198 int subid,
DumpId dumpId);
202 const char *
namespace,
const char *owner,
251 const char *servername,
const char *
namespace,
257 const char *nspname,
const char *owner,
263 DumpId **dependencies,
int *nDeps,
int *allocDeps);
278 const FuncInfo *finfo,
bool honor_quotes);
299 bool force_array_type,
300 bool include_multirange_type);
306 Oid pg_class_oid,
bool is_index);
311 const char *objnamespace);
316 const char *prefix,
Archive *fout);
337 bool g_verbose =
false;
338 const char *dumpencoding = NULL;
339 const char *dumpsnapshot = NULL;
340 char *use_role = NULL;
342 int compressLevel = -1;
349 static struct option long_options[] = {
360 {
"jobs", 1, NULL,
'j'},
433 if (strcmp(argv[1],
"--help") == 0 || strcmp(argv[1],
"-?") == 0)
438 if (strcmp(argv[1],
"--version") == 0 || strcmp(argv[1],
"-V") == 0)
440 puts(
"pg_dump (PostgreSQL) " PG_VERSION);
447 while ((
c =
getopt_long(argc, argv,
"abBcCd:e:E:f:F:h:j:n:N:Op:RsS:t:T:U:vwWxZ:",
448 long_options, &optindex)) != -1)
642 pg_log_error(
"too many command-line arguments (first is \"%s\")",
661 pg_fatal(
"options -s/--schema-only and -a/--data-only cannot be used together");
664 pg_fatal(
"options -s/--schema-only and --include-foreign-data cannot be used together");
667 pg_fatal(
"option --include-foreign-data is not supported with parallel backup");
670 pg_fatal(
"options -c/--clean and -a/--data-only cannot be used together");
673 pg_fatal(
"option --if-exists requires option -c/--clean");
680 pg_fatal(
"option --on-conflict-do-nothing requires option --inserts, --rows-per-insert, or --column-inserts");
690 if (compressLevel == -1)
701 if (compressLevel != 0)
702 pg_log_warning(
"requested compression not available in this installation -- archive will be uncompressed");
715 pg_fatal(
"parallel backup only supported by the directory format");
770 pg_fatal(
"no matching schemas were found");
784 pg_fatal(
"no matching tables were found");
806 pg_fatal(
"no matching extensions were found");
841 getTableData(&dopt, tblinfo, numTables, RELKIND_SEQUENCE);
890 boundaryObjs[0].dumpId, boundaryObjs[1].dumpId);
909 for (
i = 0;
i < numObjs;
i++)
950 if (compressLevel == -1)
989 printf(
_(
"%s dumps a database as a text file or to other formats.\n\n"),
progname);
993 printf(
_(
"\nGeneral options:\n"));
994 printf(
_(
" -f, --file=FILENAME output file or directory name\n"));
995 printf(
_(
" -F, --format=c|d|t|p output file format (custom, directory, tar,\n"
996 " plain text (default))\n"));
997 printf(
_(
" -j, --jobs=NUM use this many parallel jobs to dump\n"));
998 printf(
_(
" -v, --verbose verbose mode\n"));
999 printf(
_(
" -V, --version output version information, then exit\n"));
1000 printf(
_(
" -Z, --compress=0-9 compression level for compressed formats\n"));
1001 printf(
_(
" --lock-wait-timeout=TIMEOUT fail after waiting TIMEOUT for a table lock\n"));
1002 printf(
_(
" --no-sync do not wait for changes to be written safely to disk\n"));
1003 printf(
_(
" -?, --help show this help, then exit\n"));
1005 printf(
_(
"\nOptions controlling the output content:\n"));
1006 printf(
_(
" -a, --data-only dump only the data, not the schema\n"));
1007 printf(
_(
" -b, --blobs include large objects in dump\n"));
1008 printf(
_(
" -B, --no-blobs exclude large objects in dump\n"));
1009 printf(
_(
" -c, --clean clean (drop) database objects before recreating\n"));
1010 printf(
_(
" -C, --create include commands to create database in dump\n"));
1011 printf(
_(
" -e, --extension=PATTERN dump the specified extension(s) only\n"));
1012 printf(
_(
" -E, --encoding=ENCODING dump the data in encoding ENCODING\n"));
1013 printf(
_(
" -n, --schema=PATTERN dump the specified schema(s) only\n"));
1014 printf(
_(
" -N, --exclude-schema=PATTERN do NOT dump the specified schema(s)\n"));
1015 printf(
_(
" -O, --no-owner skip restoration of object ownership in\n"
1016 " plain-text format\n"));
1017 printf(
_(
" -s, --schema-only dump only the schema, no data\n"));
1018 printf(
_(
" -S, --superuser=NAME superuser user name to use in plain-text format\n"));
1019 printf(
_(
" -t, --table=PATTERN dump the specified table(s) only\n"));
1020 printf(
_(
" -T, --exclude-table=PATTERN do NOT dump the specified table(s)\n"));
1021 printf(
_(
" -x, --no-privileges do not dump privileges (grant/revoke)\n"));
1022 printf(
_(
" --binary-upgrade for use by upgrade utilities only\n"));
1023 printf(
_(
" --column-inserts dump data as INSERT commands with column names\n"));
1024 printf(
_(
" --disable-dollar-quoting disable dollar quoting, use SQL standard quoting\n"));
1025 printf(
_(
" --disable-triggers disable triggers during data-only restore\n"));
1026 printf(
_(
" --enable-row-security enable row security (dump only content user has\n"
1028 printf(
_(
" --exclude-table-data=PATTERN do NOT dump data for the specified table(s)\n"));
1029 printf(
_(
" --extra-float-digits=NUM override default setting for extra_float_digits\n"));
1030 printf(
_(
" --if-exists use IF EXISTS when dropping objects\n"));
1031 printf(
_(
" --include-foreign-data=PATTERN\n"
1032 " include data of foreign tables on foreign\n"
1033 " servers matching PATTERN\n"));
1034 printf(
_(
" --inserts dump data as INSERT commands, rather than COPY\n"));
1035 printf(
_(
" --load-via-partition-root load partitions via the root table\n"));
1036 printf(
_(
" --no-comments do not dump comments\n"));
1037 printf(
_(
" --no-publications do not dump publications\n"));
1038 printf(
_(
" --no-security-labels do not dump security label assignments\n"));
1039 printf(
_(
" --no-subscriptions do not dump subscriptions\n"));
1040 printf(
_(
" --no-table-access-method do not dump table access methods\n"));
1041 printf(
_(
" --no-tablespaces do not dump tablespace assignments\n"));
1042 printf(
_(
" --no-toast-compression do not dump TOAST compression methods\n"));
1043 printf(
_(
" --no-unlogged-table-data do not dump unlogged table data\n"));
1044 printf(
_(
" --on-conflict-do-nothing add ON CONFLICT DO NOTHING to INSERT commands\n"));
1045 printf(
_(
" --quote-all-identifiers quote all identifiers, even if not key words\n"));
1046 printf(
_(
" --rows-per-insert=NROWS number of rows per INSERT; implies --inserts\n"));
1047 printf(
_(
" --section=SECTION dump named section (pre-data, data, or post-data)\n"));
1048 printf(
_(
" --serializable-deferrable wait until the dump can run without anomalies\n"));
1049 printf(
_(
" --snapshot=SNAPSHOT use given snapshot for the dump\n"));
1050 printf(
_(
" --strict-names require table and/or schema include patterns to\n"
1051 " match at least one entity each\n"));
1052 printf(
_(
" --use-set-session-authorization\n"
1053 " use SET SESSION AUTHORIZATION commands instead of\n"
1054 " ALTER OWNER commands to set ownership\n"));
1056 printf(
_(
"\nConnection options:\n"));
1057 printf(
_(
" -d, --dbname=DBNAME database to dump\n"));
1058 printf(
_(
" -h, --host=HOSTNAME database server host or socket directory\n"));
1059 printf(
_(
" -p, --port=PORT database server port number\n"));
1060 printf(
_(
" -U, --username=NAME connect as specified database user\n"));
1061 printf(
_(
" -w, --no-password never prompt for password\n"));
1062 printf(
_(
" -W, --password force password prompt (should happen automatically)\n"));
1063 printf(
_(
" --role=ROLENAME do SET ROLE before dump\n"));
1065 printf(
_(
"\nIf no database name is supplied, then the PGDATABASE environment\n"
1066 "variable value is used.\n\n"));
1067 printf(
_(
"Report bugs to <%s>.\n"), PACKAGE_BUGREPORT);
1068 printf(
_(
"%s home page: <%s>\n"), PACKAGE_NAME, PACKAGE_URL);
1073 const char *dumpsnapshot,
char *use_role)
1077 const char *std_strings;
1087 pg_fatal(
"invalid client encoding \"%s\" specified",
1098 AH->
std_strings = (std_strings && strcmp(std_strings,
"on") == 0);
1198 "SET TRANSACTION ISOLATION LEVEL "
1199 "SERIALIZABLE, READ ONLY, DEFERRABLE");
1202 "SET TRANSACTION ISOLATION LEVEL "
1203 "REPEATABLE READ, READ ONLY");
1225 pg_fatal(
"parallel dumps from standby servers are not supported by this server version");
1249 char *query =
"SELECT pg_catalog.pg_export_snapshot()";
1291 return archiveFormat;
1309 if (patterns->
head == NULL)
1319 for (cell = patterns->
head; cell; cell = cell->
next)
1325 "SELECT oid FROM pg_catalog.pg_namespace n\n");
1328 false, NULL,
"n.nspname", NULL, NULL, &dbbuf,
1331 pg_fatal(
"improper qualified name (too many dotted names): %s",
1333 else if (dotcnt == 1)
1339 pg_fatal(
"no matching schemas were found for pattern \"%s\"", cell->
val);
1368 if (patterns->
head == NULL)
1377 for (cell = patterns->
head; cell; cell = cell->
next)
1382 "SELECT oid FROM pg_catalog.pg_extension e\n");
1384 false, NULL,
"e.extname", NULL, NULL, NULL,
1387 pg_fatal(
"improper qualified name (too many dotted names): %s",
1392 pg_fatal(
"no matching extensions were found for pattern \"%s\"", cell->
val);
1420 if (patterns->
head == NULL)
1430 for (cell = patterns->
head; cell; cell = cell->
next)
1435 "SELECT oid FROM pg_catalog.pg_foreign_server s\n");
1437 false, NULL,
"s.srvname", NULL, NULL, NULL,
1440 pg_fatal(
"improper qualified name (too many dotted names): %s",
1445 pg_fatal(
"no matching foreign servers were found for pattern \"%s\"", cell->
val);
1472 if (patterns->
head == NULL)
1482 for (cell = patterns->
head; cell; cell = cell->
next)
1494 "\nFROM pg_catalog.pg_class c"
1495 "\n LEFT JOIN pg_catalog.pg_namespace n"
1496 "\n ON n.oid OPERATOR(pg_catalog.=) c.relnamespace"
1497 "\nWHERE c.relkind OPERATOR(pg_catalog.=) ANY"
1498 "\n (array['%c', '%c', '%c', '%c', '%c', '%c'])\n",
1499 RELKIND_RELATION, RELKIND_SEQUENCE, RELKIND_VIEW,
1500 RELKIND_MATVIEW, RELKIND_FOREIGN_TABLE,
1501 RELKIND_PARTITIONED_TABLE);
1504 false,
"n.nspname",
"c.relname", NULL,
1505 "pg_catalog.pg_table_is_visible(c.oid)", &dbbuf,
1508 pg_fatal(
"improper relation name (too many dotted names): %s",
1510 else if (dotcnt == 2)
1519 pg_fatal(
"no matching tables were found for pattern \"%s\"", cell->
val);
1546 pg_fatal(
"You are currently not connected to a database.");
1548 if (strcmp(db,
dbname) != 0)
1549 pg_fatal(
"cross-database references are not implemented: %s",
1635 strcmp(nsinfo->
dobj.
name,
"pg_catalog") == 0)
1644 else if (strncmp(nsinfo->
dobj.
name,
"pg_", 3) == 0 ||
1645 strcmp(nsinfo->
dobj.
name,
"information_schema") == 0)
1650 else if (strcmp(nsinfo->
dobj.
name,
"public") == 0)
1662 if (nsinfo->
nspowner == ROLE_PG_DATABASE_OWNER)
1742 tyinfo->
typrelkind != RELKIND_COMPOSITE_TYPE)
1747 if (tytable != NULL)
1787 if (dinfo->
dobj.namespace)
1949 if (dobj->namespace)
1966 const char *classname = tbinfo->
dobj.
name;
1978 const char *column_list;
1980 pg_log_info(
"dumping contents of table \"%s.%s\"",
1981 tbinfo->
dobj.namespace->dobj.
name, classname);
2000 if (strlen(column_list) > 2)
2086 pg_log_error(
"Dumping the contents of table \"%s\" failed: PQgetCopyData() failed.", classname);
2096 pg_log_error(
"Dumping the contents of table \"%s\" failed: PQgetResult() failed.", classname);
2105 pg_log_warning(
"unexpected extra results during COPY of table \"%s\"",
2133 int rows_this_statement = 0;
2178 pg_fatal(
"wrong number of fields retrieved from table \"%s\"",
2188 if (insertStmt == NULL)
2218 for (
int field = 0; field < nfields; field++)
2238 if (rows_this_statement == 0)
2254 if (rows_per_statement == 1)
2256 else if (rows_this_statement > 0)
2261 for (
int field = 0; field < nfields; field++)
2265 if (attgenerated[field])
2300 if (strspn(s,
"0123456789 +-eE.") == strlen(s))
2335 if (++rows_this_statement >= rows_per_statement)
2338 archputs(
" ON CONFLICT DO NOTHING;\n", fout);
2342 rows_this_statement = 0;
2355 if (rows_this_statement > 0)
2358 archputs(
" ON CONFLICT DO NOTHING;\n", fout);
2368 if (insertStmt != NULL)
2387 parentTbinfo = tbinfo->
parents[0];
2391 parentTbinfo = parentTbinfo->
parents[0];
2394 return parentTbinfo;
2412 const char *copyFrom;
2442 copyStmt = copyBuf->
data;
2462 .namespace = tbinfo->
dobj.namespace->dobj.
name,
2464 .description =
"TABLE DATA",
2466 .copyStmt = copyStmt,
2470 .dumpArg = tdinfo));
2528 .namespace = tbinfo->
dobj.namespace->dobj.
name,
2530 .description =
"MATERIALIZED VIEW DATA",
2532 .createStmt = q->
data,
2548 for (
i = 0;
i < numTables;
i++)
2551 (!relkind || tblinfo[
i].
relkind == relkind))
2575 if (tbinfo->
relkind == RELKIND_VIEW)
2578 if (tbinfo->
relkind == RELKIND_FOREIGN_TABLE &&
2584 if (tbinfo->
relkind == RELKIND_PARTITIONED_TABLE)
2600 if (tbinfo->
relkind == RELKIND_MATVIEW)
2602 else if (tbinfo->
relkind == RELKIND_SEQUENCE)
2615 tdinfo->
dobj.namespace = tbinfo->
dobj.namespace;
2655 "SELECT d1.objid, d2.refobjid, c2.relkind AS refrelkind "
2656 "FROM pg_depend d1 "
2657 "JOIN pg_class c1 ON c1.oid = d1.objid "
2659 " JOIN pg_rewrite r1 ON r1.ev_class = d1.objid "
2660 "JOIN pg_depend d2 ON d2.classid = 'pg_rewrite'::regclass "
2661 "AND d2.objid = r1.oid "
2662 "AND d2.refobjid <> d1.objid "
2663 "JOIN pg_class c2 ON c2.oid = d2.refobjid "
2664 "AND c2.relkind IN (" CppAsString2(RELKIND_MATVIEW)
","
2666 "WHERE d1.classid = 'pg_class'::regclass "
2668 "SELECT w.objid, d3.refobjid, c3.relkind "
2670 "JOIN pg_rewrite r3 ON r3.ev_class = w.refobjid "
2671 "JOIN pg_depend d3 ON d3.classid = 'pg_rewrite'::regclass "
2672 "AND d3.objid = r3.oid "
2673 "AND d3.refobjid <> w.refobjid "
2674 "JOIN pg_class c3 ON c3.oid = d3.refobjid "
2675 "AND c3.relkind IN (" CppAsString2(RELKIND_MATVIEW)
","
2678 "SELECT 'pg_class'::regclass::oid AS classid, objid, refobjid "
2690 for (
i = 0;
i < ntups;
i++)
2717 if (refdobj == NULL)
2724 if (refdobj == NULL)
2760 for (
i = 0;
i < numObjs;
i++)
2772 if (ftable == NULL ||
2843 "pg_encoding_to_char(encoding) AS encoding, "
2844 "datcollate, datctype, datfrozenxid, "
2845 "datacl, acldefault('d', datdba) AS acldefault, "
2846 "datistemplate, datconnlimit, ");
2854 appendPQExpBuffer(dbQry,
"'c' AS datlocprovider, NULL AS daticulocale, NULL AS datcollversion, ");
2856 "(SELECT spcname FROM pg_tablespace t WHERE t.oid = dattablespace) AS tablespace, "
2857 "shobj_description(oid, 'pg_database') AS description "
2859 "WHERE datname = current_database()");
2912 appendPQExpBuffer(creaQry,
"CREATE DATABASE %s WITH TEMPLATE = template0 OID = %u",
2913 qdatname, dbCatId.
oid);
2932 pg_fatal(
"unrecognized locale provider: %s",
2935 if (strlen(collate) > 0 && strcmp(collate, ctype) == 0)
2942 if (strlen(collate) > 0)
2947 if (strlen(ctype) > 0)
2998 .description =
"DATABASE",
3000 .createStmt = creaQry->
data,
3001 .dropStmt = delQry->
data));
3030 .description =
"COMMENT",
3032 .createStmt = dbQry->
data,
3050 if (seclabelQry->
len > 0)
3054 .description =
"SECURITY LABEL",
3056 .createStmt = seclabelQry->
data,
3071 qdatname, NULL, NULL,
3102 "SET datistemplate = false WHERE datname = ");
3118 "SET datfrozenxid = '%u', datminmxid = '%u'\n"
3120 frozenxid, minmxid);
3125 if (creaQry->
len > 0)
3129 .description =
"DATABASE PROPERTIES",
3131 .createStmt = creaQry->
data,
3132 .dropStmt = delQry->
data,
3133 .deps = &dbDumpId));
3152 "FROM pg_catalog.pg_class\n"
3153 "WHERE oid = %u;\n",
3154 LargeObjectRelationId);
3157 "FROM pg_catalog.pg_class\n"
3158 "WHERE oid = %u;\n",
3159 LargeObjectRelationId);
3163 i_relfrozenxid =
PQfnumber(lo_res,
"relfrozenxid");
3164 i_relminmxid =
PQfnumber(lo_res,
"relminmxid");
3166 appendPQExpBufferStr(loOutQry,
"\n-- For binary upgrade, set pg_largeobject relfrozenxid and relminmxid\n");
3168 "SET relfrozenxid = '%u', relminmxid = '%u'\n"
3169 "WHERE oid = %u;\n",
3172 LargeObjectRelationId);
3175 .description =
"pg_largeobject",
3177 .createStmt = loOutQry->
data));
3208 "WHERE setrole = 0 AND setdatabase = '%u'::oid",
3215 "DATABASE",
dbname, NULL, NULL,
3222 "FROM pg_db_role_setting s, pg_roles r "
3223 "WHERE setrole = r.oid AND setdatabase = '%u'::oid",
3256 .description =
"ENCODING",
3258 .createStmt = qry->
data));
3270 const char *stdstrings = AH->
std_strings ?
"on" :
"off";
3273 pg_log_info(
"saving standard_conforming_strings = %s",
3281 .description =
"STDSTRINGS",
3283 .createStmt = qry->
data));
3297 char **schemanames = NULL;
3298 int nschemanames = 0;
3309 "SELECT pg_catalog.current_schemas(false)");
3312 pg_fatal(
"could not parse result of current_schemas()");
3320 for (
i = 0;
i < nschemanames;
i++)
3335 .description =
"SEARCHPATH",
3337 .createStmt = qry->
data));
3373 "SELECT oid, lomowner, lomacl, "
3374 "acldefault('L', lomowner) AS acldefault "
3375 "FROM pg_largeobject_metadata");
3391 for (
i = 0;
i < ntups;
i++)
3453 "SELECT pg_catalog.lo_create('%s');\n",
3457 "SELECT pg_catalog.lo_unlink('%s');\n",
3464 .description =
"BLOB",
3466 .createStmt = cquery->
data,
3467 .dropStmt = dquery->
data));
3498 const char *blobQry;
3499 const char *blobFetchQry;
3514 "DECLARE bloboid CURSOR FOR "
3515 "SELECT oid FROM pg_largeobject_metadata ORDER BY 1";
3520 blobFetchQry =
"FETCH 1000 IN bloboid";
3529 for (
i = 0;
i < ntups;
i++)
3538 pg_fatal(
"could not open large object %u: %s",
3548 pg_fatal(
"error reading large object %u: %s",
3560 }
while (ntups > 0);
3581 int i_polpermissive;
3600 for (
i = 0;
i < numTables;
i++)
3609 if (tbinfo->
relkind != RELKIND_RELATION &&
3610 tbinfo->
relkind != RELKIND_PARTITIONED_TABLE)
3614 if (tbloids->
len > 1)
3635 polinfo->
dobj.namespace = tbinfo->
dobj.namespace;
3654 pg_log_info(
"reading row-level security policies");
3657 "SELECT pol.oid, pol.tableoid, pol.polrelid, pol.polname, pol.polcmd, ");
3663 "CASE WHEN pol.polroles = '{0}' THEN NULL ELSE "
3664 " pg_catalog.array_to_string(ARRAY(SELECT pg_catalog.quote_ident(rolname) from pg_catalog.pg_roles WHERE oid = ANY(pol.polroles)), ', ') END AS polroles, "
3665 "pg_catalog.pg_get_expr(pol.polqual, pol.polrelid) AS polqual, "
3666 "pg_catalog.pg_get_expr(pol.polwithcheck, pol.polrelid) AS polwithcheck "
3667 "FROM unnest('%s'::pg_catalog.oid[]) AS src(tbloid)\n"
3668 "JOIN pg_catalog.pg_policy pol ON (src.tbloid = pol.polrelid)",
3688 for (
j = 0;
j < ntups;
j++)
3700 polinfo[
j].
dobj.namespace = tbinfo->
dobj.namespace;
3709 polinfo[
j].polroles = NULL;
3772 .namespace = polinfo->
dobj.namespace->dobj.
name,
3774 .description =
"ROW SECURITY",
3776 .createStmt = query->
data,
3784 if (polinfo->
polcmd ==
'*')
3786 else if (polinfo->
polcmd ==
'r')
3787 cmd =
" FOR SELECT";
3788 else if (polinfo->
polcmd ==
'a')
3789 cmd =
" FOR INSERT";
3790 else if (polinfo->
polcmd ==
'w')
3791 cmd =
" FOR UPDATE";
3792 else if (polinfo->
polcmd ==
'd')
3793 cmd =
" FOR DELETE";
3795 pg_fatal(
"unexpected policy command type: %c",
3831 .
namespace = polinfo->
dobj.namespace->dobj.
name,
3833 .description =
"POLICY",
3835 .createStmt = query->
data,
3836 .dropStmt = delqry->
data));
3876 *numPublications = 0;
3887 "SELECT p.tableoid, p.oid, p.pubname, "
3889 "p.puballtables, p.pubinsert, p.pubupdate, p.pubdelete, p.pubtruncate, p.pubviaroot "
3890 "FROM pg_publication p");
3893 "SELECT p.tableoid, p.oid, p.pubname, "
3895 "p.puballtables, p.pubinsert, p.pubupdate, p.pubdelete, p.pubtruncate, false AS pubviaroot "
3896 "FROM pg_publication p");
3899 "SELECT p.tableoid, p.oid, p.pubname, "
3901 "p.puballtables, p.pubinsert, p.pubupdate, p.pubdelete, false AS pubtruncate, false AS pubviaroot "
3902 "FROM pg_publication p");
3921 for (
i = 0;
i < ntups;
i++)
3950 *numPublications = ntups;
4030 .description =
"PUBLICATION",
4032 .createStmt = query->
data,
4033 .dropStmt = delq->
data));
4076 "SELECT tableoid, oid, pnpubid, pnnspid "
4077 "FROM pg_catalog.pg_publication_namespace");
4091 for (
i = 0;
i < ntups;
i++)
4103 if (pubinfo == NULL)
4106 if (nspinfo == NULL)
4122 pubsinfo[
j].
dobj.namespace = nspinfo->
dobj.namespace;
4166 "SELECT tableoid, oid, prpubid, prrelid, "
4167 "pg_catalog.pg_get_expr(prqual, prrelid) AS prrelqual, "
4169 " WHEN pr.prattrs IS NOT NULL THEN\n"
4170 " (SELECT array_agg(attname)\n"
4172 " pg_catalog.generate_series(0, pg_catalog.array_upper(pr.prattrs::pg_catalog.int2[], 1)) s,\n"
4173 " pg_catalog.pg_attribute\n"
4174 " WHERE attrelid = pr.prrelid AND attnum = prattrs[s])\n"
4175 " ELSE NULL END) prattrs "
4176 "FROM pg_catalog.pg_publication_rel pr");
4179 "SELECT tableoid, oid, prpubid, prrelid, "
4180 "NULL AS prrelqual, NULL AS prattrs "
4181 "FROM pg_catalog.pg_publication_rel");
4197 for (
i = 0;
i < ntups;
i++)
4209 if (pubinfo == NULL)
4224 pubrinfo[
j].dobj.catId.tableoid =
4228 pubrinfo[
j].dobj.namespace = tbinfo->
dobj.namespace;
4229 pubrinfo[
j].dobj.name = tbinfo->
dobj.
name;
4230 pubrinfo[
j].publication = pubinfo;
4231 pubrinfo[
j].pubtable = tbinfo;
4233 pubrinfo[
j].pubrelqual = NULL;
4244 &attnames, &nattnames))
4245 pg_fatal(
"could not parse %s array",
"prattrs");
4247 for (
int k = 0; k < nattnames; k++)
4254 pubrinfo[
j].pubrattrs = attribs->
data;
4257 pubrinfo[
j].pubrattrs = NULL;
4300 .
namespace = schemainfo->
dobj.
name,
4302 .description =
"PUBLICATION TABLES IN SCHEMA",
4304 .createStmt = query->
data));
4338 if (pubrinfo->pubrattrs)
4341 if (pubrinfo->pubrelqual)
4360 ArchiveEntry(fout, pubrinfo->dobj.catId, pubrinfo->dobj.dumpId,
4362 .
namespace = tbinfo->
dobj.namespace->dobj.
name,
4364 .description =
"PUBLICATION TABLE",
4366 .createStmt = query->
data));
4385 if (
val && strcmp(
val,
"on") == 0)
4407 int i_subtwophasestate;
4408 int i_subdisableonerr;
4411 int i_subsynccommit;
4412 int i_subpublications;
4425 "SELECT count(*) FROM pg_subscription "
4426 "WHERE subdbid = (SELECT oid FROM pg_database"
4427 " WHERE datname = current_database())",
4431 pg_log_warning(
"subscriptions not dumped because current user is not a superuser");
4440 "SELECT s.tableoid, s.oid, s.subname,\n"
4442 " s.subconninfo, s.subslotname, s.subsynccommit,\n"
4443 " s.subpublications,\n");
4457 " s.subtwophasestate,\n"
4458 " s.subdisableonerr\n");
4461 " '%c' AS subtwophasestate,\n"
4462 " false AS subdisableonerr\n",
4466 "FROM pg_subscription s\n"
4467 "WHERE s.subdbid = (SELECT oid FROM pg_database\n"
4468 " WHERE datname = current_database())");
4488 i_subtwophasestate =
PQfnumber(
res,
"subtwophasestate");
4493 for (
i = 0;
i < ntups;
i++)
4540 char **pubnames = NULL;
4563 pg_fatal(
"could not parse %s array",
"subpublications");
4566 for (
i = 0;
i < npubnames;
i++)
4574 appendPQExpBuffer(query,
" PUBLICATION %s WITH (connect = false, slot_name = ", publications->
data);
4580 if (strcmp(subinfo->
subbinary,
"t") == 0)
4583 if (strcmp(subinfo->
substream,
"f") != 0)
4601 .description =
"SUBSCRIPTION",
4603 .createStmt = query->
data,
4604 .dropStmt = delq->
data));
4633 const char *catalog,
4634 const char *keyword,
4635 const char *objname)
4652 "FROM pg_catalog.pg_depend d, pg_catalog.pg_extension e "
4653 "WHERE d.refobjid = e.oid AND classid = '%s'::pg_catalog.regclass "
4654 "AND objid = '%u'::pg_catalog.oid AND deptype = 'x' "
4655 "AND refclassid = 'pg_catalog.pg_extension'::pg_catalog.regclass",
4661 for (
i = 0;
i < ntups;
i++)
4691 ++next_possible_free_oid;
4693 "SELECT EXISTS(SELECT 1 "
4694 "FROM pg_catalog.pg_type "
4695 "WHERE oid = '%u'::pg_catalog.oid);",
4696 next_possible_free_oid);
4702 return next_possible_free_oid;
4709 bool force_array_type,
4710 bool include_multirange_type)
4714 Oid pg_type_array_oid;
4715 Oid pg_type_multirange_oid;
4716 Oid pg_type_multirange_array_oid;
4720 "SELECT pg_catalog.binary_upgrade_set_next_pg_type_oid('%u'::pg_catalog.oid);\n\n",
4725 "FROM pg_catalog.pg_type "
4726 "WHERE oid = '%u'::pg_catalog.oid;",
4735 if (!
OidIsValid(pg_type_array_oid) && force_array_type)
4741 "\n-- For binary upgrade, must preserve pg_type array oid\n");
4743 "SELECT pg_catalog.binary_upgrade_set_next_array_pg_type_oid('%u'::pg_catalog.oid);\n\n",
4750 if (include_multirange_type)
4755 "SELECT t.oid, t.typarray "
4756 "FROM pg_catalog.pg_type t "
4757 "JOIN pg_catalog.pg_range r "
4758 "ON t.oid = r.rngmultitypid "
4759 "WHERE r.rngtypid = '%u'::pg_catalog.oid;",
4776 "\n-- For binary upgrade, must preserve multirange pg_type oid\n");
4778 "SELECT pg_catalog.binary_upgrade_set_next_multirange_pg_type_oid('%u'::pg_catalog.oid);\n\n",
4779 pg_type_multirange_oid);
4781 "\n-- For binary upgrade, must preserve multirange pg_type array oid\n");
4783 "SELECT pg_catalog.binary_upgrade_set_next_multirange_array_pg_type_oid('%u'::pg_catalog.oid);\n\n",
4784 pg_type_multirange_array_oid);
4799 pg_type_oid,
false,
false);
4811 Oid toast_relfilenode;
4813 Oid toast_index_oid;
4814 Oid toast_index_relfilenode;
4828 "SELECT c.relkind, c.relfilenode, c.reltoastrelid, ct.relfilenode AS toast_relfilenode, i.indexrelid, cti.relfilenode AS toast_index_relfilenode "
4829 "FROM pg_catalog.pg_class c LEFT JOIN "
4830 "pg_catalog.pg_index i ON (c.reltoastrelid = i.indrelid AND i.indisvalid) "
4831 "LEFT JOIN pg_catalog.pg_class ct ON (c.reltoastrelid = ct.oid) "
4832 "LEFT JOIN pg_catalog.pg_class AS cti ON (i.indexrelid = cti.oid) "
4833 "WHERE c.oid = '%u'::pg_catalog.oid;",
4841 PQfnumber(upgrade_res,
"relfilenode")));
4843 PQfnumber(upgrade_res,
"reltoastrelid")));
4845 PQfnumber(upgrade_res,
"toast_relfilenode")));
4849 PQfnumber(upgrade_res,
"toast_index_relfilenode")));
4852 "\n-- For binary upgrade, must preserve pg_class oids and relfilenodes\n");
4857 "SELECT pg_catalog.binary_upgrade_set_next_heap_pg_class_oid('%u'::pg_catalog.oid);\n",
4865 if (
OidIsValid(relfilenode) && relkind != RELKIND_PARTITIONED_TABLE)
4867 "SELECT pg_catalog.binary_upgrade_set_next_heap_relfilenode('%u'::pg_catalog.oid);\n",
4875 relkind != RELKIND_PARTITIONED_TABLE)
4878 "SELECT pg_catalog.binary_upgrade_set_next_toast_pg_class_oid('%u'::pg_catalog.oid);\n",
4881 "SELECT pg_catalog.binary_upgrade_set_next_toast_relfilenode('%u'::pg_catalog.oid);\n",
4886 "SELECT pg_catalog.binary_upgrade_set_next_index_pg_class_oid('%u'::pg_catalog.oid);\n",
4889 "SELECT pg_catalog.binary_upgrade_set_next_index_relfilenode('%u'::pg_catalog.oid);\n",
4890 toast_index_relfilenode);
4899 "SELECT pg_catalog.binary_upgrade_set_next_index_pg_class_oid('%u'::pg_catalog.oid);\n",
4902 "SELECT pg_catalog.binary_upgrade_set_next_index_relfilenode('%u'::pg_catalog.oid);\n",
4921 const char *objtype,
4922 const char *objname,
4923 const char *objnamespace)
4945 pg_fatal(
"could not find parent extension for %s %s",
4949 "\n-- For binary upgrade, handle extension membership the hard way\n");
4953 if (objnamespace && *objnamespace)
4989 "acldefault('n', n.nspowner) AS acldefault "
4990 "FROM pg_namespace n");
5005 for (
i = 0;
i < ntups;
i++)
5007 const char *nspowner;