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"
159 #define DUMP_DEFAULT_ROWS_PER_INSERT 1
164 #define fmtQualifiedDumpable(obj) \
165 fmtQualifiedId((obj)->dobj.namespace->dobj.name, \
170 const char *dumpencoding,
const char *dumpsnapshot,
188 bool with_child_tables);
190 const char *pattern);
195 static const char *
getRoleName(
const char *roleoid_str);
199 const char *
name,
const char *
namespace,
202 const char *initdb_comment);
204 const char *
name,
const char *
namespace,
206 int subid,
DumpId dumpId);
210 const char *
namespace,
const char *owner,
259 const char *servername,
const char *
namespace,
265 const char *nspname,
const char *owner,
271 DumpId **dependencies,
int *nDeps,
int *allocDeps);
286 const FuncInfo *finfo,
bool honor_quotes);
307 bool force_array_type,
308 bool include_multirange_type);
314 Oid pg_class_oid,
bool is_index);
319 const char *objnamespace);
324 const char *prefix,
Archive *fout);
346 bool g_verbose =
false;
347 const char *dumpencoding = NULL;
348 const char *dumpsnapshot = NULL;
349 char *use_role = NULL;
355 char *compression_detail = NULL;
356 char *compression_algorithm_str =
"none";
357 char *error_detail = NULL;
358 bool user_compression_defined =
false;
362 static struct option long_options[] = {
375 {
"jobs", 1, NULL,
'j'},
451 if (strcmp(argv[1],
"--help") == 0 || strcmp(argv[1],
"-?") == 0)
456 if (strcmp(argv[1],
"--version") == 0 || strcmp(argv[1],
"-V") == 0)
458 puts(
"pg_dump (PostgreSQL) " PG_VERSION);
465 while ((
c =
getopt_long(argc, argv,
"abBcCd:e:E:f:F:h:j:n:N:Op:RsS:t:T:U:vwWxZ:",
466 long_options, &optindex)) != -1)
583 &compression_detail);
584 user_compression_defined =
true;
676 pg_log_error(
"too many command-line arguments (first is \"%s\")",
695 pg_fatal(
"options -s/--schema-only and -a/--data-only cannot be used together");
698 pg_fatal(
"options -s/--schema-only and --include-foreign-data cannot be used together");
701 pg_fatal(
"option --include-foreign-data is not supported with parallel backup");
704 pg_fatal(
"options -c/--clean and -a/--data-only cannot be used together");
707 pg_fatal(
"option --if-exists requires option -c/--clean");
714 pg_fatal(
"option --on-conflict-do-nothing requires option --inserts, --rows-per-insert, or --column-inserts");
728 pg_fatal(
"unrecognized compression algorithm: \"%s\"",
729 compression_algorithm_str);
734 if (error_detail != NULL)
735 pg_fatal(
"invalid compression specification: %s",
747 pg_fatal(
"compression with %s is not yet supported",
"ZSTD");
756 !user_compression_defined)
775 pg_fatal(
"parallel backup only supported by the directory format");
830 pg_fatal(
"no matching schemas were found");
847 pg_fatal(
"no matching tables were found");
875 pg_fatal(
"no matching extensions were found");
910 getTableData(&dopt, tblinfo, numTables, RELKIND_SEQUENCE);
959 boundaryObjs[0].dumpId, boundaryObjs[1].dumpId);
978 for (
i = 0;
i < numObjs;
i++)
1055 printf(
_(
"%s dumps a database as a text file or to other formats.\n\n"),
progname);
1059 printf(
_(
"\nGeneral options:\n"));
1060 printf(
_(
" -f, --file=FILENAME output file or directory name\n"));
1061 printf(
_(
" -F, --format=c|d|t|p output file format (custom, directory, tar,\n"
1062 " plain text (default))\n"));
1063 printf(
_(
" -j, --jobs=NUM use this many parallel jobs to dump\n"));
1064 printf(
_(
" -v, --verbose verbose mode\n"));
1065 printf(
_(
" -V, --version output version information, then exit\n"));
1066 printf(
_(
" -Z, --compress=METHOD[:LEVEL]\n"
1067 " compress as specified\n"));
1068 printf(
_(
" --lock-wait-timeout=TIMEOUT fail after waiting TIMEOUT for a table lock\n"));
1069 printf(
_(
" --no-sync do not wait for changes to be written safely to disk\n"));
1070 printf(
_(
" -?, --help show this help, then exit\n"));
1072 printf(
_(
"\nOptions controlling the output content:\n"));
1073 printf(
_(
" -a, --data-only dump only the data, not the schema\n"));
1074 printf(
_(
" -b, --large-objects include large objects in dump\n"
1075 " --blobs (same as --large-objects, deprecated)\n"));
1076 printf(
_(
" -B, --no-large-objects exclude large objects in dump\n"
1077 " --no-blobs (same as --no-large-objects, deprecated)\n"));
1078 printf(
_(
" -c, --clean clean (drop) database objects before recreating\n"));
1079 printf(
_(
" -C, --create include commands to create database in dump\n"));
1080 printf(
_(
" -e, --extension=PATTERN dump the specified extension(s) only\n"));
1081 printf(
_(
" -E, --encoding=ENCODING dump the data in encoding ENCODING\n"));
1082 printf(
_(
" -n, --schema=PATTERN dump the specified schema(s) only\n"));
1083 printf(
_(
" -N, --exclude-schema=PATTERN do NOT dump the specified schema(s)\n"));
1084 printf(
_(
" -O, --no-owner skip restoration of object ownership in\n"
1085 " plain-text format\n"));
1086 printf(
_(
" -s, --schema-only dump only the schema, no data\n"));
1087 printf(
_(
" -S, --superuser=NAME superuser user name to use in plain-text format\n"));
1088 printf(
_(
" -t, --table=PATTERN dump only the specified table(s)\n"));
1089 printf(
_(
" -T, --exclude-table=PATTERN do NOT dump the specified table(s)\n"));
1090 printf(
_(
" -x, --no-privileges do not dump privileges (grant/revoke)\n"));
1091 printf(
_(
" --binary-upgrade for use by upgrade utilities only\n"));
1092 printf(
_(
" --column-inserts dump data as INSERT commands with column names\n"));
1093 printf(
_(
" --disable-dollar-quoting disable dollar quoting, use SQL standard quoting\n"));
1094 printf(
_(
" --disable-triggers disable triggers during data-only restore\n"));
1095 printf(
_(
" --enable-row-security enable row security (dump only content user has\n"
1097 printf(
_(
" --exclude-table-and-children=PATTERN\n"
1098 " do NOT dump the specified table(s),\n"
1099 " including child and partition tables\n"));
1100 printf(
_(
" --exclude-table-data=PATTERN do NOT dump data for the specified table(s)\n"));
1101 printf(
_(
" --exclude-table-data-and-children=PATTERN\n"
1102 " do NOT dump data for the specified table(s),\n"
1103 " including child and partition tables\n"));
1104 printf(
_(
" --extra-float-digits=NUM override default setting for extra_float_digits\n"));
1105 printf(
_(
" --if-exists use IF EXISTS when dropping objects\n"));
1106 printf(
_(
" --include-foreign-data=PATTERN\n"
1107 " include data of foreign tables on foreign\n"
1108 " servers matching PATTERN\n"));
1109 printf(
_(
" --inserts dump data as INSERT commands, rather than COPY\n"));
1110 printf(
_(
" --load-via-partition-root load partitions via the root table\n"));
1111 printf(
_(
" --no-comments do not dump comments\n"));
1112 printf(
_(
" --no-publications do not dump publications\n"));
1113 printf(
_(
" --no-security-labels do not dump security label assignments\n"));
1114 printf(
_(
" --no-subscriptions do not dump subscriptions\n"));
1115 printf(
_(
" --no-table-access-method do not dump table access methods\n"));
1116 printf(
_(
" --no-tablespaces do not dump tablespace assignments\n"));
1117 printf(
_(
" --no-toast-compression do not dump TOAST compression methods\n"));
1118 printf(
_(
" --no-unlogged-table-data do not dump unlogged table data\n"));
1119 printf(
_(
" --on-conflict-do-nothing add ON CONFLICT DO NOTHING to INSERT commands\n"));
1120 printf(
_(
" --quote-all-identifiers quote all identifiers, even if not key words\n"));
1121 printf(
_(
" --rows-per-insert=NROWS number of rows per INSERT; implies --inserts\n"));
1122 printf(
_(
" --section=SECTION dump named section (pre-data, data, or post-data)\n"));
1123 printf(
_(
" --serializable-deferrable wait until the dump can run without anomalies\n"));
1124 printf(
_(
" --snapshot=SNAPSHOT use given snapshot for the dump\n"));
1125 printf(
_(
" --strict-names require table and/or schema include patterns to\n"
1126 " match at least one entity each\n"));
1127 printf(
_(
" --table-and-children=PATTERN dump only the specified table(s),\n"
1128 " including child and partition tables\n"));
1129 printf(
_(
" --use-set-session-authorization\n"
1130 " use SET SESSION AUTHORIZATION commands instead of\n"
1131 " ALTER OWNER commands to set ownership\n"));
1133 printf(
_(
"\nConnection options:\n"));
1134 printf(
_(
" -d, --dbname=DBNAME database to dump\n"));
1135 printf(
_(
" -h, --host=HOSTNAME database server host or socket directory\n"));
1136 printf(
_(
" -p, --port=PORT database server port number\n"));
1137 printf(
_(
" -U, --username=NAME connect as specified database user\n"));
1138 printf(
_(
" -w, --no-password never prompt for password\n"));
1139 printf(
_(
" -W, --password force password prompt (should happen automatically)\n"));
1140 printf(
_(
" --role=ROLENAME do SET ROLE before dump\n"));
1142 printf(
_(
"\nIf no database name is supplied, then the PGDATABASE environment\n"
1143 "variable value is used.\n\n"));
1144 printf(
_(
"Report bugs to <%s>.\n"), PACKAGE_BUGREPORT);
1145 printf(
_(
"%s home page: <%s>\n"), PACKAGE_NAME, PACKAGE_URL);
1150 const char *dumpsnapshot,
char *use_role)
1154 const char *std_strings;
1164 pg_fatal(
"invalid client encoding \"%s\" specified",
1175 AH->
std_strings = (std_strings && strcmp(std_strings,
"on") == 0);
1275 "SET TRANSACTION ISOLATION LEVEL "
1276 "SERIALIZABLE, READ ONLY, DEFERRABLE");
1279 "SET TRANSACTION ISOLATION LEVEL "
1280 "REPEATABLE READ, READ ONLY");
1302 pg_fatal(
"parallel dumps from standby servers are not supported by this server version");
1326 char *query =
"SELECT pg_catalog.pg_export_snapshot()";
1368 return archiveFormat;
1386 if (patterns->
head == NULL)
1396 for (cell = patterns->
head; cell; cell = cell->
next)
1402 "SELECT oid FROM pg_catalog.pg_namespace n\n");
1405 false, NULL,
"n.nspname", NULL, NULL, &dbbuf,
1408 pg_fatal(
"improper qualified name (too many dotted names): %s",
1410 else if (dotcnt == 1)
1416 pg_fatal(
"no matching schemas were found for pattern \"%s\"", cell->
val);
1445 if (patterns->
head == NULL)
1454 for (cell = patterns->
head; cell; cell = cell->
next)
1459 "SELECT oid FROM pg_catalog.pg_extension e\n");
1461 false, NULL,
"e.extname", NULL, NULL, NULL,
1464 pg_fatal(
"improper qualified name (too many dotted names): %s",
1469 pg_fatal(
"no matching extensions were found for pattern \"%s\"", cell->
val);
1497 if (patterns->
head == NULL)
1507 for (cell = patterns->
head; cell; cell = cell->
next)
1512 "SELECT oid FROM pg_catalog.pg_foreign_server s\n");
1514 false, NULL,
"s.srvname", NULL, NULL, NULL,
1517 pg_fatal(
"improper qualified name (too many dotted names): %s",
1522 pg_fatal(
"no matching foreign servers were found for pattern \"%s\"", cell->
val);
1549 if (patterns->
head == NULL)
1559 for (cell = patterns->
head; cell; cell = cell->
next)
1572 if (with_child_tables)
1579 "\nFROM pg_catalog.pg_class c"
1580 "\n LEFT JOIN pg_catalog.pg_namespace n"
1581 "\n ON n.oid OPERATOR(pg_catalog.=) c.relnamespace"
1582 "\nWHERE c.relkind OPERATOR(pg_catalog.=) ANY"
1583 "\n (array['%c', '%c', '%c', '%c', '%c', '%c'])\n",
1584 RELKIND_RELATION, RELKIND_SEQUENCE, RELKIND_VIEW,
1585 RELKIND_MATVIEW, RELKIND_FOREIGN_TABLE,
1586 RELKIND_PARTITIONED_TABLE);
1589 false,
"n.nspname",
"c.relname", NULL,
1590 "pg_catalog.pg_table_is_visible(c.oid)", &dbbuf,
1593 pg_fatal(
"improper relation name (too many dotted names): %s",
1595 else if (dotcnt == 2)
1599 if (with_child_tables)
1602 "\nSELECT i.inhrelid"
1603 "\nFROM partition_tree p"
1604 "\n JOIN pg_catalog.pg_inherits i"
1605 "\n ON p.relid OPERATOR(pg_catalog.=) i.inhparent"
1607 "\nSELECT relid FROM partition_tree");
1615 pg_fatal(
"no matching tables were found for pattern \"%s\"", cell->
val);
1642 pg_fatal(
"You are currently not connected to a database.");
1644 if (strcmp(db,
dbname) != 0)
1645 pg_fatal(
"cross-database references are not implemented: %s",
1731 strcmp(nsinfo->
dobj.
name,
"pg_catalog") == 0)
1740 else if (strncmp(nsinfo->
dobj.
name,
"pg_", 3) == 0 ||
1741 strcmp(nsinfo->
dobj.
name,
"information_schema") == 0)
1746 else if (strcmp(nsinfo->
dobj.
name,
"public") == 0)
1758 if (nsinfo->
nspowner == ROLE_PG_DATABASE_OWNER)
1838 tyinfo->
typrelkind != RELKIND_COMPOSITE_TYPE)
1843 if (tytable != NULL)
1883 if (dinfo->
dobj.namespace)
2045 if (dobj->namespace)
2062 const char *classname = tbinfo->
dobj.
name;
2074 const char *column_list;
2076 pg_log_info(
"dumping contents of table \"%s.%s\"",
2077 tbinfo->
dobj.namespace->dobj.
name, classname);
2096 if (strlen(column_list) > 2)
2182 pg_log_error(
"Dumping the contents of table \"%s\" failed: PQgetCopyData() failed.", classname);
2192 pg_log_error(
"Dumping the contents of table \"%s\" failed: PQgetResult() failed.", classname);
2201 pg_log_warning(
"unexpected extra results during COPY of table \"%s\"",
2229 int rows_this_statement = 0;
2274 pg_fatal(
"wrong number of fields retrieved from table \"%s\"",
2284 if (insertStmt == NULL)
2316 for (
int field = 0; field < nfields; field++)
2336 if (rows_this_statement == 0)
2352 if (rows_per_statement == 1)
2354 else if (rows_this_statement > 0)
2359 for (
int field = 0; field < nfields; field++)
2363 if (attgenerated[field])
2398 if (strspn(s,
"0123456789 +-eE.") == strlen(s))
2433 if (++rows_this_statement >= rows_per_statement)
2436 archputs(
" ON CONFLICT DO NOTHING;\n", fout);
2440 rows_this_statement = 0;
2453 if (rows_this_statement > 0)
2456 archputs(
" ON CONFLICT DO NOTHING;\n", fout);
2466 if (insertStmt != NULL)
2485 parentTbinfo = tbinfo->
parents[0];
2489 parentTbinfo = parentTbinfo->
parents[0];
2492 return parentTbinfo;
2510 parentTbinfo = tbinfo->
parents[0];
2516 parentTbinfo = parentTbinfo->
parents[0];
2538 char *tdDefn = NULL;
2540 const char *copyFrom;
2575 copyStmt = copyBuf->
data;
2595 .namespace = tbinfo->
dobj.namespace->dobj.
name,
2597 .description =
"TABLE DATA",
2599 .createStmt = tdDefn,
2600 .copyStmt = copyStmt,
2604 .dumpArg = tdinfo));
2662 .namespace = tbinfo->
dobj.namespace->dobj.
name,
2664 .description =
"MATERIALIZED VIEW DATA",
2666 .createStmt = q->
data,
2682 for (
i = 0;
i < numTables;
i++)
2685 (!relkind || tblinfo[
i].
relkind == relkind))
2709 if (tbinfo->
relkind == RELKIND_VIEW)
2712 if (tbinfo->
relkind == RELKIND_FOREIGN_TABLE &&
2718 if (tbinfo->
relkind == RELKIND_PARTITIONED_TABLE)
2734 if (tbinfo->
relkind == RELKIND_MATVIEW)
2736 else if (tbinfo->
relkind == RELKIND_SEQUENCE)
2749 tdinfo->
dobj.namespace = tbinfo->
dobj.namespace;
2789 "SELECT d1.objid, d2.refobjid, c2.relkind AS refrelkind "
2790 "FROM pg_depend d1 "
2791 "JOIN pg_class c1 ON c1.oid = d1.objid "
2793 " JOIN pg_rewrite r1 ON r1.ev_class = d1.objid "
2794 "JOIN pg_depend d2 ON d2.classid = 'pg_rewrite'::regclass "
2795 "AND d2.objid = r1.oid "
2796 "AND d2.refobjid <> d1.objid "
2797 "JOIN pg_class c2 ON c2.oid = d2.refobjid "
2798 "AND c2.relkind IN (" CppAsString2(RELKIND_MATVIEW)
","
2800 "WHERE d1.classid = 'pg_class'::regclass "
2802 "SELECT w.objid, d3.refobjid, c3.relkind "
2804 "JOIN pg_rewrite r3 ON r3.ev_class = w.refobjid "
2805 "JOIN pg_depend d3 ON d3.classid = 'pg_rewrite'::regclass "
2806 "AND d3.objid = r3.oid "
2807 "AND d3.refobjid <> w.refobjid "
2808 "JOIN pg_class c3 ON c3.oid = d3.refobjid "
2809 "AND c3.relkind IN (" CppAsString2(RELKIND_MATVIEW)
","
2812 "SELECT 'pg_class'::regclass::oid AS classid, objid, refobjid "
2824 for (
i = 0;
i < ntups;
i++)
2851 if (refdobj == NULL)
2858 if (refdobj == NULL)
2894 for (
i = 0;
i < numObjs;
i++)
2906 if (ftable == NULL ||
2979 "pg_encoding_to_char(encoding) AS encoding, "
2980 "datcollate, datctype, datfrozenxid, "
2981 "datacl, acldefault('d', datdba) AS acldefault, "
2982 "datistemplate, datconnlimit, ");
2990 appendPQExpBufferStr(dbQry,
"'c' AS datlocprovider, NULL AS daticulocale, NULL AS datcollversion, ");
2996 "(SELECT spcname FROM pg_tablespace t WHERE t.oid = dattablespace) AS tablespace, "
2997 "shobj_description(oid, 'pg_database') AS description "
2999 "WHERE datname = current_database()");
3057 appendPQExpBuffer(creaQry,
"CREATE DATABASE %s WITH TEMPLATE = template0 OID = %u",
3058 qdatname, dbCatId.
oid);
3077 pg_fatal(
"unrecognized locale provider: %s",
3080 if (strlen(collate) > 0 && strcmp(collate, ctype) == 0)
3087 if (strlen(collate) > 0)
3092 if (strlen(ctype) > 0)
3148 .description =
"DATABASE",
3150 .createStmt = creaQry->
data,
3151 .dropStmt = delQry->
data));
3180 .description =
"COMMENT",
3182 .createStmt = dbQry->
data,
3200 if (seclabelQry->
len > 0)
3204 .description =
"SECURITY LABEL",
3206 .createStmt = seclabelQry->
data,
3221 qdatname, NULL, NULL,
3252 "SET datistemplate = false WHERE datname = ");
3268 "SET datfrozenxid = '%u', datminmxid = '%u'\n"
3270 frozenxid, minmxid);
3275 if (creaQry->
len > 0)
3279 .description =
"DATABASE PROPERTIES",
3281 .createStmt = creaQry->
data,
3282 .dropStmt = delQry->
data,
3283 .deps = &dbDumpId));
3295 int ii_relfrozenxid,
3304 appendPQExpBuffer(loFrozenQry,
"SELECT relfrozenxid, relminmxid, relfilenode, oid\n"
3305 "FROM pg_catalog.pg_class\n"
3306 "WHERE oid IN (%u, %u);\n",
3307 LargeObjectRelationId, LargeObjectLOidPNIndexId);
3309 appendPQExpBuffer(loFrozenQry,
"SELECT relfrozenxid, 0 AS relminmxid, relfilenode, oid\n"
3310 "FROM pg_catalog.pg_class\n"
3311 "WHERE oid IN (%u, %u);\n",
3312 LargeObjectRelationId, LargeObjectLOidPNIndexId);
3316 ii_relfrozenxid =
PQfnumber(lo_res,
"relfrozenxid");
3317 ii_relminmxid =
PQfnumber(lo_res,
"relminmxid");
3318 ii_relfilenode =
PQfnumber(lo_res,
"relfilenode");
3321 appendPQExpBufferStr(loHorizonQry,
"\n-- For binary upgrade, set pg_largeobject relfrozenxid and relminmxid\n");
3322 appendPQExpBufferStr(loOutQry,
"\n-- For binary upgrade, preserve pg_largeobject and index relfilenodes\n");
3329 "SET relfrozenxid = '%u', relminmxid = '%u'\n"
3330 "WHERE oid = %u;\n",
3338 if (oid == LargeObjectRelationId)
3340 "SELECT pg_catalog.binary_upgrade_set_next_heap_relfilenode('%u'::pg_catalog.oid);\n",
3342 else if (oid == LargeObjectLOidPNIndexId)
3344 "SELECT pg_catalog.binary_upgrade_set_next_index_relfilenode('%u'::pg_catalog.oid);\n",
3349 "TRUNCATE pg_catalog.pg_largeobject;\n");
3354 .description =
"pg_largeobject",
3356 .createStmt = loOutQry->
data));
3391 "WHERE setrole = 0 AND setdatabase = '%u'::oid",
3398 char *userset = NULL;
3403 "DATABASE",
dbname, NULL, NULL,
3414 "WHERE setrole = r.oid AND setdatabase = '%u'::oid",
3421 char *userset = NULL;
3453 .description =
"ENCODING",
3455 .createStmt = qry->
data));
3467 const char *stdstrings = AH->
std_strings ?
"on" :
"off";
3470 pg_log_info(
"saving standard_conforming_strings = %s",
3478 .description =
"STDSTRINGS",
3480 .createStmt = qry->
data));
3494 char **schemanames = NULL;
3495 int nschemanames = 0;
3506 "SELECT pg_catalog.current_schemas(false)");
3509 pg_fatal(
"could not parse result of current_schemas()");
3517 for (
i = 0;
i < nschemanames;
i++)
3532 .description =
"SEARCHPATH",
3534 .createStmt = qry->
data));
3569 "SELECT oid, lomowner, lomacl, "
3570 "acldefault('L', lomowner) AS acldefault "
3571 "FROM pg_largeobject_metadata");
3587 for (
i = 0;
i < ntups;
i++)
3649 "SELECT pg_catalog.lo_create('%s');\n",
3653 "SELECT pg_catalog.lo_unlink('%s');\n",
3660 .description =
"BLOB",
3662 .createStmt = cquery->
data,
3663 .dropStmt = dquery->
data));
3695 const char *loFetchQry;
3710 "DECLARE looid CURSOR FOR "
3711 "SELECT oid FROM pg_largeobject_metadata ORDER BY 1";
3716 loFetchQry =
"FETCH 1000 IN looid";
3725 for (
i = 0;
i < ntups;
i++)
3734 pg_fatal(
"could not open large object %u: %s",
3744 pg_fatal(
"error reading large object %u: %s",
3756 }
while (ntups > 0);
3777 int i_polpermissive;
3796 for (
i = 0;
i < numTables;
i++)
3805 if (tbinfo->
relkind != RELKIND_RELATION &&
3806 tbinfo->
relkind != RELKIND_PARTITIONED_TABLE)
3810 if (tbloids->
len > 1)
3831 polinfo->
dobj.namespace = tbinfo->
dobj.namespace;
3850 pg_log_info(
"reading row-level security policies");
3853 "SELECT pol.oid, pol.tableoid, pol.polrelid, pol.polname, pol.polcmd, ");
3859 "CASE WHEN pol.polroles = '{0}' THEN NULL ELSE "
3860 " 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, "
3861 "pg_catalog.pg_get_expr(pol.polqual, pol.polrelid) AS polqual, "
3862 "pg_catalog.pg_get_expr(pol.polwithcheck, pol.polrelid) AS polwithcheck "
3863 "FROM unnest('%s'::pg_catalog.oid[]) AS src(tbloid)\n"
3864 "JOIN pg_catalog.pg_policy pol ON (src.tbloid = pol.polrelid)",
3884 for (
j = 0;
j < ntups;
j++)
3896 polinfo[
j].
dobj.namespace = tbinfo->
dobj.namespace;
3905 polinfo[
j].polroles = NULL;
3968 .namespace = polinfo->
dobj.namespace->dobj.
name,
3970 .description =
"ROW SECURITY",
3972 .createStmt = query->
data,
3980 if (polinfo->
polcmd ==
'*')
3982 else if (polinfo->
polcmd ==
'r')
3983 cmd =
" FOR SELECT";
3984 else if (polinfo->
polcmd ==
'a')
3985 cmd =
" FOR INSERT";
3986 else if (polinfo->
polcmd ==
'w')
3987 cmd =
" FOR UPDATE";
3988 else if (polinfo->
polcmd ==
'd')
3989 cmd =
" FOR DELETE";
3991 pg_fatal(
"unexpected policy command type: %c",
4027 .
namespace = polinfo->
dobj.namespace->dobj.
name,
4029 .description =
"POLICY",
4031 .createStmt = query->
data,
4032 .dropStmt = delqry->
data));
4072 *numPublications = 0;
4083 "SELECT p.tableoid, p.oid, p.pubname, "
4085 "p.puballtables, p.pubinsert, p.pubupdate, p.pubdelete, p.pubtruncate, p.pubviaroot "
4086 "FROM pg_publication p");
4089 "SELECT p.tableoid, p.oid, p.pubname, "
4091 "p.puballtables, p.pubinsert, p.pubupdate, p.pubdelete, p.pubtruncate, false AS pubviaroot "
4092 "FROM pg_publication p");
4095 "SELECT p.tableoid, p.oid, p.pubname, "
4097 "p.puballtables, p.pubinsert, p.pubupdate, p.pubdelete, false AS pubtruncate, false AS pubviaroot "
4098 "FROM pg_publication p");
4117 for (
i = 0;
i < ntups;
i++)
4146 *numPublications = ntups;
4226 .description =
"PUBLICATION",
4228 .createStmt = query->
data,
4229 .dropStmt = delq->
data));
4272 "SELECT tableoid, oid, pnpubid, pnnspid "
4273 "FROM pg_catalog.pg_publication_namespace");
4287 for (
i = 0;
i < ntups;
i++)
4299 if (pubinfo == NULL)
4302 if (nspinfo == NULL)
4318 pubsinfo[
j].
dobj.namespace = nspinfo->
dobj.namespace;
4362 "SELECT tableoid, oid, prpubid, prrelid, "
4363 "pg_catalog.pg_get_expr(prqual, prrelid) AS prrelqual, "
4365 " WHEN pr.prattrs IS NOT NULL THEN\n"
4366 " (SELECT array_agg(attname)\n"
4368 " pg_catalog.generate_series(0, pg_catalog.array_upper(pr.prattrs::pg_catalog.int2[], 1)) s,\n"
4369 " pg_catalog.pg_attribute\n"
4370 " WHERE attrelid = pr.prrelid AND attnum = prattrs[s])\n"
4371 " ELSE NULL END) prattrs "
4372 "FROM pg_catalog.pg_publication_rel pr");
4375 "SELECT tableoid, oid, prpubid, prrelid, "
4376 "NULL AS prrelqual, NULL AS prattrs "
4377 "FROM pg_catalog.pg_publication_rel");
4393 for (
i = 0;
i < ntups;
i++)
4405 if (pubinfo == NULL)
4420 pubrinfo[
j].dobj.catId.tableoid =
4424 pubrinfo[
j].dobj.namespace = tbinfo->
dobj.namespace;
4425 pubrinfo[
j].dobj.name = tbinfo->
dobj.
name;
4426 pubrinfo[
j].publication = pubinfo;
4427 pubrinfo[
j].pubtable = tbinfo;
4429 pubrinfo[
j].pubrelqual = NULL;
4440 &attnames, &nattnames))
4441 pg_fatal(
"could not parse %s array",
"prattrs");
4443 for (
int k = 0; k < nattnames; k++)
4450 pubrinfo[
j].pubrattrs = attribs->
data;
4453 pubrinfo[
j].pubrattrs = NULL;
4496 .
namespace = schemainfo->
dobj.
name,
4498 .description =
"PUBLICATION TABLES IN SCHEMA",
4500 .createStmt = query->
data));
4534 if (pubrinfo->pubrattrs)
4537 if (pubrinfo->pubrelqual)
4556 ArchiveEntry(fout, pubrinfo->dobj.catId, pubrinfo->dobj.dumpId,
4558 .
namespace = tbinfo->
dobj.namespace->dobj.
name,
4560 .description =
"PUBLICATION TABLE",
4562 .createStmt = query->
data));
4581 if (
val && strcmp(
val,
"on") == 0)
4603 int i_subtwophasestate;
4604 int i_subdisableonerr;
4608 int i_subsynccommit;
4609 int i_subpublications;
4622 "SELECT count(*) FROM pg_subscription "
4623 "WHERE subdbid = (SELECT oid FROM pg_database"
4624 " WHERE datname = current_database())",
4628 pg_log_warning(
"subscriptions not dumped because current user is not a superuser");
4637 "SELECT s.tableoid, s.oid, s.subname,\n"
4639 " s.subconninfo, s.subslotname, s.subsynccommit,\n"
4640 " s.subpublications,\n");
4654 " s.subtwophasestate,\n"
4655 " s.subdisableonerr,\n");
4658 " '%c' AS subtwophasestate,\n"
4659 " false AS subdisableonerr,\n",
4668 "FROM pg_subscription s\n"
4669 "WHERE s.subdbid = (SELECT oid FROM pg_database\n"
4670 " WHERE datname = current_database())");
4690 i_subtwophasestate =
PQfnumber(
res,
"subtwophasestate");
4696 for (
i = 0;
i < ntups;
i++)
4744 char **pubnames = NULL;
4767 pg_fatal(
"could not parse %s array",
"subpublications");
4770 for (
i = 0;
i < npubnames;
i++)
4778 appendPQExpBuffer(query,
" PUBLICATION %s WITH (connect = false, slot_name = ", publications->
data);
4784 if (strcmp(subinfo->
subbinary,
"t") == 0)
4787 if (strcmp(subinfo->
substream,
"t") == 0)
4789 else if (strcmp(subinfo->
substream,
"p") == 0)
4810 .description =
"SUBSCRIPTION",
4812 .createStmt = query->
data,
4813 .dropStmt = delq->
data));
4841 const char *catalog,
4842 const char *keyword,
4843 const char *objname)
4860 "FROM pg_catalog.pg_depend d, pg_catalog.pg_extension e "
4861 "WHERE d.refobjid = e.oid AND classid = '%s'::pg_catalog.regclass "
4862 "AND objid = '%u'::pg_catalog.oid AND deptype = 'x' "
4863 "AND refclassid = 'pg_catalog.pg_extension'::pg_catalog.regclass",
4869 for (
i = 0;
i < ntups;
i++)
4899 ++next_possible_free_oid;
4901 "SELECT EXISTS(SELECT 1 "
4902 "FROM pg_catalog.pg_type "
4903 "WHERE oid = '%u'::pg_catalog.oid);",
4904 next_possible_free_oid);
4910 return next_possible_free_oid;
4917 bool force_array_type,
4918 bool include_multirange_type)
4922 Oid pg_type_array_oid;
4923 Oid pg_type_multirange_oid;
4924 Oid pg_type_multirange_array_oid;
4928 "SELECT pg_catalog.binary_upgrade_set_next_pg_type_oid('%u'::pg_catalog.oid);\n\n",
4933 "FROM pg_catalog.pg_type "
4934 "WHERE oid = '%u'::pg_catalog.oid;",
4943 if (!
OidIsValid(pg_type_array_oid) && force_array_type)
4949 "\n-- For binary upgrade, must preserve pg_type array oid\n");
4951 "SELECT pg_catalog.binary_upgrade_set_next_array_pg_type_oid('%u'::pg_catalog.oid);\n\n",
4958 if (include_multirange_type)
4963 "SELECT t.oid, t.typarray "
4964 "FROM pg_catalog.pg_type t "
4965 "JOIN pg_catalog.pg_range r "
4966 "ON t.oid = r.rngmultitypid "
4967 "WHERE r.rngtypid = '%u'::pg_catalog.oid;",
4984 "\n-- For binary upgrade, must preserve multirange pg_type oid\n");