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"
160 #define DUMP_DEFAULT_ROWS_PER_INSERT 1
165 #define fmtQualifiedDumpable(obj) \
166 fmtQualifiedId((obj)->dobj.namespace->dobj.name, \
171 const char *dumpencoding,
const char *dumpsnapshot,
189 bool with_child_tables);
191 const char *pattern);
196 static const char *
getRoleName(
const char *roleoid_str);
200 const char *
name,
const char *
namespace,
203 const char *initdb_comment);
205 const char *
name,
const char *
namespace,
207 int subid,
DumpId dumpId);
211 const char *
namespace,
const char *owner,
260 const char *servername,
const char *
namespace,
266 const char *nspname,
const char *owner,
272 DumpId **dependencies,
int *nDeps,
int *allocDeps);
287 const FuncInfo *finfo,
bool honor_quotes);
308 bool force_array_type,
309 bool include_multirange_type);
315 Oid pg_class_oid,
bool is_index);
320 const char *objnamespace);
325 const char *prefix,
Archive *fout);
347 bool g_verbose =
false;
348 const char *dumpencoding = NULL;
349 const char *dumpsnapshot = NULL;
350 char *use_role = NULL;
356 char *compression_detail = NULL;
357 char *compression_algorithm_str =
"none";
358 char *error_detail = NULL;
359 bool user_compression_defined =
false;
364 static struct option long_options[] = {
377 {
"jobs", 1, NULL,
'j'},
454 if (strcmp(argv[1],
"--help") == 0 || strcmp(argv[1],
"-?") == 0)
459 if (strcmp(argv[1],
"--version") == 0 || strcmp(argv[1],
"-V") == 0)
461 puts(
"pg_dump (PostgreSQL) " PG_VERSION);
468 while ((
c =
getopt_long(argc, argv,
"abBcCd:e:E:f:F:h:j:n:N:Op:RsS:t:T:U:vwWxZ:",
469 long_options, &optindex)) != -1)
586 &compression_detail);
587 user_compression_defined =
true;
684 pg_log_error(
"too many command-line arguments (first is \"%s\")",
703 pg_fatal(
"options -s/--schema-only and -a/--data-only cannot be used together");
706 pg_fatal(
"options -s/--schema-only and --include-foreign-data cannot be used together");
709 pg_fatal(
"option --include-foreign-data is not supported with parallel backup");
712 pg_fatal(
"options -c/--clean and -a/--data-only cannot be used together");
715 pg_fatal(
"option --if-exists requires option -c/--clean");
722 pg_fatal(
"option --on-conflict-do-nothing requires option --inserts, --rows-per-insert, or --column-inserts");
737 !user_compression_defined)
740 compression_algorithm_str =
"gzip";
742 compression_algorithm_str =
"none";
751 pg_fatal(
"unrecognized compression algorithm: \"%s\"",
752 compression_algorithm_str);
757 if (error_detail != NULL)
758 pg_fatal(
"invalid compression specification: %s",
762 if (error_detail != NULL)
771 pg_log_warning(
"compression option \"%s\" is not currently supported by pg_dump",
783 pg_fatal(
"parallel backup only supported by the directory format");
838 pg_fatal(
"no matching schemas were found");
855 pg_fatal(
"no matching tables were found");
883 pg_fatal(
"no matching extensions were found");
918 getTableData(&dopt, tblinfo, numTables, RELKIND_SEQUENCE);
967 boundaryObjs[0].dumpId, boundaryObjs[1].dumpId);
986 for (
i = 0;
i < numObjs;
i++)
1063 printf(
_(
"%s dumps a database as a text file or to other formats.\n\n"),
progname);
1067 printf(
_(
"\nGeneral options:\n"));
1068 printf(
_(
" -f, --file=FILENAME output file or directory name\n"));
1069 printf(
_(
" -F, --format=c|d|t|p output file format (custom, directory, tar,\n"
1070 " plain text (default))\n"));
1071 printf(
_(
" -j, --jobs=NUM use this many parallel jobs to dump\n"));
1072 printf(
_(
" -v, --verbose verbose mode\n"));
1073 printf(
_(
" -V, --version output version information, then exit\n"));
1074 printf(
_(
" -Z, --compress=METHOD[:DETAIL]\n"
1075 " compress as specified\n"));
1076 printf(
_(
" --lock-wait-timeout=TIMEOUT fail after waiting TIMEOUT for a table lock\n"));
1077 printf(
_(
" --no-sync do not wait for changes to be written safely to disk\n"));
1078 printf(
_(
" --sync-method=METHOD set method for syncing files to disk\n"));
1079 printf(
_(
" -?, --help show this help, then exit\n"));
1081 printf(
_(
"\nOptions controlling the output content:\n"));
1082 printf(
_(
" -a, --data-only dump only the data, not the schema\n"));
1083 printf(
_(
" -b, --large-objects include large objects in dump\n"));
1084 printf(
_(
" --blobs (same as --large-objects, deprecated)\n"));
1085 printf(
_(
" -B, --no-large-objects exclude large objects in dump\n"));
1086 printf(
_(
" --no-blobs (same as --no-large-objects, deprecated)\n"));
1087 printf(
_(
" -c, --clean clean (drop) database objects before recreating\n"));
1088 printf(
_(
" -C, --create include commands to create database in dump\n"));
1089 printf(
_(
" -e, --extension=PATTERN dump the specified extension(s) only\n"));
1090 printf(
_(
" -E, --encoding=ENCODING dump the data in encoding ENCODING\n"));
1091 printf(
_(
" -n, --schema=PATTERN dump the specified schema(s) only\n"));
1092 printf(
_(
" -N, --exclude-schema=PATTERN do NOT dump the specified schema(s)\n"));
1093 printf(
_(
" -O, --no-owner skip restoration of object ownership in\n"
1094 " plain-text format\n"));
1095 printf(
_(
" -s, --schema-only dump only the schema, no data\n"));
1096 printf(
_(
" -S, --superuser=NAME superuser user name to use in plain-text format\n"));
1097 printf(
_(
" -t, --table=PATTERN dump only the specified table(s)\n"));
1098 printf(
_(
" -T, --exclude-table=PATTERN do NOT dump the specified table(s)\n"));
1099 printf(
_(
" -x, --no-privileges do not dump privileges (grant/revoke)\n"));
1100 printf(
_(
" --binary-upgrade for use by upgrade utilities only\n"));
1101 printf(
_(
" --column-inserts dump data as INSERT commands with column names\n"));
1102 printf(
_(
" --disable-dollar-quoting disable dollar quoting, use SQL standard quoting\n"));
1103 printf(
_(
" --disable-triggers disable triggers during data-only restore\n"));
1104 printf(
_(
" --enable-row-security enable row security (dump only content user has\n"
1106 printf(
_(
" --exclude-table-and-children=PATTERN\n"
1107 " do NOT dump the specified table(s), including\n"
1108 " child and partition tables\n"));
1109 printf(
_(
" --exclude-table-data=PATTERN do NOT dump data for the specified table(s)\n"));
1110 printf(
_(
" --exclude-table-data-and-children=PATTERN\n"
1111 " do NOT dump data for the specified table(s),\n"
1112 " including child and partition tables\n"));
1113 printf(
_(
" --extra-float-digits=NUM override default setting for extra_float_digits\n"));
1114 printf(
_(
" --if-exists use IF EXISTS when dropping objects\n"));
1115 printf(
_(
" --include-foreign-data=PATTERN\n"
1116 " include data of foreign tables on foreign\n"
1117 " servers matching PATTERN\n"));
1118 printf(
_(
" --inserts dump data as INSERT commands, rather than COPY\n"));
1119 printf(
_(
" --load-via-partition-root load partitions via the root table\n"));
1120 printf(
_(
" --no-comments do not dump comments\n"));
1121 printf(
_(
" --no-publications do not dump publications\n"));
1122 printf(
_(
" --no-security-labels do not dump security label assignments\n"));
1123 printf(
_(
" --no-subscriptions do not dump subscriptions\n"));
1124 printf(
_(
" --no-table-access-method do not dump table access methods\n"));
1125 printf(
_(
" --no-tablespaces do not dump tablespace assignments\n"));
1126 printf(
_(
" --no-toast-compression do not dump TOAST compression methods\n"));
1127 printf(
_(
" --no-unlogged-table-data do not dump unlogged table data\n"));
1128 printf(
_(
" --on-conflict-do-nothing add ON CONFLICT DO NOTHING to INSERT commands\n"));
1129 printf(
_(
" --quote-all-identifiers quote all identifiers, even if not key words\n"));
1130 printf(
_(
" --rows-per-insert=NROWS number of rows per INSERT; implies --inserts\n"));
1131 printf(
_(
" --section=SECTION dump named section (pre-data, data, or post-data)\n"));
1132 printf(
_(
" --serializable-deferrable wait until the dump can run without anomalies\n"));
1133 printf(
_(
" --snapshot=SNAPSHOT use given snapshot for the dump\n"));
1134 printf(
_(
" --strict-names require table and/or schema include patterns to\n"
1135 " match at least one entity each\n"));
1136 printf(
_(
" --table-and-children=PATTERN dump only the specified table(s), including\n"
1137 " child and partition tables\n"));
1138 printf(
_(
" --use-set-session-authorization\n"
1139 " use SET SESSION AUTHORIZATION commands instead of\n"
1140 " ALTER OWNER commands to set ownership\n"));
1142 printf(
_(
"\nConnection options:\n"));
1143 printf(
_(
" -d, --dbname=DBNAME database to dump\n"));
1144 printf(
_(
" -h, --host=HOSTNAME database server host or socket directory\n"));
1145 printf(
_(
" -p, --port=PORT database server port number\n"));
1146 printf(
_(
" -U, --username=NAME connect as specified database user\n"));
1147 printf(
_(
" -w, --no-password never prompt for password\n"));
1148 printf(
_(
" -W, --password force password prompt (should happen automatically)\n"));
1149 printf(
_(
" --role=ROLENAME do SET ROLE before dump\n"));
1151 printf(
_(
"\nIf no database name is supplied, then the PGDATABASE environment\n"
1152 "variable value is used.\n\n"));
1153 printf(
_(
"Report bugs to <%s>.\n"), PACKAGE_BUGREPORT);
1154 printf(
_(
"%s home page: <%s>\n"), PACKAGE_NAME, PACKAGE_URL);
1159 const char *dumpsnapshot,
char *use_role)
1163 const char *std_strings;
1173 pg_fatal(
"invalid client encoding \"%s\" specified",
1184 AH->
std_strings = (std_strings && strcmp(std_strings,
"on") == 0);
1284 "SET TRANSACTION ISOLATION LEVEL "
1285 "SERIALIZABLE, READ ONLY, DEFERRABLE");
1288 "SET TRANSACTION ISOLATION LEVEL "
1289 "REPEATABLE READ, READ ONLY");
1311 pg_fatal(
"parallel dumps from standby servers are not supported by this server version");
1335 char *query =
"SELECT pg_catalog.pg_export_snapshot()";
1377 return archiveFormat;
1395 if (patterns->
head == NULL)
1405 for (cell = patterns->
head; cell; cell = cell->
next)
1411 "SELECT oid FROM pg_catalog.pg_namespace n\n");
1414 false, NULL,
"n.nspname", NULL, NULL, &dbbuf,
1417 pg_fatal(
"improper qualified name (too many dotted names): %s",
1419 else if (dotcnt == 1)
1425 pg_fatal(
"no matching schemas were found for pattern \"%s\"", cell->
val);
1454 if (patterns->
head == NULL)
1463 for (cell = patterns->
head; cell; cell = cell->
next)
1468 "SELECT oid FROM pg_catalog.pg_extension e\n");
1470 false, NULL,
"e.extname", NULL, NULL, NULL,
1473 pg_fatal(
"improper qualified name (too many dotted names): %s",
1478 pg_fatal(
"no matching extensions were found for pattern \"%s\"", cell->
val);
1506 if (patterns->
head == NULL)
1516 for (cell = patterns->
head; cell; cell = cell->
next)
1521 "SELECT oid FROM pg_catalog.pg_foreign_server s\n");
1523 false, NULL,
"s.srvname", NULL, NULL, NULL,
1526 pg_fatal(
"improper qualified name (too many dotted names): %s",
1531 pg_fatal(
"no matching foreign servers were found for pattern \"%s\"", cell->
val);
1558 if (patterns->
head == NULL)
1568 for (cell = patterns->
head; cell; cell = cell->
next)
1581 if (with_child_tables)
1588 "\nFROM pg_catalog.pg_class c"
1589 "\n LEFT JOIN pg_catalog.pg_namespace n"
1590 "\n ON n.oid OPERATOR(pg_catalog.=) c.relnamespace"
1591 "\nWHERE c.relkind OPERATOR(pg_catalog.=) ANY"
1592 "\n (array['%c', '%c', '%c', '%c', '%c', '%c'])\n",
1593 RELKIND_RELATION, RELKIND_SEQUENCE, RELKIND_VIEW,
1594 RELKIND_MATVIEW, RELKIND_FOREIGN_TABLE,
1595 RELKIND_PARTITIONED_TABLE);
1598 false,
"n.nspname",
"c.relname", NULL,
1599 "pg_catalog.pg_table_is_visible(c.oid)", &dbbuf,
1602 pg_fatal(
"improper relation name (too many dotted names): %s",
1604 else if (dotcnt == 2)
1608 if (with_child_tables)
1611 "\nSELECT i.inhrelid"
1612 "\nFROM partition_tree p"
1613 "\n JOIN pg_catalog.pg_inherits i"
1614 "\n ON p.relid OPERATOR(pg_catalog.=) i.inhparent"
1616 "\nSELECT relid FROM partition_tree");
1624 pg_fatal(
"no matching tables were found for pattern \"%s\"", cell->
val);
1651 pg_fatal(
"You are currently not connected to a database.");
1653 if (strcmp(db,
dbname) != 0)
1654 pg_fatal(
"cross-database references are not implemented: %s",
1740 strcmp(nsinfo->
dobj.
name,
"pg_catalog") == 0)
1749 else if (strncmp(nsinfo->
dobj.
name,
"pg_", 3) == 0 ||
1750 strcmp(nsinfo->
dobj.
name,
"information_schema") == 0)
1755 else if (strcmp(nsinfo->
dobj.
name,
"public") == 0)
1767 if (nsinfo->
nspowner == ROLE_PG_DATABASE_OWNER)
1847 tyinfo->
typrelkind != RELKIND_COMPOSITE_TYPE)
1852 if (tytable != NULL)
1892 if (dinfo->
dobj.namespace)
2054 if (dobj->namespace)
2071 const char *classname = tbinfo->
dobj.
name;
2083 const char *column_list;
2085 pg_log_info(
"dumping contents of table \"%s.%s\"",
2086 tbinfo->
dobj.namespace->dobj.
name, classname);
2105 if (strlen(column_list) > 2)
2191 pg_log_error(
"Dumping the contents of table \"%s\" failed: PQgetCopyData() failed.", classname);
2201 pg_log_error(
"Dumping the contents of table \"%s\" failed: PQgetResult() failed.", classname);
2210 pg_log_warning(
"unexpected extra results during COPY of table \"%s\"",
2238 int rows_this_statement = 0;
2283 pg_fatal(
"wrong number of fields retrieved from table \"%s\"",
2293 if (insertStmt == NULL)
2325 for (
int field = 0; field < nfields; field++)
2345 if (rows_this_statement == 0)
2361 if (rows_per_statement == 1)
2363 else if (rows_this_statement > 0)
2368 for (
int field = 0; field < nfields; field++)
2372 if (attgenerated[field])
2407 if (strspn(s,
"0123456789 +-eE.") == strlen(s))
2442 if (++rows_this_statement >= rows_per_statement)
2445 archputs(
" ON CONFLICT DO NOTHING;\n", fout);
2449 rows_this_statement = 0;
2462 if (rows_this_statement > 0)
2465 archputs(
" ON CONFLICT DO NOTHING;\n", fout);
2475 if (insertStmt != NULL)
2494 parentTbinfo = tbinfo->
parents[0];
2498 parentTbinfo = parentTbinfo->
parents[0];
2501 return parentTbinfo;
2519 parentTbinfo = tbinfo->
parents[0];
2525 parentTbinfo = parentTbinfo->
parents[0];
2547 char *tdDefn = NULL;
2549 const char *copyFrom;
2584 copyStmt = copyBuf->
data;
2604 .namespace = tbinfo->
dobj.namespace->dobj.
name,
2606 .description =
"TABLE DATA",
2608 .createStmt = tdDefn,
2609 .copyStmt = copyStmt,
2613 .dumpArg = tdinfo));
2671 .namespace = tbinfo->
dobj.namespace->dobj.
name,
2673 .description =
"MATERIALIZED VIEW DATA",
2675 .createStmt = q->
data,
2691 for (
i = 0;
i < numTables;
i++)
2694 (!relkind || tblinfo[
i].
relkind == relkind))
2718 if (tbinfo->
relkind == RELKIND_VIEW)
2721 if (tbinfo->
relkind == RELKIND_FOREIGN_TABLE &&
2727 if (tbinfo->
relkind == RELKIND_PARTITIONED_TABLE)
2743 if (tbinfo->
relkind == RELKIND_MATVIEW)
2745 else if (tbinfo->
relkind == RELKIND_SEQUENCE)
2758 tdinfo->
dobj.namespace = tbinfo->
dobj.namespace;
2798 "SELECT d1.objid, d2.refobjid, c2.relkind AS refrelkind "
2799 "FROM pg_depend d1 "
2800 "JOIN pg_class c1 ON c1.oid = d1.objid "
2802 " JOIN pg_rewrite r1 ON r1.ev_class = d1.objid "
2803 "JOIN pg_depend d2 ON d2.classid = 'pg_rewrite'::regclass "
2804 "AND d2.objid = r1.oid "
2805 "AND d2.refobjid <> d1.objid "
2806 "JOIN pg_class c2 ON c2.oid = d2.refobjid "
2807 "AND c2.relkind IN (" CppAsString2(RELKIND_MATVIEW)
","
2809 "WHERE d1.classid = 'pg_class'::regclass "
2811 "SELECT w.objid, d3.refobjid, c3.relkind "
2813 "JOIN pg_rewrite r3 ON r3.ev_class = w.refobjid "
2814 "JOIN pg_depend d3 ON d3.classid = 'pg_rewrite'::regclass "
2815 "AND d3.objid = r3.oid "
2816 "AND d3.refobjid <> w.refobjid "
2817 "JOIN pg_class c3 ON c3.oid = d3.refobjid "
2818 "AND c3.relkind IN (" CppAsString2(RELKIND_MATVIEW)
","
2821 "SELECT 'pg_class'::regclass::oid AS classid, objid, refobjid "
2833 for (
i = 0;
i < ntups;
i++)
2860 if (refdobj == NULL)
2867 if (refdobj == NULL)
2903 for (
i = 0;
i < numObjs;
i++)
2915 if (ftable == NULL ||
2988 "pg_encoding_to_char(encoding) AS encoding, "
2989 "datcollate, datctype, datfrozenxid, "
2990 "datacl, acldefault('d', datdba) AS acldefault, "
2991 "datistemplate, datconnlimit, ");
2999 appendPQExpBufferStr(dbQry,
"'c' AS datlocprovider, NULL AS daticulocale, NULL AS datcollversion, ");
3005 "(SELECT spcname FROM pg_tablespace t WHERE t.oid = dattablespace) AS tablespace, "
3006 "shobj_description(oid, 'pg_database') AS description "
3008 "WHERE datname = current_database()");
3066 appendPQExpBuffer(creaQry,
"CREATE DATABASE %s WITH TEMPLATE = template0 OID = %u",
3067 qdatname, dbCatId.
oid);
3086 pg_fatal(
"unrecognized locale provider: %s",
3089 if (strlen(collate) > 0 && strcmp(collate, ctype) == 0)
3096 if (strlen(collate) > 0)
3101 if (strlen(ctype) > 0)
3159 .createStmt = creaQry->
data,
3160 .dropStmt = delQry->
data));
3189 .description =
"COMMENT",
3191 .createStmt = dbQry->
data,
3209 if (seclabelQry->
len > 0)
3213 .description =
"SECURITY LABEL",
3215 .createStmt = seclabelQry->
data,
3230 qdatname, NULL, NULL,
3261 "SET datistemplate = false WHERE datname = ");
3277 "SET datfrozenxid = '%u', datminmxid = '%u'\n"
3279 frozenxid, minmxid);
3284 if (creaQry->
len > 0)
3290 .createStmt = creaQry->
data,
3291 .dropStmt = delQry->
data,
3292 .deps = &dbDumpId));
3304 int ii_relfrozenxid,
3313 appendPQExpBuffer(loFrozenQry,
"SELECT relfrozenxid, relminmxid, relfilenode, oid\n"
3314 "FROM pg_catalog.pg_class\n"
3315 "WHERE oid IN (%u, %u);\n",
3316 LargeObjectRelationId, LargeObjectLOidPNIndexId);
3318 appendPQExpBuffer(loFrozenQry,
"SELECT relfrozenxid, 0 AS relminmxid, relfilenode, oid\n"
3319 "FROM pg_catalog.pg_class\n"
3320 "WHERE oid IN (%u, %u);\n",
3321 LargeObjectRelationId, LargeObjectLOidPNIndexId);
3325 ii_relfrozenxid =
PQfnumber(lo_res,
"relfrozenxid");
3326 ii_relminmxid =
PQfnumber(lo_res,
"relminmxid");
3327 ii_relfilenode =
PQfnumber(lo_res,
"relfilenode");
3330 appendPQExpBufferStr(loHorizonQry,
"\n-- For binary upgrade, set pg_largeobject relfrozenxid and relminmxid\n");
3331 appendPQExpBufferStr(loOutQry,
"\n-- For binary upgrade, preserve pg_largeobject and index relfilenodes\n");
3338 "SET relfrozenxid = '%u', relminmxid = '%u'\n"
3339 "WHERE oid = %u;\n",
3347 if (oid == LargeObjectRelationId)
3349 "SELECT pg_catalog.binary_upgrade_set_next_heap_relfilenode('%u'::pg_catalog.oid);\n",
3351 else if (oid == LargeObjectLOidPNIndexId)
3353 "SELECT pg_catalog.binary_upgrade_set_next_index_relfilenode('%u'::pg_catalog.oid);\n",
3358 "TRUNCATE pg_catalog.pg_largeobject;\n");
3365 .createStmt = loOutQry->
data));
3397 "WHERE setrole = 0 AND setdatabase = '%u'::oid",
3404 "DATABASE",
dbname, NULL, NULL,
3411 "FROM pg_db_role_setting s, pg_roles r "
3412 "WHERE setrole = r.oid AND setdatabase = '%u'::oid",
3447 .createStmt = qry->
data));
3459 const char *stdstrings = AH->
std_strings ?
"on" :
"off";
3462 pg_log_info(
"saving standard_conforming_strings = %s",
3472 .createStmt = qry->
data));
3486 char **schemanames = NULL;
3487 int nschemanames = 0;
3498 "SELECT pg_catalog.current_schemas(false)");
3501 pg_fatal(
"could not parse result of current_schemas()");
3509 for (
i = 0;
i < nschemanames;
i++)
3526 .createStmt = qry->
data));
3561 "SELECT oid, lomowner, lomacl, "
3562 "acldefault('L', lomowner) AS acldefault "
3563 "FROM pg_largeobject_metadata");
3579 for (
i = 0;
i < ntups;
i++)
3641 "SELECT pg_catalog.lo_create('%s');\n",
3645 "SELECT pg_catalog.lo_unlink('%s');\n",
3652 .description =
"BLOB",
3654 .createStmt = cquery->
data,
3655 .dropStmt = dquery->
data));
3687 const char *loFetchQry;
3702 "DECLARE looid CURSOR FOR "
3703 "SELECT oid FROM pg_largeobject_metadata ORDER BY 1";
3708 loFetchQry =
"FETCH 1000 IN looid";
3717 for (
i = 0;
i < ntups;
i++)
3726 pg_fatal(
"could not open large object %u: %s",
3736 pg_fatal(
"error reading large object %u: %s",
3748 }
while (ntups > 0);
3769 int i_polpermissive;
3788 for (
i = 0;
i < numTables;
i++)
3797 if (tbinfo->
relkind != RELKIND_RELATION &&
3798 tbinfo->
relkind != RELKIND_PARTITIONED_TABLE)
3802 if (tbloids->
len > 1)
3823 polinfo->
dobj.namespace = tbinfo->
dobj.namespace;
3842 pg_log_info(
"reading row-level security policies");
3845 "SELECT pol.oid, pol.tableoid, pol.polrelid, pol.polname, pol.polcmd, ");
3851 "CASE WHEN pol.polroles = '{0}' THEN NULL ELSE "
3852 " 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, "
3853 "pg_catalog.pg_get_expr(pol.polqual, pol.polrelid) AS polqual, "
3854 "pg_catalog.pg_get_expr(pol.polwithcheck, pol.polrelid) AS polwithcheck "
3855 "FROM unnest('%s'::pg_catalog.oid[]) AS src(tbloid)\n"
3856 "JOIN pg_catalog.pg_policy pol ON (src.tbloid = pol.polrelid)",
3876 for (
j = 0;
j < ntups;
j++)
3888 polinfo[
j].
dobj.namespace = tbinfo->
dobj.namespace;
3897 polinfo[
j].polroles = NULL;
3960 .namespace = polinfo->
dobj.namespace->dobj.
name,
3962 .description =
"ROW SECURITY",
3964 .createStmt = query->
data,
3972 if (polinfo->
polcmd ==
'*')
3974 else if (polinfo->
polcmd ==
'r')
3975 cmd =
" FOR SELECT";
3976 else if (polinfo->
polcmd ==
'a')
3977 cmd =
" FOR INSERT";
3978 else if (polinfo->
polcmd ==
'w')
3979 cmd =
" FOR UPDATE";
3980 else if (polinfo->
polcmd ==
'd')
3981 cmd =
" FOR DELETE";
3983 pg_fatal(
"unexpected policy command type: %c",
4019 .
namespace = polinfo->
dobj.namespace->dobj.
name,
4021 .description =
"POLICY",
4023 .createStmt = query->
data,
4024 .dropStmt = delqry->
data));
4064 *numPublications = 0;
4075 "SELECT p.tableoid, p.oid, p.pubname, "
4077 "p.puballtables, p.pubinsert, p.pubupdate, p.pubdelete, p.pubtruncate, p.pubviaroot "
4078 "FROM pg_publication p");
4081 "SELECT p.tableoid, p.oid, p.pubname, "
4083 "p.puballtables, p.pubinsert, p.pubupdate, p.pubdelete, p.pubtruncate, false AS pubviaroot "
4084 "FROM pg_publication p");
4087 "SELECT p.tableoid, p.oid, p.pubname, "
4089 "p.puballtables, p.pubinsert, p.pubupdate, p.pubdelete, false AS pubtruncate, false AS pubviaroot "
4090 "FROM pg_publication p");
4109 for (
i = 0;
i < ntups;
i++)
4138 *numPublications = ntups;
4218 .description =
"PUBLICATION",
4220 .createStmt = query->
data,
4221 .dropStmt = delq->
data));
4264 "SELECT tableoid, oid, pnpubid, pnnspid "
4265 "FROM pg_catalog.pg_publication_namespace");
4279 for (
i = 0;
i < ntups;
i++)
4291 if (pubinfo == NULL)
4294 if (nspinfo == NULL)
4310 pubsinfo[
j].
dobj.namespace = nspinfo->
dobj.namespace;
4354 "SELECT tableoid, oid, prpubid, prrelid, "
4355 "pg_catalog.pg_get_expr(prqual, prrelid) AS prrelqual, "
4357 " WHEN pr.prattrs IS NOT NULL THEN\n"
4358 " (SELECT array_agg(attname)\n"
4360 " pg_catalog.generate_series(0, pg_catalog.array_upper(pr.prattrs::pg_catalog.int2[], 1)) s,\n"
4361 " pg_catalog.pg_attribute\n"
4362 " WHERE attrelid = pr.prrelid AND attnum = prattrs[s])\n"
4363 " ELSE NULL END) prattrs "
4364 "FROM pg_catalog.pg_publication_rel pr");
4367 "SELECT tableoid, oid, prpubid, prrelid, "
4368 "NULL AS prrelqual, NULL AS prattrs "
4369 "FROM pg_catalog.pg_publication_rel");
4385 for (
i = 0;
i < ntups;
i++)
4397 if (pubinfo == NULL)
4412 pubrinfo[
j].dobj.catId.tableoid =
4416 pubrinfo[
j].dobj.namespace = tbinfo->
dobj.namespace;
4417 pubrinfo[
j].dobj.name = tbinfo->
dobj.
name;
4418 pubrinfo[
j].publication = pubinfo;
4419 pubrinfo[
j].pubtable = tbinfo;
4421 pubrinfo[
j].pubrelqual = NULL;
4432 &attnames, &nattnames))
4433 pg_fatal(
"could not parse %s array",
"prattrs");
4435 for (
int k = 0; k < nattnames; k++)
4442 pubrinfo[
j].pubrattrs = attribs->
data;
4445 pubrinfo[
j].pubrattrs = NULL;
4488 .
namespace = schemainfo->
dobj.
name,
4490 .description =
"PUBLICATION TABLES IN SCHEMA",
4492 .createStmt = query->
data));
4526 if (pubrinfo->pubrattrs)
4529 if (pubrinfo->pubrelqual)
4548 ArchiveEntry(fout, pubrinfo->dobj.catId, pubrinfo->dobj.dumpId,
4550 .
namespace = tbinfo->
dobj.namespace->dobj.
name,
4552 .description =
"PUBLICATION TABLE",
4554 .createStmt = query->
data));
4573 if (
val && strcmp(
val,
"on") == 0)
4595 int i_subtwophasestate;
4596 int i_subdisableonerr;
4600 int i_subsynccommit;
4601 int i_subpublications;
4603 int i_subpasswordrequired;
4615 "SELECT count(*) FROM pg_subscription "
4616 "WHERE subdbid = (SELECT oid FROM pg_database"
4617 " WHERE datname = current_database())",
4621 pg_log_warning(
"subscriptions not dumped because current user is not a superuser");
4630 "SELECT s.tableoid, s.oid, s.subname,\n"
4632 " s.subconninfo, s.subslotname, s.subsynccommit,\n"
4633 " s.subpublications,\n");
4647 " s.subtwophasestate,\n"
4648 " s.subdisableonerr,\n");
4651 " '%c' AS subtwophasestate,\n"
4652 " false AS subdisableonerr,\n",
4658 " s.subpasswordrequired\n");
4661 " '%s' AS suborigin,\n"
4662 " 't' AS subpasswordrequired\n",
4666 "FROM pg_subscription s\n"
4667 "WHERE s.subdbid = (SELECT oid FROM pg_database\n"
4668 " WHERE datname = current_database())");
4688 i_subtwophasestate =
PQfnumber(
res,
"subtwophasestate");
4691 i_subpasswordrequired =
PQfnumber(
res,
"subpasswordrequired");
4695 for (
i = 0;
i < ntups;
i++)
4745 char **pubnames = NULL;
4768 pg_fatal(
"could not parse %s array",
"subpublications");
4771 for (
i = 0;
i < npubnames;
i++)
4779 appendPQExpBuffer(query,
" PUBLICATION %s WITH (connect = false, slot_name = ", publications->
data);
4785 if (strcmp(subinfo->
subbinary,
"t") == 0)
4788 if (strcmp(subinfo->
substream,
"t") == 0)
4790 else if (strcmp(subinfo->
substream,
"p") == 0)
4814 .description =
"SUBSCRIPTION",
4816 .createStmt = query->
data,
4817 .dropStmt = delq->
data));
4845 const char *catalog,
4846 const char *keyword,
4847 const char *objname)
4864 "FROM pg_catalog.pg_depend d, pg_catalog.pg_extension e "
4865 "WHERE d.refobjid = e.oid AND classid = '%s'::pg_catalog.regclass "
4866 "AND objid = '%u'::pg_catalog.oid AND deptype = 'x' "
4867 "AND refclassid = 'pg_catalog.pg_extension'::pg_catalog.regclass",
4873 for (
i = 0;
i < ntups;
i++)
4903 ++next_possible_free_oid;
4905 "SELECT EXISTS(SELECT 1 "
4906 "FROM pg_catalog.pg_type "
4907 "WHERE oid = '%u'::pg_catalog.oid);",
4908 next_possible_free_oid);
4914 return next_possible_free_oid;
4921 bool force_array_type,
4922 bool include_multirange_type)
4926 Oid pg_type_array_oid;
4927 Oid pg_type_multirange_oid;
4928 Oid pg_type_multirange_array_oid;
4932 "SELECT pg_catalog.binary_upgrade_set_next_pg_type_oid('%u'::pg_catalog.oid);\n\n",
4937 "FROM pg_catalog.pg_type "
4938 "WHERE oid = '%u'::pg_catalog.oid;",
4947 if (!
OidIsValid(pg_type_array_oid) && force_array_type)
4953 "\n-- For binary upgrade, must preserve pg_type array oid\n");
4955 "SELECT pg_catalog.binary_upgrade_set_next_array_pg_type_oid('%u'::pg_catalog.oid);\n\n",
4962 if (include_multirange_type)
4967 "SELECT t.oid, t.typarray "
4968 "FROM pg_catalog.pg_type t "
4969 "JOIN pg_catalog.pg_range r "
4970 "ON t.oid = r.rngmultitypid "
4971 "WHERE r.rngtypid = '%u'::pg_catalog.oid;",