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"
161 #define DUMP_DEFAULT_ROWS_PER_INSERT 1
166 #define fmtQualifiedDumpable(obj) \
167 fmtQualifiedId((obj)->dobj.namespace->dobj.name, \
172 const char *dumpencoding,
const char *dumpsnapshot,
190 bool with_child_tables);
192 const char *pattern);
197 static const char *
getRoleName(
const char *roleoid_str);
201 const char *
name,
const char *
namespace,
204 const char *initdb_comment);
206 const char *
name,
const char *
namespace,
208 int subid,
DumpId dumpId);
212 const char *
namespace,
const char *owner,
261 const char *servername,
const char *
namespace,
267 const char *nspname,
const char *owner,
273 DumpId **dependencies,
int *nDeps,
int *allocDeps);
288 const FuncInfo *finfo,
bool honor_quotes);
310 bool force_array_type,
311 bool include_multirange_type);
317 Oid pg_class_oid,
bool is_index);
322 const char *objnamespace);
327 const char *prefix,
Archive *fout);
350 bool g_verbose =
false;
351 const char *dumpencoding = NULL;
352 const char *dumpsnapshot = NULL;
353 char *use_role = NULL;
359 char *compression_detail = NULL;
360 char *compression_algorithm_str =
"none";
361 char *error_detail = NULL;
362 bool user_compression_defined =
false;
367 static struct option long_options[] = {
380 {
"jobs", 1, NULL,
'j'},
458 if (strcmp(argv[1],
"--help") == 0 || strcmp(argv[1],
"-?") == 0)
463 if (strcmp(argv[1],
"--version") == 0 || strcmp(argv[1],
"-V") == 0)
465 puts(
"pg_dump (PostgreSQL) " PG_VERSION);
472 while ((
c =
getopt_long(argc, argv,
"abBcCd:e:E:f:F:h:j:n:N:Op:RsS:t:T:U:vwWxZ:",
473 long_options, &optindex)) != -1)
590 &compression_detail);
591 user_compression_defined =
true;
692 pg_log_error(
"too many command-line arguments (first is \"%s\")",
711 pg_fatal(
"options -s/--schema-only and -a/--data-only cannot be used together");
714 pg_fatal(
"options -s/--schema-only and --include-foreign-data cannot be used together");
717 pg_fatal(
"option --include-foreign-data is not supported with parallel backup");
720 pg_fatal(
"options -c/--clean and -a/--data-only cannot be used together");
723 pg_fatal(
"option --if-exists requires option -c/--clean");
730 pg_fatal(
"option --on-conflict-do-nothing requires option --inserts, --rows-per-insert, or --column-inserts");
745 !user_compression_defined)
748 compression_algorithm_str =
"gzip";
750 compression_algorithm_str =
"none";
759 pg_fatal(
"unrecognized compression algorithm: \"%s\"",
760 compression_algorithm_str);
765 if (error_detail != NULL)
766 pg_fatal(
"invalid compression specification: %s",
770 if (error_detail != NULL)
779 pg_log_warning(
"compression option \"%s\" is not currently supported by pg_dump",
791 pg_fatal(
"parallel backup only supported by the directory format");
846 pg_fatal(
"no matching schemas were found");
863 pg_fatal(
"no matching tables were found");
891 pg_fatal(
"no matching extensions were found");
926 getTableData(&dopt, tblinfo, numTables, RELKIND_SEQUENCE);
975 boundaryObjs[0].dumpId, boundaryObjs[1].dumpId);
994 for (
i = 0;
i < numObjs;
i++)
1071 printf(
_(
"%s dumps a database as a text file or to other formats.\n\n"),
progname);
1075 printf(
_(
"\nGeneral options:\n"));
1076 printf(
_(
" -f, --file=FILENAME output file or directory name\n"));
1077 printf(
_(
" -F, --format=c|d|t|p output file format (custom, directory, tar,\n"
1078 " plain text (default))\n"));
1079 printf(
_(
" -j, --jobs=NUM use this many parallel jobs to dump\n"));
1080 printf(
_(
" -v, --verbose verbose mode\n"));
1081 printf(
_(
" -V, --version output version information, then exit\n"));
1082 printf(
_(
" -Z, --compress=METHOD[:DETAIL]\n"
1083 " compress as specified\n"));
1084 printf(
_(
" --lock-wait-timeout=TIMEOUT fail after waiting TIMEOUT for a table lock\n"));
1085 printf(
_(
" --no-sync do not wait for changes to be written safely to disk\n"));
1086 printf(
_(
" --sync-method=METHOD set method for syncing files to disk\n"));
1087 printf(
_(
" -?, --help show this help, then exit\n"));
1089 printf(
_(
"\nOptions controlling the output content:\n"));
1090 printf(
_(
" -a, --data-only dump only the data, not the schema\n"));
1091 printf(
_(
" -b, --large-objects include large objects in dump\n"));
1092 printf(
_(
" --blobs (same as --large-objects, deprecated)\n"));
1093 printf(
_(
" -B, --no-large-objects exclude large objects in dump\n"));
1094 printf(
_(
" --no-blobs (same as --no-large-objects, deprecated)\n"));
1095 printf(
_(
" -c, --clean clean (drop) database objects before recreating\n"));
1096 printf(
_(
" -C, --create include commands to create database in dump\n"));
1097 printf(
_(
" -e, --extension=PATTERN dump the specified extension(s) only\n"));
1098 printf(
_(
" -E, --encoding=ENCODING dump the data in encoding ENCODING\n"));
1099 printf(
_(
" -n, --schema=PATTERN dump the specified schema(s) only\n"));
1100 printf(
_(
" -N, --exclude-schema=PATTERN do NOT dump the specified schema(s)\n"));
1101 printf(
_(
" -O, --no-owner skip restoration of object ownership in\n"
1102 " plain-text format\n"));
1103 printf(
_(
" -s, --schema-only dump only the schema, no data\n"));
1104 printf(
_(
" -S, --superuser=NAME superuser user name to use in plain-text format\n"));
1105 printf(
_(
" -t, --table=PATTERN dump only the specified table(s)\n"));
1106 printf(
_(
" -T, --exclude-table=PATTERN do NOT dump the specified table(s)\n"));
1107 printf(
_(
" -x, --no-privileges do not dump privileges (grant/revoke)\n"));
1108 printf(
_(
" --binary-upgrade for use by upgrade utilities only\n"));
1109 printf(
_(
" --column-inserts dump data as INSERT commands with column names\n"));
1110 printf(
_(
" --disable-dollar-quoting disable dollar quoting, use SQL standard quoting\n"));
1111 printf(
_(
" --disable-triggers disable triggers during data-only restore\n"));
1112 printf(
_(
" --enable-row-security enable row security (dump only content user has\n"
1114 printf(
_(
" --exclude-table-and-children=PATTERN\n"
1115 " do NOT dump the specified table(s), including\n"
1116 " child and partition tables\n"));
1117 printf(
_(
" --exclude-table-data=PATTERN do NOT dump data for the specified table(s)\n"));
1118 printf(
_(
" --exclude-table-data-and-children=PATTERN\n"
1119 " do NOT dump data for the specified table(s),\n"
1120 " including child and partition tables\n"));
1121 printf(
_(
" --extra-float-digits=NUM override default setting for extra_float_digits\n"));
1122 printf(
_(
" --filter=FILENAME include or exclude objects and data from dump\n"
1123 " based on expressions in FILENAME\n"));
1124 printf(
_(
" --if-exists use IF EXISTS when dropping objects\n"));
1125 printf(
_(
" --include-foreign-data=PATTERN\n"
1126 " include data of foreign tables on foreign\n"
1127 " servers matching PATTERN\n"));
1128 printf(
_(
" --inserts dump data as INSERT commands, rather than COPY\n"));
1129 printf(
_(
" --load-via-partition-root load partitions via the root table\n"));
1130 printf(
_(
" --no-comments do not dump comments\n"));
1131 printf(
_(
" --no-publications do not dump publications\n"));
1132 printf(
_(
" --no-security-labels do not dump security label assignments\n"));
1133 printf(
_(
" --no-subscriptions do not dump subscriptions\n"));
1134 printf(
_(
" --no-table-access-method do not dump table access methods\n"));
1135 printf(
_(
" --no-tablespaces do not dump tablespace assignments\n"));
1136 printf(
_(
" --no-toast-compression do not dump TOAST compression methods\n"));
1137 printf(
_(
" --no-unlogged-table-data do not dump unlogged table data\n"));
1138 printf(
_(
" --on-conflict-do-nothing add ON CONFLICT DO NOTHING to INSERT commands\n"));
1139 printf(
_(
" --quote-all-identifiers quote all identifiers, even if not key words\n"));
1140 printf(
_(
" --rows-per-insert=NROWS number of rows per INSERT; implies --inserts\n"));
1141 printf(
_(
" --section=SECTION dump named section (pre-data, data, or post-data)\n"));
1142 printf(
_(
" --serializable-deferrable wait until the dump can run without anomalies\n"));
1143 printf(
_(
" --snapshot=SNAPSHOT use given snapshot for the dump\n"));
1144 printf(
_(
" --strict-names require table and/or schema include patterns to\n"
1145 " match at least one entity each\n"));
1146 printf(
_(
" --table-and-children=PATTERN dump only the specified table(s), including\n"
1147 " child and partition tables\n"));
1148 printf(
_(
" --use-set-session-authorization\n"
1149 " use SET SESSION AUTHORIZATION commands instead of\n"
1150 " ALTER OWNER commands to set ownership\n"));
1152 printf(
_(
"\nConnection options:\n"));
1153 printf(
_(
" -d, --dbname=DBNAME database to dump\n"));
1154 printf(
_(
" -h, --host=HOSTNAME database server host or socket directory\n"));
1155 printf(
_(
" -p, --port=PORT database server port number\n"));
1156 printf(
_(
" -U, --username=NAME connect as specified database user\n"));
1157 printf(
_(
" -w, --no-password never prompt for password\n"));
1158 printf(
_(
" -W, --password force password prompt (should happen automatically)\n"));
1159 printf(
_(
" --role=ROLENAME do SET ROLE before dump\n"));
1161 printf(
_(
"\nIf no database name is supplied, then the PGDATABASE environment\n"
1162 "variable value is used.\n\n"));
1163 printf(
_(
"Report bugs to <%s>.\n"), PACKAGE_BUGREPORT);
1164 printf(
_(
"%s home page: <%s>\n"), PACKAGE_NAME, PACKAGE_URL);
1169 const char *dumpsnapshot,
char *use_role)
1173 const char *std_strings;
1183 pg_fatal(
"invalid client encoding \"%s\" specified",
1194 AH->
std_strings = (std_strings && strcmp(std_strings,
"on") == 0);
1296 "SET TRANSACTION ISOLATION LEVEL "
1297 "SERIALIZABLE, READ ONLY, DEFERRABLE");
1300 "SET TRANSACTION ISOLATION LEVEL "
1301 "REPEATABLE READ, READ ONLY");
1323 pg_fatal(
"parallel dumps from standby servers are not supported by this server version");
1347 char *query =
"SELECT pg_catalog.pg_export_snapshot()";
1389 return archiveFormat;
1407 if (patterns->
head == NULL)
1417 for (cell = patterns->
head; cell; cell = cell->
next)
1423 "SELECT oid FROM pg_catalog.pg_namespace n\n");
1426 false, NULL,
"n.nspname", NULL, NULL, &dbbuf,
1429 pg_fatal(
"improper qualified name (too many dotted names): %s",
1431 else if (dotcnt == 1)
1437 pg_fatal(
"no matching schemas were found for pattern \"%s\"", cell->
val);
1466 if (patterns->
head == NULL)
1475 for (cell = patterns->
head; cell; cell = cell->
next)
1480 "SELECT oid FROM pg_catalog.pg_extension e\n");
1482 false, NULL,
"e.extname", NULL, NULL, NULL,
1485 pg_fatal(
"improper qualified name (too many dotted names): %s",
1490 pg_fatal(
"no matching extensions were found for pattern \"%s\"", cell->
val);
1518 if (patterns->
head == NULL)
1528 for (cell = patterns->
head; cell; cell = cell->
next)
1533 "SELECT oid FROM pg_catalog.pg_foreign_server s\n");
1535 false, NULL,
"s.srvname", NULL, NULL, NULL,
1538 pg_fatal(
"improper qualified name (too many dotted names): %s",
1543 pg_fatal(
"no matching foreign servers were found for pattern \"%s\"", cell->
val);
1570 if (patterns->
head == NULL)
1580 for (cell = patterns->
head; cell; cell = cell->
next)
1593 if (with_child_tables)
1600 "\nFROM pg_catalog.pg_class c"
1601 "\n LEFT JOIN pg_catalog.pg_namespace n"
1602 "\n ON n.oid OPERATOR(pg_catalog.=) c.relnamespace"
1603 "\nWHERE c.relkind OPERATOR(pg_catalog.=) ANY"
1604 "\n (array['%c', '%c', '%c', '%c', '%c', '%c'])\n",
1605 RELKIND_RELATION, RELKIND_SEQUENCE, RELKIND_VIEW,
1606 RELKIND_MATVIEW, RELKIND_FOREIGN_TABLE,
1607 RELKIND_PARTITIONED_TABLE);
1610 false,
"n.nspname",
"c.relname", NULL,
1611 "pg_catalog.pg_table_is_visible(c.oid)", &dbbuf,
1614 pg_fatal(
"improper relation name (too many dotted names): %s",
1616 else if (dotcnt == 2)
1620 if (with_child_tables)
1623 "\nSELECT i.inhrelid"
1624 "\nFROM partition_tree p"
1625 "\n JOIN pg_catalog.pg_inherits i"
1626 "\n ON p.relid OPERATOR(pg_catalog.=) i.inhparent"
1628 "\nSELECT relid FROM partition_tree");
1636 pg_fatal(
"no matching tables were found for pattern \"%s\"", cell->
val);
1663 pg_fatal(
"You are currently not connected to a database.");
1665 if (strcmp(db,
dbname) != 0)
1666 pg_fatal(
"cross-database references are not implemented: %s",
1754 strcmp(nsinfo->
dobj.
name,
"pg_catalog") == 0)
1763 else if (strncmp(nsinfo->
dobj.
name,
"pg_", 3) == 0 ||
1764 strcmp(nsinfo->
dobj.
name,
"information_schema") == 0)
1769 else if (strcmp(nsinfo->
dobj.
name,
"public") == 0)
1781 if (nsinfo->
nspowner == ROLE_PG_DATABASE_OWNER)
1861 tyinfo->
typrelkind != RELKIND_COMPOSITE_TYPE)
1866 if (tytable != NULL)
1906 if (dinfo->
dobj.namespace)
2088 if (dobj->namespace)
2105 const char *classname = tbinfo->
dobj.
name;
2117 const char *column_list;
2119 pg_log_info(
"dumping contents of table \"%s.%s\"",
2120 tbinfo->
dobj.namespace->dobj.
name, classname);
2139 if (strlen(column_list) > 2)
2225 pg_log_error(
"Dumping the contents of table \"%s\" failed: PQgetCopyData() failed.", classname);
2235 pg_log_error(
"Dumping the contents of table \"%s\" failed: PQgetResult() failed.", classname);
2244 pg_log_warning(
"unexpected extra results during COPY of table \"%s\"",
2272 int rows_this_statement = 0;
2317 pg_fatal(
"wrong number of fields retrieved from table \"%s\"",
2327 if (insertStmt == NULL)
2359 for (
int field = 0; field < nfields; field++)
2379 if (rows_this_statement == 0)
2395 if (rows_per_statement == 1)
2397 else if (rows_this_statement > 0)
2402 for (
int field = 0; field < nfields; field++)
2406 if (attgenerated[field])
2441 if (strspn(s,
"0123456789 +-eE.") == strlen(s))
2476 if (++rows_this_statement >= rows_per_statement)
2479 archputs(
" ON CONFLICT DO NOTHING;\n", fout);
2483 rows_this_statement = 0;
2496 if (rows_this_statement > 0)
2499 archputs(
" ON CONFLICT DO NOTHING;\n", fout);
2509 if (insertStmt != NULL)
2528 parentTbinfo = tbinfo->
parents[0];
2532 parentTbinfo = parentTbinfo->
parents[0];
2535 return parentTbinfo;
2553 parentTbinfo = tbinfo->
parents[0];
2559 parentTbinfo = parentTbinfo->
parents[0];
2581 char *tdDefn = NULL;
2583 const char *copyFrom;
2618 copyStmt = copyBuf->
data;
2638 .namespace = tbinfo->
dobj.namespace->dobj.
name,
2640 .description =
"TABLE DATA",
2642 .createStmt = tdDefn,
2643 .copyStmt = copyStmt,
2647 .dumpArg = tdinfo));
2705 .namespace = tbinfo->
dobj.namespace->dobj.
name,
2707 .description =
"MATERIALIZED VIEW DATA",
2709 .createStmt = q->
data,
2725 for (
i = 0;
i < numTables;
i++)
2728 (!relkind || tblinfo[
i].
relkind == relkind))
2752 if (tbinfo->
relkind == RELKIND_VIEW)
2755 if (tbinfo->
relkind == RELKIND_FOREIGN_TABLE &&
2761 if (tbinfo->
relkind == RELKIND_PARTITIONED_TABLE)
2777 if (tbinfo->
relkind == RELKIND_MATVIEW)
2779 else if (tbinfo->
relkind == RELKIND_SEQUENCE)
2792 tdinfo->
dobj.namespace = tbinfo->
dobj.namespace;
2832 "SELECT d1.objid, d2.refobjid, c2.relkind AS refrelkind "
2833 "FROM pg_depend d1 "
2834 "JOIN pg_class c1 ON c1.oid = d1.objid "
2836 " JOIN pg_rewrite r1 ON r1.ev_class = d1.objid "
2837 "JOIN pg_depend d2 ON d2.classid = 'pg_rewrite'::regclass "
2838 "AND d2.objid = r1.oid "
2839 "AND d2.refobjid <> d1.objid "
2840 "JOIN pg_class c2 ON c2.oid = d2.refobjid "
2841 "AND c2.relkind IN (" CppAsString2(RELKIND_MATVIEW)
","
2843 "WHERE d1.classid = 'pg_class'::regclass "
2845 "SELECT w.objid, d3.refobjid, c3.relkind "
2847 "JOIN pg_rewrite r3 ON r3.ev_class = w.refobjid "
2848 "JOIN pg_depend d3 ON d3.classid = 'pg_rewrite'::regclass "
2849 "AND d3.objid = r3.oid "
2850 "AND d3.refobjid <> w.refobjid "
2851 "JOIN pg_class c3 ON c3.oid = d3.refobjid "
2852 "AND c3.relkind IN (" CppAsString2(RELKIND_MATVIEW)
","
2855 "SELECT 'pg_class'::regclass::oid AS classid, objid, refobjid "
2867 for (
i = 0;
i < ntups;
i++)
2894 if (refdobj == NULL)
2901 if (refdobj == NULL)
2937 for (
i = 0;
i < numObjs;
i++)
2949 if (ftable == NULL ||
3022 "pg_encoding_to_char(encoding) AS encoding, "
3023 "datcollate, datctype, datfrozenxid, "
3024 "datacl, acldefault('d', datdba) AS acldefault, "
3025 "datistemplate, datconnlimit, ");
3035 appendPQExpBufferStr(dbQry,
"'c' AS datlocprovider, NULL AS datlocale, NULL AS datcollversion, ");
3041 "(SELECT spcname FROM pg_tablespace t WHERE t.oid = dattablespace) AS tablespace, "
3042 "shobj_description(oid, 'pg_database') AS description "
3044 "WHERE datname = current_database()");
3102 appendPQExpBuffer(creaQry,
"CREATE DATABASE %s WITH TEMPLATE = template0 OID = %u",
3103 qdatname, dbCatId.
oid);
3124 pg_fatal(
"unrecognized locale provider: %s",
3127 if (strlen(collate) > 0 && strcmp(collate, ctype) == 0)
3134 if (strlen(collate) > 0)
3139 if (strlen(ctype) > 0)
3202 .createStmt = creaQry->
data,
3203 .dropStmt = delQry->
data));
3232 .description =
"COMMENT",
3234 .createStmt = dbQry->
data,
3252 if (seclabelQry->
len > 0)
3256 .description =
"SECURITY LABEL",
3258 .createStmt = seclabelQry->
data,
3273 qdatname, NULL, NULL,
3304 "SET datistemplate = false WHERE datname = ");
3325 "SET datfrozenxid = '%u', datminmxid = '%u'\n"
3327 frozenxid, minmxid);
3332 if (creaQry->
len > 0)
3338 .createStmt = creaQry->
data,
3339 .dropStmt = delQry->
data,
3340 .deps = &dbDumpId));
3352 int ii_relfrozenxid,
3361 appendPQExpBuffer(loFrozenQry,
"SELECT relfrozenxid, relminmxid, relfilenode, oid\n"
3362 "FROM pg_catalog.pg_class\n"
3363 "WHERE oid IN (%u, %u);\n",
3364 LargeObjectRelationId, LargeObjectLOidPNIndexId);
3366 appendPQExpBuffer(loFrozenQry,
"SELECT relfrozenxid, 0 AS relminmxid, relfilenode, oid\n"
3367 "FROM pg_catalog.pg_class\n"
3368 "WHERE oid IN (%u, %u);\n",
3369 LargeObjectRelationId, LargeObjectLOidPNIndexId);
3373 ii_relfrozenxid =
PQfnumber(lo_res,
"relfrozenxid");
3374 ii_relminmxid =
PQfnumber(lo_res,
"relminmxid");
3375 ii_relfilenode =
PQfnumber(lo_res,
"relfilenode");
3378 appendPQExpBufferStr(loHorizonQry,
"\n-- For binary upgrade, set pg_largeobject relfrozenxid and relminmxid\n");
3379 appendPQExpBufferStr(loOutQry,
"\n-- For binary upgrade, preserve pg_largeobject and index relfilenodes\n");
3386 "SET relfrozenxid = '%u', relminmxid = '%u'\n"
3387 "WHERE oid = %u;\n",
3395 if (oid == LargeObjectRelationId)
3397 "SELECT pg_catalog.binary_upgrade_set_next_heap_relfilenode('%u'::pg_catalog.oid);\n",
3399 else if (oid == LargeObjectLOidPNIndexId)
3401 "SELECT pg_catalog.binary_upgrade_set_next_index_relfilenode('%u'::pg_catalog.oid);\n",
3406 "TRUNCATE pg_catalog.pg_largeobject;\n");
3413 .createStmt = loOutQry->
data));
3445 "WHERE setrole = 0 AND setdatabase = '%u'::oid",
3452 "DATABASE",
dbname, NULL, NULL,
3459 "FROM pg_db_role_setting s, pg_roles r "
3460 "WHERE setrole = r.oid AND setdatabase = '%u'::oid",
3495 .createStmt = qry->
data));
3507 const char *stdstrings = AH->
std_strings ?
"on" :
"off";
3510 pg_log_info(
"saving standard_conforming_strings = %s",
3520 .createStmt = qry->
data));
3534 char **schemanames = NULL;
3535 int nschemanames = 0;
3546 "SELECT pg_catalog.current_schemas(false)");
3549 pg_fatal(
"could not parse result of current_schemas()");
3557 for (
i = 0;
i < nschemanames;
i++)
3574 .createStmt = qry->
data));
3609 "SELECT oid, lomowner, lomacl, "
3610 "acldefault('L', lomowner) AS acldefault "
3611 "FROM pg_largeobject_metadata");
3627 for (
i = 0;
i < ntups;
i++)
3689 "SELECT pg_catalog.lo_create('%s');\n",
3693 "SELECT pg_catalog.lo_unlink('%s');\n",
3700 .description =
"BLOB",
3702 .createStmt = cquery->
data,
3703 .dropStmt = dquery->
data));
3735 const char *loFetchQry;
3750 "DECLARE looid CURSOR FOR "
3751 "SELECT oid FROM pg_largeobject_metadata ORDER BY 1";
3756 loFetchQry =
"FETCH 1000 IN looid";
3765 for (
i = 0;
i < ntups;
i++)
3774 pg_fatal(
"could not open large object %u: %s",
3784 pg_fatal(
"error reading large object %u: %s",
3796 }
while (ntups > 0);
3817 int i_polpermissive;
3836 for (
i = 0;
i < numTables;
i++)
3845 if (tbinfo->
relkind != RELKIND_RELATION &&
3846 tbinfo->
relkind != RELKIND_PARTITIONED_TABLE)
3850 if (tbloids->
len > 1)
3871 polinfo->
dobj.namespace = tbinfo->
dobj.namespace;
3890 pg_log_info(
"reading row-level security policies");
3893 "SELECT pol.oid, pol.tableoid, pol.polrelid, pol.polname, pol.polcmd, ");
3899 "CASE WHEN pol.polroles = '{0}' THEN NULL ELSE "
3900 " 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, "
3901 "pg_catalog.pg_get_expr(pol.polqual, pol.polrelid) AS polqual, "
3902 "pg_catalog.pg_get_expr(pol.polwithcheck, pol.polrelid) AS polwithcheck "
3903 "FROM unnest('%s'::pg_catalog.oid[]) AS src(tbloid)\n"
3904 "JOIN pg_catalog.pg_policy pol ON (src.tbloid = pol.polrelid)",
3924 for (
j = 0;
j < ntups;
j++)
3936 polinfo[
j].
dobj.namespace = tbinfo->
dobj.namespace;
3945 polinfo[
j].polroles = NULL;
4008 .namespace = polinfo->
dobj.namespace->dobj.
name,
4010 .description =
"ROW SECURITY",
4012 .createStmt = query->
data,
4020 if (polinfo->
polcmd ==
'*')
4022 else if (polinfo->
polcmd ==
'r')
4023 cmd =
" FOR SELECT";
4024 else if (polinfo->
polcmd ==
'a')
4025 cmd =
" FOR INSERT";
4026 else if (polinfo->
polcmd ==
'w')
4027 cmd =
" FOR UPDATE";
4028 else if (polinfo->
polcmd ==
'd')
4029 cmd =
" FOR DELETE";
4031 pg_fatal(
"unexpected policy command type: %c",
4067 .
namespace = polinfo->
dobj.namespace->dobj.
name,
4069 .description =
"POLICY",
4071 .createStmt = query->
data,
4072 .dropStmt = delqry->
data));
4112 *numPublications = 0;
4123 "SELECT p.tableoid, p.oid, p.pubname, "
4125 "p.puballtables, p.pubinsert, p.pubupdate, p.pubdelete, p.pubtruncate, p.pubviaroot "
4126 "FROM pg_publication p");
4129 "SELECT p.tableoid, p.oid, p.pubname, "
4131 "p.puballtables, p.pubinsert, p.pubupdate, p.pubdelete, p.pubtruncate, false AS pubviaroot "
4132 "FROM pg_publication p");
4135 "SELECT p.tableoid, p.oid, p.pubname, "
4137 "p.puballtables, p.pubinsert, p.pubupdate, p.pubdelete, false AS pubtruncate, false AS pubviaroot "
4138 "FROM pg_publication p");
4157 for (
i = 0;
i < ntups;
i++)
4186 *numPublications = ntups;
4266 .description =
"PUBLICATION",
4268 .createStmt = query->
data,
4269 .dropStmt = delq->
data));
4312 "SELECT tableoid, oid, pnpubid, pnnspid "
4313 "FROM pg_catalog.pg_publication_namespace");
4327 for (
i = 0;
i < ntups;
i++)
4339 if (pubinfo == NULL)
4342 if (nspinfo == NULL)
4358 pubsinfo[
j].
dobj.namespace = nspinfo->
dobj.namespace;
4402 "SELECT tableoid, oid, prpubid, prrelid, "
4403 "pg_catalog.pg_get_expr(prqual, prrelid) AS prrelqual, "
4405 " WHEN pr.prattrs IS NOT NULL THEN\n"
4406 " (SELECT array_agg(attname)\n"
4408 " pg_catalog.generate_series(0, pg_catalog.array_upper(pr.prattrs::pg_catalog.int2[], 1)) s,\n"
4409 " pg_catalog.pg_attribute\n"
4410 " WHERE attrelid = pr.prrelid AND attnum = prattrs[s])\n"
4411 " ELSE NULL END) prattrs "
4412 "FROM pg_catalog.pg_publication_rel pr");
4415 "SELECT tableoid, oid, prpubid, prrelid, "
4416 "NULL AS prrelqual, NULL AS prattrs "
4417 "FROM pg_catalog.pg_publication_rel");
4433 for (
i = 0;
i < ntups;
i++)
4445 if (pubinfo == NULL)
4460 pubrinfo[
j].dobj.catId.tableoid =
4464 pubrinfo[
j].dobj.namespace = tbinfo->
dobj.namespace;
4465 pubrinfo[
j].dobj.name = tbinfo->
dobj.
name;
4466 pubrinfo[
j].publication = pubinfo;
4467 pubrinfo[
j].pubtable = tbinfo;
4469 pubrinfo[
j].pubrelqual = NULL;
4480 &attnames, &nattnames))
4481 pg_fatal(
"could not parse %s array",
"prattrs");
4483 for (
int k = 0; k < nattnames; k++)
4490 pubrinfo[
j].pubrattrs = attribs->
data;
4493 pubrinfo[
j].pubrattrs = NULL;
4536 .
namespace = schemainfo->
dobj.
name,
4538 .description =
"PUBLICATION TABLES IN SCHEMA",
4540 .createStmt = query->
data));
4574 if (pubrinfo->pubrattrs)
4577 if (pubrinfo->pubrelqual)
4596 ArchiveEntry(fout, pubrinfo->dobj.catId, pubrinfo->dobj.dumpId,
4598 .
namespace = tbinfo->
dobj.namespace->dobj.
name,
4600 .description =
"PUBLICATION TABLE",
4602 .createStmt = query->
data));
4621 if (
val && strcmp(
val,
"on") == 0)
4644 int i_subtwophasestate;
4645 int i_subdisableonerr;
4646 int i_subpasswordrequired;
4647 int i_subrunasowner;
4650 int i_subsynccommit;
4651 int i_subpublications;
4653 int i_suboriginremotelsn;
4667 "SELECT count(*) FROM pg_subscription "
4668 "WHERE subdbid = (SELECT oid FROM pg_database"
4669 " WHERE datname = current_database())",
4673 pg_log_warning(
"subscriptions not dumped because current user is not a superuser");
4682 "SELECT s.tableoid, s.oid, s.subname,\n"
4684 " s.subconninfo, s.subslotname, s.subsynccommit,\n"
4685 " s.subpublications,\n");
4699 " s.subtwophasestate,\n"
4700 " s.subdisableonerr,\n");
4703 " '%c' AS subtwophasestate,\n"
4704 " false AS subdisableonerr,\n",
4709 " s.subpasswordrequired,\n"
4710 " s.subrunasowner,\n"
4714 " 't' AS subpasswordrequired,\n"
4715 " 't' AS subrunasowner,\n"
4716 " '%s' AS suborigin,\n",
4722 " s.subfailover\n");
4725 " false AS subenabled,\n"
4726 " false AS subfailover\n");
4729 "FROM pg_subscription s\n");
4733 "LEFT JOIN pg_catalog.pg_replication_origin_status o \n"
4734 " ON o.external_id = 'pg_' || s.oid::text \n");
4737 "WHERE s.subdbid = (SELECT oid FROM pg_database\n"
4738 " WHERE datname = current_database())");
4754 i_subtwophasestate =
PQfnumber(
res,
"subtwophasestate");
4756 i_subpasswordrequired =
PQfnumber(
res,
"subpasswordrequired");
4763 i_suboriginremotelsn =
PQfnumber(
res,
"suboriginremotelsn");
4769 for (
i = 0;
i < ntups;
i++)
4845 "SELECT srsubid, srrelid, srsubstate, srsublsn "
4846 "FROM pg_catalog.pg_subscription_rel "
4860 for (
int i = 0;
i < ntups;
i++)
4870 if (cur_srsubid != last_srsubid)
4873 if (subinfo == NULL)
4874 pg_fatal(
"subscription with OID %u does not exist", cur_srsubid);
4876 last_srsubid = cur_srsubid;
4880 if (tblinfo == NULL)
4881 pg_fatal(
"failed sanity check, table with OID %u not found",
4938 "\n-- For binary upgrade, must preserve the subscriber table.\n");
4940 "SELECT pg_catalog.binary_upgrade_add_sub_rel_state(");
4967 .description =
"SUBSCRIPTION TABLE",
4969 .createStmt = query->
data));
4989 char **pubnames = NULL;
5012 pg_fatal(
"could not parse %s array",
"subpublications");
5015 for (
i = 0;
i < npubnames;
i++)
5023 appendPQExpBuffer(query,
" PUBLICATION %s WITH (connect = false, slot_name = ", publications->
data);
5029 if (strcmp(subinfo->
subbinary,
"t") == 0)
5032 if (strcmp(subinfo->
substream,
"t") == 0)
5034 else if (strcmp(subinfo->
substream,
"p") == 0)
5075 "\n-- For binary upgrade, must preserve the remote_lsn for the subscriber's replication origin.\n");
5077 "SELECT pg_catalog.binary_upgrade_replorigin_advance(");
5089 "\n-- For binary upgrade, must preserve the subscriber's failover option.\n");
5090 appendPQExpBuffer(query,
"ALTER SUBSCRIPTION %s SET(failover = true);\n", qsubname);
5100 "\n-- For binary upgrade, must preserve the subscriber's running state.\n");
5109 .description =
"SUBSCRIPTION",
5111 .createStmt = query->
data,
5112 .dropStmt = delq->
data));
5140 const char *catalog,
5141 const char *keyword,
5142 const char *objname)
5159 "FROM pg_catalog.pg_depend d, pg_catalog.pg_extension e "
5160 "WHERE d.refobjid = e.oid AND classid = '%s'::pg_catalog.regclass "
5161 "AND objid = '%u'::pg_catalog.oid AND deptype = 'x' "
5162 "AND refclassid = 'pg_catalog.pg_extension'::pg_catalog.regclass",
5168 for (
i = 0;
i < ntups;
i++)
5198 ++next_possible_free_oid;
5200 "SELECT EXISTS(SELECT 1 "
5201 "FROM pg_catalog.pg_type "
5202 "WHERE oid = '%u'::pg_catalog.oid);",
5203 next_possible_free_oid);
5209 return next_possible_free_oid;
5216 bool force_array_type,
5217 bool include_multirange_type)
5221 Oid pg_type_array_oid;
5222 Oid pg_type_multirange_oid;
5223 Oid pg_type_multirange_array_oid;
5227 "SELECT pg_catalog.binary_upgrade_set_next_pg_type_oid('%u'::pg_catalog.oid);\n\n",
5232 "FROM pg_catalog.pg_type "
5233 "WHERE oid = '%u'::pg_catalog.oid;",
5242 if (!
OidIsValid(pg_type_array_oid) && force_array_type)
5248 "\n-- For binary upgrade, must preserve pg_type array oid\n");
5250 "SELECT pg_catalog.binary_upgrade_set_next_array_pg_type_oid('%u'::pg_catalog.oid);\n\n",
5257 if (include_multirange_type)
5262 "SELECT t.oid, t.typarray "
5263 "FROM pg_catalog.pg_type t "
5264 "JOIN pg_catalog.pg_range r "
5265 "ON t.oid = r.rngmultitypid "
5266 "WHERE r.rngtypid = '%u'::pg_catalog.oid;",
5283 "\n-- For binary upgrade, must preserve multirange pg_type oid\n");
5285 "SELECT pg_catalog.binary_upgrade_set_next_multirange_pg_type_oid('%u'::pg_catalog.oid);\n\n",
5286 pg_type_multirange_oid);
5288 "\n-- For binary upgrade, must preserve multirange pg_type array oid\n");
5290 "SELECT pg_catalog.binary_upgrade_set_next_multirange_array_pg_type_oid('%u'::pg_catalog.oid);\n\n",
5291 pg_type_multirange_array_oid);
5306 pg_type_oid,
false,
false);
5320 Oid toast_index_oid;
5335 "SELECT c.relkind, c.relfilenode, c.reltoastrelid, ct.relfilenode AS toast_relfilenode, i.indexrelid, cti.relfilenode AS toast_index_relfilenode "
5336 "FROM pg_catalog.pg_class c LEFT JOIN "
5337 "pg_catalog.pg_index i ON (c.reltoastrelid = i.indrelid AND i.indisvalid) "
5338 "LEFT JOIN pg_catalog.pg_class ct ON (c.reltoastrelid = ct.oid) "
5339 "LEFT JOIN pg_catalog.pg_class AS cti ON (i.indexrelid = cti.oid) "
5340 "WHERE c.oid = '%u'::pg_catalog.oid;",
5348 PQfnumber(upgrade_res,
"relfilenode")));
5350 PQfnumber(upgrade_res,
"reltoastrelid")));
5352 PQfnumber(upgrade_res,
"toast_relfilenode")));
5356 PQfnumber(upgrade_res,
"toast_index_relfilenode")));
5359 "\n-- For binary upgrade, must preserve pg_class oids and relfilenodes\n");
5364 "SELECT pg_catalog.binary_upgrade_set_next_heap_pg_class_oid('%u'::pg_catalog.oid);\n",
5374 "SELECT pg_catalog.binary_upgrade_set_next_heap_relfilenode('%u'::pg_catalog.oid);\n",
5382 relkind != RELKIND_PARTITIONED_TABLE)
5385 "SELECT pg_catalog.binary_upgrade_set_next_toast_pg_class_oid('%u'::pg_catalog.oid);\n",
5388 "SELECT pg_catalog.binary_upgrade_set_next_toast_relfilenode('%u'::pg_catalog.oid);\n",
5389 toast_relfilenumber);
5393 "SELECT pg_catalog.binary_upgrade_set_next_index_pg_class_oid('%u'::pg_catalog.oid);\n",
5396 "SELECT pg_catalog.binary_upgrade_set_next_index_relfilenode('%u'::pg_catalog.oid);\n",
5397 toast_index_relfilenumber);
5406 "SELECT pg_catalog.binary_upgrade_set_next_index_pg_class_oid('%u'::pg_catalog.oid);\n",
5409 "SELECT pg_catalog.binary_upgrade_set_next_index_relfilenode('%u'::pg_catalog.oid);\n",
5428 const char *objtype,
5429 const char *objname,
5430 const char *objnamespace)
5452 pg_fatal(
"could not find parent extension for %s %s",
5456 "\n-- For binary upgrade, handle extension membership the hard way\n");
5460 if (objnamespace && *objnamespace)
5496 "acldefault('n', n.nspowner) AS acldefault "
5497 "FROM pg_namespace n");
5512 for (
i = 0;
i < ntups;
i++)
5514 const char *nspowner;
5552 if (strcmp(nsinfo[
i].dobj.name,
"public") == 0)
5581 *numNamespaces = ntups;
5597 pg_fatal(
"schema with OID %u does not exist", nsoid);
5621 int i_extrelocatable;
5629 "x.extname, n.nspname, x.extrelocatable, x.extversion, x.extconfig, x.extcondition "
5630 "FROM pg_extension x "
5631 "JOIN pg_namespace n ON n.oid = x.extnamespace");
5648 for (
i = 0;
i < ntups;
i++)
5668 *numExtensions = ntups;
5722 "typnamespace, typacl, "
5723 "acldefault('T', typowner) AS acldefault, "
5725 "typelem, typrelid, "
5726 "CASE WHEN typrelid = 0 THEN ' '::\"char\" "
5727 "ELSE (SELECT relkind FROM pg_class WHERE oid = typrelid) END AS typrelkind, "
5728 "typtype, typisdefined, "
5729 "typname[0] = '_' AND typelem != 0 AND "
5730 "(SELECT typarray FROM pg_type te WHERE oid = pg_type.typelem) = oid AS isarray "
5753 for (
i = 0;
i < ntups;
i++)
5760 tyinfo[
i].
dobj.namespace =
5784 if (tyinfo[
i].typtype == TYPTYPE_MULTIRANGE)
5802 tyinfo[
i].
typtype == TYPTYPE_DOMAIN)
5816 (tyinfo[
i].
typtype == TYPTYPE_BASE ||
5817 tyinfo[
i].
typtype == TYPTYPE_RANGE))
5824 stinfo->
dobj.namespace = tyinfo[
i].
dobj.namespace;
5878 "oprcode::oid AS oprcode "
5879 "FROM pg_operator");
5896 for (
i = 0;
i < ntups;
i++)
5903 oprinfo[
i].
dobj.namespace =
5938 int i_collnamespace;
5951 "FROM pg_collation");
5956 *numCollations = ntups;
5966 for (
i = 0;
i < ntups;
i++)
5973 collinfo[
i].
dobj.namespace =
6019 "FROM pg_conversion");
6024 *numConversions = ntups;
6034 for (
i = 0;
i < ntups;
i++)
6041 convinfo[
i].
dobj.namespace =
6080 *numAccessMethods = 0;
6088 "amhandler::pg_catalog.regproc AS amhandler "
6094 *numAccessMethods = ntups;
6104 for (
i = 0;
i < ntups;
i++)
6111 aminfo[
i].
dobj.namespace = NULL;
6161 *numOpclasses = ntups;
6171 for (
i = 0;
i < ntups;
i++)
6178 opcinfo[
i].
dobj.namespace =
6224 "FROM pg_opfamily");
6229 *numOpfamilies = ntups;
6239 for (
i = 0;
i < ntups;
i++)
6246 opfinfo[
i].
dobj.namespace =
6293 const char *agg_check;
6295 agg_check = (fout->
remoteVersion >= 110000 ?
"p.prokind = 'a'"
6299 "p.proname AS aggname, "
6300 "p.pronamespace AS aggnamespace, "
6301 "p.pronargs, p.proargtypes, "
6303 "p.proacl AS aggacl, "
6304 "acldefault('f', p.proowner) AS acldefault "
6306 "LEFT JOIN pg_init_privs pip ON "
6307 "(p.oid = pip.objoid "
6308 "AND pip.classoid = 'pg_proc'::regclass "
6309 "AND pip.objsubid = 0) "
6311 "p.pronamespace != "
6312 "(SELECT oid FROM pg_namespace "
6313 "WHERE nspname = 'pg_catalog') OR "
6314 "p.proacl IS DISTINCT FROM pip.initprivs",
6318 " OR EXISTS(SELECT 1 FROM pg_depend WHERE "
6319 "classid = 'pg_proc'::regclass AND "
6320 "objid = p.oid AND "
6321 "refclassid = 'pg_extension'::regclass AND "
6328 "pronamespace AS aggnamespace, "
6329 "pronargs, proargtypes, "
6331 "proacl AS aggacl, "
6332 "acldefault('f', proowner) AS acldefault "
6334 "WHERE proisagg AND ("
6336 "(SELECT oid FROM pg_namespace "
6337 "WHERE nspname = 'pg_catalog')");
6340 " OR EXISTS(SELECT 1 FROM pg_depend WHERE "
6341 "classid = 'pg_proc'::regclass AND "
6342 "objid = p.oid AND "
6343 "refclassid = 'pg_extension'::regclass AND "
6365 for (
i = 0;
i < ntups;
i++)
6367 agginfo[
i].aggfn.dobj.objType =
DO_AGG;
6372 agginfo[
i].aggfn.dobj.namespace =
6376 agginfo[
i].aggfn.dacl.privtype = 0;
6377 agginfo[
i].aggfn.dacl.initprivs = NULL;
6382 if (agginfo[
i].aggfn.nargs == 0)
6383 agginfo[
i].aggfn.argtypes = NULL;
6386 agginfo[
i].aggfn.argtypes = (
Oid *)
pg_malloc(agginfo[
i].aggfn.nargs *
sizeof(
Oid));
6388 agginfo[
i].aggfn.argtypes,
6389 agginfo[
i].aggfn.nargs);
6391 agginfo[
i].aggfn.postponed_def =
false;
6459 const char *not_agg_check;
6461 not_agg_check = (fout->
remoteVersion >= 110000 ?
"p.prokind <> 'a'"
6462 :
"NOT p.proisagg");
6465 "SELECT p.tableoid, p.oid, p.proname, p.prolang, "
6466 "p.pronargs, p.proargtypes, p.prorettype, "
6468 "acldefault('f', p.proowner) AS acldefault, "
6472 "LEFT JOIN pg_init_privs pip ON "
6473 "(p.oid = pip.objoid "
6474 "AND pip.classoid = 'pg_proc'::regclass "
6475 "AND pip.objsubid = 0) "
6477 "\n AND NOT EXISTS (SELECT 1 FROM pg_depend "
6478 "WHERE classid = 'pg_proc'::regclass AND "
6479 "objid = p.oid AND deptype = 'i')"
6481 "\n pronamespace != "
6482 "(SELECT oid FROM pg_namespace "
6483 "WHERE nspname = 'pg_catalog')"
6484 "\n OR EXISTS (SELECT 1 FROM pg_cast"
6485 "\n WHERE pg_cast.oid > %u "
6486 "\n AND p.oid = pg_cast.castfunc)"
6487 "\n OR EXISTS (SELECT 1 FROM pg_transform"
6488 "\n WHERE pg_transform.oid > %u AND "
6489 "\n (p.oid = pg_transform.trffromsql"
6490 "\n OR p.oid = pg_transform.trftosql))",
6496 "\n OR EXISTS(SELECT 1 FROM pg_depend WHERE "
6497 "classid = 'pg_proc'::regclass AND "
6498 "objid = p.oid AND "
6499 "refclassid = 'pg_extension'::regclass AND "
6502 "\n OR p.proacl IS DISTINCT FROM pip.initprivs");
6508 "SELECT tableoid, oid, proname, prolang, "
6509 "pronargs, proargtypes, prorettype, proacl, "
6510 "acldefault('f', proowner) AS acldefault, "
6514 "WHERE NOT proisagg"
6515 "\n AND NOT EXISTS (SELECT 1 FROM pg_depend "
6516 "WHERE classid = 'pg_proc'::regclass AND "
6517 "objid = p.oid AND deptype = 'i')"
6519 "\n pronamespace != "
6520 "(SELECT oid FROM pg_namespace "
6521 "WHERE nspname = 'pg_catalog')"
6522 "\n OR EXISTS (SELECT 1 FROM pg_cast"
6523 "\n WHERE pg_cast.oid > '%u'::oid"
6524 "\n AND p.oid = pg_cast.castfunc)",
6529 "\n OR EXISTS (SELECT 1 FROM pg_transform"
6530 "\n WHERE pg_transform.oid > '%u'::oid"
6531 "\n AND (p.oid = pg_transform.trffromsql"
6532 "\n OR p.oid = pg_transform.trftosql))",
6537 "\n OR EXISTS(SELECT 1 FROM pg_depend WHERE "
6538 "classid = 'pg_proc'::regclass AND "
6539 "objid = p.oid AND "
6540 "refclassid = 'pg_extension'::regclass AND "
6565 for (
i = 0;
i < ntups;
i++)
6572 finfo[
i].
dobj.namespace =
6582 if (finfo[
i].nargs == 0)
6588 finfo[
i].argtypes, finfo[
i].nargs);
6637 int i_reltablespace;
6639 int i_relhastriggers;
6640 int i_relpersistence;
6641 int i_relispopulated;
6644 int i_relforcerowsec;
6646 int i_toastfrozenxid;
6652 int i_toastreloptions;
6654 int i_foreignserver;
6656 int i_is_identity_sequence;
6679 "SELECT c.tableoid, c.oid, c.relname, "
6680 "c.relnamespace, c.relkind, c.reltype, "
6683 "c.relhasindex, c.relhasrules, c.relpages, "
6684 "c.relhastriggers, "
6685 "c.relpersistence, "
6688 "acldefault(CASE WHEN c.relkind = " CppAsString2(RELKIND_SEQUENCE)
6689 " THEN 's'::\"char\" ELSE 'r'::\"char\" END, c.relowner) AS acldefault, "
6690 "CASE WHEN c.relkind = " CppAsString2(RELKIND_FOREIGN_TABLE)
" THEN "
6691 "(SELECT ftserver FROM pg_catalog.pg_foreign_table WHERE ftrelid = c.oid) "
6692 "ELSE 0 END AS foreignserver, "
6693 "c.relfrozenxid, tc.relfrozenxid AS tfrozenxid, "
6695 "tc.relpages AS toastpages, "
6696 "tc.reloptions AS toast_reloptions, "
6697 "d.refobjid AS owning_tab, "
6698 "d.refobjsubid AS owning_col, "
6699 "tsp.spcname AS reltablespace, ");
6703 "false AS relhasoids, ");
6710 "c.relispopulated, ");
6713 "'t' as relispopulated, ");
6717 "c.relreplident, ");
6720 "'d' AS relreplident, ");
6724 "c.relrowsecurity, c.relforcerowsecurity, ");
6727 "false AS relrowsecurity, "
6728 "false AS relforcerowsecurity, ");
6732 "c.relminmxid, tc.relminmxid AS tminmxid, ");
6735 "0 AS relminmxid, 0 AS tminmxid, ");
6739 "array_remove(array_remove(c.reloptions,'check_option=local'),'check_option=cascaded') AS reloptions, "
6740 "CASE WHEN 'check_option=local' = ANY (c.reloptions) THEN 'LOCAL'::text "
6741 "WHEN 'check_option=cascaded' = ANY (c.reloptions) THEN 'CASCADED'::text ELSE NULL END AS checkoption, ");
6744 "c.reloptions, NULL AS checkoption, ");
6751 "NULL AS amname, ");
6755 "(d.deptype = 'i') IS TRUE AS is_identity_sequence, ");
6758 "false AS is_identity_sequence, ");
6762 "c.relispartition AS ispartition ");
6765 "false AS ispartition ");
6774 "\nFROM pg_class c\n"
6775 "LEFT JOIN pg_depend d ON "
6777 "d.classid = 'pg_class'::regclass AND d.objid = c.oid AND "
6778 "d.objsubid = 0 AND "
6779 "d.refclassid = 'pg_class'::regclass AND d.deptype IN ('a', 'i'))\n"
6780 "LEFT JOIN pg_tablespace tsp ON (tsp.oid = c.reltablespace)\n");
6787 "LEFT JOIN pg_am am ON (c.relam = am.oid)\n");
6795 "LEFT JOIN pg_class tc ON (c.reltoastrelid = tc.oid"
6797 " AND c.relkind <> " CppAsString2(RELKIND_PARTITIONED_TABLE)
")\n");
6810 "WHERE c.relkind IN ("
6858 i_relforcerowsec =
PQfnumber(
res,
"relforcerowsecurity");
6866 i_toastreloptions =
PQfnumber(
res,
"toast_reloptions");
6870 i_is_identity_sequence =
PQfnumber(
res,
"is_identity_sequence");
6892 for (
i = 0;
i < ntups;
i++)
6899 tblinfo[
i].
dobj.namespace =
6959 if (tblinfo[
i].relkind == RELKIND_COMPOSITE_TYPE)
7006 (tblinfo[
i].
relkind == RELKIND_RELATION ||
7007 tblinfo[
i].
relkind == RELKIND_PARTITIONED_TABLE))
7014 if (query->
len == 0)
7023 if (query->
len >= 100000)
7034 if (query->
len != 0)
7069 for (
i = 0;
i < numTables;
i++)
7078 if (owning_tab == NULL)
7079 pg_fatal(
"failed sanity check, parent table with OID %u of sequence with OID %u not found",
7142 *numInherits = ntups;
7149 for (
i = 0;
i < ntups;
i++)
7204 "SELECT partrelid FROM pg_partitioned_table WHERE\n"
7205 "(SELECT c.oid FROM pg_opclass c JOIN pg_am a "
7206 "ON c.opcmethod = a.oid\n"
7207 "WHERE opcname = 'enum_ops' "
7208 "AND opcnamespace = 'pg_catalog'::regnamespace "
7209 "AND amname = 'hash') = ANY(partclass)");
7215 for (
int i = 0;
i < ntups;
i++)
7222 pg_fatal(
"failed sanity check, table OID %u appearing in pg_partitioned_table not found",
7259 i_indnullsnotdistinct,
7282 for (
int i = 0;
i < numTables;
i++)
7296 if (tbloids->
len > 1)
7303 "SELECT t.tableoid, t.oid, i.indrelid, "
7304 "t.relname AS indexname, "
7305 "pg_catalog.pg_get_indexdef(i.indexrelid) AS indexdef, "
7306 "i.indkey, i.indisclustered, "
7307 "c.contype, c.conname, "
7308 "c.condeferrable, c.condeferred, "
7309 "c.tableoid AS contableoid, "
7311 "pg_catalog.pg_get_constraintdef(c.oid, false) AS condef, "
7312 "(SELECT spcname FROM pg_catalog.pg_tablespace s WHERE s.oid = t.reltablespace) AS tablespace, "
7313 "t.reloptions AS indreloptions, ");
7318 "i.indisreplident, ");
7321 "false AS indisreplident, ");
7325 "inh.inhparent AS parentidx, "
7326 "i.indnkeyatts AS indnkeyatts, "
7327 "i.indnatts AS indnatts, "
7328 "(SELECT pg_catalog.array_agg(attnum ORDER BY attnum) "
7329 " FROM pg_catalog.pg_attribute "
7330 " WHERE attrelid = i.indexrelid AND "
7331 " attstattarget >= 0) AS indstatcols, "
7332 "(SELECT pg_catalog.array_agg(attstattarget ORDER BY attnum) "
7333 " FROM pg_catalog.pg_attribute "
7334 " WHERE attrelid = i.indexrelid AND "
7335 " attstattarget >= 0) AS indstatvals, ");
7339 "i.indnatts AS indnkeyatts, "
7340 "i.indnatts AS indnatts, "
7341 "'' AS indstatcols, "
7342 "'' AS indstatvals, ");
7346 "i.indnullsnotdistinct, ");
7349 "false AS indnullsnotdistinct, ");
7356 "NULL AS conperiod ");
7370 "FROM unnest('%s'::pg_catalog.oid[]) AS src(tbloid)\n"
7371 "JOIN pg_catalog.pg_index i ON (src.tbloid = i.indrelid) "
7372 "JOIN pg_catalog.pg_class t ON (t.oid = i.indexrelid) "
7373 "JOIN pg_catalog.pg_class t2 ON (t2.oid = i.indrelid) "
7374 "LEFT JOIN pg_catalog.pg_constraint c "
7375 "ON (i.indrelid = c.conrelid AND "
7376 "i.indexrelid = c.conindid AND "
7377 "c.contype IN ('p','u','x')) "
7378 "LEFT JOIN pg_catalog.pg_inherits inh "
7379 "ON (inh.inhrelid = indexrelid) "
7380 "WHERE (i.indisvalid OR t2.relkind = 'p') "
7382 "ORDER BY i.indrelid, indexname",
7392 "FROM unnest('%s'::pg_catalog.oid[]) AS src(tbloid)\n"
7393 "JOIN pg_catalog.pg_index i ON (src.tbloid = i.indrelid) "
7394 "JOIN pg_catalog.pg_class t ON (t.oid = i.indexrelid) "
7395 "LEFT JOIN pg_catalog.pg_constraint c "
7396 "ON (i.indrelid = c.conrelid AND "
7397 "i.indexrelid = c.conindid AND "
7398 "c.contype IN ('p','u','x')) "
7399 "WHERE i.indisvalid AND i.indisready "
7400 "ORDER BY i.indrelid, indexname",
7419 i_indnullsnotdistinct =
PQfnumber(
res,
"indnullsnotdistinct");
7440 for (
int j = 0;
j < ntups;)
7447 for (numinds = 1; numinds < ntups -
j; numinds++)
7455 while (++curtblindx < numTables)
7457 tbinfo = &tblinfo[curtblindx];
7461 if (curtblindx >= numTables)
7462 pg_fatal(
"unrecognized table OID %u", indrelid);
7466 pg_fatal(
"unexpected index data for table \"%s\"",
7473 for (
int c = 0;
c < numinds;
c++,
j++)
7483 indxinfo[
j].
dobj.namespace = tbinfo->
dobj.namespace;
7494 indxinfo[
j].indkeys, indxinfo[
j].indnattrs);
7505 if (contype ==
'p' || contype ==
'u' || contype ==
'x')
7520 constrinfo->
dobj.namespace = tbinfo->
dobj.namespace;
7523 constrinfo->
contype = contype;
7527 constrinfo->
condef = NULL;
7583 "stxnamespace, stxowner, stxrelid, NULL AS stxstattarget "
7584 "FROM pg_catalog.pg_statistic_ext");
7587 "stxnamespace, stxowner, stxrelid, stxstattarget "
7588 "FROM pg_catalog.pg_statistic_ext");
7604 for (
i = 0;
i < ntups;
i++)
7611 statsextinfo[
i].
dobj.namespace =
7665 for (
int i = 0;
i < numTables;
i++)
7673 if ((!
tinfo->hastriggers &&
7674 tinfo->relkind != RELKIND_PARTITIONED_TABLE) ||
7679 if (tbloids->
len > 1)
7686 "SELECT c.tableoid, c.oid, "
7687 "conrelid, conname, confrelid, ");
7693 "pg_catalog.pg_get_constraintdef(c.oid) AS condef\n"
7694 "FROM unnest('%s'::pg_catalog.oid[]) AS src(tbloid)\n"
7695 "JOIN pg_catalog.pg_constraint c ON (src.tbloid = c.conrelid)\n"
7696 "WHERE contype = 'f' ",
7700 "AND conparentid = 0 ");
7702 "ORDER BY conrelid, conname");
7719 for (
int j = 0;
j < ntups;
j++)
7728 if (tbinfo == NULL || tbinfo->
dobj.
catId.
oid != conrelid)
7730 while (++curtblindx < numTables)
7732 tbinfo = &tblinfo[curtblindx];
7736 if (curtblindx >= numTables)
7737 pg_fatal(
"unrecognized table OID %u", conrelid);
7745 constrinfo[
j].
dobj.namespace = tbinfo->
dobj.namespace;
7764 if (reftable && reftable->
relkind == RELKIND_PARTITIONED_TABLE)
7770 for (
int k = 0; k < reftable->
numIndexes; k++)
7778 refidx = &reftable->
indexes[k];
7843 "PREPARE getDomainConstraints(pg_catalog.oid) AS\n"
7844 "SELECT tableoid, oid, conname, "
7845 "pg_catalog.pg_get_constraintdef(oid) AS consrc, "
7847 "FROM pg_catalog.pg_constraint "
7848 "WHERE contypid = $1 "
7849 "ORDER BY conname");
7857 "EXECUTE getDomainConstraints('%u')",
7874 for (
i = 0;
i < ntups;
i++)
7883 constrinfo[
i].
dobj.namespace = tyinfo->
dobj.namespace;
7935 "tableoid, oid, rulename, "
7936 "ev_class AS ruletable, ev_type, is_instead, "
7957 for (
i = 0;
i < ntups;
i++)
7968 if (ruleinfo[
i].ruletable == NULL)
7969 pg_fatal(
"failed sanity check, parent table with OID %u of pg_rewrite entry with OID %u not found",
7970 ruletableoid, ruleinfo[
i].dobj.catId.oid);
7976 if (ruleinfo[
i].ruletable)
7985 if ((ruleinfo[
i].ruletable->relkind == RELKIND_VIEW ||
8045 for (
int i = 0;
i < numTables;
i++)
8054 if (tbloids->
len > 1)
8071 "SELECT t.tgrelid, t.tgname, "
8072 "pg_catalog.pg_get_triggerdef(t.oid, false) AS tgdef, "
8073 "t.tgenabled, t.tableoid, t.oid, "
8074 "t.tgparentid <> 0 AS tgispartition\n"
8075 "FROM unnest('%s'::pg_catalog.oid[]) AS src(tbloid)\n"
8076 "JOIN pg_catalog.pg_trigger t ON (src.tbloid = t.tgrelid) "
8077 "LEFT JOIN pg_catalog.pg_trigger u ON (u.oid = t.tgparentid) "
8078 "WHERE ((NOT t.tgisinternal AND t.tgparentid = 0) "
8079 "OR t.tgenabled != u.tgenabled) "
8080 "ORDER BY t.tgrelid, t.tgname",
8094 "SELECT t.tgrelid, t.tgname, "
8095 "pg_catalog.pg_get_triggerdef(t.oid, false) AS tgdef, "
8096 "t.tgenabled, t.tableoid, t.oid, t.tgisinternal as tgispartition\n"
8097 "FROM unnest('%s'::pg_catalog.oid[]) AS src(tbloid)\n"
8098 "JOIN pg_catalog.pg_trigger t ON (src.tbloid = t.tgrelid) "
8099 "LEFT JOIN pg_catalog.pg_trigger u ON (u.oid = t.tgparentid) "
8100 "WHERE (NOT t.tgisinternal OR t.tgenabled != u.tgenabled) "
8101 "ORDER BY t.tgrelid, t.tgname",
8114 "SELECT t.tgrelid, t.tgname, "
8115 "pg_catalog.pg_get_triggerdef(t.oid, false) AS tgdef, "
8116 "t.tgenabled, t.tableoid, t.oid, t.tgisinternal as tgispartition "
8117 "FROM unnest('%s'::pg_catalog.oid[]) AS src(tbloid)\n"
8118 "JOIN pg_catalog.pg_trigger t ON (src.tbloid = t.tgrelid) "
8119 "LEFT JOIN pg_catalog.pg_depend AS d ON "
8120 " d.classid = 'pg_catalog.pg_trigger'::pg_catalog.regclass AND "
8121 " d.refclassid = 'pg_catalog.pg_trigger'::pg_catalog.regclass AND "
8123 "LEFT JOIN pg_catalog.pg_trigger AS pt ON pt.oid = refobjid "
8124 "WHERE (NOT t.tgisinternal OR t.tgenabled != pt.tgenabled) "
8125 "ORDER BY t.tgrelid, t.tgname",
8132 "SELECT t.tgrelid, t.tgname, "
8133 "pg_catalog.pg_get_triggerdef(t.oid, false) AS tgdef, "
8134 "t.tgenabled, false as tgispartition, "
8135 "t.tableoid, t.oid "
8136 "FROM unnest('%s'::pg_catalog.oid[]) AS src(tbloid)\n"
8137 "JOIN pg_catalog.pg_trigger t ON (src.tbloid = t.tgrelid) "
8138 "WHERE NOT tgisinternal "
8139 "ORDER BY t.tgrelid, t.tgname",
8162 for (
int j = 0;
j < ntups;)
8169 for (numtrigs = 1; numtrigs < ntups -
j; numtrigs++)
8177 while (++curtblindx < numTables)
8179 tbinfo = &tblinfo[curtblindx];
8183 if (curtblindx >= numTables)
8184 pg_fatal(
"unrecognized table OID %u", tgrelid);
8190 for (
int c = 0;
c < numtrigs;
c++,
j++)
8197 tginfo[
j].
dobj.namespace = tbinfo->
dobj.namespace;
8235 *numEventTriggers = 0;
8242 "SELECT e.tableoid, e.oid, evtname, evtenabled, "
8243 "evtevent, evtowner, "
8244 "array_to_string(array("
8245 "select quote_literal(x) "
8246 " from unnest(evttags) as t(x)), ', ') as evttags, "
8247 "e.evtfoid::regproc as evtfname "
8248 "FROM pg_event_trigger e "
8255 *numEventTriggers = ntups;
8268 for (
i = 0;
i < ntups;
i++)
8314 int i_lanplcallfoid;
8322 "lanname, lanpltrusted, lanplcallfoid, "
8323 "laninline, lanvalidator, "
8325 "acldefault('l', lanowner) AS acldefault, "
8335 *numProcLangs = ntups;
8350 for (
i = 0;
i < ntups;
i++)
8411 "castsource, casttarget, castfunc, castcontext, "
8414 "WHERE NOT EXISTS ( "
8415 "SELECT 1 FROM pg_range r "
8416 "WHERE c.castsource = r.rngtypid "
8417 "AND c.casttarget = r.rngmultitypid "
8424 "castsource, casttarget, castfunc, castcontext, "
8426 "FROM pg_cast ORDER BY 3,4");
8445 for (
i = 0;
i < ntups;
i++)
8469 if (sTypeInfo && tTypeInfo)
8493 appendPQExpBuffer(query,
"SELECT lanname FROM pg_language WHERE oid = %u", langid);
8533 "trftype, trflang, trffromsql::oid, trftosql::oid "
8534 "FROM pg_transform "
8541 *numTransforms = ntups;
8552 for (
i = 0;
i < ntups;
i++)
8575 if (typeInfo && lanname)
8589 return transforminfo;
8613 int i_attstattarget;
8623 int i_notnull_noinherit;
8624 int i_notnull_is_pk;
8628 int i_attcompression;
8629 int i_attfdwoptions;
8630 int i_attmissingval;
8645 for (
int i = 0;
i < numTables;
i++)
8650 if (tbinfo->
relkind == RELKIND_SEQUENCE)
8658 if (tbloids->
len > 1)
8665 if (checkoids->
len > 1)
8685 "a.attstattarget,\n"
8693 "pg_catalog.format_type(t.oid, a.atttypmod) AS atttypname,\n"
8694 "array_to_string(a.attoptions, ', ') AS attoptions,\n"
8695 "CASE WHEN a.attcollation <> t.typcollation "
8696 "THEN a.attcollation ELSE 0 END AS attcollation,\n"
8697 "pg_catalog.array_to_string(ARRAY("
8698 "SELECT pg_catalog.quote_ident(option_name) || "
8699 "' ' || pg_catalog.quote_literal(option_value) "
8700 "FROM pg_catalog.pg_options_to_table(attfdwoptions) "
8701 "ORDER BY option_name"
8702 "), E',\n ') AS attfdwoptions,\n");
8721 "co.conname AS notnull_name,\n"
8722 "co.connoinherit AS notnull_noinherit,\n"
8723 "copk.conname IS NOT NULL as notnull_is_pk,\n"
8724 "coalesce(NOT co.conislocal, true) AS notnull_inh,\n");
8727 "CASE WHEN a.attnotnull THEN '' ELSE NULL END AS notnull_name,\n"
8728 "false AS notnull_noinherit,\n"
8729 "copk.conname IS NOT NULL AS notnull_is_pk,\n"
8730 "NOT a.attislocal AS notnull_inh,\n");
8734 "a.attcompression AS attcompression,\n");
8737 "'' AS attcompression,\n");
8741 "a.attidentity,\n");
8744 "'' AS attidentity,\n");
8748 "CASE WHEN a.atthasmissing AND NOT a.attisdropped "
8749 "THEN a.attmissingval ELSE null END AS attmissingval,\n");
8752 "NULL AS attmissingval,\n");
8756 "a.attgenerated\n");
8759 "'' AS attgenerated\n");
8763 "FROM unnest('%s'::pg_catalog.oid[]) AS src(tbloid)\n"
8764 "JOIN pg_catalog.pg_attribute a ON (src.tbloid = a.attrelid) "
8765 "LEFT JOIN pg_catalog.pg_type t "
8766 "ON (a.atttypid = t.oid)\n",
8776 " LEFT JOIN pg_catalog.pg_constraint co ON "
8777 "(a.attrelid = co.conrelid\n"
8778 " AND co.contype = 'n' AND "
8779 "co.conkey = array[a.attnum])\n");
8782 "LEFT JOIN pg_catalog.pg_constraint copk ON "
8783 "(copk.conrelid = src.tbloid\n"
8784 " AND copk.contype = 'p' AND "
8785 "copk.conkey @> array[a.attnum])\n"
8786 "WHERE a.attnum > 0::pg_catalog.int2\n"
8787 "ORDER BY a.attrelid, a.attnum");
8807 i_notnull_noinherit =
PQfnumber(
res,
"notnull_noinherit");
8826 for (
int r = 0; r < ntups;)
8835 for (numatts = 1; numatts < ntups - r; numatts++)
8843 while (++curtblindx < numTables)
8845 tbinfo = &tblinfo[curtblindx];
8849 if (curtblindx >= numTables)
8850 pg_fatal(
"unrecognized table OID %u", attrelid);
8852 if (tbinfo->
relkind == RELKIND_SEQUENCE ||
8854 pg_fatal(
"unexpected column data for table \"%s\"",
8882 hasdefaults =
false;
8884 for (
int j = 0;
j < numatts;
j++, r++)
8886 bool use_named_notnull =
false;
8887 bool use_unnamed_notnull =
false;
8888 bool use_throwaway_notnull =
false;
8891 pg_fatal(
"invalid column numbering in table \"%s\"",
8951 use_named_notnull =
true;
8958 use_throwaway_notnull =
true;
8960 use_unnamed_notnull =
true;
8974 use_named_notnull =
true;
8986 if (strcmp(default_name,
8988 use_unnamed_notnull =
true;
8991 use_named_notnull =
true;
8998 use_throwaway_notnull =
true;
9001 if (use_unnamed_notnull)
9006 else if (use_named_notnull)
9011 else if (use_throwaway_notnull)
9014 psprintf(
"pgdump_throwaway_notnull_%d", notnullcount++);
9044 if (tbloids->
len > 1)
9067 "pg_catalog.pg_get_expr(adbin, adrelid) AS adsrc\n"
9068 "FROM unnest('%s'::pg_catalog.oid[]) AS src(tbloid)\n"
9069 "JOIN pg_catalog.pg_attrdef a ON (src.tbloid = a.adrelid)\n"
9070 "ORDER BY a.adrelid, a.adnum",
9079 for (
int j = 0;
j < numDefaults;
j++)
9091 if (tbinfo == NULL || tbinfo->
dobj.
catId.
oid != adrelid)
9093 while (++curtblindx < numTables)
9095 tbinfo = &tblinfo[curtblindx];
9099 if (curtblindx >= numTables)
9100 pg_fatal(
"unrecognized table OID %u", adrelid);
9103 if (adnum <= 0 || adnum > tbinfo->
numatts)
9104 pg_fatal(
"invalid adnum value %d for table \"%s\"",
9119 attrdefs[
j].
adnum = adnum;
9123 attrdefs[
j].
dobj.namespace = tbinfo->
dobj.namespace;
9146 else if (tbinfo->
relkind == RELKIND_VIEW)
9164 if (!attrdefs[
j].separate)
9176 tbinfo->
attrdefs[adnum - 1] = &attrdefs[
j];
9202 "SELECT c.tableoid, c.oid, conrelid, conname, "
9203 "pg_catalog.pg_get_constraintdef(c.oid) AS consrc, "
9204 "conislocal, convalidated "
9205 "FROM unnest('%s'::pg_catalog.oid[]) AS src(tbloid)\n"
9206 "JOIN pg_catalog.pg_constraint c ON (src.tbloid = c.conrelid)\n"
9207 "WHERE contype = 'c' "
9208 "ORDER BY c.conrelid, c.conname",
9226 for (
int j = 0;
j < numConstrs;)
9233 for (numcons = 1; numcons < numConstrs -
j; numcons++)
9241 while (++curtblindx < numTables)
9243 tbinfo = &tblinfo[curtblindx];
9247 if (curtblindx >= numTables)
9248 pg_fatal(
"unrecognized table OID %u", conrelid);
9250 if (numcons != tbinfo->
ncheck)
9253 "expected %d check constraints on table \"%s\" but found %d",
9262 for (
int c = 0;
c < numcons;
c++,
j++)
9271 constrs[
j].
dobj.namespace = tbinfo->
dobj.namespace;
9300 if (!constrs[
j].separate)
9380 "prsstart::oid, prstoken::oid, "
9381 "prsend::oid, prsheadline::oid, prslextype::oid "
9382 "FROM pg_ts_parser");
9387 *numTSParsers = ntups;
9401 for (
i = 0;
i < ntups;
i++)
9408 prsinfo[
i].
dobj.namespace =
9445 int i_dictnamespace;
9448 int i_dictinitoption;
9453 "dictnamespace, dictowner, "
9454 "dicttemplate, dictinitoption "
9460 *numTSDicts = ntups;
9472 for (
i = 0;
i < ntups;
i++)
9479 dictinfo[
i].
dobj.namespace =
9517 int i_tmplnamespace;
9524 "tmplnamespace, tmplinit::oid, tmpllexize::oid "
9525 "FROM pg_ts_template");
9530 *numTSTemplates = ntups;
9541 for (
i = 0;
i < ntups;
i++)
9548 tmplinfo[
i].
dobj.namespace =
9589 "cfgnamespace, cfgowner, cfgparser "
9590 "FROM pg_ts_config");
9595 *numTSConfigs = ntups;
9606 for (
i = 0;
i < ntups;
i++)
9613 cfginfo[
i].
dobj.namespace =
9658 "fdwhandler::pg_catalog.regproc, "
9659 "fdwvalidator::pg_catalog.regproc, "
9661 "acldefault('F', fdwowner) AS acldefault, "
9662 "array_to_string(ARRAY("
9663 "SELECT quote_ident(option_name) || ' ' || "
9664 "quote_literal(option_value) "
9665 "FROM pg_options_to_table(fdwoptions) "
9666 "ORDER BY option_name"
9667 "), E',\n ') AS fdwoptions "
9668 "FROM pg_foreign_data_wrapper");
9673 *numForeignDataWrappers = ntups;
9687 for (
i = 0;
i < ntups;
i++)
9694 fdwinfo[
i].
dobj.namespace = NULL;
9749 "srvfdw, srvtype, srvversion, srvacl, "
9750 "acldefault('S', srvowner) AS acldefault, "
9751 "array_to_string(ARRAY("
9752 "SELECT quote_ident(option_name) || ' ' || "
9753 "quote_literal(option_value) "
9754 "FROM pg_options_to_table(srvoptions) "
9755 "ORDER BY option_name"
9756 "), E',\n ') AS srvoptions "
9757 "FROM pg_foreign_server");
9762 *numForeignServers = ntups;
9777 for (
i = 0;
i < ntups;
i++)
9784 srvinfo[
i].
dobj.namespace = NULL;
9830 int i_defaclnamespace;
9831 int i_defaclobjtype;
9852 "SELECT oid, tableoid, "
9857 "CASE WHEN defaclnamespace = 0 THEN "
9858 "acldefault(CASE WHEN defaclobjtype = 'S' "
9859 "THEN 's'::\"char\" ELSE defaclobjtype END, "
9860 "defaclrole) ELSE '{}' END AS acldefault "
9861 "FROM pg_default_acl");
9866 *numDefaultACLs = ntups;
9878 for (
i = 0;
i < ntups;
i++)
9892 daclinfo[
i].
dobj.namespace = NULL;
9937 if (roleoid < middle->roleoid)
9939 else if (roleoid > middle->
roleoid)
9946 pg_fatal(
"role with OID %u does not exist", roleoid);
9963 query =
"SELECT oid, rolname FROM pg_catalog.pg_roles ORDER BY 1";
10001 "SELECT DISTINCT attrelid FROM pg_attribute "
10002 "WHERE attacl IS NOT NULL");
10007 for (
i = 0;
i < ntups;
i++)
10026 "SELECT objoid, classoid, objsubid, privtype, initprivs "
10027 "FROM pg_init_privs");
10032 for (
i = 0;
i < ntups;
i++)
10043 objId.
oid = objoid;
10055 ((
TableInfo *) dobj)->hascolumnACLs =
true;
10059 classoid, objoid, objsubid);
10068 strcmp(dobj->
name,
"public") == 0)
10088 classoid, objoid, objsubid);
10122 const char *
name,
const char *
namespace,
10123 const char *owner,
CatalogId catalogId,
10124 int subid,
DumpId dumpId,
10125 const char *initdb_comment)
10136 if (strcmp(
type,
"LARGE OBJECT") != 0)
10161 if (initdb_comment != NULL)
10187 if (
namespace && *
namespace)
10202 .namespace =
namespace,
10204 .description =
"COMMENT",
10206 .createStmt = query->
data,
10222 const char *
name,
const char *
namespace,
10223 const char *owner,
CatalogId catalogId,
10224 int subid,
DumpId dumpId)
10227 catalogId, subid, dumpId, NULL);
10238 const char *reltypename)
10285 .namespace = tbinfo->
dobj.namespace->dobj.
name,
10287 .description =
"COMMENT",
10289 .createStmt = query->
data,
10293 else if (objsubid > 0 && objsubid <= tbinfo->numatts)
10310 .namespace = tbinfo->
dobj.namespace->dobj.
name,
10312 .description =
"COMMENT",
10314 .createStmt = query->
data,
10347 while (low <= high)
10349 middle = low + (high - low) / 2;
10351 if (classoid < middle->classoid)
10353 else if (classoid > middle->
classoid)
10355 else if (objoid < middle->objoid)
10357 else if (objoid > middle->
objoid)
10375 while (middle > low)
10377 if (classoid != middle[-1].classoid ||
10378 objoid != middle[-1].objoid)
10387 while (middle <= high)
10389 if (classoid != middle->
classoid ||
10390 objoid != middle->
objoid)
10427 "FROM pg_catalog.pg_description "
10428 "ORDER BY classoid, objoid, objsubid");
10445 for (
i = 0;
i < ntups;
i++)
10455 if (dobj == NULL ||
10468 ((
TableInfo *) dobj)->relkind == RELKIND_COMPOSITE_TYPE)
10507 if (dobj->
dump == 0)
10633 .description =
"BLOBS",
10709 "-- *not* dropping schema, since initdb creates it\n");
10711 "-- *not* creating schema, since initdb creates it\n");
10716 "SCHEMA", qnspname, NULL);
10722 .description =
"SCHEMA",
10724 .createStmt = q->
data,
10725 .dropStmt = delq->
data));
10730 const char *initdb_comment = NULL;
10732 if (!nspinfo->
create && strcmp(qnspname,
"public") == 0)
10733 initdb_comment =
"standard public schema";
10747 qnspname, NULL, NULL,
10792 qextname,
fmtId(extinfo->namespace));
10807 appendPQExpBufferStr(q,
"-- For binary upgrade, create an empty extension and insert objects into it\n");
10817 "SELECT pg_catalog.binary_upgrade_create_empty_extension(");
10862 .description =
"EXTENSION",
10864 .createStmt = q->
data,
10865 .dropStmt = delq->
data));
10898 if (tyinfo->
typtype == TYPTYPE_BASE)
10900 else if (tyinfo->
typtype == TYPTYPE_DOMAIN)
10902 else if (tyinfo->
typtype == TYPTYPE_COMPOSITE)
10904 else if (tyinfo->
typtype == TYPTYPE_ENUM)
10906 else if (tyinfo->
typtype == TYPTYPE_RANGE)
10911 pg_log_warning(
"typtype of data type \"%s\" appears to be invalid",
10940 "PREPARE dumpEnumType(pg_catalog.oid) AS\n"
10941 "SELECT oid, enumlabel "
10942 "FROM pg_catalog.pg_enum "
10943 "WHERE enumtypid = $1 "
10944 "ORDER BY enumsortorder");
10952 "EXECUTE dumpEnumType('%u')",
10981 for (
i = 0;
i < num;
i++)
10999 for (
i = 0;
i < num;
i++)
11007 "SELECT pg_catalog.binary_upgrade_set_next_pg_enum_oid('%u'::pg_catalog.oid);\n",
11018 tyinfo->
dobj.namespace->dobj.
name);
11023 .namespace = tyinfo->
dobj.namespace->dobj.
name,
11025 .description =
"TYPE",
11027 .createStmt = q->
data,
11028 .dropStmt = delq->
data));
11044 tyinfo->
dobj.namespace->dobj.
name,
11076 "PREPARE dumpRangeType(pg_catalog.oid) AS\n");
11083 "pg_catalog.format_type(rngmultitypid, NULL) AS rngmultitype, ");
11086 "NULL AS rngmultitype, ");
11089 "pg_catalog.format_type(rngsubtype, NULL) AS rngsubtype, "
11090 "opc.opcname AS opcname, "
11091 "(SELECT nspname FROM pg_catalog.pg_namespace nsp "
11092 " WHERE nsp.oid = opc.opcnamespace) AS opcnsp, "
11094 "CASE WHEN rngcollation = st.typcollation THEN 0 "
11095 " ELSE rngcollation END AS collation, "
11096 "rngcanonical, rngsubdiff "
11097 "FROM pg_catalog.pg_range r, pg_catalog.pg_type st, "
11098 " pg_catalog.pg_opclass opc "
11099 "WHERE st.oid = rngsubtype AND opc.oid = rngsubopc AND "
11108 "EXECUTE dumpRangeType('%u')",
11159 if (strcmp(procname,
"-") != 0)
11163 if (strcmp(procname,
"-") != 0)
11171 tyinfo->
dobj.namespace->dobj.
name);
11176 .namespace = tyinfo->
dobj.namespace->dobj.
name,
11178 .description =
"TYPE",
11180 .createStmt = q->
data,
11181 .dropStmt = delq->
data));
11197 tyinfo->
dobj.namespace->dobj.
name,
11242 tyinfo->
dobj.namespace->dobj.
name);
11247 .namespace = tyinfo->
dobj.namespace->dobj.
name,
11249 .description =
"TYPE",
11251 .createStmt = q->
data,
11252 .dropStmt = delq->
data));
11268 tyinfo->
dobj.namespace->dobj.
name,
11299 char *typsubscript;
11305 Oid typsubscriptoid;
11307 char *typispreferred;
11312 char *typcollatable;
11314 bool typdefault_is_literal =
false;
11320 "PREPARE dumpBaseType(pg_catalog.oid) AS\n"
11322 "typinput, typoutput, typreceive, typsend, "
11323 "typreceive::pg_catalog.oid AS typreceiveoid, "
11324 "typsend::pg_catalog.oid AS typsendoid, "
11326 "typanalyze::pg_catalog.oid AS typanalyzeoid, "
11327 "typdelim, typbyval, typalign, typstorage, "
11328 "typmodin, typmodout, "
11329 "typmodin::pg_catalog.oid AS typmodinoid, "
11330 "typmodout::pg_catalog.oid AS typmodoutoid, "
11331 "typcategory, typispreferred, "
11332 "(typcollation <> 0) AS typcollatable, "
11333 "pg_catalog.pg_get_expr(typdefaultbin, 0) AS typdefaultbin, typdefault, ");
11338 "typsubscript::pg_catalog.oid AS typsubscriptoid ");
11341 "'-' AS typsubscript, 0 AS typsubscriptoid ");
11352 "EXECUTE dumpBaseType('%u')",
11384 typdefault_is_literal =
true;
11409 "CREATE TYPE %s (\n"
11410 " INTERNALLENGTH = %s",
11412 (strcmp(typlen,
"-1") == 0) ?
"variable" : typlen);
11428 if (strcmp(typcollatable,
"t") == 0)
11431 if (typdefault != NULL)
11434 if (typdefault_is_literal)
11448 if (strcmp(typcategory,
"U") != 0)
11454 if (strcmp(typispreferred,
"t") == 0)
11457 if (typdelim && strcmp(typdelim,
",") != 0)
11465 else if (*
typalign == TYPALIGN_SHORT)
11467 else if (*
typalign == TYPALIGN_INT)
11469 else if (*
typalign == TYPALIGN_DOUBLE)
11472 if (*typstorage == TYPSTORAGE_PLAIN)
11474 else if (*typstorage == TYPSTORAGE_EXTERNAL)
11476 else if (*typstorage == TYPSTORAGE_EXTENDED)
11478 else if (*typstorage == TYPSTORAGE_MAIN)
11481 if (strcmp(typbyval,
"t") == 0)
11489 tyinfo->
dobj.namespace->dobj.
name);
11494 .namespace = tyinfo->
dobj.namespace->dobj.
name,
11496 .description =
"TYPE",
11498 .createStmt = q->
data,
11499 .dropStmt = delq->
data));
11515 tyinfo->
dobj.namespace->dobj.
name,
11545 bool typdefault_is_literal =
false;
11551 "PREPARE dumpDomain(pg_catalog.oid) AS\n");
11554 "pg_catalog.format_type(t.typbasetype, t.typtypmod) AS typdefn, "
11555 "pg_catalog.pg_get_expr(t.typdefaultbin, 'pg_catalog.pg_type'::pg_catalog.regclass) AS typdefaultbin, "
11557 "CASE WHEN t.typcollation <> u.typcollation "
11558 "THEN t.typcollation ELSE 0 END AS typcollation "
11559 "FROM pg_catalog.pg_type t "
11560 "LEFT JOIN pg_catalog.pg_type u ON (t.typbasetype = u.oid) "
11561 "WHERE t.oid = $1");
11569 "EXECUTE dumpDomain('%u')",
11581 typdefault_is_literal =
true;
11597 "CREATE DOMAIN %s AS %s",
11611 if (typnotnull[0] ==
't')
11614 if (typdefault != NULL)
11617 if (typdefault_is_literal)
11643 "DOMAIN", qtypname,
11644 tyinfo->
dobj.namespace->dobj.
name);
11649 .namespace = tyinfo->
dobj.namespace->dobj.
name,
11651 .description =
"DOMAIN",
11653 .createStmt = q->
data,
11654 .dropStmt = delq->
data));
11670 tyinfo->
dobj.namespace->dobj.
name,
11684 tyinfo->
dobj.namespace->dobj.
name,
11719 int i_attisdropped;
11720 int i_attcollation;
11735 "PREPARE dumpCompositeType(pg_catalog.oid) AS\n"
11736 "SELECT a.attname, a.attnum, "
11737 "pg_catalog.format_type(a.atttypid, a.atttypmod) AS atttypdefn, "
11738 "a.attlen, a.attalign, a.attisdropped, "
11739 "CASE WHEN a.attcollation <> at.typcollation "
11740 "THEN a.attcollation ELSE 0 END AS attcollation "
11741 "FROM pg_catalog.pg_type ct "
11742 "JOIN pg_catalog.pg_attribute a ON a.attrelid = ct.typrelid "
11743 "LEFT JOIN pg_catalog.pg_type at ON at.oid = a.atttypid "
11744 "WHERE ct.oid = $1 "
11745 "ORDER BY a.attnum");
11753 "EXECUTE dumpCompositeType('%u')",
11782 for (
i = 0;
i < ntups;
i++)
11802 if (actual_atts++ > 0)
11833 "\n-- For binary upgrade, recreate dropped column.\n");
11835 "SET attlen = %s, "
11836 "attalign = '%s', attbyval = false\n"
11857 tyinfo->
dobj.namespace->dobj.
name);
11862 .namespace = tyinfo->
dobj.namespace->dobj.
name,
11864 .description =
"TYPE",
11866 .createStmt = q->
data,
11867 .dropStmt = delq->
data));
11884 tyinfo->
dobj.namespace->dobj.
name,
11921 int i_attisdropped;
11948 for (
i = 0;
i < ntups;
i++)
11975 .namespace = tyinfo->
dobj.namespace->dobj.
name,
11977 .description =
"COMMENT",
11979 .createStmt = query->
data,
12030 .namespace = stinfo->
dobj.namespace->dobj.
name,
12032 .description =
"SHELL TYPE",
12034 .createStmt = q->
data));
12069 if (funcInfo != NULL && !funcInfo->
dobj.
dump)
12075 if (inlineInfo != NULL && !inlineInfo->
dobj.
dump)
12082 if (validatorInfo != NULL && !validatorInfo->
dobj.
dump)
12083 validatorInfo = NULL;
12091 useParams = (funcInfo != NULL &&
12135 "LANGUAGE", qlanname, NULL);
12141 .description =
"PROCEDURAL LANGUAGE",
12143 .createStmt = defqry->
data,
12144 .dropStmt = delqry->
data,
12160 qlanname, NULL, NULL,
12183 if (is_agg && finfo->
nargs == 0)
12210 for (
j = 0;
j < finfo->
nargs;
j++)
12238 char *funcfullsig = NULL;
12240 char *qual_funcsig;
12253 char *proleakproof;
12260 char **configitems = NULL;
12261 int nconfigitems = 0;
12262 const char *keyword;
12277 "PREPARE dumpFunc(pg_catalog.oid) AS\n");
12291 "pg_catalog.pg_get_function_arguments(p.oid) AS funcargs,\n"
12292 "pg_catalog.pg_get_function_identity_arguments(p.oid) AS funciargs,\n"
12293 "pg_catalog.pg_get_function_result(p.oid) AS funcresult,\n"
12294 "proleakproof,\n");
12298 "array_to_string(protrftypes, ' ') AS protrftypes,\n");
12301 "NULL AS protrftypes,\n");
12308 "'u' AS proparallel,\n");
12315 "CASE WHEN proiswindow THEN 'w' ELSE 'f' END AS prokind,\n");
12322 "'-' AS prosupport,\n");
12326 "pg_get_function_sqlbody(p.oid) AS prosqlbody\n");
12329 "NULL AS prosqlbody\n");
12332 "FROM pg_catalog.pg_proc p, pg_catalog.pg_language l\n"
12333 "WHERE p.oid = $1 "
12334 "AND l.oid = p.prolang");
12342 "EXECUTE dumpFunc('%u')",
12384 else if (probin[0] !=
'\0')
12388 if (prosrc[0] !=
'\0')
12397 (strchr(prosrc,
'\'') == NULL && strchr(prosrc,
'\\') == NULL))
12415 if (!
parsePGArray(proconfig, &configitems, &nconfigitems))
12416 pg_fatal(
"could not parse %s array",
"proconfig");
12420 configitems = NULL;
12433 if (prokind[0] == PROKIND_PROCEDURE)
12434 keyword =
"PROCEDURE";
12436 keyword =
"FUNCTION";
12439 keyword, qual_funcsig);
12444 funcfullsig ? funcfullsig :
12447 if (prokind[0] == PROKIND_PROCEDURE)
12449 else if (funcresult)
12453 (proretset[0] ==
't') ?
"SETOF " :
"",
12466 for (
i = 0; typeids[
i];
i++)
12475 if (prokind[0] == PROKIND_WINDOW)
12478 if (provolatile[0] != PROVOLATILE_VOLATILE)
12480 if (provolatile[0] == PROVOLATILE_IMMUTABLE)
12482 else if (provolatile[0] == PROVOLATILE_STABLE)
12484 else if (provolatile[0] != PROVOLATILE_VOLATILE)
12485 pg_fatal(
"unrecognized provolatile value for function \"%s\"",
12489 if (proisstrict[0] ==
't')
12492 if (prosecdef[0] ==
't')
12495 if (proleakproof[0] ==
't')
12503 if (strcmp(procost,
"0") != 0)
12505 if (strcmp(lanname,
"internal") == 0 || strcmp(lanname,
"c") == 0)
12508 if (strcmp(procost,
"1") != 0)
12514 if (strcmp(procost,
"100") != 0)
12518 if (proretset[0] ==
't' &&
12519 strcmp(prorows,
"0") != 0 && strcmp(prorows,
"1000") != 0)
12522 if (strcmp(prosupport,
"-") != 0)
12528 if (proparallel[0] != PROPARALLEL_UNSAFE)
12530 if (proparallel[0] == PROPARALLEL_SAFE)
12532 else if (proparallel[0] == PROPARALLEL_RESTRICTED)
12534 else if (proparallel[0] != PROPARALLEL_UNSAFE)
12535 pg_fatal(
"unrecognized proparallel value for function \"%s\"",
12539 for (
int i = 0;
i < nconfigitems;
i++)
12542 char *configitem = configitems[
i];
12545 pos = strchr(configitem,
'=');
12575 for (nameptr = namelist; *nameptr; nameptr++)
12577 if (nameptr != namelist)
12591 "pg_catalog.pg_proc", keyword,
12597 finfo->
dobj.namespace->dobj.
name);
12602 .
namespace = finfo->
dobj.namespace->dobj.
name,
12604 .description = keyword,
12607 .createStmt = q->
data,
12608 .dropStmt = delqry->
data));
12636 free(qual_funcsig);
12653 const char *sourceType;
12654 const char *targetType;
12664 if (funcInfo == NULL)
12665 pg_fatal(
"could not find function definition for function with OID %u",
12677 sourceType, targetType);
12680 sourceType, targetType);
12684 case COERCION_METHOD_BINARY:
12687 case COERCION_METHOD_INOUT:
12690 case COERCION_METHOD_FUNCTION:
12704 pg_log_warning(
"bogus value in pg_cast.castfunc or pg_cast.castmethod field");
12717 sourceType, targetType);
12720 sourceType, targetType);
12724 "CAST", castargs->
data, NULL);
12729 .description =
"CAST",
12731 .createStmt = defqry->
data,
12732 .dropStmt = delqry->
data));
12760 const char *transformType;
12770 if (fromsqlFuncInfo == NULL)
12771 pg_fatal(
"could not find function definition for function with OID %u",
12777 if (tosqlFuncInfo == NULL)
12778 pg_fatal(
"could not find function definition for function with OID %u",
12791 transformType, lanname);
12794 transformType, lanname);
12797 pg_log_warning(
"bogus transform definition, at least one of trffromsql and trftosql should be nonzero");
12801 if (fromsqlFuncInfo)
12841 transformType, lanname);
12844 transformType, lanname);
12848 "TRANSFORM", transformargs->
data, NULL);
12853 .description =
"TRANSFORM",
12855 .createStmt = defqry->
data,
12856 .dropStmt = delqry->
data,
12932 "PREPARE dumpOpr(pg_catalog.oid) AS\n"
12934 "oprcode::pg_catalog.regprocedure, "
12935 "oprleft::pg_catalog.regtype, "
12936 "oprright::pg_catalog.regtype, "
12939 "oprrest::pg_catalog.regprocedure, "
12940 "oprjoin::pg_catalog.regprocedure, "
12941 "oprcanmerge, oprcanhash "
12942 "FROM pg_catalog.pg_operator "
12951 "EXECUTE dumpOpr('%u')",
12979 if (strcmp(oprkind,
"r") == 0)
12980 pg_log_warning(
"postfix operators are not supported anymore (operator \"%s\")",
12998 if (strcmp(oprkind,
"r") == 0 ||
12999 strcmp(oprkind,
"b") == 0)
13007 if (strcmp(oprkind,
"l") == 0 ||
13008 strcmp(oprkind,
"b") == 0)
13030 if (strcmp(oprcanmerge,
"t") == 0)
13033 if (strcmp(oprcanhash,
"t") == 0)
13060 "OPERATOR",
oprid->data,
13061 oprinfo->
dobj.namespace->dobj.
name);
13066 .namespace = oprinfo->
dobj.namespace->dobj.
name,
13068 .description =
"OPERATOR",
13070 .createStmt = q->
data,
13071 .dropStmt = delq->
data));
13105 if (strcmp(proc,
"-") == 0)
13111 for (paren =
name; *paren; paren++)
13113 if (*paren ==
'(' && !inquote)
13119 inquote = !inquote;
13144 if (strcmp(oproid,
"0") == 0)
13148 if (oprInfo == NULL)
13155 return psprintf(
"OPERATOR(%s.%s)",
13176 "SELECT '%u'::pg_catalog.regproc", funcOid);
13219 aminfo->
amtype, qamname);
13233 "ACCESS METHOD", qamname, NULL);
13238 .description =
"ACCESS METHOD",
13240 .createStmt = q->
data,
13241 .dropStmt = delq->
data));
13272 int i_opcfamilyname;
13273 int i_opcfamilynsp;
13275 int i_amopstrategy;
13278 int i_sortfamilynsp;
13281 int i_amproclefttype;
13282 int i_amprocrighttype;
13287 char *opcfamilyname;
13288 char *opcfamilynsp;
13290 char *amopstrategy;
13293 char *sortfamilynsp;
13296 char *amproclefttype;
13297 char *amprocrighttype;
13312 "opckeytype::pg_catalog.regtype, "
13313 "opcdefault, opcfamily, "
13314 "opfname AS opcfamilyname, "
13315 "nspname AS opcfamilynsp, "
13316 "(SELECT amname FROM pg_catalog.pg_am WHERE oid = opcmethod) AS amname "
13317 "FROM pg_catalog.pg_opclass c "
13318 "LEFT JOIN pg_catalog.pg_opfamily f ON f.oid = opcfamily "
13319 "LEFT JOIN pg_catalog.pg_namespace n ON n.oid = opfnamespace "
13320 "WHERE c.oid = '%u'::pg_catalog.oid",
13352 if (strcmp(opcdefault,
"t") == 0)
13357 if (strlen(opcfamilyname) > 0)
13367 if (strcmp(opckeytype,
"-") != 0)
13384 "amopopr::pg_catalog.regoperator, "
13385 "opfname AS sortfamily, "
13386 "nspname AS sortfamilynsp "
13387 "FROM pg_catalog.pg_amop ao JOIN pg_catalog.pg_depend ON "
13388 "(classid = 'pg_catalog.pg_amop'::pg_catalog.regclass AND objid = ao.oid) "
13389 "LEFT JOIN pg_catalog.pg_opfamily f ON f.oid = amopsortfamily "
13390 "LEFT JOIN pg_catalog.pg_namespace n ON n.oid = opfnamespace "
13391 "WHERE refclassid = 'pg_catalog.pg_opclass'::pg_catalog.regclass "
13392 "AND refobjid = '%u'::pg_catalog.oid "
13393 "AND amopfamily = '%s'::pg_catalog.oid "
13394 "ORDER BY amopstrategy",
13407 for (
i = 0;
i < ntups;
i++)
13418 amopstrategy, amopopr);
13420 if (strlen(sortfamily) > 0)
13445 "amproc::pg_catalog.regprocedure, "
13446 "amproclefttype::pg_catalog.regtype, "
13447 "amprocrighttype::pg_catalog.regtype "
13448 "FROM pg_catalog.pg_amproc ap, pg_catalog.pg_depend "
13449 "WHERE refclassid = 'pg_catalog.pg_opclass'::pg_catalog.regclass "
13450 "AND refobjid = '%u'::pg_catalog.oid "
13451 "AND classid = 'pg_catalog.pg_amproc'::pg_catalog.regclass "
13452 "AND objid = ap.oid "
13453 "ORDER BY amprocnum",
13463 i_amprocrighttype =
PQfnumber(
res,
"amprocrighttype");
13465 for (
i = 0;
i < ntups;
i++)
13477 if (*amproclefttype && *amprocrighttype)
13504 "OPERATOR CLASS", nameusing->
data,
13505 opcinfo->
dobj.namespace->dobj.
name);
13510 .namespace = opcinfo->
dobj.namespace->dobj.
name,
13512 .description =
"OPERATOR CLASS",
13514 .createStmt = q->
data,
13515 .dropStmt = delq->
data));
13552 int i_amopstrategy;
13555 int i_sortfamilynsp;
13558 int i_amproclefttype;
13559 int i_amprocrighttype;
13561 char *amopstrategy;
13564 char *sortfamilynsp;
13567 char *amproclefttype;
13568 char *amprocrighttype;
13586 "amopopr::pg_catalog.regoperator, "
13587 "opfname AS sortfamily, "
13588 "nspname AS sortfamilynsp "
13589 "FROM pg_catalog.pg_amop ao JOIN pg_catalog.pg_depend ON "
13590 "(classid = 'pg_catalog.pg_amop'::pg_catalog.regclass AND objid = ao.oid) "
13591 "LEFT JOIN pg_catalog.pg_opfamily f ON f.oid = amopsortfamily "
13592 "LEFT JOIN pg_catalog.pg_namespace n ON n.oid = opfnamespace "
13593 "WHERE refclassid = 'pg_catalog.pg_opfamily'::pg_catalog.regclass "
13594 "AND refobjid = '%u'::pg_catalog.oid "
13595 "AND amopfamily = '%u'::pg_catalog.oid "
13596 "ORDER BY amopstrategy",
13605 "amproc::pg_catalog.regprocedure, "
13606 "amproclefttype::pg_catalog.regtype, "
13607 "amprocrighttype::pg_catalog.regtype "
13608 "FROM pg_catalog.pg_amproc ap, pg_catalog.pg_depend "
13609 "WHERE refclassid = 'pg_catalog.pg_opfamily'::pg_catalog.regclass "
13610 "AND refobjid = '%u'::pg_catalog.oid "
13611 "AND classid = 'pg_catalog.pg_amproc'::pg_catalog.regclass "
13612 "AND objid = ap.oid "
13613 "ORDER BY amprocnum",
13622 "(SELECT amname FROM pg_catalog.pg_am WHERE oid = opfmethod) AS amname "
13623 "FROM pg_catalog.pg_opfamily "
13624 "WHERE oid = '%u'::pg_catalog.oid",
13662 i_amopstrategy =
PQfnumber(res_ops,
"amopstrategy");
13663 i_amopopr =
PQfnumber(res_ops,
"amopopr");
13664 i_sortfamily =
PQfnumber(res_ops,
"sortfamily");
13665 i_sortfamilynsp =
PQfnumber(res_ops,
"sortfamilynsp");
13667 for (
i = 0;
i < ntups;
i++)
13669 amopstrategy =
PQgetvalue(res_ops,
i, i_amopstrategy);
13671 sortfamily =
PQgetvalue(res_ops,
i, i_sortfamily);
13672 sortfamilynsp =
PQgetvalue(res_ops,
i, i_sortfamilynsp);
13678 amopstrategy, amopopr);
13680 if (strlen(sortfamily) > 0)
13695 i_amprocnum =
PQfnumber(res_procs,
"amprocnum");
13696 i_amproc =
PQfnumber(res_procs,
"amproc");
13697 i_amproclefttype =
PQfnumber(res_procs,
"amproclefttype");
13698 i_amprocrighttype =
PQfnumber(res_procs,
"amprocrighttype");
13700 for (
i = 0;
i < ntups;
i++)
13702 amprocnum =
PQgetvalue(res_procs,
i, i_amprocnum);
13704 amproclefttype =
PQgetvalue(res_procs,
i, i_amproclefttype);
13705 amprocrighttype =
PQgetvalue(res_procs,
i, i_amprocrighttype);
13711 amprocnum, amproclefttype, amprocrighttype,
13726 "OPERATOR FAMILY", nameusing->
data,
13727 opfinfo->
dobj.namespace->dobj.
name);
13732 .namespace = opfinfo->
dobj.namespace->dobj.
name,
13734 .description =
"OPERATOR FAMILY",
13736 .createStmt = q->
data,
13737 .dropStmt = delq->
data));
13767 int i_collprovider;
13768 int i_collisdeterministic;
13772 int i_collicurules;
13773 const char *collprovider;
13774 const char *collcollate;
13775 const char *collctype;
13776 const char *colllocale;
13777 const char *collicurules;
13798 "'c' AS collprovider, "
13799 "NULL AS collversion, ");
13803 "collisdeterministic, ");
13806 "true AS collisdeterministic, ");
13813 "colliculocale AS colllocale, ");
13816 "NULL AS colllocale, ");
13823 "NULL AS collicurules, ");
13828 "FROM pg_catalog.pg_collation c "
13829 "WHERE c.oid = '%u'::pg_catalog.oid",
13835 i_collisdeterministic =
PQfnumber(
res,
"collisdeterministic");
13846 collcollate = NULL;
13859 if (collcollate[0] ==
'\0')
13860 collcollate = NULL;
13861 if (collctype[0] ==
'\0')
13873 collicurules = NULL;
13882 if (collprovider[0] ==
'b')
13884 else if (collprovider[0] ==
'c')
13886 else if (collprovider[0] ==
'i')
13888 else if (collprovider[0] ==
'd')
13892 pg_fatal(
"unrecognized collation provider: %s",
13895 if (strcmp(
PQgetvalue(
res, 0, i_collisdeterministic),
"f") == 0)
13898 if (collprovider[0] ==
'd')
13900 if (collcollate || collctype || colllocale || collicurules)
13905 else if (collprovider[0] ==
'b')
13907 if (collcollate || collctype || !colllocale || collicurules)
13914 else if (collprovider[0] ==
'i')
13918 if (collcollate || collctype || !colllocale)
13927 if (!collcollate || !collctype || colllocale ||
13928 strcmp(collcollate, collctype) != 0)
13941 else if (collprovider[0] ==
'c')
13943 if (colllocale || collicurules || !collcollate || !collctype)
13946 if (collcollate && collctype && strcmp(collcollate, collctype) == 0)
13960 pg_fatal(
"unrecognized collation provider: %s", collprovider);
13984 "COLLATION", qcollname,
13985 collinfo->
dobj.namespace->dobj.
name);
13990 .namespace = collinfo->
dobj.namespace->dobj.
name,
13992 .description =
"COLLATION",
13994 .createStmt = q->
data,
13995 .dropStmt = delq->
data));
14024 int i_conforencoding;
14025 int i_contoencoding;
14028 const char *conforencoding;
14029 const char *contoencoding;
14030 const char *conproc;
14045 "pg_catalog.pg_encoding_to_char(conforencoding) AS conforencoding, "
14046 "pg_catalog.pg_encoding_to_char(contoencoding) AS contoencoding, "
14047 "conproc, condefault "
14048 "FROM pg_catalog.pg_conversion c "
14049 "WHERE c.oid = '%u'::pg_catalog.oid",
14068 (condefault) ?
"DEFAULT " :
"",
14078 "CONVERSION", qconvname,
14079 convinfo->
dobj.namespace->dobj.
name);
14084 .namespace = convinfo->
dobj.namespace->dobj.
name,
14086 .description =
"CONVERSION",
14088 .createStmt = q->
data,
14089 .dropStmt = delq->
data));
14123 if (agginfo->aggfn.nargs == 0)
14128 for (
j = 0;
j < agginfo->aggfn.nargs;
j++)
14130 (
j > 0) ?
", " :
"",
14132 agginfo->aggfn.argtypes[
j],
14152 char *aggfullsig = NULL;
14157 const char *aggtransfn;
14158 const char *aggfinalfn;
14159 const char *aggcombinefn;
14160 const char *aggserialfn;
14161 const char *aggdeserialfn;
14162 const char *aggmtransfn;
14163 const char *aggminvtransfn;
14164 const char *aggmfinalfn;
14165 bool aggfinalextra;
14166 bool aggmfinalextra;
14167 char aggfinalmodify;
14168 char aggmfinalmodify;
14169 const char *aggsortop;
14170 char *aggsortconvop;
14172 const char *aggtranstype;
14173 const char *aggtransspace;
14174 const char *aggmtranstype;
14175 const char *aggmtransspace;
14176 const char *agginitval;
14177 const char *aggminitval;
14178 const char *proparallel;
14179 char defaultfinalmodify;
14194 "PREPARE dumpAgg(pg_catalog.oid) AS\n");
14200 "aggtranstype::pg_catalog.regtype,\n"
14203 "pg_catalog.pg_get_function_arguments(p.oid) AS funcargs,\n"
14204 "pg_catalog.pg_get_function_identity_arguments(p.oid) AS funciargs,\n");
14210 "aggminvtransfn,\n"
14212 "aggmtranstype::pg_catalog.regtype,\n"
14214 "aggmfinalextra,\n"
14216 "aggmtransspace,\n"
14220 "'n' AS aggkind,\n"
14221 "'-' AS aggmtransfn,\n"
14222 "'-' AS aggminvtransfn,\n"
14223 "'-' AS aggmfinalfn,\n"
14224 "0 AS aggmtranstype,\n"
14225 "false AS aggfinalextra,\n"
14226 "false AS aggmfinalextra,\n"
14227 "0 AS aggtransspace,\n"
14228 "0 AS aggmtransspace,\n"
14229 "NULL AS aggminitval,\n");
14239 "'-' AS aggcombinefn,\n"
14240 "'-' AS aggserialfn,\n"
14241 "'-' AS aggdeserialfn,\n"
14242 "'u' AS proparallel,\n");
14246 "aggfinalmodify,\n"
14247 "aggmfinalmodify\n");
14250 "'0' AS aggfinalmodify,\n"
14251 "'0' AS aggmfinalmodify\n");
14254 "FROM pg_catalog.pg_aggregate a, pg_catalog.pg_proc p "
14255 "WHERE a.aggfnoid = p.oid "
14264 "EXECUTE dumpAgg('%u')",
14265 agginfo->aggfn.dobj.catId.oid);
14307 defaultfinalmodify = (aggkind == AGGKIND_NORMAL) ? AGGMODIFY_READ_ONLY : AGGMODIFY_READ_WRITE;
14309 if (aggfinalmodify ==
'0')
14310 aggfinalmodify = defaultfinalmodify;
14311 if (aggmfinalmodify ==
'0')
14312 aggmfinalmodify = defaultfinalmodify;
14316 aggtransfn, aggtranstype);
14318 if (strcmp(aggtransspace,
"0") != 0)
14330 if (strcmp(aggfinalfn,
"-") != 0)
14336 if (aggfinalmodify != defaultfinalmodify)
14338 switch (aggfinalmodify)
14340 case AGGMODIFY_READ_ONLY:
14343 case AGGMODIFY_SHAREABLE:
14346 case AGGMODIFY_READ_WRITE:
14350 pg_fatal(
"unrecognized aggfinalmodify value for aggregate \"%s\"",
14351 agginfo->aggfn.dobj.name);
14357 if (strcmp(aggcombinefn,
"-") != 0)
14360 if (strcmp(aggserialfn,
"-") != 0)
14363 if (strcmp(aggdeserialfn,
"-") != 0)
14366 if (strcmp(aggmtransfn,
"-") != 0)
14374 if (strcmp(aggmtransspace,
"0") != 0)
14386 if (strcmp(aggmfinalfn,
"-") != 0)
14390 if (aggmfinalextra)
14392 if (aggmfinalmodify != defaultfinalmodify)
14394 switch (aggmfinalmodify)
14396 case AGGMODIFY_READ_ONLY:
14399 case AGGMODIFY_SHAREABLE:
14402 case AGGMODIFY_READ_WRITE:
14406 pg_fatal(
"unrecognized aggmfinalmodify value for aggregate \"%s\"",
14407 agginfo->aggfn.dobj.name);
14418 free(aggsortconvop);
14421 if (aggkind == AGGKIND_HYPOTHETICAL)
14424 if (proparallel[0] != PROPARALLEL_UNSAFE)
14426 if (proparallel[0] == PROPARALLEL_SAFE)
14428 else if (proparallel[0] == PROPARALLEL_RESTRICTED)
14430 else if (proparallel[0] != PROPARALLEL_UNSAFE)
14431 pg_fatal(
"unrecognized proparallel value for function \"%s\"",
14432 agginfo->aggfn.dobj.name);
14436 fmtId(agginfo->aggfn.dobj.namespace->dobj.name),
14440 fmtId(agginfo->aggfn.dobj.namespace->dobj.name),
14441 aggfullsig ? aggfullsig : aggsig, details->
data);
14445 "AGGREGATE", aggsig,
14446 agginfo->aggfn.dobj.namespace->dobj.name);
14450 agginfo->aggfn.dobj.dumpId,
14452 .
namespace = agginfo->aggfn.dobj.namespace->dobj.name,
14453 .owner = agginfo->aggfn.rolname,
14454 .description =
"AGGREGATE",
14456 .createStmt = q->
data,
14457 .dropStmt = delq->
data));
14462 agginfo->aggfn.dobj.namespace->dobj.name,
14463 agginfo->aggfn.rolname,
14464 agginfo->aggfn.dobj.catId, 0, agginfo->aggfn.dobj.dumpId);
14468 agginfo->aggfn.dobj.namespace->dobj.name,
14469 agginfo->aggfn.rolname,
14470 agginfo->aggfn.dobj.catId, 0, agginfo->aggfn.dobj.dumpId);
14483 "FUNCTION", aggsig, NULL,
14484 agginfo->aggfn.dobj.namespace->dobj.name,
14485 agginfo->aggfn.rolname, &agginfo->aggfn.dacl);
14540 "TEXT SEARCH PARSER", qprsname,
14541 prsinfo->
dobj.namespace->dobj.
name);
14546 .namespace = prsinfo->
dobj.namespace->dobj.
name,
14547 .description =
"TEXT SEARCH PARSER",
14549 .createStmt = q->
data,
14550 .dropStmt = delq->
data));
14554 dumpComment(fout,
"TEXT SEARCH PARSER", qprsname,
14555 prsinfo->
dobj.namespace->dobj.
name,
"",
14591 "FROM pg_ts_template p, pg_namespace n "
14592 "WHERE p.oid = '%u' AND n.oid = tmplnamespace",
14618 "TEXT SEARCH DICTIONARY", qdictname,
14619 dictinfo->
dobj.namespace->dobj.
name);
14624 .namespace = dictinfo->
dobj.namespace->dobj.
name,
14626 .description =
"TEXT SEARCH DICTIONARY",
14628 .createStmt = q->
data,
14629 .dropStmt = delq->
data));
14633 dumpComment(fout,
"TEXT SEARCH DICTIONARY", qdictname,
14678 "TEXT SEARCH TEMPLATE", qtmplname,
14679 tmplinfo->
dobj.namespace->dobj.
name);
14684 .namespace = tmplinfo->
dobj.namespace->dobj.
name,
14685 .description =
"TEXT SEARCH TEMPLATE",
14687 .createStmt = q->
data,
14688 .dropStmt = delq->
data));
14692 dumpComment(fout,
"TEXT SEARCH TEMPLATE", qtmplname,
14693 tmplinfo->
dobj.namespace->dobj.
name,
"",
14733 "FROM pg_ts_parser p, pg_namespace n "
14734 "WHERE p.oid = '%u' AND n.oid = prsnamespace",
14751 " ( SELECT alias FROM pg_catalog.ts_token_type('%u'::pg_catalog.oid) AS t\n"
14752 " WHERE t.tokid = m.maptokentype ) AS tokenname,\n"
14753 " m.mapdict::pg_catalog.regdictionary AS dictname\n"
14754 "FROM pg_catalog.pg_ts_config_map AS m\n"
14755 "WHERE m.mapcfg = '%u'\n"
14756 "ORDER BY m.mapcfg, m.maptokentype, m.mapseqno",
14765 for (
i = 0;
i < ntups;
i++)
14780 fmtId(tokenname), dictname);
14796 "TEXT SEARCH CONFIGURATION", qcfgname,
14797 cfginfo->
dobj.namespace->dobj.
name);
14802 .namespace = cfginfo->
dobj.namespace->dobj.
name,
14804 .description =
"TEXT SEARCH CONFIGURATION",
14806 .createStmt = q->
data,
14807 .dropStmt = delq->
data));
14811 dumpComment(fout,
"TEXT SEARCH CONFIGURATION", qcfgname,
14861 "FOREIGN DATA WRAPPER", qfdwname,
14868 .description =
"FOREIGN DATA WRAPPER",
14870 .createStmt = q->
data,
14871 .dropStmt = delq->
data));
14875 dumpComment(fout,
"FOREIGN DATA WRAPPER", qfdwname,
14882 "FOREIGN DATA WRAPPER", qfdwname, NULL,
14918 "FROM pg_foreign_data_wrapper w "
14919 "WHERE w.oid = '%u'",
14949 "SERVER", qsrvname, NULL);
14955 .description =
"SERVER",
14957 .createStmt = q->
data,
14958 .dropStmt = delq->
data));
14969 "FOREIGN SERVER", qsrvname, NULL,
14997 const char *servername,
const char *
namespace,
15026 "array_to_string(ARRAY("
15027 "SELECT quote_ident(option_name) || ' ' || "
15028 "quote_literal(option_value) "
15029 "FROM pg_options_to_table(umoptions) "
15030 "ORDER BY option_name"
15031 "), E',\n ') AS umoptions "
15032 "FROM pg_user_mappings "
15033 "WHERE srvid = '%u' "
15034 "ORDER BY usename",
15043 for (
i = 0;
i < ntups;
i++)
15055 if (umoptions && strlen(umoptions) > 0)
15066 usename, servername);
15070 .namespace =
namespace,
15072 .description =
"USER MAPPING",
15074 .createStmt = q->
data,
15075 .dropStmt = delq->
data));
15106 case DEFACLOBJ_RELATION:
15109 case DEFACLOBJ_SEQUENCE:
15110 type =
"SEQUENCES";
15112 case DEFACLOBJ_FUNCTION:
15113 type =
"FUNCTIONS";
15115 case DEFACLOBJ_TYPE:
15118 case DEFACLOBJ_NAMESPACE:
15123 pg_fatal(
"unrecognized object type in default privileges: %d",
15132 daclinfo->
dobj.namespace != NULL ?
15133 daclinfo->
dobj.namespace->dobj.
name : NULL,
15139 pg_fatal(
"could not parse default ACL list (%s)",
15145 .namespace = daclinfo->
dobj.namespace ?
15146 daclinfo->
dobj.namespace->dobj.
name : NULL,
15148 .description =
"DEFAULT ACL",
15150 .createStmt = q->
data));
15179 const char *nspname,
const char *owner,
15184 const char *acls = dacl->
acl;
15187 const char *initprivs = dacl->
initprivs;
15188 const char *baseacls;
15196 if (dopt->
dataOnly && strcmp(
type,
"LARGE OBJECT") != 0)
15215 initprivs && *initprivs !=
'\0')
15221 pg_fatal(
"could not parse initial ACL list (%s) or default (%s) for object \"%s\" (%s)",
15223 appendPQExpBufferStr(sql,
"SELECT pg_catalog.binary_upgrade_set_record_init_privs(false);\n");
15234 if (initprivs && *initprivs !=
'\0')
15236 baseacls = initprivs;
15237 if (acls == NULL || *acls ==
'\0')
15244 acls, baseacls, owner,
15246 pg_fatal(
"could not parse ACL list (%s) or default (%s) for object \"%s\" (%s)",
15260 aclDeps[nDeps++] = objDumpId;
15262 aclDeps[nDeps++] = altDumpId;
15268 .namespace = nspname,
15270 .description =
"ACL",
15272 .createStmt = sql->
data,
15304 const char *
namespace,
const char *owner,
15321 if (strcmp(
type,
"LARGE OBJECT") != 0)
15338 for (
i = 0;
i < nlabels;
i++)
15343 if (labels[
i].objsubid != subid)
15347 "SECURITY LABEL FOR %s ON %s ",
15349 if (
namespace && *
namespace)
15356 if (query->
len > 0)
15363 .namespace =
namespace,
15365 .description =
"SECURITY LABEL",
15367 .createStmt = query->
data,
15412 for (
i = 0;
i < nlabels;
i++)
15414 const char *colname;
15438 if (query->
len > 0)
15445 .namespace = tbinfo->
dobj.namespace->dobj.
name,
15447 .description =
"SECURITY LABEL",
15449 .createStmt = query->
data,
15483 while (low <= high)
15485 middle = low + (high - low) / 2;
15487 if (classoid < middle->classoid)
15489 else if (classoid > middle->
classoid)
15491 else if (objoid < middle->objoid)
15493 else if (objoid > middle->
objoid)
15511 while (middle > low)
15513 if (classoid != middle[-1].classoid ||
15514 objoid != middle[-1].objoid)
15523 while (middle <= high)
15525 if (classoid != middle->
classoid ||
15526 objoid != middle->
objoid)
15560 "SELECT label, provider, classoid, objoid, objsubid "
15561 "FROM pg_catalog.pg_seclabel "
15562 "ORDER BY classoid, objoid, objsubid");
15579 for (
i = 0;
i < ntups;
i++)
15589 if (dobj == NULL ||
15602 ((
TableInfo *) dobj)->relkind == RELKIND_COMPOSITE_TYPE)
15642 if (tbinfo->
relkind == RELKIND_SEQUENCE)
15652 const char *objtype =
15653 (tbinfo->
relkind == RELKIND_SEQUENCE) ?
"SEQUENCE" :
"TABLE";
15657 objtype, namecopy, NULL,
15678 "PREPARE getColumnACLs(pg_catalog.oid) AS\n");
15693 "SELECT at.attname, "
15695 "'{}' AS acldefault, "
15696 "pip.privtype, pip.initprivs "
15697 "FROM pg_catalog.pg_attribute at "
15698 "LEFT JOIN pg_catalog.pg_init_privs pip ON "
15699 "(at.attrelid = pip.objoid "
15700 "AND pip.classoid = 'pg_catalog.pg_class'::pg_catalog.regclass "
15701 "AND at.attnum = pip.objsubid) "
15702 "WHERE at.attrelid = $1 AND "
15703 "NOT at.attisdropped "
15704 "AND (at.attacl IS NOT NULL OR pip.initprivs IS NOT NULL) "
15705 "ORDER BY at.attnum");
15710 "SELECT attname, attacl, '{}' AS acldefault, "
15711 "NULL AS privtype, NULL AS initprivs "
15712 "FROM pg_catalog.pg_attribute "
15713 "WHERE attrelid = $1 AND NOT attisdropped "
15714 "AND attacl IS NOT NULL "
15715 "ORDER BY attnum");
15724 "EXECUTE getColumnACLs('%u')",
15739 coldacl.
acl = attacl;
15751 "TABLE", namecopy, attnamecopy,
15779 "SELECT pg_catalog.pg_get_viewdef('%u'::pg_catalog.oid) AS viewdef",
15787 pg_fatal(
"query to obtain definition of view \"%s\" returned no data",
15790 pg_fatal(
"query to obtain definition of view \"%s\" returned more than one definition",
15797 pg_fatal(
"definition of view \"%s\" appears to be empty (length zero)",
15869 const char *reltypename;
15881 pg_log_warning(
"WITH OIDS is not supported anymore (table \"%s\")",
15888 if (tbinfo->
relkind == RELKIND_VIEW)
15896 reltypename =
"VIEW";
15927 char *partkeydef = NULL;
15928 char *ftoptions = NULL;
15929 char *srvname = NULL;
15930 char *foreign =
"";
15938 case RELKIND_PARTITIONED_TABLE:
15943 reltypename =
"TABLE";
15947 "SELECT pg_get_partkeydef('%u')",
15955 case RELKIND_FOREIGN_TABLE:
15962 reltypename =
"FOREIGN TABLE";
15966 "SELECT fs.srvname, "
15967 "pg_catalog.array_to_string(ARRAY("
15968 "SELECT pg_catalog.quote_ident(option_name) || "
15969 "' ' || pg_catalog.quote_literal(option_value) "
15970 "FROM pg_catalog.pg_options_to_table(ftoptions) "
15971 "ORDER BY option_name"
15972 "), E',\n ') AS ftoptions "
15973 "FROM pg_catalog.pg_foreign_table ft "
15974 "JOIN pg_catalog.pg_foreign_server fs "
15975 "ON (fs.oid = ft.ftserver) "
15976 "WHERE ft.ftrelid = '%u'",
15986 foreign =
"FOREIGN ";
15989 case RELKIND_MATVIEW:
15990 reltypename =
"MATERIALIZED VIEW";
15993 reltypename =
"TABLE";
16021 if (tbinfo->
relkind != RELKIND_MATVIEW)
16035 bool print_default;
16036 bool print_notnull;
16042 print_default = (tbinfo->
attrdefs[
j] != NULL &&
16061 !print_default && !print_notnull &&
16066 if (actual_atts == 0)
16152 if (actual_atts == 0)
16183 for (k = 0; k < numParents; k++)
16194 if (tbinfo->
relkind == RELKIND_PARTITIONED_TABLE)
16197 if (tbinfo->
relkind == RELKIND_FOREIGN_TABLE)
16204 bool addcomma =
false;
16223 if (ftoptions && ftoptions[0])
16230 if (tbinfo->
relkind == RELKIND_MATVIEW)
16243 if (tbinfo->
relkind == RELKIND_MATVIEW)
16245 "pg_catalog.pg_class",
16246 "MATERIALIZED VIEW",
16261 "SELECT pg_catalog.binary_upgrade_set_missing_value(");
16294 (tbinfo->
relkind == RELKIND_RELATION ||
16295 tbinfo->
relkind == RELKIND_FOREIGN_TABLE ||
16296 tbinfo->
relkind == RELKIND_PARTITIONED_TABLE))
16304 "SET attlen = %d, "
16305 "attalign = '%c', attbyval = false\n"
16306 "WHERE attname = ",
16314 if (tbinfo->
relkind == RELKIND_RELATION ||
16315 tbinfo->
relkind == RELKIND_PARTITIONED_TABLE)
16328 "SET attislocal = false\n"
16329 "WHERE attname = ");
16345 "SET conislocal = false\n"
16346 "WHERE contype = 'n' AND conrelid = ");
16362 for (k = 0; k < tbinfo->
ncheck; k++)
16371 foreign, qualrelname,
16375 "SET conislocal = false\n"
16376 "WHERE contype = 'c' AND conname = ");
16386 for (k = 0; k < numParents; k++)
16414 (tbinfo->
relkind == RELKIND_RELATION ||
16415 tbinfo->
relkind == RELKIND_MATVIEW))
16419 "SET relfrozenxid = '%u', relminmxid = '%u'\n"
16431 appendPQExpBufferStr(q,
"\n-- For binary upgrade, set toast's relfrozenxid and relminmxid\n");
16433 "SET relfrozenxid = '%u', relminmxid = '%u'\n"
16434 "WHERE oid = '%u';\n",
16452 "SET relispopulated = 't'\n"
16480 "ALTER %sTABLE ONLY %s ALTER COLUMN %s SET NOT NULL;\n",
16481 foreign, qualrelname,
16485 "ALTER %sTABLE ONLY %s ADD CONSTRAINT %s NOT NULL %s;\n",
16486 foreign, qualrelname,
16497 appendPQExpBuffer(q,
"ALTER %sTABLE ONLY %s ALTER COLUMN %s SET STATISTICS %d;\n",
16498 foreign, qualrelname,
16510 case TYPSTORAGE_PLAIN:
16513 case TYPSTORAGE_EXTERNAL:
16516 case TYPSTORAGE_EXTENDED:
16519 case TYPSTORAGE_MAIN:
16530 appendPQExpBuffer(q,
"ALTER %sTABLE ONLY %s ALTER COLUMN %s SET STORAGE %s;\n",
16531 foreign, qualrelname,
16541 const char *cmname;
16556 if (cmname != NULL)
16557 appendPQExpBuffer(q,
"ALTER %sTABLE ONLY %s ALTER COLUMN %s SET COMPRESSION %s;\n",
16558 foreign, qualrelname,
16568 foreign, qualrelname,
16575 if (tbinfo->
relkind == RELKIND_FOREIGN_TABLE &&
16578 "ALTER FOREIGN TABLE %s ALTER COLUMN %s OPTIONS (\n"
16594 if ((tbinfo->
relkind == RELKIND_RELATION ||
16595 tbinfo->
relkind == RELKIND_PARTITIONED_TABLE ||
16596 tbinfo->
relkind == RELKIND_MATVIEW) &&
16603 else if (tbinfo->
relreplident == REPLICA_IDENTITY_NOTHING)
16608 else if (tbinfo->
relreplident == REPLICA_IDENTITY_FULL)
16621 reltypename, qrelname,
16622 tbinfo->
dobj.namespace->dobj.
name);
16627 char *tableam = NULL;
16636 if (RELKIND_HAS_TABLESPACE(tbinfo->
relkind))
16639 if (RELKIND_HAS_TABLE_AM(tbinfo->
relkind))
16640 tableam = tbinfo->
amname;
16644 .namespace = tbinfo->
dobj.namespace->dobj.
name,
16646 .tableam = tableam,
16648 .description = reltypename,
16651 .createStmt = q->
data,
16652 .dropStmt = delq->
data));
16714 "PREPARE dumpTableAttach(pg_catalog.oid) AS\n");
16717 "SELECT pg_get_expr(c.relpartbound, c.oid) "
16719 "WHERE c.oid = $1");
16727 "EXECUTE dumpTableAttach('%u')",
16735 "ALTER TABLE ONLY %s ",
16738 "ATTACH PARTITION %s %s;\n",
16751 .namespace = attachinfo->
dobj.namespace->dobj.
name,
16753 .description =
"TABLE ATTACH",
16755 .createStmt = q->
data));
16769 int adnum = adinfo->
adnum;
16789 foreign = tbinfo->
relkind == RELKIND_FOREIGN_TABLE ?
"FOREIGN " :
"";
16792 "ALTER %sTABLE ONLY %s ALTER COLUMN %s SET DEFAULT %s;\n",
16797 foreign, qualrelname,
16805 .
namespace = tbinfo->
dobj.namespace->dobj.
name,
16807 .description =
"DEFAULT",
16809 .createStmt = q->
data,
16810 .dropStmt = delq->
data));
16825 static const char *
16828 if (attrnum > 0 && attrnum <= tblInfo->numatts)
16829 return tblInfo->
attnames[attrnum - 1];
16845 pg_fatal(
"invalid column number %d for table \"%s\"",
16882 if (!is_constraint)
16886 char **indstatcolsarray = NULL;
16887 char **indstatvalsarray = NULL;
16918 if (strlen(indstatcols) != 0 || strlen(indstatvals) != 0)
16922 if (!
parsePGArray(indstatcols, &indstatcolsarray, &nstatcols))
16923 pg_fatal(
"could not parse index statistic columns");
16924 if (!
parsePGArray(indstatvals, &indstatvalsarray, &nstatvals))
16925 pg_fatal(
"could not parse index statistic values");
16926 if (nstatcols != nstatvals)
16927 pg_fatal(
"mismatched number of columns and values for index statistics");
16929 for (
j = 0;
j < nstatcols;
j++)
16938 indstatcolsarray[
j]);
16940 indstatvalsarray[
j]);
16946 "pg_catalog.pg_class",
16947 "INDEX", qqindxname);
16964 .namespace = tbinfo->
dobj.namespace->dobj.
name,
16967 .description =
"INDEX",
16969 .createStmt = q->
data,
16970 .dropStmt = delq->
data));
16972 free(indstatcolsarray);
16973 free(indstatvalsarray);
16979 tbinfo->
dobj.namespace->dobj.
name,
17020 .namespace = attachinfo->
dobj.namespace->dobj.
name,
17022 .description =
"INDEX ATTACH",
17024 .createStmt = q->
data));
17041 char *qstatsextname;
17056 "pg_catalog.pg_get_statisticsobjdef('%u'::pg_catalog.oid)",
17085 .namespace = statsextinfo->
dobj.namespace->dobj.
name,
17086 .owner = statsextinfo->
rolname,
17087 .description =
"STATISTICS",
17089 .createStmt = q->
data,
17090 .dropStmt = delq->
data));
17095 statsextinfo->
dobj.namespace->dobj.
name,
17104 free(qstatsextname);
17128 foreign = tbinfo &&
17129 tbinfo->
relkind == RELKIND_FOREIGN_TABLE ?
"FOREIGN " :
"";
17131 if (coninfo->
contype ==
'p' ||
17141 if (indxinfo == NULL)
17142 pg_fatal(
"missing index for constraint \"%s\"",
17162 coninfo->
contype ==
'p' ?
"PRIMARY KEY" :
"UNIQUE");
17175 int indkey = (int) indxinfo->
indkeys[k];
17183 (k == 0) ?
"" :
", ",
17192 for (k = indxinfo->
indnkeyattrs; k < indxinfo->indnattrs; k++)
17194 int indkey = (int) indxinfo->
indkeys[k];
17261 "pg_catalog.pg_class",
"INDEX",
17274 .
namespace = tbinfo->
dobj.namespace->dobj.
name,
17277 .description =
"CONSTRAINT",
17279 .createStmt = q->
data,
17280 .dropStmt = delq->
data));
17282 else if (coninfo->
contype ==
'f')
17292 only = tbinfo->
relkind == RELKIND_PARTITIONED_TABLE ?
"" :
"ONLY ";
17314 .
namespace = tbinfo->
dobj.namespace->dobj.
name,
17316 .description =
"FK CONSTRAINT",
17318 .createStmt = q->
data,
17319 .dropStmt = delq->
data));
17321 else if (coninfo->
contype ==
'c' && tbinfo)
17345 .
namespace = tbinfo->
dobj.namespace->dobj.
name,
17347 .description =
"CHECK CONSTRAINT",
17349 .createStmt = q->
data,
17350 .dropStmt = delq->
data));
17353 else if (coninfo->
contype ==
'c' && tbinfo == NULL)
17377 .
namespace = tyinfo->
dobj.namespace->dobj.
name,
17379 .description =
"CHECK CONSTRAINT",
17381 .createStmt = q->
data,
17382 .dropStmt = delq->
data));
17387 pg_fatal(
"unrecognized constraint type: %c",
17392 if (tbinfo && coninfo->
separate &&
17422 tbinfo->
dobj.namespace->dobj.
name,
17448 int64 default_minv,
17462 "SELECT format_type(seqtypid, NULL), "
17463 "seqstart, seqincrement, "
17465 "seqcache, seqcycle "
17466 "FROM pg_catalog.pg_sequence "
17467 "WHERE seqrelid = '%u'::oid",
17479 "SELECT 'bigint' AS sequence_type, "
17480 "start_value, increment_by, max_value, min_value, "
17481 "cache_value, is_cycled FROM %s",
17488 pg_fatal(
ngettext(
"query to get data of sequence \"%s\" returned %d row (expected 1)",
17489 "query to get data of sequence \"%s\" returned %d rows (expected 1)",
17502 is_ascending = (incby[0] !=
'-');
17503 if (strcmp(seqtype,
"smallint") == 0)
17508 else if (strcmp(seqtype,
"integer") == 0)
17513 else if (strcmp(seqtype,
"bigint") == 0)
17520 pg_fatal(
"unrecognized sequence type: %s", seqtype);
17521 default_minv = default_maxv = 0;
17532 if (strcmp(minv, bufm) == 0)
17534 if (strcmp(maxv, bufx) == 0)
17567 "ALTER COLUMN %s ADD GENERATED ",
17579 "CREATE %sSEQUENCE %s\n",
17584 if (strcmp(seqtype,
"bigint") != 0)
17604 cache, (cycled ?
"\n CYCLE" :
""));
17611 "ALTER SEQUENCE %s SET %s;\n",
17614 "UNLOGGED" :
"LOGGED");
17623 "SEQUENCE", qseqname,
17624 tbinfo->
dobj.namespace->dobj.
name);
17629 .namespace = tbinfo->
dobj.namespace->dobj.
name,
17631 .description =
"SEQUENCE",
17633 .createStmt = query->
data,
17634 .dropStmt = delqry->
data));
17652 if (owning_tab == NULL)
17653 pg_fatal(
"failed sanity check, parent table with OID %u of sequence with OID %u not found",
17669 .namespace = tbinfo->
dobj.namespace->dobj.
name,
17671 .description =
"SEQUENCE OWNED BY",
17673 .createStmt = query->
data,
17711 "SELECT last_value, is_called FROM %s",
17717 pg_fatal(
ngettext(
"query to get data of sequence \"%s\" returned %d row (expected 1)",
17718 "query to get data of sequence \"%s\" returned %d rows (expected 1)",
17729 last, (called ?
"true" :
"false"));
17734 .namespace = tbinfo->
dobj.namespace->dobj.
name,
17736 .description =
"SEQUENCE SET",
17738 .createStmt = query->
data,
17782 "pg_catalog.pg_trigger",
"TRIGGER",
17783 trigidentity->
data);
17798 tbinfo->
relkind == RELKIND_FOREIGN_TABLE ?
"FOREIGN " :
"",
17823 tbinfo->
relkind == RELKIND_FOREIGN_TABLE ?
"FOREIGN " :
"",
17853 .
namespace = tbinfo->
dobj.namespace->dobj.
name,
17855 .description =
"TRIGGER",
17857 .createStmt = query->
data,
17858 .dropStmt = delqry->
data));
17899 if (strcmp(
"", evtinfo->
evttags) != 0)
17937 "EVENT TRIGGER", qevtname, NULL);
17943 .description =
"EVENT TRIGGER",
17945 .createStmt = query->
data,
17946 .dropStmt = delqry->
data));
18028 "SELECT pg_catalog.pg_get_ruledef('%u'::pg_catalog.oid)",
18034 pg_fatal(
"query to get rule \"%s\" for table \"%s\" failed: wrong number of rows returned",
18097 .
namespace = tbinfo->
dobj.namespace->dobj.
name,
18099 .description =
"RULE",
18101 .createStmt = cmd->
data,
18102 .dropStmt = delcmd->
data));
18107 tbinfo->
dobj.namespace->dobj.
name,
18143 if (numExtensions == 0)
18150 "classid, objid, refobjid "
18152 "WHERE refclassid = 'pg_extension'::regclass "
18153 "AND deptype = 'e' "
18171 for (
i = 0;
i < ntups;
i++)
18187 pg_log_warning(
"could not find referenced extension %u", extId);
18235 if (numExtensions == 0)
18249 for (
i = 0;
i < numExtensions;
i++)
18254 char **extconfigarray = NULL;
18255 char **extconditionarray = NULL;
18256 int nconfigitems = 0;
18257 int nconditionitems = 0;
18268 if (strlen(extconfig) != 0 || strlen(extcondition) != 0)
18272 if (!
parsePGArray(extconfig, &extconfigarray, &nconfigitems))
18273 pg_fatal(
"could not parse %s array",
"extconfig");
18274 if (!
parsePGArray(extcondition, &extconditionarray, &nconditionitems))
18275 pg_fatal(
"could not parse %s array",
"extcondition");
18276 if (nconfigitems != nconditionitems)
18277 pg_fatal(
"mismatched number of configurations and conditions for extension");
18279 for (
j = 0;
j < nconfigitems;
j++)
18282 Oid configtbloid =
atooid(extconfigarray[
j]);
18287 if (configtbl == NULL)
18303 if (configtbl->
dobj.namespace->dobj.
dump &
18322 if (configtbl->
dataObj != NULL)
18324 if (strlen(extconditionarray[
j]) > 0)
18330 if (extconfigarray)
18331 free(extconfigarray);
18332 if (extconditionarray)
18333 free(extconditionarray);
18348 "SELECT conrelid, confrelid "
18349 "FROM pg_constraint "
18350 "JOIN pg_depend ON (objid = confrelid) "
18351 "WHERE contype = 'f' "
18352 "AND refclassid = 'pg_extension'::regclass "
18353 "AND classid = 'pg_class'::regclass;");
18362 for (
i = 0;
i < ntups;
i++)
18374 if (reftable == NULL ||
18376 contable == NULL ||
18422 "classid, objid, refclassid, refobjid, deptype "
18424 "WHERE deptype != 'p' AND deptype != 'e'\n");
18437 "SELECT 'pg_opfamily'::regclass AS classid, amopfamily AS objid, refclassid, refobjid, deptype "
18438 "FROM pg_depend d, pg_amop o "
18439 "WHERE deptype NOT IN ('p', 'e', 'i') AND "
18440 "classid = 'pg_amop'::regclass AND objid = o.oid "
18441 "AND NOT (refclassid = 'pg_opfamily'::regclass AND amopfamily = refobjid)\n");
18445 "SELECT 'pg_opfamily'::regclass AS classid, amprocfamily AS objid, refclassid, refobjid, deptype "
18446 "FROM pg_depend d, pg_amproc p "
18447 "WHERE deptype NOT IN ('p', 'e', 'i') AND "
18448 "classid = 'pg_amproc'::regclass AND objid = p.oid "
18449 "AND NOT (refclassid = 'pg_opfamily'::regclass AND amprocfamily = refobjid)\n");
18471 for (
i = 0;
i < ntups;
i++)
18483 if (dobj == NULL ||
18503 if (refdobj == NULL)
18518 if (deptype ==
'x')
18528 if (deptype ==
'i' &&
18579 for (
i = 0;
i < numObjs;
i++)
18643 if (((
RuleInfo *) dobj)->separate)
18712 if (dobj->
nDeps <= 0)
18720 &dependencies, &nDeps, &allocDeps);
18725 nDeps *
sizeof(
DumpId));
18730 free(dependencies);
18737 DumpId **dependencies,
int *nDeps,
int *allocDeps)
18756 if (*nDeps >= *allocDeps)
18760 *allocDeps *
sizeof(
DumpId));
18762 (*dependencies)[*nDeps] = depid;
18776 dependencies, nDeps, allocDeps);
18791 static const char *
18809 if (typeInfo && typeInfo->
ftypname)
18813 appendPQExpBuffer(query,
"SELECT pg_catalog.format_type('%u'::pg_catalog.oid, NULL)",
18842 static const char *
18854 for (
i = 0;
i < numatts;
i++)
18856 if (attisdropped[
i])
18858 if (attgenerated[
i])
18870 return buffer->
data;
18880 return (reloptions != NULL && strlen(reloptions) > 2);
18890 const char *prefix,
Archive *fout)
Acl * acldefault(ObjectType objtype, Oid ownerId)
#define InvalidAttrNumber
int lo_read(int fd, char *buf, int len)
void recordExtensionMembership(CatalogId catId, ExtensionInfo *ext)
FuncInfo * findFuncByOid(Oid oid)
NamespaceInfo * findNamespaceByOid(Oid oid)
SubscriptionInfo * findSubscriptionByOid(Oid oid)
ExtensionInfo * findOwningExtension(CatalogId catalogId)
TableInfo * getSchemaData(Archive *fout, int *numTablesPtr)
DumpableObject * findObjectByCatalogId(CatalogId catalogId)
void addObjectDependency(DumpableObject *dobj, DumpId refId)
DumpableObject * findObjectByDumpId(DumpId dumpId)
void parseOidArray(const char *str, Oid *array, int arraysize)
TableInfo * findTableByOid(Oid oid)
DumpId createDumpId(void)
ExtensionInfo * findExtensionByOid(Oid oid)
void AssignDumpId(DumpableObject *dobj)
void getDumpableObjects(DumpableObject ***objs, int *numObjs)
CollInfo * findCollationByOid(Oid oid)
TypeInfo * findTypeByOid(Oid oid)
OprInfo * findOprByOid(Oid oid)
PublicationInfo * findPublicationByOid(Oid oid)
void on_exit_close_archive(Archive *AHX)
void init_parallel_dump_utils(void)
static void cleanup(void)
static const gbtree_vinfo tinfo
#define ngettext(s, p, n)
#define PG_TEXTDOMAIN(domain)
#define OidIsValid(objectId)
void set_pglocale_pgservice(const char *argv0, const char *app)
char * supports_compression(const pg_compress_specification compression_spec)
bool parse_compress_algorithm(char *name, pg_compress_algorithm *algorithm)
void parse_compress_specification(pg_compress_algorithm algorithm, char *specification, pg_compress_specification *result)
char * validate_compress_specification(pg_compress_specification *spec)
#define PG_COMPRESSION_OPTION_WORKERS
void parse_compress_options(const char *option, char **algorithm, char **detail)
#define ALWAYS_SECURE_SEARCH_PATH_SQL
PGconn * GetConnection(UserMapping *user, bool will_prep_stmt, PgFdwConnState **state)
static void PGresult * res
bool buildACLCommands(const char *name, const char *subname, const char *nspname, const char *type, const char *acls, const char *baseacls, const char *owner, const char *prefix, int remoteVersion, PQExpBuffer sql)
void buildShSecLabelQuery(const char *catalog_name, Oid objectId, PQExpBuffer sql)
void makeAlterConfigCommand(PGconn *conn, const char *configitem, const char *type, const char *name, const char *type2, const char *name2, PQExpBuffer buf)
bool buildDefaultACLCommands(const char *type, const char *nspname, const char *acls, const char *acldefault, const char *owner, int remoteVersion, PQExpBuffer sql)
bool variable_is_guc_list_quote(const char *name)
void quoteAclUserName(PQExpBuffer output, const char *input)
void emitShSecLabels(PGconn *conn, PGresult *res, PQExpBuffer buffer, const char *objtype, const char *objname)
const char * PQparameterStatus(const PGconn *conn, const char *paramName)
char * PQdb(const PGconn *conn)
char * PQerrorMessage(const PGconn *conn)
int PQclientEncoding(const PGconn *conn)
int PQsetClientEncoding(PGconn *conn, const char *encoding)
int PQgetlength(const PGresult *res, int tup_num, int field_num)
void PQfreemem(void *ptr)
Oid PQftype(const PGresult *res, int field_num)
ExecStatusType PQresultStatus(const PGresult *res)
int PQntuples(const PGresult *res)
char * PQfname(const PGresult *res, int field_num)
char * PQgetvalue(const PGresult *res, int tup_num, int field_num)
int PQfnumber(const PGresult *res, const char *field_name)
int PQgetisnull(const PGresult *res, int tup_num, int field_num)
int PQnfields(const PGresult *res)
PGresult * PQgetResult(PGconn *conn)
int PQgetCopyData(PGconn *conn, char **buffer, int async)
int lo_close(PGconn *conn, int fd)
int lo_open(PGconn *conn, Oid lobjId, int mode)
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
void filter_init(FilterStateData *fstate, const char *filename, exit_function f_exit)
void filter_free(FilterStateData *fstate)
bool filter_read_item(FilterStateData *fstate, char **objname, FilterCommandType *comtype, FilterObjectType *objtype)
void pg_log_filter_error(FilterStateData *fstate, const char *fmt,...)
const char * filter_object_type_name(FilterObjectType fot)
@ FILTER_OBJECT_TYPE_TABLE_DATA_AND_CHILDREN
@ FILTER_OBJECT_TYPE_SCHEMA
@ FILTER_OBJECT_TYPE_INDEX
@ FILTER_OBJECT_TYPE_TRIGGER
@ FILTER_OBJECT_TYPE_FOREIGN_DATA
@ FILTER_OBJECT_TYPE_DATABASE
@ FILTER_OBJECT_TYPE_FUNCTION
@ FILTER_OBJECT_TYPE_TABLE_DATA
@ FILTER_OBJECT_TYPE_NONE
@ FILTER_OBJECT_TYPE_TABLE_AND_CHILDREN
@ FILTER_OBJECT_TYPE_EXTENSION
@ FILTER_OBJECT_TYPE_TABLE
@ FILTER_COMMAND_TYPE_NONE
@ FILTER_COMMAND_TYPE_EXCLUDE
@ FILTER_COMMAND_TYPE_INCLUDE
int getopt_long(int argc, char *const argv[], const char *optstring, const struct option *longopts, int *longindex)
#define required_argument
static DataDirSyncMethod sync_method
if(TABLE==NULL||TABLE_index==NULL)
static JitProviderCallbacks provider
Assert(fmt[strlen(fmt) - 1] !='\n')
void pg_logging_increase_verbosity(void)
void pg_logging_init(const char *argv0)
void pg_logging_set_level(enum pg_log_level new_level)
#define pg_log_error(...)
#define pg_log_error_hint(...)
#define pg_log_error_detail(...)
char * pstrdup(const char *in)
bool option_parse_int(const char *optarg, const char *optname, int min_range, int max_range, int *result)
bool parse_sync_method(const char *optarg, DataDirSyncMethod *sync_method)
static AmcheckOptions opts
void ConnectDatabase(Archive *AHX, const ConnParams *cparams, bool isReconnect)
int EndLO(Archive *AHX, Oid oid)
void ProcessArchiveRestoreOptions(Archive *AHX)
#define appendStringLiteralAH(buf, str, AH)
RestoreOptions * NewRestoreOptions(void)
int StartLO(Archive *AHX, Oid oid)
Archive * CreateArchive(const char *FileSpec, const ArchiveFormat fmt, const pg_compress_specification compression_spec, bool dosync, ArchiveMode mode, SetupWorkerPtrType setupDumpWorker, DataDirSyncMethod sync_method)
enum _archiveFormat ArchiveFormat
void CloseArchive(Archive *AHX)
@ PREPQUERY_DUMPTABLEATTACH
@ PREPQUERY_DUMPRANGETYPE
@ PREPQUERY_DUMPCOMPOSITETYPE
@ PREPQUERY_GETCOLUMNACLS
@ PREPQUERY_GETDOMAINCONSTRAINTS
int archprintf(Archive *AH, const char *fmt,...) pg_attribute_printf(2
void SetArchiveOptions(Archive *AH, DumpOptions *dopt, RestoreOptions *ropt)
void RestoreArchive(Archive *AHX)
void archputs(const char *s, Archive *AH)
void InitDumpOptions(DumpOptions *opts)
void WriteData(Archive *AHX, const void *data, size_t dLen)
int(* DataDumperPtr)(Archive *AH, const void *userArg)
int TocIDRequired(ArchiveHandle *AH, DumpId id)
TocEntry * ArchiveEntry(Archive *AHX, CatalogId catalogId, DumpId dumpId, ArchiveOpts *opts)
#define ARCHIVE_OPTS(...)
void ExecuteSqlStatement(Archive *AHX, const char *query)
PGresult * ExecuteSqlQuery(Archive *AHX, const char *query, ExecStatusType status)
PGresult * ExecuteSqlQueryForSingleRow(Archive *fout, const char *query)
void set_dump_section(const char *arg, int *dumpSections)
static PgChecksumMode mode
static void expand_schema_name_patterns(Archive *fout, SimpleStringList *patterns, SimpleOidList *oids, bool strict_names)
NamespaceInfo * getNamespaces(Archive *fout, int *numNamespaces)
static const CatalogId nilCatalogId
static void dumpEncoding(Archive *AH)
void getConstraints(Archive *fout, TableInfo tblinfo[], int numTables)
static SimpleStringList schema_include_patterns
static void dumpAttrDef(Archive *fout, const AttrDefInfo *adinfo)
static void selectDumpableProcLang(ProcLangInfo *plang, Archive *fout)
static PQExpBuffer createDummyViewAsClause(Archive *fout, const TableInfo *tbinfo)
static void dumpUserMappings(Archive *fout, const char *servername, const char *namespace, const char *owner, CatalogId catalogId, DumpId dumpId)
static void dumpPublicationNamespace(Archive *fout, const PublicationSchemaInfo *pubsinfo)
static void addBoundaryDependencies(DumpableObject **dobjs, int numObjs, DumpableObject *boundaryObjs)
void getPublicationNamespaces(Archive *fout)
static void dumpSearchPath(Archive *AH)
static void selectDumpableTable(TableInfo *tbinfo, Archive *fout)
static DumpableObject * createBoundaryObjects(void)
static char * convertTSFunction(Archive *fout, Oid funcOid)
static void dumpDatabase(Archive *fout)
static SimpleStringList table_include_patterns
static void append_depends_on_extension(Archive *fout, PQExpBuffer create, const DumpableObject *dobj, const char *catalog, const char *keyword, const char *objname)
static Oid get_next_possible_free_pg_type_oid(Archive *fout, PQExpBuffer upgrade_query)
static void dumpNamespace(Archive *fout, const NamespaceInfo *nspinfo)
static bool forcePartitionRootLoad(const TableInfo *tbinfo)
static void dumpCast(Archive *fout, const CastInfo *cast)
static SimpleOidList schema_exclude_oids
static bool have_extra_float_digits
static void dumpIndex(Archive *fout, const IndxInfo *indxinfo)
void getPartitioningInfo(Archive *fout)
static void dumpBaseType(Archive *fout, const TypeInfo *tyinfo)
DefaultACLInfo * getDefaultACLs(Archive *fout, int *numDefaultACLs)
static SimpleOidList extension_include_oids
static void dumpTSDictionary(Archive *fout, const TSDictInfo *dictinfo)
static void dumpAgg(Archive *fout, const AggInfo *agginfo)
static int extra_float_digits
static void dumpTableComment(Archive *fout, const TableInfo *tbinfo, const char *reltypename)
static SimpleStringList extension_include_patterns
static void selectDumpableNamespace(NamespaceInfo *nsinfo, Archive *fout)
static void dumpTrigger(Archive *fout, const TriggerInfo *tginfo)
static void binary_upgrade_set_type_oids_by_rel(Archive *fout, PQExpBuffer upgrade_buffer, const TableInfo *tbinfo)
static void dumpTable(Archive *fout, const TableInfo *tbinfo)
static SimpleStringList table_exclude_patterns
static PQExpBuffer createViewAsClause(Archive *fout, const TableInfo *tbinfo)
static void dumpStatisticsExt(Archive *fout, const StatsExtInfo *statsextinfo)
void getPolicies(Archive *fout, TableInfo tblinfo[], int numTables)
static void dumpRangeType(Archive *fout, const TypeInfo *tyinfo)
static void binary_upgrade_set_pg_class_oids(Archive *fout, PQExpBuffer upgrade_buffer, Oid pg_class_oid, bool is_index)
void getExtensionMembership(Archive *fout, ExtensionInfo extinfo[], int numExtensions)
static void dumpComment(Archive *fout, const char *type, const char *name, const char *namespace, const char *owner, CatalogId catalogId, int subid, DumpId dumpId)
static char * getFormattedOperatorName(const char *oproid)
ForeignServerInfo * getForeignServers(Archive *fout, int *numForeignServers)
static char * format_function_signature(Archive *fout, const FuncInfo *finfo, bool honor_quotes)
static pg_compress_algorithm compression_algorithm
static void dumpStdStrings(Archive *AH)
static void dumpConstraint(Archive *fout, const ConstraintInfo *coninfo)
static void dumpType(Archive *fout, const TypeInfo *tyinfo)
static void dumpTableAttach(Archive *fout, const TableAttachInfo *attachinfo)
AccessMethodInfo * getAccessMethods(Archive *fout, int *numAccessMethods)
FdwInfo * getForeignDataWrappers(Archive *fout, int *numForeignDataWrappers)
FuncInfo * getFuncs(Archive *fout, int *numFuncs)
static void help(const char *progname)
static void dumpAccessMethod(Archive *fout, const AccessMethodInfo *aminfo)
TSConfigInfo * getTSConfigurations(Archive *fout, int *numTSConfigs)
int main(int argc, char **argv)
static void dumpOpr(Archive *fout, const OprInfo *oprinfo)
static void selectDumpableStatisticsObject(StatsExtInfo *sobj, Archive *fout)
static void selectDumpablePublicationObject(DumpableObject *dobj, Archive *fout)
static void dumpSequenceData(Archive *fout, const TableDataInfo *tdinfo)
static void dumpFunc(Archive *fout, const FuncInfo *finfo)
static void selectDumpableDefaultACL(DefaultACLInfo *dinfo, DumpOptions *dopt)
static void BuildArchiveDependencies(Archive *fout)
ConvInfo * getConversions(Archive *fout, int *numConversions)
void getOwnedSeqs(Archive *fout, TableInfo tblinfo[], int numTables)
static void makeTableDataInfo(DumpOptions *dopt, TableInfo *tbinfo)
static const char * getAttrName(int attrnum, const TableInfo *tblInfo)
static void dumpForeignServer(Archive *fout, const ForeignServerInfo *srvinfo)
static RoleNameItem * rolenames
static void collectRoleNames(Archive *fout)
static void appendReloptionsArrayAH(PQExpBuffer buffer, const char *reloptions, const char *prefix, Archive *fout)
static void dumpTableData(Archive *fout, const TableDataInfo *tdinfo)
static void prohibit_crossdb_refs(PGconn *conn, const char *dbname, const char *pattern)
static int dumpTableData_copy(Archive *fout, const void *dcontext)
static const char * getFormattedTypeName(Archive *fout, Oid oid, OidOptions opts)
static void getDependencies(Archive *fout)
static void buildMatViewRefreshDependencies(Archive *fout)
static void binary_upgrade_set_type_oids_by_type_oid(Archive *fout, PQExpBuffer upgrade_buffer, Oid pg_type_oid, bool force_array_type, bool include_multirange_type)
#define DUMP_DEFAULT_ROWS_PER_INSERT
void getPublicationTables(Archive *fout, TableInfo tblinfo[], int numTables)
static const char * getRoleName(const char *roleoid_str)
AggInfo * getAggregates(Archive *fout, int *numAggs)
static void dumpShellType(Archive *fout, const ShellTypeInfo *stinfo)
static void refreshMatViewData(Archive *fout, const TableDataInfo *tdinfo)
static int findComments(Oid classoid, Oid objoid, CommentItem **items)
static SimpleStringList foreign_servers_include_patterns
static char * format_aggregate_signature(const AggInfo *agginfo, Archive *fout, bool honor_quotes)
static void selectDumpableCast(CastInfo *cast, Archive *fout)
static void dumpPublication(Archive *fout, const PublicationInfo *pubinfo)
static char * get_language_name(Archive *fout, Oid langid)
static void dumpPolicy(Archive *fout, const PolicyInfo *polinfo)
void getIndexes(Archive *fout, TableInfo tblinfo[], int numTables)
static void setupDumpWorker(Archive *AH)
static void addConstrChildIdxDeps(DumpableObject *dobj, const IndxInfo *refidx)
static int findSecLabels(Oid classoid, Oid objoid, SecLabelItem **items)
static SimpleStringList table_include_patterns_and_children
static char * convertRegProcReference(const char *proc)
static void getAdditionalACLs(Archive *fout)
static bool is_superuser(Archive *fout)
static void getTableDataFKConstraints(void)
static void getTableData(DumpOptions *dopt, TableInfo *tblinfo, int numTables, char relkind)
static SimpleOidList table_exclude_oids
static DumpId dumpACL(Archive *fout, DumpId objDumpId, DumpId altDumpId, const char *type, const char *name, const char *subname, const char *nspname, const char *owner, const DumpableAcl *dacl)
TSDictInfo * getTSDictionaries(Archive *fout, int *numTSDicts)
InhInfo * getInherits(Archive *fout, int *numInherits)
OpfamilyInfo * getOpfamilies(Archive *fout, int *numOpfamilies)
static void dumpDomain(Archive *fout, const TypeInfo *tyinfo)
void getTableAttrs(Archive *fout, TableInfo *tblinfo, int numTables)
static void collectComments(Archive *fout)
static void getDomainConstraints(Archive *fout, TypeInfo *tyinfo)
static void dumpOpfamily(Archive *fout, const OpfamilyInfo *opfinfo)
static void dumpDefaultACL(Archive *fout, const DefaultACLInfo *daclinfo)
void getSubscriptionTables(Archive *fout)
static void selectDumpableObject(DumpableObject *dobj, Archive *fout)
static void dumpTSTemplate(Archive *fout, const TSTemplateInfo *tmplinfo)
static void dumpIndexAttach(Archive *fout, const IndexAttachInfo *attachinfo)
static void dumpSubscriptionTable(Archive *fout, const SubRelInfo *subrinfo)
static char * format_function_arguments(const FuncInfo *finfo, const char *funcargs, bool is_agg)
static void dumpTransform(Archive *fout, const TransformInfo *transform)
static void dumpLO(Archive *fout, const LoInfo *loinfo)
static void dumpPublicationTable(Archive *fout, const PublicationRelInfo *pubrinfo)
static void binary_upgrade_extension_member(PQExpBuffer upgrade_buffer, const DumpableObject *dobj, const char *objtype, const char *objname, const char *objnamespace)
static void dumpDumpableObject(Archive *fout, DumpableObject *dobj)
static void getLOs(Archive *fout)
static void dumpDatabaseConfig(Archive *AH, PQExpBuffer outbuf, const char *dbname, Oid dboid)
static void setup_connection(Archive *AH, const char *dumpencoding, const char *dumpsnapshot, char *use_role)
static void dumpTableConstraintComment(Archive *fout, const ConstraintInfo *coninfo)
static void dumpUndefinedType(Archive *fout, const TypeInfo *tyinfo)
static void selectDumpableAccessMethod(AccessMethodInfo *method, Archive *fout)
static const char * fmtCopyColumnList(const TableInfo *ti, PQExpBuffer buffer)
PublicationInfo * getPublications(Archive *fout, int *numPublications)
static void expand_table_name_patterns(Archive *fout, SimpleStringList *patterns, SimpleOidList *oids, bool strict_names, bool with_child_tables)
static void findDumpableDependencies(ArchiveHandle *AH, const DumpableObject *dobj, DumpId **dependencies, int *nDeps, int *allocDeps)
static void dumpTableSchema(Archive *fout, const TableInfo *tbinfo)
static void dumpTSParser(Archive *fout, const TSParserInfo *prsinfo)
static void expand_foreign_server_name_patterns(Archive *fout, SimpleStringList *patterns, SimpleOidList *oids)
TSTemplateInfo * getTSTemplates(Archive *fout, int *numTSTemplates)
static void dumpRule(Archive *fout, const RuleInfo *rinfo)
static void dumpCompositeType(Archive *fout, const TypeInfo *tyinfo)
ProcLangInfo * getProcLangs(Archive *fout, int *numProcLangs)
static void dumpEnumType(Archive *fout, const TypeInfo *tyinfo)
static void dumpExtension(Archive *fout, const ExtensionInfo *extinfo)
#define fmtQualifiedDumpable(obj)
TypeInfo * getTypes(Archive *fout, int *numTypes)
static bool nonemptyReloptions(const char *reloptions)
static SimpleOidList table_include_oids
void getExtendedStatistics(Archive *fout)
static NamespaceInfo * findNamespace(Oid nsoid)
static char * get_synchronized_snapshot(Archive *fout)
static int dumpLOs(Archive *fout, const void *arg)
static void dumpSubscription(Archive *fout, const SubscriptionInfo *subinfo)
void processExtensionTables(Archive *fout, ExtensionInfo extinfo[], int numExtensions)
static void dumpEventTrigger(Archive *fout, const EventTriggerInfo *evtinfo)
static void dumpCommentExtended(Archive *fout, const char *type, const char *name, const char *namespace, const char *owner, CatalogId catalogId, int subid, DumpId dumpId, const char *initdb_comment)
static SimpleStringList tabledata_exclude_patterns
OpclassInfo * getOpclasses(Archive *fout, int *numOpclasses)
static void dumpConversion(Archive *fout, const ConvInfo *convinfo)
static void dumpForeignDataWrapper(Archive *fout, const FdwInfo *fdwinfo)
CollInfo * getCollations(Archive *fout, int *numCollations)
static void dumpProcLang(Archive *fout, const ProcLangInfo *plang)
static void dumpSecLabel(Archive *fout, const char *type, const char *name, const char *namespace, const char *owner, CatalogId catalogId, int subid, DumpId dumpId)
void getSubscriptions(Archive *fout)
static void collectSecLabels(Archive *fout)
static void selectDumpableExtension(ExtensionInfo *extinfo, DumpOptions *dopt)
static Oid g_last_builtin_oid
ExtensionInfo * getExtensions(Archive *fout, int *numExtensions)
TSParserInfo * getTSParsers(Archive *fout, int *numTSParsers)
TransformInfo * getTransforms(Archive *fout, int *numTransforms)
void getTriggers(Archive *fout, TableInfo tblinfo[], int numTables)
static ArchiveFormat parseArchiveFormat(const char *format, ArchiveMode *mode)
static void read_dump_filters(const char *filename, DumpOptions *dopt)
static void dumpTSConfig(Archive *fout, const TSConfigInfo *cfginfo)
OprInfo * getOperators(Archive *fout, int *numOprs)
static SecLabelItem * seclabels
static SimpleStringList tabledata_exclude_patterns_and_children
static bool checkExtensionMembership(DumpableObject *dobj, Archive *fout)
RuleInfo * getRules(Archive *fout, int *numRules)
static CommentItem * comments
static int dumpTableData_insert(Archive *fout, const void *dcontext)
static SimpleOidList tabledata_exclude_oids
EventTriggerInfo * getEventTriggers(Archive *fout, int *numEventTriggers)
static SimpleStringList table_exclude_patterns_and_children
TableInfo * getTables(Archive *fout, int *numTables)
static void dumpSequence(Archive *fout, const TableInfo *tbinfo)
bool shouldPrintColumn(const DumpOptions *dopt, const TableInfo *tbinfo, int colno)
static TableInfo * getRootTableInfo(const TableInfo *tbinfo)
static SimpleOidList foreign_servers_include_oids
static void dumpCollation(Archive *fout, const CollInfo *collinfo)
static void dumpTableSecLabel(Archive *fout, const TableInfo *tbinfo, const char *reltypename)
CastInfo * getCasts(Archive *fout, int *numCasts)
static void dumpCompositeTypeColComments(Archive *fout, const TypeInfo *tyinfo, PGresult *res)
static void expand_extension_name_patterns(Archive *fout, SimpleStringList *patterns, SimpleOidList *oids, bool strict_names)
static void selectDumpableType(TypeInfo *tyinfo, Archive *fout)
static SimpleOidList schema_include_oids
static void dumpOpclass(Archive *fout, const OpclassInfo *opcinfo)
static SimpleStringList schema_exclude_patterns
#define DUMP_COMPONENT_COMMENT
#define DUMP_COMPONENT_DATA
#define DUMP_COMPONENT_USERMAP
#define DUMP_COMPONENT_POLICY
#define DUMP_COMPONENT_SECLABEL
#define DUMP_COMPONENT_ALL
#define DUMP_COMPONENT_ACL
#define DUMP_COMPONENT_NONE
#define DUMP_COMPONENTS_REQUIRING_LOCK
void sortDumpableObjects(DumpableObject **objs, int numObjs, DumpId preBoundaryId, DumpId postBoundaryId)
#define DUMP_COMPONENT_DEFINITION
@ DO_PUBLICATION_TABLE_IN_SCHEMA
void sortDumpableObjectsByTypeName(DumpableObject **objs, int numObjs)
#define exit_nicely(code)
PGDLLIMPORT char * optarg
#define LOGICALREP_ORIGIN_ANY
#define LOGICALREP_TWOPHASE_STATE_DISABLED
#define pg_encoding_to_char
#define pg_log_warning(...)
int pg_strcasecmp(const char *s1, const char *s2)
const char * get_progname(const char *argv0)
void printfPQExpBuffer(PQExpBuffer str, const char *fmt,...)
PQExpBuffer createPQExpBuffer(void)
void initPQExpBuffer(PQExpBuffer str)
void resetPQExpBuffer(PQExpBuffer str)
void appendPQExpBuffer(PQExpBuffer str, const char *fmt,...)
void appendBinaryPQExpBuffer(PQExpBuffer str, const char *data, size_t datalen)
void destroyPQExpBuffer(PQExpBuffer str)
void appendPQExpBufferChar(PQExpBuffer str, char ch)
void appendPQExpBufferStr(PQExpBuffer str, const char *data)
void termPQExpBuffer(PQExpBuffer str)
char * psprintf(const char *fmt,...)
#define RelFileNumberIsValid(relnumber)
bool quote_all_identifiers
void simple_string_list_append(SimpleStringList *list, const char *val)
bool simple_oid_list_member(SimpleOidList *list, Oid val)
void simple_oid_list_append(SimpleOidList *list, Oid val)
struct SimplePtrList SimplePtrList
void appendStringLiteralConn(PQExpBuffer buf, const char *str, PGconn *conn)
void appendPGArray(PQExpBuffer buffer, const char *value)
bool processSQLNamePattern(PGconn *conn, PQExpBuffer buf, const char *pattern, bool have_where, bool force_escape, const char *schemavar, const char *namevar, const char *altnamevar, const char *visibilityrule, PQExpBuffer dbnamebuf, int *dotcnt)
const char * fmtId(const char *rawid)
bool parsePGArray(const char *atext, char ***itemarray, int *nitems)
bool appendReloptionsArray(PQExpBuffer buffer, const char *reloptions, const char *prefix, int encoding, bool std_strings)
void appendStringLiteralDQ(PQExpBuffer buf, const char *str, const char *dqprefix)
struct SimplePtrListCell * next
char val[FLEXIBLE_ARRAY_MEMBER]
struct SimpleStringListCell * next
SimpleStringListCell * head
NamespaceInfo * pubschema
PublicationInfo * publication
SubscriptionInfo * subinfo
char * suboriginremotelsn
char * subpasswordrequired
int disable_dollar_quoting
int serializable_deferrable
int no_unlogged_table_data
const char * lockWaitTimeout
int load_via_partition_root
DumpComponents components
DumpableObjectType objType
DumpComponents dump_contains
SimplePtrList partattaches
pg_compress_specification compression_spec
int disable_dollar_quoting
const char * lockWaitTimeout
struct _indxInfo * indexes
bool is_identity_sequence
struct _tableInfo ** parents
struct _triggerInfo * triggers
struct _constraintInfo * checkexprs
struct _attrDefInfo ** attrdefs
struct _tableDataInfo * dataObj
struct _constraintInfo * domChecks
struct _shellTypeInfo * shellType
#define MinTransactionIdAttributeNumber
#define MaxCommandIdAttributeNumber
#define MaxTransactionIdAttributeNumber
#define TableOidAttributeNumber
#define SelfItemPointerAttributeNumber
#define MinCommandIdAttributeNumber
static StringInfo copybuf
static void * fn(void *arg)
#define FirstNormalObjectId
bool SplitGUCList(char *rawstring, char separator, List **namelist)