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"
164 #define DUMP_DEFAULT_ROWS_PER_INSERT 1
171 #define MAX_BLOBS_PER_ARCHIVE_ENTRY 1000
176 #define fmtQualifiedDumpable(obj) \
177 fmtQualifiedId((obj)->dobj.namespace->dobj.name, \
182 const char *dumpencoding,
const char *dumpsnapshot,
200 bool with_child_tables);
202 const char *pattern);
207 static const char *
getRoleName(
const char *roleoid_str);
211 const char *
name,
const char *
namespace,
214 const char *initdb_comment);
216 const char *
name,
const char *
namespace,
218 int subid,
DumpId dumpId);
222 const char *
namespace,
const char *owner,
271 const char *servername,
const char *
namespace,
277 const char *nspname,
const char *tag,
const char *owner,
283 DumpId **dependencies,
int *nDeps,
int *allocDeps);
298 const FuncInfo *finfo,
bool honor_quotes);
320 bool force_array_type,
321 bool include_multirange_type);
327 Oid pg_class_oid,
bool is_index);
332 const char *objnamespace);
337 const char *prefix,
Archive *fout);
360 bool g_verbose =
false;
361 const char *dumpencoding = NULL;
362 const char *dumpsnapshot = NULL;
363 char *use_role = NULL;
369 char *compression_detail = NULL;
370 char *compression_algorithm_str =
"none";
371 char *error_detail = NULL;
372 bool user_compression_defined =
false;
377 static struct option long_options[] = {
390 {
"jobs", 1, NULL,
'j'},
469 if (strcmp(argv[1],
"--help") == 0 || strcmp(argv[1],
"-?") == 0)
474 if (strcmp(argv[1],
"--version") == 0 || strcmp(argv[1],
"-V") == 0)
476 puts(
"pg_dump (PostgreSQL) " PG_VERSION);
483 while ((
c =
getopt_long(argc, argv,
"abBcCd:e:E:f:F:h:j:n:N:Op:RsS:t:T:U:vwWxZ:",
484 long_options, &optindex)) != -1)
601 &compression_detail);
602 user_compression_defined =
true;
708 pg_log_error(
"too many command-line arguments (first is \"%s\")",
727 pg_fatal(
"options -s/--schema-only and -a/--data-only cannot be used together");
730 pg_fatal(
"options -s/--schema-only and --include-foreign-data cannot be used together");
733 pg_fatal(
"option --include-foreign-data is not supported with parallel backup");
736 pg_fatal(
"options -c/--clean and -a/--data-only cannot be used together");
739 pg_fatal(
"option --if-exists requires option -c/--clean");
746 pg_fatal(
"option --on-conflict-do-nothing requires option --inserts, --rows-per-insert, or --column-inserts");
761 !user_compression_defined)
764 compression_algorithm_str =
"gzip";
766 compression_algorithm_str =
"none";
775 pg_fatal(
"unrecognized compression algorithm: \"%s\"",
776 compression_algorithm_str);
781 if (error_detail != NULL)
782 pg_fatal(
"invalid compression specification: %s",
786 if (error_detail != NULL)
795 pg_log_warning(
"compression option \"%s\" is not currently supported by pg_dump",
807 pg_fatal(
"parallel backup only supported by the directory format");
862 pg_fatal(
"no matching schemas were found");
879 pg_fatal(
"no matching tables were found");
907 pg_fatal(
"no matching extensions were found");
946 getTableData(&dopt, tblinfo, numTables, RELKIND_SEQUENCE);
995 boundaryObjs[0].dumpId, boundaryObjs[1].dumpId);
1014 for (
i = 0;
i < numObjs;
i++)
1091 printf(
_(
"%s dumps a database as a text file or to other formats.\n\n"),
progname);
1095 printf(
_(
"\nGeneral options:\n"));
1096 printf(
_(
" -f, --file=FILENAME output file or directory name\n"));
1097 printf(
_(
" -F, --format=c|d|t|p output file format (custom, directory, tar,\n"
1098 " plain text (default))\n"));
1099 printf(
_(
" -j, --jobs=NUM use this many parallel jobs to dump\n"));
1100 printf(
_(
" -v, --verbose verbose mode\n"));
1101 printf(
_(
" -V, --version output version information, then exit\n"));
1102 printf(
_(
" -Z, --compress=METHOD[:DETAIL]\n"
1103 " compress as specified\n"));
1104 printf(
_(
" --lock-wait-timeout=TIMEOUT fail after waiting TIMEOUT for a table lock\n"));
1105 printf(
_(
" --no-sync do not wait for changes to be written safely to disk\n"));
1106 printf(
_(
" --sync-method=METHOD set method for syncing files to disk\n"));
1107 printf(
_(
" -?, --help show this help, then exit\n"));
1109 printf(
_(
"\nOptions controlling the output content:\n"));
1110 printf(
_(
" -a, --data-only dump only the data, not the schema\n"));
1111 printf(
_(
" -b, --large-objects include large objects in dump\n"));
1112 printf(
_(
" --blobs (same as --large-objects, deprecated)\n"));
1113 printf(
_(
" -B, --no-large-objects exclude large objects in dump\n"));
1114 printf(
_(
" --no-blobs (same as --no-large-objects, deprecated)\n"));
1115 printf(
_(
" -c, --clean clean (drop) database objects before recreating\n"));
1116 printf(
_(
" -C, --create include commands to create database in dump\n"));
1117 printf(
_(
" -e, --extension=PATTERN dump the specified extension(s) only\n"));
1118 printf(
_(
" -E, --encoding=ENCODING dump the data in encoding ENCODING\n"));
1119 printf(
_(
" -n, --schema=PATTERN dump the specified schema(s) only\n"));
1120 printf(
_(
" -N, --exclude-schema=PATTERN do NOT dump the specified schema(s)\n"));
1121 printf(
_(
" -O, --no-owner skip restoration of object ownership in\n"
1122 " plain-text format\n"));
1123 printf(
_(
" -s, --schema-only dump only the schema, no data\n"));
1124 printf(
_(
" -S, --superuser=NAME superuser user name to use in plain-text format\n"));
1125 printf(
_(
" -t, --table=PATTERN dump only the specified table(s)\n"));
1126 printf(
_(
" -T, --exclude-table=PATTERN do NOT dump the specified table(s)\n"));
1127 printf(
_(
" -x, --no-privileges do not dump privileges (grant/revoke)\n"));
1128 printf(
_(
" --binary-upgrade for use by upgrade utilities only\n"));
1129 printf(
_(
" --column-inserts dump data as INSERT commands with column names\n"));
1130 printf(
_(
" --disable-dollar-quoting disable dollar quoting, use SQL standard quoting\n"));
1131 printf(
_(
" --disable-triggers disable triggers during data-only restore\n"));
1132 printf(
_(
" --enable-row-security enable row security (dump only content user has\n"
1134 printf(
_(
" --exclude-extension=PATTERN do NOT dump the specified extension(s)\n"));
1135 printf(
_(
" --exclude-table-and-children=PATTERN\n"
1136 " do NOT dump the specified table(s), including\n"
1137 " child and partition tables\n"));
1138 printf(
_(
" --exclude-table-data=PATTERN do NOT dump data for the specified table(s)\n"));
1139 printf(
_(
" --exclude-table-data-and-children=PATTERN\n"
1140 " do NOT dump data for the specified table(s),\n"
1141 " including child and partition tables\n"));
1142 printf(
_(
" --extra-float-digits=NUM override default setting for extra_float_digits\n"));
1143 printf(
_(
" --filter=FILENAME include or exclude objects and data from dump\n"
1144 " based on expressions in FILENAME\n"));
1145 printf(
_(
" --if-exists use IF EXISTS when dropping objects\n"));
1146 printf(
_(
" --include-foreign-data=PATTERN\n"
1147 " include data of foreign tables on foreign\n"
1148 " servers matching PATTERN\n"));
1149 printf(
_(
" --inserts dump data as INSERT commands, rather than COPY\n"));
1150 printf(
_(
" --load-via-partition-root load partitions via the root table\n"));
1151 printf(
_(
" --no-comments do not dump comments\n"));
1152 printf(
_(
" --no-publications do not dump publications\n"));
1153 printf(
_(
" --no-security-labels do not dump security label assignments\n"));
1154 printf(
_(
" --no-subscriptions do not dump subscriptions\n"));
1155 printf(
_(
" --no-table-access-method do not dump table access methods\n"));
1156 printf(
_(
" --no-tablespaces do not dump tablespace assignments\n"));
1157 printf(
_(
" --no-toast-compression do not dump TOAST compression methods\n"));
1158 printf(
_(
" --no-unlogged-table-data do not dump unlogged table data\n"));
1159 printf(
_(
" --on-conflict-do-nothing add ON CONFLICT DO NOTHING to INSERT commands\n"));
1160 printf(
_(
" --quote-all-identifiers quote all identifiers, even if not key words\n"));
1161 printf(
_(
" --rows-per-insert=NROWS number of rows per INSERT; implies --inserts\n"));
1162 printf(
_(
" --section=SECTION dump named section (pre-data, data, or post-data)\n"));
1163 printf(
_(
" --serializable-deferrable wait until the dump can run without anomalies\n"));
1164 printf(
_(
" --snapshot=SNAPSHOT use given snapshot for the dump\n"));
1165 printf(
_(
" --strict-names require table and/or schema include patterns to\n"
1166 " match at least one entity each\n"));
1167 printf(
_(
" --table-and-children=PATTERN dump only the specified table(s), including\n"
1168 " child and partition tables\n"));
1169 printf(
_(
" --use-set-session-authorization\n"
1170 " use SET SESSION AUTHORIZATION commands instead of\n"
1171 " ALTER OWNER commands to set ownership\n"));
1173 printf(
_(
"\nConnection options:\n"));
1174 printf(
_(
" -d, --dbname=DBNAME database to dump\n"));
1175 printf(
_(
" -h, --host=HOSTNAME database server host or socket directory\n"));
1176 printf(
_(
" -p, --port=PORT database server port number\n"));
1177 printf(
_(
" -U, --username=NAME connect as specified database user\n"));
1178 printf(
_(
" -w, --no-password never prompt for password\n"));
1179 printf(
_(
" -W, --password force password prompt (should happen automatically)\n"));
1180 printf(
_(
" --role=ROLENAME do SET ROLE before dump\n"));
1182 printf(
_(
"\nIf no database name is supplied, then the PGDATABASE environment\n"
1183 "variable value is used.\n\n"));
1184 printf(
_(
"Report bugs to <%s>.\n"), PACKAGE_BUGREPORT);
1185 printf(
_(
"%s home page: <%s>\n"), PACKAGE_NAME, PACKAGE_URL);
1190 const char *dumpsnapshot,
char *use_role)
1194 const char *std_strings;
1204 pg_fatal(
"invalid client encoding \"%s\" specified",
1215 AH->
std_strings = (std_strings && strcmp(std_strings,
"on") == 0);
1317 "SET TRANSACTION ISOLATION LEVEL "
1318 "SERIALIZABLE, READ ONLY, DEFERRABLE");
1321 "SET TRANSACTION ISOLATION LEVEL "
1322 "REPEATABLE READ, READ ONLY");
1344 pg_fatal(
"parallel dumps from standby servers are not supported by this server version");
1368 char *query =
"SELECT pg_catalog.pg_export_snapshot()";
1410 return archiveFormat;
1428 if (patterns->
head == NULL)
1438 for (cell = patterns->
head; cell; cell = cell->
next)
1444 "SELECT oid FROM pg_catalog.pg_namespace n\n");
1447 false, NULL,
"n.nspname", NULL, NULL, &dbbuf,
1450 pg_fatal(
"improper qualified name (too many dotted names): %s",
1452 else if (dotcnt == 1)
1458 pg_fatal(
"no matching schemas were found for pattern \"%s\"", cell->
val);
1487 if (patterns->
head == NULL)
1496 for (cell = patterns->
head; cell; cell = cell->
next)
1501 "SELECT oid FROM pg_catalog.pg_extension e\n");
1503 false, NULL,
"e.extname", NULL, NULL, NULL,
1506 pg_fatal(
"improper qualified name (too many dotted names): %s",
1511 pg_fatal(
"no matching extensions were found for pattern \"%s\"", cell->
val);
1539 if (patterns->
head == NULL)
1549 for (cell = patterns->
head; cell; cell = cell->
next)
1554 "SELECT oid FROM pg_catalog.pg_foreign_server s\n");
1556 false, NULL,
"s.srvname", NULL, NULL, NULL,
1559 pg_fatal(
"improper qualified name (too many dotted names): %s",
1564 pg_fatal(
"no matching foreign servers were found for pattern \"%s\"", cell->
val);
1591 if (patterns->
head == NULL)
1601 for (cell = patterns->
head; cell; cell = cell->
next)
1614 if (with_child_tables)
1621 "\nFROM pg_catalog.pg_class c"
1622 "\n LEFT JOIN pg_catalog.pg_namespace n"
1623 "\n ON n.oid OPERATOR(pg_catalog.=) c.relnamespace"
1624 "\nWHERE c.relkind OPERATOR(pg_catalog.=) ANY"
1625 "\n (array['%c', '%c', '%c', '%c', '%c', '%c'])\n",
1626 RELKIND_RELATION, RELKIND_SEQUENCE, RELKIND_VIEW,
1627 RELKIND_MATVIEW, RELKIND_FOREIGN_TABLE,
1628 RELKIND_PARTITIONED_TABLE);
1631 false,
"n.nspname",
"c.relname", NULL,
1632 "pg_catalog.pg_table_is_visible(c.oid)", &dbbuf,
1635 pg_fatal(
"improper relation name (too many dotted names): %s",
1637 else if (dotcnt == 2)
1641 if (with_child_tables)
1644 "\nSELECT i.inhrelid"
1645 "\nFROM partition_tree p"
1646 "\n JOIN pg_catalog.pg_inherits i"
1647 "\n ON p.relid OPERATOR(pg_catalog.=) i.inhparent"
1649 "\nSELECT relid FROM partition_tree");
1657 pg_fatal(
"no matching tables were found for pattern \"%s\"", cell->
val);
1684 pg_fatal(
"You are currently not connected to a database.");
1686 if (strcmp(db,
dbname) != 0)
1687 pg_fatal(
"cross-database references are not implemented: %s",
1775 strcmp(nsinfo->
dobj.
name,
"pg_catalog") == 0)
1784 else if (strncmp(nsinfo->
dobj.
name,
"pg_", 3) == 0 ||
1785 strcmp(nsinfo->
dobj.
name,
"information_schema") == 0)
1790 else if (strcmp(nsinfo->
dobj.
name,
"public") == 0)
1802 if (nsinfo->
nspowner == ROLE_PG_DATABASE_OWNER)
1882 tyinfo->
typrelkind != RELKIND_COMPOSITE_TYPE)
1887 if (tytable != NULL)
1927 if (dinfo->
dobj.namespace)
2115 if (dobj->namespace)
2132 const char *classname = tbinfo->
dobj.
name;
2144 const char *column_list;
2146 pg_log_info(
"dumping contents of table \"%s.%s\"",
2147 tbinfo->
dobj.namespace->dobj.
name, classname);
2166 if (strlen(column_list) > 2)
2252 pg_log_error(
"Dumping the contents of table \"%s\" failed: PQgetCopyData() failed.", classname);
2262 pg_log_error(
"Dumping the contents of table \"%s\" failed: PQgetResult() failed.", classname);
2271 pg_log_warning(
"unexpected extra results during COPY of table \"%s\"",
2299 int rows_this_statement = 0;
2344 pg_fatal(
"wrong number of fields retrieved from table \"%s\"",
2354 if (insertStmt == NULL)
2386 for (
int field = 0; field < nfields; field++)
2406 if (rows_this_statement == 0)
2422 if (rows_per_statement == 1)
2424 else if (rows_this_statement > 0)
2429 for (
int field = 0; field < nfields; field++)
2433 if (attgenerated[field])
2468 if (strspn(s,
"0123456789 +-eE.") == strlen(s))
2503 if (++rows_this_statement >= rows_per_statement)
2506 archputs(
" ON CONFLICT DO NOTHING;\n", fout);
2510 rows_this_statement = 0;
2523 if (rows_this_statement > 0)
2526 archputs(
" ON CONFLICT DO NOTHING;\n", fout);
2536 if (insertStmt != NULL)
2555 parentTbinfo = tbinfo->
parents[0];
2559 parentTbinfo = parentTbinfo->
parents[0];
2562 return parentTbinfo;
2580 parentTbinfo = tbinfo->
parents[0];
2586 parentTbinfo = parentTbinfo->
parents[0];
2608 char *tdDefn = NULL;
2610 const char *copyFrom;
2645 copyStmt = copyBuf->
data;
2665 .namespace = tbinfo->
dobj.namespace->dobj.
name,
2667 .description =
"TABLE DATA",
2669 .createStmt = tdDefn,
2670 .copyStmt = copyStmt,
2674 .dumpArg = tdinfo));
2732 .namespace = tbinfo->
dobj.namespace->dobj.
name,
2734 .description =
"MATERIALIZED VIEW DATA",
2736 .createStmt = q->
data,
2752 for (
i = 0;
i < numTables;
i++)
2755 (!relkind || tblinfo[
i].
relkind == relkind))
2779 if (tbinfo->
relkind == RELKIND_VIEW)
2782 if (tbinfo->
relkind == RELKIND_FOREIGN_TABLE &&
2788 if (tbinfo->
relkind == RELKIND_PARTITIONED_TABLE)
2804 if (tbinfo->
relkind == RELKIND_MATVIEW)
2806 else if (tbinfo->
relkind == RELKIND_SEQUENCE)
2819 tdinfo->
dobj.namespace = tbinfo->
dobj.namespace;
2859 "SELECT d1.objid, d2.refobjid, c2.relkind AS refrelkind "
2860 "FROM pg_depend d1 "
2861 "JOIN pg_class c1 ON c1.oid = d1.objid "
2863 " JOIN pg_rewrite r1 ON r1.ev_class = d1.objid "
2864 "JOIN pg_depend d2 ON d2.classid = 'pg_rewrite'::regclass "
2865 "AND d2.objid = r1.oid "
2866 "AND d2.refobjid <> d1.objid "
2867 "JOIN pg_class c2 ON c2.oid = d2.refobjid "
2868 "AND c2.relkind IN (" CppAsString2(RELKIND_MATVIEW)
","
2870 "WHERE d1.classid = 'pg_class'::regclass "
2872 "SELECT w.objid, d3.refobjid, c3.relkind "
2874 "JOIN pg_rewrite r3 ON r3.ev_class = w.refobjid "
2875 "JOIN pg_depend d3 ON d3.classid = 'pg_rewrite'::regclass "
2876 "AND d3.objid = r3.oid "
2877 "AND d3.refobjid <> w.refobjid "
2878 "JOIN pg_class c3 ON c3.oid = d3.refobjid "
2879 "AND c3.relkind IN (" CppAsString2(RELKIND_MATVIEW)
","
2882 "SELECT 'pg_class'::regclass::oid AS classid, objid, refobjid "
2894 for (
i = 0;
i < ntups;
i++)
2921 if (refdobj == NULL)
2928 if (refdobj == NULL)
2964 for (
i = 0;
i < numObjs;
i++)
2976 if (ftable == NULL ||
3049 "pg_encoding_to_char(encoding) AS encoding, "
3050 "datcollate, datctype, datfrozenxid, "
3051 "datacl, acldefault('d', datdba) AS acldefault, "
3052 "datistemplate, datconnlimit, ");
3062 appendPQExpBufferStr(dbQry,
"'c' AS datlocprovider, NULL AS datlocale, NULL AS datcollversion, ");
3068 "(SELECT spcname FROM pg_tablespace t WHERE t.oid = dattablespace) AS tablespace, "
3069 "shobj_description(oid, 'pg_database') AS description "
3071 "WHERE datname = current_database()");
3129 appendPQExpBuffer(creaQry,
"CREATE DATABASE %s WITH TEMPLATE = template0 OID = %u",
3130 qdatname, dbCatId.
oid);
3151 pg_fatal(
"unrecognized locale provider: %s",
3154 if (strlen(collate) > 0 && strcmp(collate, ctype) == 0)
3161 if (strlen(collate) > 0)
3166 if (strlen(ctype) > 0)
3229 .createStmt = creaQry->
data,
3230 .dropStmt = delQry->
data));
3259 .description =
"COMMENT",
3261 .createStmt = dbQry->
data,
3279 if (seclabelQry->
len > 0)
3283 .description =
"SECURITY LABEL",
3285 .createStmt = seclabelQry->
data,
3300 qdatname, NULL, NULL,
3301 NULL, dba, &dbdacl);
3331 "SET datistemplate = false WHERE datname = ");
3352 "SET datfrozenxid = '%u', datminmxid = '%u'\n"
3354 frozenxid, minmxid);
3359 if (creaQry->
len > 0)
3365 .createStmt = creaQry->
data,
3366 .dropStmt = delQry->
data,
3367 .deps = &dbDumpId));
3379 int ii_relfrozenxid,
3388 appendPQExpBuffer(loFrozenQry,
"SELECT relfrozenxid, relminmxid, relfilenode, oid\n"
3389 "FROM pg_catalog.pg_class\n"
3390 "WHERE oid IN (%u, %u);\n",
3391 LargeObjectRelationId, LargeObjectLOidPNIndexId);
3393 appendPQExpBuffer(loFrozenQry,
"SELECT relfrozenxid, 0 AS relminmxid, relfilenode, oid\n"
3394 "FROM pg_catalog.pg_class\n"
3395 "WHERE oid IN (%u, %u);\n",
3396 LargeObjectRelationId, LargeObjectLOidPNIndexId);
3400 ii_relfrozenxid =
PQfnumber(lo_res,
"relfrozenxid");
3401 ii_relminmxid =
PQfnumber(lo_res,
"relminmxid");
3402 ii_relfilenode =
PQfnumber(lo_res,
"relfilenode");
3405 appendPQExpBufferStr(loHorizonQry,
"\n-- For binary upgrade, set pg_largeobject relfrozenxid and relminmxid\n");
3406 appendPQExpBufferStr(loOutQry,
"\n-- For binary upgrade, preserve pg_largeobject and index relfilenodes\n");
3413 "SET relfrozenxid = '%u', relminmxid = '%u'\n"
3414 "WHERE oid = %u;\n",
3422 if (oid == LargeObjectRelationId)
3424 "SELECT pg_catalog.binary_upgrade_set_next_heap_relfilenode('%u'::pg_catalog.oid);\n",
3426 else if (oid == LargeObjectLOidPNIndexId)
3428 "SELECT pg_catalog.binary_upgrade_set_next_index_relfilenode('%u'::pg_catalog.oid);\n",
3433 "TRUNCATE pg_catalog.pg_largeobject;\n");
3440 .createStmt = loOutQry->
data));
3472 "WHERE setrole = 0 AND setdatabase = '%u'::oid",
3479 "DATABASE",
dbname, NULL, NULL,
3486 "FROM pg_db_role_setting s, pg_roles r "
3487 "WHERE setrole = r.oid AND setdatabase = '%u'::oid",
3522 .createStmt = qry->
data));
3534 const char *stdstrings = AH->
std_strings ?
"on" :
"off";
3537 pg_log_info(
"saving standard_conforming_strings = %s",
3547 .createStmt = qry->
data));
3561 char **schemanames = NULL;
3562 int nschemanames = 0;
3573 "SELECT pg_catalog.current_schemas(false)");
3576 pg_fatal(
"could not parse result of current_schemas()");
3584 for (
i = 0;
i < nschemanames;
i++)
3601 .createStmt = qry->
data));
3638 "SELECT oid, lomowner, lomacl, "
3639 "acldefault('L', lomowner) AS acldefault "
3640 "FROM pg_largeobject_metadata "
3641 "ORDER BY lomowner, lomacl::pg_catalog.text, oid");
3660 for (
i = 0;
i < ntups;
i += n)
3673 if (strcmp(thisowner,
PQgetvalue(
res,
i + n, i_lomowner)) != 0 ||
3688 snprintf(namebuf,
sizeof(namebuf),
"%u..%u", thisoid,
3691 snprintf(namebuf,
sizeof(namebuf),
"%u", thisoid);
3699 loinfo->
looids[0] = thisoid;
3701 for (
int k = 1; k < n; k++)
3708 extraID.
tableoid = LargeObjectRelationId;
3764 for (
int i = 0;
i < loinfo->
numlos;
i++)
3771 .description =
"BLOB METADATA",
3773 .createStmt = cquery->
data,
3774 .dropStmt =
"-- dummy"));
3783 for (
int i = 0;
i < loinfo->
numlos;
i++)
3823 snprintf(tagbuf,
sizeof(tagbuf),
"LARGE OBJECTS %u..%u",
3827 "LARGE OBJECT", namebuf, NULL, NULL,
3833 "LARGE OBJECT", namebuf, NULL, NULL,
3854 for (
int i = 0;
i < loinfo->
numlos;
i++)
3863 pg_fatal(
"could not open large object %u: %s",
3873 pg_fatal(
"error reading large object %u: %s",
3903 int i_polpermissive;
3922 for (
i = 0;
i < numTables;
i++)
3931 if (tbinfo->
relkind != RELKIND_RELATION &&
3932 tbinfo->
relkind != RELKIND_PARTITIONED_TABLE)
3936 if (tbloids->
len > 1)
3957 polinfo->
dobj.namespace = tbinfo->
dobj.namespace;
3976 pg_log_info(
"reading row-level security policies");
3979 "SELECT pol.oid, pol.tableoid, pol.polrelid, pol.polname, pol.polcmd, ");
3985 "CASE WHEN pol.polroles = '{0}' THEN NULL ELSE "
3986 " 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, "
3987 "pg_catalog.pg_get_expr(pol.polqual, pol.polrelid) AS polqual, "
3988 "pg_catalog.pg_get_expr(pol.polwithcheck, pol.polrelid) AS polwithcheck "
3989 "FROM unnest('%s'::pg_catalog.oid[]) AS src(tbloid)\n"
3990 "JOIN pg_catalog.pg_policy pol ON (src.tbloid = pol.polrelid)",
4010 for (
j = 0;
j < ntups;
j++)
4022 polinfo[
j].
dobj.namespace = tbinfo->
dobj.namespace;
4031 polinfo[
j].polroles = NULL;
4094 .namespace = polinfo->
dobj.namespace->dobj.
name,
4096 .description =
"ROW SECURITY",
4098 .createStmt = query->
data,
4106 if (polinfo->
polcmd ==
'*')
4108 else if (polinfo->
polcmd ==
'r')
4109 cmd =
" FOR SELECT";
4110 else if (polinfo->
polcmd ==
'a')
4111 cmd =
" FOR INSERT";
4112 else if (polinfo->
polcmd ==
'w')
4113 cmd =
" FOR UPDATE";
4114 else if (polinfo->
polcmd ==
'd')
4115 cmd =
" FOR DELETE";
4117 pg_fatal(
"unexpected policy command type: %c",
4153 .
namespace = polinfo->
dobj.namespace->dobj.
name,
4155 .description =
"POLICY",
4157 .createStmt = query->
data,
4158 .dropStmt = delqry->
data));
4198 *numPublications = 0;
4209 "SELECT p.tableoid, p.oid, p.pubname, "
4211 "p.puballtables, p.pubinsert, p.pubupdate, p.pubdelete, p.pubtruncate, p.pubviaroot "
4212 "FROM pg_publication p");
4215 "SELECT p.tableoid, p.oid, p.pubname, "
4217 "p.puballtables, p.pubinsert, p.pubupdate, p.pubdelete, p.pubtruncate, false AS pubviaroot "
4218 "FROM pg_publication p");
4221 "SELECT p.tableoid, p.oid, p.pubname, "
4223 "p.puballtables, p.pubinsert, p.pubupdate, p.pubdelete, false AS pubtruncate, false AS pubviaroot "
4224 "FROM pg_publication p");
4243 for (
i = 0;
i < ntups;
i++)
4272 *numPublications = ntups;
4352 .description =
"PUBLICATION",
4354 .createStmt = query->
data,
4355 .dropStmt = delq->
data));
4398 "SELECT tableoid, oid, pnpubid, pnnspid "
4399 "FROM pg_catalog.pg_publication_namespace");
4413 for (
i = 0;
i < ntups;
i++)
4425 if (pubinfo == NULL)
4428 if (nspinfo == NULL)
4444 pubsinfo[
j].
dobj.namespace = nspinfo->
dobj.namespace;
4488 "SELECT tableoid, oid, prpubid, prrelid, "
4489 "pg_catalog.pg_get_expr(prqual, prrelid) AS prrelqual, "
4491 " WHEN pr.prattrs IS NOT NULL THEN\n"
4492 " (SELECT array_agg(attname)\n"
4494 " pg_catalog.generate_series(0, pg_catalog.array_upper(pr.prattrs::pg_catalog.int2[], 1)) s,\n"
4495 " pg_catalog.pg_attribute\n"
4496 " WHERE attrelid = pr.prrelid AND attnum = prattrs[s])\n"
4497 " ELSE NULL END) prattrs "
4498 "FROM pg_catalog.pg_publication_rel pr");
4501 "SELECT tableoid, oid, prpubid, prrelid, "
4502 "NULL AS prrelqual, NULL AS prattrs "
4503 "FROM pg_catalog.pg_publication_rel");
4519 for (
i = 0;
i < ntups;
i++)
4531 if (pubinfo == NULL)
4546 pubrinfo[
j].dobj.catId.tableoid =
4550 pubrinfo[
j].dobj.namespace = tbinfo->
dobj.namespace;
4551 pubrinfo[
j].dobj.name = tbinfo->
dobj.
name;
4552 pubrinfo[
j].publication = pubinfo;
4553 pubrinfo[
j].pubtable = tbinfo;
4555 pubrinfo[
j].pubrelqual = NULL;
4566 &attnames, &nattnames))
4567 pg_fatal(
"could not parse %s array",
"prattrs");
4569 for (
int k = 0; k < nattnames; k++)
4576 pubrinfo[
j].pubrattrs = attribs->
data;
4579 pubrinfo[
j].pubrattrs = NULL;
4622 .
namespace = schemainfo->
dobj.
name,
4624 .description =
"PUBLICATION TABLES IN SCHEMA",
4626 .createStmt = query->
data));
4660 if (pubrinfo->pubrattrs)
4663 if (pubrinfo->pubrelqual)
4682 ArchiveEntry(fout, pubrinfo->dobj.catId, pubrinfo->dobj.dumpId,
4684 .
namespace = tbinfo->
dobj.namespace->dobj.
name,
4686 .description =
"PUBLICATION TABLE",
4688 .createStmt = query->
data));
4707 if (
val && strcmp(
val,
"on") == 0)
4730 int i_subtwophasestate;
4731 int i_subdisableonerr;
4732 int i_subpasswordrequired;
4733 int i_subrunasowner;
4736 int i_subsynccommit;
4737 int i_subpublications;
4739 int i_suboriginremotelsn;
4753 "SELECT count(*) FROM pg_subscription "
4754 "WHERE subdbid = (SELECT oid FROM pg_database"
4755 " WHERE datname = current_database())",
4759 pg_log_warning(
"subscriptions not dumped because current user is not a superuser");
4768 "SELECT s.tableoid, s.oid, s.subname,\n"
4770 " s.subconninfo, s.subslotname, s.subsynccommit,\n"
4771 " s.subpublications,\n");
4785 " s.subtwophasestate,\n"
4786 " s.subdisableonerr,\n");
4789 " '%c' AS subtwophasestate,\n"
4790 " false AS subdisableonerr,\n",
4795 " s.subpasswordrequired,\n"
4796 " s.subrunasowner,\n"
4800 " 't' AS subpasswordrequired,\n"
4801 " 't' AS subrunasowner,\n"
4802 " '%s' AS suborigin,\n",
4807 " s.subenabled,\n");
4810 " false AS subenabled,\n");
4814 " s.subfailover\n");
4817 " false AS subfailover\n");
4820 "FROM pg_subscription s\n");
4824 "LEFT JOIN pg_catalog.pg_replication_origin_status o \n"
4825 " ON o.external_id = 'pg_' || s.oid::text \n");
4828 "WHERE s.subdbid = (SELECT oid FROM pg_database\n"
4829 " WHERE datname = current_database())");
4845 i_subtwophasestate =
PQfnumber(
res,
"subtwophasestate");
4847 i_subpasswordrequired =
PQfnumber(
res,
"subpasswordrequired");
4854 i_suboriginremotelsn =
PQfnumber(
res,
"suboriginremotelsn");
4860 for (
i = 0;
i < ntups;
i++)
4936 "SELECT srsubid, srrelid, srsubstate, srsublsn "
4937 "FROM pg_catalog.pg_subscription_rel "
4951 for (
int i = 0;
i < ntups;
i++)
4961 if (cur_srsubid != last_srsubid)
4964 if (subinfo == NULL)
4965 pg_fatal(
"subscription with OID %u does not exist", cur_srsubid);
4967 last_srsubid = cur_srsubid;
4971 if (tblinfo == NULL)
4972 pg_fatal(
"failed sanity check, table with OID %u not found",
5029 "\n-- For binary upgrade, must preserve the subscriber table.\n");
5031 "SELECT pg_catalog.binary_upgrade_add_sub_rel_state(");
5058 .description =
"SUBSCRIPTION TABLE",
5060 .createStmt = query->
data));
5080 char **pubnames = NULL;
5103 pg_fatal(
"could not parse %s array",
"subpublications");
5106 for (
i = 0;
i < npubnames;
i++)
5114 appendPQExpBuffer(query,
" PUBLICATION %s WITH (connect = false, slot_name = ", publications->
data);
5120 if (strcmp(subinfo->
subbinary,
"t") == 0)
5123 if (strcmp(subinfo->
substream,
"t") == 0)
5125 else if (strcmp(subinfo->
substream,
"p") == 0)
5169 "\n-- For binary upgrade, must preserve the remote_lsn for the subscriber's replication origin.\n");
5171 "SELECT pg_catalog.binary_upgrade_replorigin_advance(");
5183 "\n-- For binary upgrade, must preserve the subscriber's running state.\n");
5192 .description =
"SUBSCRIPTION",
5194 .createStmt = query->
data,
5195 .dropStmt = delq->
data));
5223 const char *catalog,
5224 const char *keyword,
5225 const char *objname)
5242 "FROM pg_catalog.pg_depend d, pg_catalog.pg_extension e "
5243 "WHERE d.refobjid = e.oid AND classid = '%s'::pg_catalog.regclass "
5244 "AND objid = '%u'::pg_catalog.oid AND deptype = 'x' "
5245 "AND refclassid = 'pg_catalog.pg_extension'::pg_catalog.regclass",
5251 for (
i = 0;
i < ntups;
i++)
5281 ++next_possible_free_oid;
5283 "SELECT EXISTS(SELECT 1 "
5284 "FROM pg_catalog.pg_type "
5285 "WHERE oid = '%u'::pg_catalog.oid);",
5286 next_possible_free_oid);
5292 return next_possible_free_oid;
5299 bool force_array_type,
5300 bool include_multirange_type)
5304 Oid pg_type_array_oid;
5305 Oid pg_type_multirange_oid;
5306 Oid pg_type_multirange_array_oid;
5310 "SELECT pg_catalog.binary_upgrade_set_next_pg_type_oid('%u'::pg_catalog.oid);\n\n",
5315 "FROM pg_catalog.pg_type "
5316 "WHERE oid = '%u'::pg_catalog.oid;",
5325 if (!
OidIsValid(pg_type_array_oid) && force_array_type)
5331 "\n-- For binary upgrade, must preserve pg_type array oid\n");
5333 "SELECT pg_catalog.binary_upgrade_set_next_array_pg_type_oid('%u'::pg_catalog.oid);\n\n",
5340 if (include_multirange_type)
5345 "SELECT t.oid, t.typarray "
5346 "FROM pg_catalog.pg_type t "
5347 "JOIN pg_catalog.pg_range r "
5348 "ON t.oid = r.rngmultitypid "
5349 "WHERE r.rngtypid = '%u'::pg_catalog.oid;",
5366 "\n-- For binary upgrade, must preserve multirange pg_type oid\n");
5368 "SELECT pg_catalog.binary_upgrade_set_next_multirange_pg_type_oid('%u'::pg_catalog.oid);\n\n",
5369 pg_type_multirange_oid);
5371 "\n-- For binary upgrade, must preserve multirange pg_type array oid\n");
5373 "SELECT pg_catalog.binary_upgrade_set_next_multirange_array_pg_type_oid('%u'::pg_catalog.oid);\n\n",
5374 pg_type_multirange_array_oid);
5389 pg_type_oid,
false,
false);
5403 Oid toast_index_oid;
5418 "SELECT c.relkind, c.relfilenode, c.reltoastrelid, ct.relfilenode AS toast_relfilenode, i.indexrelid, cti.relfilenode AS toast_index_relfilenode "
5419 "FROM pg_catalog.pg_class c LEFT JOIN "
5420 "pg_catalog.pg_index i ON (c.reltoastrelid = i.indrelid AND i.indisvalid) "
5421 "LEFT JOIN pg_catalog.pg_class ct ON (c.reltoastrelid = ct.oid) "
5422 "LEFT JOIN pg_catalog.pg_class AS cti ON (i.indexrelid = cti.oid) "
5423 "WHERE c.oid = '%u'::pg_catalog.oid;",
5431 PQfnumber(upgrade_res,
"relfilenode")));
5433 PQfnumber(upgrade_res,
"reltoastrelid")));
5435 PQfnumber(upgrade_res,
"toast_relfilenode")));
5439 PQfnumber(upgrade_res,
"toast_index_relfilenode")));
5442 "\n-- For binary upgrade, must preserve pg_class oids and relfilenodes\n");
5447 "SELECT pg_catalog.binary_upgrade_set_next_heap_pg_class_oid('%u'::pg_catalog.oid);\n",
5457 "SELECT pg_catalog.binary_upgrade_set_next_heap_relfilenode('%u'::pg_catalog.oid);\n",
5465 relkind != RELKIND_PARTITIONED_TABLE)
5468 "SELECT pg_catalog.binary_upgrade_set_next_toast_pg_class_oid('%u'::pg_catalog.oid);\n",
5471 "SELECT pg_catalog.binary_upgrade_set_next_toast_relfilenode('%u'::pg_catalog.oid);\n",
5472 toast_relfilenumber);
5476 "SELECT pg_catalog.binary_upgrade_set_next_index_pg_class_oid('%u'::pg_catalog.oid);\n",
5479 "SELECT pg_catalog.binary_upgrade_set_next_index_relfilenode('%u'::pg_catalog.oid);\n",
5480 toast_index_relfilenumber);
5489 "SELECT pg_catalog.binary_upgrade_set_next_index_pg_class_oid('%u'::pg_catalog.oid);\n",
5492 "SELECT pg_catalog.binary_upgrade_set_next_index_relfilenode('%u'::pg_catalog.oid);\n",
5511 const char *objtype,
5512 const char *objname,
5513 const char *objnamespace)
5535 pg_fatal(
"could not find parent extension for %s %s",
5539 "\n-- For binary upgrade, handle extension membership the hard way\n");
5543 if (objnamespace && *objnamespace)
5579 "acldefault('n', n.nspowner) AS acldefault "
5580 "FROM pg_namespace n");
5595 for (
i = 0;
i < ntups;
i++)
5597 const char *nspowner;
5635 if (strcmp(nsinfo[
i].dobj.name,
"public") == 0)
5664 *numNamespaces = ntups;
5680 pg_fatal(
"schema with OID %u does not exist", nsoid);
5704 int i_extrelocatable;
5712 "x.extname, n.nspname, x.extrelocatable, x.extversion, x.extconfig, x.extcondition "
5713 "FROM pg_extension x "
5714 "JOIN pg_namespace n ON n.oid = x.extnamespace");
5731 for (
i = 0;
i < ntups;
i++)
5751 *numExtensions = ntups;
5805 "typnamespace, typacl, "
5806 "acldefault('T', typowner) AS acldefault, "
5808 "typelem, typrelid, "
5809 "CASE WHEN typrelid = 0 THEN ' '::\"char\" "
5810 "ELSE (SELECT relkind FROM pg_class WHERE oid = typrelid) END AS typrelkind, "
5811 "typtype, typisdefined, "
5812 "typname[0] = '_' AND typelem != 0 AND "
5813 "(SELECT typarray FROM pg_type te WHERE oid = pg_type.typelem) = oid AS isarray "
5836 for (
i = 0;
i < ntups;
i++)
5843 tyinfo[
i].
dobj.namespace =
5867 if (tyinfo[
i].typtype == TYPTYPE_MULTIRANGE)
5885 tyinfo[
i].
typtype == TYPTYPE_DOMAIN)
5899 (tyinfo[
i].
typtype == TYPTYPE_BASE ||
5900 tyinfo[
i].
typtype == TYPTYPE_RANGE))
5907 stinfo->
dobj.namespace = tyinfo[
i].
dobj.namespace;
5961 "oprcode::oid AS oprcode "
5962 "FROM pg_operator");
5979 for (
i = 0;
i < ntups;
i++)
5986 oprinfo[
i].
dobj.namespace =
6021 int i_collnamespace;
6034 "FROM pg_collation");
6039 *numCollations = ntups;
6049 for (
i = 0;
i < ntups;
i++)
6056 collinfo[
i].
dobj.namespace =
6102 "FROM pg_conversion");
6107 *numConversions = ntups;
6117 for (
i = 0;
i < ntups;
i++)
6124 convinfo[
i].
dobj.namespace =
6163 *numAccessMethods = 0;
6171 "amhandler::pg_catalog.regproc AS amhandler "
6177 *numAccessMethods = ntups;
6187 for (
i = 0;
i < ntups;
i++)
6194 aminfo[
i].
dobj.namespace = NULL;
6244 *numOpclasses = ntups;
6254 for (
i = 0;
i < ntups;
i++)
6261 opcinfo[
i].
dobj.namespace =
6307 "FROM pg_opfamily");
6312 *numOpfamilies = ntups;
6322 for (
i = 0;
i < ntups;
i++)
6329 opfinfo[
i].
dobj.namespace =
6376 const char *agg_check;
6378 agg_check = (fout->
remoteVersion >= 110000 ?
"p.prokind = 'a'"
6382 "p.proname AS aggname, "
6383 "p.pronamespace AS aggnamespace, "
6384 "p.pronargs, p.proargtypes, "
6386 "p.proacl AS aggacl, "
6387 "acldefault('f', p.proowner) AS acldefault "
6389 "LEFT JOIN pg_init_privs pip ON "
6390 "(p.oid = pip.objoid "
6391 "AND pip.classoid = 'pg_proc'::regclass "
6392 "AND pip.objsubid = 0) "
6394 "p.pronamespace != "
6395 "(SELECT oid FROM pg_namespace "
6396 "WHERE nspname = 'pg_catalog') OR "
6397 "p.proacl IS DISTINCT FROM pip.initprivs",
6401 " OR EXISTS(SELECT 1 FROM pg_depend WHERE "
6402 "classid = 'pg_proc'::regclass AND "
6403 "objid = p.oid AND "
6404 "refclassid = 'pg_extension'::regclass AND "
6411 "pronamespace AS aggnamespace, "
6412 "pronargs, proargtypes, "
6414 "proacl AS aggacl, "
6415 "acldefault('f', proowner) AS acldefault "
6417 "WHERE proisagg AND ("
6419 "(SELECT oid FROM pg_namespace "
6420 "WHERE nspname = 'pg_catalog')");
6423 " OR EXISTS(SELECT 1 FROM pg_depend WHERE "
6424 "classid = 'pg_proc'::regclass AND "
6425 "objid = p.oid AND "
6426 "refclassid = 'pg_extension'::regclass AND "
6448 for (
i = 0;
i < ntups;
i++)
6450 agginfo[
i].aggfn.dobj.objType =
DO_AGG;
6455 agginfo[
i].aggfn.dobj.namespace =
6459 agginfo[
i].aggfn.dacl.privtype = 0;
6460 agginfo[
i].aggfn.dacl.initprivs = NULL;
6465 if (agginfo[
i].aggfn.nargs == 0)
6466 agginfo[
i].aggfn.argtypes = NULL;
6469 agginfo[
i].aggfn.argtypes = (
Oid *)
pg_malloc(agginfo[
i].aggfn.nargs *
sizeof(
Oid));
6471 agginfo[
i].aggfn.argtypes,
6472 agginfo[
i].aggfn.nargs);
6474 agginfo[
i].aggfn.postponed_def =
false;
6542 const char *not_agg_check;
6544 not_agg_check = (fout->
remoteVersion >= 110000 ?
"p.prokind <> 'a'"
6545 :
"NOT p.proisagg");
6548 "SELECT p.tableoid, p.oid, p.proname, p.prolang, "
6549 "p.pronargs, p.proargtypes, p.prorettype, "
6551 "acldefault('f', p.proowner) AS acldefault, "
6555 "LEFT JOIN pg_init_privs pip ON "
6556 "(p.oid = pip.objoid "
6557 "AND pip.classoid = 'pg_proc'::regclass "
6558 "AND pip.objsubid = 0) "
6560 "\n AND NOT EXISTS (SELECT 1 FROM pg_depend "
6561 "WHERE classid = 'pg_proc'::regclass AND "
6562 "objid = p.oid AND deptype = 'i')"
6564 "\n pronamespace != "
6565 "(SELECT oid FROM pg_namespace "
6566 "WHERE nspname = 'pg_catalog')"
6567 "\n OR EXISTS (SELECT 1 FROM pg_cast"
6568 "\n WHERE pg_cast.oid > %u "
6569 "\n AND p.oid = pg_cast.castfunc)"
6570 "\n OR EXISTS (SELECT 1 FROM pg_transform"
6571 "\n WHERE pg_transform.oid > %u AND "
6572 "\n (p.oid = pg_transform.trffromsql"
6573 "\n OR p.oid = pg_transform.trftosql))",
6579 "\n OR EXISTS(SELECT 1 FROM pg_depend WHERE "
6580 "classid = 'pg_proc'::regclass AND "
6581 "objid = p.oid AND "
6582 "refclassid = 'pg_extension'::regclass AND "
6585 "\n OR p.proacl IS DISTINCT FROM pip.initprivs");
6591 "SELECT tableoid, oid, proname, prolang, "
6592 "pronargs, proargtypes, prorettype, proacl, "
6593 "acldefault('f', proowner) AS acldefault, "
6597 "WHERE NOT proisagg"
6598 "\n AND NOT EXISTS (SELECT 1 FROM pg_depend "
6599 "WHERE classid = 'pg_proc'::regclass AND "
6600 "objid = p.oid AND deptype = 'i')"
6602 "\n pronamespace != "
6603 "(SELECT oid FROM pg_namespace "
6604 "WHERE nspname = 'pg_catalog')"
6605 "\n OR EXISTS (SELECT 1 FROM pg_cast"
6606 "\n WHERE pg_cast.oid > '%u'::oid"
6607 "\n AND p.oid = pg_cast.castfunc)",
6612 "\n OR EXISTS (SELECT 1 FROM pg_transform"
6613 "\n WHERE pg_transform.oid > '%u'::oid"
6614 "\n AND (p.oid = pg_transform.trffromsql"
6615 "\n OR p.oid = pg_transform.trftosql))",
6620 "\n OR EXISTS(SELECT 1 FROM pg_depend WHERE "
6621 "classid = 'pg_proc'::regclass AND "
6622 "objid = p.oid AND "
6623 "refclassid = 'pg_extension'::regclass AND "
6648 for (
i = 0;
i < ntups;
i++)
6655 finfo[
i].
dobj.namespace =
6665 if (finfo[
i].nargs == 0)
6671 finfo[
i].argtypes, finfo[
i].nargs);
6720 int i_reltablespace;
6722 int i_relhastriggers;
6723 int i_relpersistence;
6724 int i_relispopulated;
6727 int i_relforcerowsec;
6729 int i_toastfrozenxid;
6735 int i_toastreloptions;
6737 int i_foreignserver;
6739 int i_is_identity_sequence;
6762 "SELECT c.tableoid, c.oid, c.relname, "
6763 "c.relnamespace, c.relkind, c.reltype, "
6766 "c.relhasindex, c.relhasrules, c.relpages, "
6767 "c.relhastriggers, "
6768 "c.relpersistence, "
6771 "acldefault(CASE WHEN c.relkind = " CppAsString2(RELKIND_SEQUENCE)
6772 " THEN 's'::\"char\" ELSE 'r'::\"char\" END, c.relowner) AS acldefault, "
6773 "CASE WHEN c.relkind = " CppAsString2(RELKIND_FOREIGN_TABLE)
" THEN "
6774 "(SELECT ftserver FROM pg_catalog.pg_foreign_table WHERE ftrelid = c.oid) "
6775 "ELSE 0 END AS foreignserver, "
6776 "c.relfrozenxid, tc.relfrozenxid AS tfrozenxid, "
6778 "tc.relpages AS toastpages, "
6779 "tc.reloptions AS toast_reloptions, "
6780 "d.refobjid AS owning_tab, "
6781 "d.refobjsubid AS owning_col, "
6782 "tsp.spcname AS reltablespace, ");
6786 "false AS relhasoids, ");
6793 "c.relispopulated, ");
6796 "'t' as relispopulated, ");
6800 "c.relreplident, ");
6803 "'d' AS relreplident, ");
6807 "c.relrowsecurity, c.relforcerowsecurity, ");
6810 "false AS relrowsecurity, "
6811 "false AS relforcerowsecurity, ");
6815 "c.relminmxid, tc.relminmxid AS tminmxid, ");
6818 "0 AS relminmxid, 0 AS tminmxid, ");
6822 "array_remove(array_remove(c.reloptions,'check_option=local'),'check_option=cascaded') AS reloptions, "
6823 "CASE WHEN 'check_option=local' = ANY (c.reloptions) THEN 'LOCAL'::text "
6824 "WHEN 'check_option=cascaded' = ANY (c.reloptions) THEN 'CASCADED'::text ELSE NULL END AS checkoption, ");
6827 "c.reloptions, NULL AS checkoption, ");
6834 "NULL AS amname, ");
6838 "(d.deptype = 'i') IS TRUE AS is_identity_sequence, ");
6841 "false AS is_identity_sequence, ");
6845 "c.relispartition AS ispartition ");
6848 "false AS ispartition ");
6857 "\nFROM pg_class c\n"
6858 "LEFT JOIN pg_depend d ON "
6860 "d.classid = 'pg_class'::regclass AND d.objid = c.oid AND "
6861 "d.objsubid = 0 AND "
6862 "d.refclassid = 'pg_class'::regclass AND d.deptype IN ('a', 'i'))\n"
6863 "LEFT JOIN pg_tablespace tsp ON (tsp.oid = c.reltablespace)\n");
6870 "LEFT JOIN pg_am am ON (c.relam = am.oid)\n");
6878 "LEFT JOIN pg_class tc ON (c.reltoastrelid = tc.oid"
6880 " AND c.relkind <> " CppAsString2(RELKIND_PARTITIONED_TABLE)
")\n");
6893 "WHERE c.relkind IN ("
6941 i_relforcerowsec =
PQfnumber(
res,
"relforcerowsecurity");
6949 i_toastreloptions =
PQfnumber(
res,
"toast_reloptions");
6953 i_is_identity_sequence =
PQfnumber(
res,
"is_identity_sequence");
6975 for (
i = 0;
i < ntups;
i++)
6982 tblinfo[
i].
dobj.namespace =
7042 if (tblinfo[
i].relkind == RELKIND_COMPOSITE_TYPE)
7089 (tblinfo[
i].
relkind == RELKIND_RELATION ||
7090 tblinfo[
i].
relkind == RELKIND_PARTITIONED_TABLE))
7097 if (query->
len == 0)
7106 if (query->
len >= 100000)
7117 if (query->
len != 0)
7152 for (
i = 0;
i < numTables;
i++)
7161 if (owning_tab == NULL)
7162 pg_fatal(
"failed sanity check, parent table with OID %u of sequence with OID %u not found",
7225 *numInherits = ntups;
7232 for (
i = 0;
i < ntups;
i++)
7287 "SELECT partrelid FROM pg_partitioned_table WHERE\n"
7288 "(SELECT c.oid FROM pg_opclass c JOIN pg_am a "
7289 "ON c.opcmethod = a.oid\n"
7290 "WHERE opcname = 'enum_ops' "
7291 "AND opcnamespace = 'pg_catalog'::regnamespace "
7292 "AND amname = 'hash') = ANY(partclass)");
7298 for (
int i = 0;
i < ntups;
i++)
7305 pg_fatal(
"failed sanity check, table OID %u appearing in pg_partitioned_table not found",
7342 i_indnullsnotdistinct,
7365 for (
int i = 0;
i < numTables;
i++)
7379 if (tbloids->
len > 1)
7386 "SELECT t.tableoid, t.oid, i.indrelid, "
7387 "t.relname AS indexname, "
7388 "pg_catalog.pg_get_indexdef(i.indexrelid) AS indexdef, "
7389 "i.indkey, i.indisclustered, "
7390 "c.contype, c.conname, "
7391 "c.condeferrable, c.condeferred, "
7392 "c.tableoid AS contableoid, "
7394 "pg_catalog.pg_get_constraintdef(c.oid, false) AS condef, "
7395 "(SELECT spcname FROM pg_catalog.pg_tablespace s WHERE s.oid = t.reltablespace) AS tablespace, "
7396 "t.reloptions AS indreloptions, ");
7401 "i.indisreplident, ");
7404 "false AS indisreplident, ");
7408 "inh.inhparent AS parentidx, "
7409 "i.indnkeyatts AS indnkeyatts, "
7410 "i.indnatts AS indnatts, "
7411 "(SELECT pg_catalog.array_agg(attnum ORDER BY attnum) "
7412 " FROM pg_catalog.pg_attribute "
7413 " WHERE attrelid = i.indexrelid AND "
7414 " attstattarget >= 0) AS indstatcols, "
7415 "(SELECT pg_catalog.array_agg(attstattarget ORDER BY attnum) "
7416 " FROM pg_catalog.pg_attribute "
7417 " WHERE attrelid = i.indexrelid AND "
7418 " attstattarget >= 0) AS indstatvals, ");
7422 "i.indnatts AS indnkeyatts, "
7423 "i.indnatts AS indnatts, "
7424 "'' AS indstatcols, "
7425 "'' AS indstatvals, ");
7429 "i.indnullsnotdistinct, ");
7432 "false AS indnullsnotdistinct, ");
7439 "NULL AS conperiod ");
7453 "FROM unnest('%s'::pg_catalog.oid[]) AS src(tbloid)\n"
7454 "JOIN pg_catalog.pg_index i ON (src.tbloid = i.indrelid) "
7455 "JOIN pg_catalog.pg_class t ON (t.oid = i.indexrelid) "
7456 "JOIN pg_catalog.pg_class t2 ON (t2.oid = i.indrelid) "
7457 "LEFT JOIN pg_catalog.pg_constraint c "
7458 "ON (i.indrelid = c.conrelid AND "
7459 "i.indexrelid = c.conindid AND "
7460 "c.contype IN ('p','u','x')) "
7461 "LEFT JOIN pg_catalog.pg_inherits inh "
7462 "ON (inh.inhrelid = indexrelid) "
7463 "WHERE (i.indisvalid OR t2.relkind = 'p') "
7465 "ORDER BY i.indrelid, indexname",
7475 "FROM unnest('%s'::pg_catalog.oid[]) AS src(tbloid)\n"
7476 "JOIN pg_catalog.pg_index i ON (src.tbloid = i.indrelid) "
7477 "JOIN pg_catalog.pg_class t ON (t.oid = i.indexrelid) "
7478 "LEFT JOIN pg_catalog.pg_constraint c "
7479 "ON (i.indrelid = c.conrelid AND "
7480 "i.indexrelid = c.conindid AND "
7481 "c.contype IN ('p','u','x')) "
7482 "WHERE i.indisvalid AND i.indisready "
7483 "ORDER BY i.indrelid, indexname",
7502 i_indnullsnotdistinct =
PQfnumber(
res,
"indnullsnotdistinct");
7523 for (
int j = 0;
j < ntups;)
7530 for (numinds = 1; numinds < ntups -
j; numinds++)
7538 while (++curtblindx < numTables)
7540 tbinfo = &tblinfo[curtblindx];
7544 if (curtblindx >= numTables)
7545 pg_fatal(
"unrecognized table OID %u", indrelid);
7549 pg_fatal(
"unexpected index data for table \"%s\"",
7556 for (
int c = 0;
c < numinds;
c++,
j++)
7566 indxinfo[
j].
dobj.namespace = tbinfo->
dobj.namespace;
7577 indxinfo[
j].indkeys, indxinfo[
j].indnattrs);
7588 if (contype ==
'p' || contype ==
'u' || contype ==
'x')
7603 constrinfo->
dobj.namespace = tbinfo->
dobj.namespace;
7606 constrinfo->
contype = contype;
7610 constrinfo->
condef = NULL;
7666 "stxnamespace, stxowner, stxrelid, NULL AS stxstattarget "
7667 "FROM pg_catalog.pg_statistic_ext");
7670 "stxnamespace, stxowner, stxrelid, stxstattarget "
7671 "FROM pg_catalog.pg_statistic_ext");
7687 for (
i = 0;
i < ntups;
i++)
7694 statsextinfo[
i].
dobj.namespace =
7748 for (
int i = 0;
i < numTables;
i++)
7756 if ((!
tinfo->hastriggers &&
7757 tinfo->relkind != RELKIND_PARTITIONED_TABLE) ||
7762 if (tbloids->
len > 1)
7769 "SELECT c.tableoid, c.oid, "
7770 "conrelid, conname, confrelid, ");
7776 "pg_catalog.pg_get_constraintdef(c.oid) AS condef\n"
7777 "FROM unnest('%s'::pg_catalog.oid[]) AS src(tbloid)\n"
7778 "JOIN pg_catalog.pg_constraint c ON (src.tbloid = c.conrelid)\n"
7779 "WHERE contype = 'f' ",
7783 "AND conparentid = 0 ");
7785 "ORDER BY conrelid, conname");
7802 for (
int j = 0;
j < ntups;
j++)
7811 if (tbinfo == NULL || tbinfo->
dobj.
catId.
oid != conrelid)
7813 while (++curtblindx < numTables)
7815 tbinfo = &tblinfo[curtblindx];
7819 if (curtblindx >= numTables)
7820 pg_fatal(
"unrecognized table OID %u", conrelid);
7828 constrinfo[
j].
dobj.namespace = tbinfo->
dobj.namespace;
7847 if (reftable && reftable->
relkind == RELKIND_PARTITIONED_TABLE)
7853 for (
int k = 0; k < reftable->
numIndexes; k++)
7861 refidx = &reftable->
indexes[k];
7926 "PREPARE getDomainConstraints(pg_catalog.oid) AS\n"
7927 "SELECT tableoid, oid, conname, "
7928 "pg_catalog.pg_get_constraintdef(oid) AS consrc, "
7930 "FROM pg_catalog.pg_constraint "
7931 "WHERE contypid = $1 AND contype = 'c' "
7932 "ORDER BY conname");
7940 "EXECUTE getDomainConstraints('%u')",
7957 for (
i = 0;
i < ntups;
i++)
7966 constrinfo[
i].
dobj.namespace = tyinfo->
dobj.namespace;
8018 "tableoid, oid, rulename, "
8019 "ev_class AS ruletable, ev_type, is_instead, "
8040 for (
i = 0;
i < ntups;
i++)
8051 if (ruleinfo[
i].ruletable == NULL)
8052 pg_fatal(
"failed sanity check, parent table with OID %u of pg_rewrite entry with OID %u not found",
8053 ruletableoid, ruleinfo[
i].dobj.catId.oid);
8059 if (ruleinfo[
i].ruletable)
8068 if ((ruleinfo[
i].ruletable->relkind == RELKIND_VIEW ||
8128 for (
int i = 0;
i < numTables;
i++)
8137 if (tbloids->
len > 1)
8154 "SELECT t.tgrelid, t.tgname, "
8155 "pg_catalog.pg_get_triggerdef(t.oid, false) AS tgdef, "
8156 "t.tgenabled, t.tableoid, t.oid, "
8157 "t.tgparentid <> 0 AS tgispartition\n"
8158 "FROM unnest('%s'::pg_catalog.oid[]) AS src(tbloid)\n"
8159 "JOIN pg_catalog.pg_trigger t ON (src.tbloid = t.tgrelid) "
8160 "LEFT JOIN pg_catalog.pg_trigger u ON (u.oid = t.tgparentid) "
8161 "WHERE ((NOT t.tgisinternal AND t.tgparentid = 0) "
8162 "OR t.tgenabled != u.tgenabled) "
8163 "ORDER BY t.tgrelid, t.tgname",
8177 "SELECT t.tgrelid, t.tgname, "
8178 "pg_catalog.pg_get_triggerdef(t.oid, false) AS tgdef, "
8179 "t.tgenabled, t.tableoid, t.oid, t.tgisinternal as tgispartition\n"
8180 "FROM unnest('%s'::pg_catalog.oid[]) AS src(tbloid)\n"
8181 "JOIN pg_catalog.pg_trigger t ON (src.tbloid = t.tgrelid) "
8182 "LEFT JOIN pg_catalog.pg_trigger u ON (u.oid = t.tgparentid) "
8183 "WHERE (NOT t.tgisinternal OR t.tgenabled != u.tgenabled) "
8184 "ORDER BY t.tgrelid, t.tgname",
8197 "SELECT t.tgrelid, t.tgname, "
8198 "pg_catalog.pg_get_triggerdef(t.oid, false) AS tgdef, "
8199 "t.tgenabled, t.tableoid, t.oid, t.tgisinternal as tgispartition "
8200 "FROM unnest('%s'::pg_catalog.oid[]) AS src(tbloid)\n"
8201 "JOIN pg_catalog.pg_trigger t ON (src.tbloid = t.tgrelid) "
8202 "LEFT JOIN pg_catalog.pg_depend AS d ON "
8203 " d.classid = 'pg_catalog.pg_trigger'::pg_catalog.regclass AND "
8204 " d.refclassid = 'pg_catalog.pg_trigger'::pg_catalog.regclass AND "
8206 "LEFT JOIN pg_catalog.pg_trigger AS pt ON pt.oid = refobjid "
8207 "WHERE (NOT t.tgisinternal OR t.tgenabled != pt.tgenabled) "
8208 "ORDER BY t.tgrelid, t.tgname",
8215 "SELECT t.tgrelid, t.tgname, "
8216 "pg_catalog.pg_get_triggerdef(t.oid, false) AS tgdef, "
8217 "t.tgenabled, false as tgispartition, "
8218 "t.tableoid, t.oid "
8219 "FROM unnest('%s'::pg_catalog.oid[]) AS src(tbloid)\n"
8220 "JOIN pg_catalog.pg_trigger t ON (src.tbloid = t.tgrelid) "
8221 "WHERE NOT tgisinternal "
8222 "ORDER BY t.tgrelid, t.tgname",
8245 for (
int j = 0;
j < ntups;)
8252 for (numtrigs = 1; numtrigs < ntups -
j; numtrigs++)
8260 while (++curtblindx < numTables)
8262 tbinfo = &tblinfo[curtblindx];
8266 if (curtblindx >= numTables)
8267 pg_fatal(
"unrecognized table OID %u", tgrelid);
8273 for (
int c = 0;
c < numtrigs;
c++,
j++)
8280 tginfo[
j].
dobj.namespace = tbinfo->
dobj.namespace;
8318 *numEventTriggers = 0;
8325 "SELECT e.tableoid, e.oid, evtname, evtenabled, "
8326 "evtevent, evtowner, "
8327 "array_to_string(array("
8328 "select quote_literal(x) "
8329 " from unnest(evttags) as t(x)), ', ') as evttags, "
8330 "e.evtfoid::regproc as evtfname "
8331 "FROM pg_event_trigger e "
8338 *numEventTriggers = ntups;
8351 for (
i = 0;
i < ntups;
i++)
8397 int i_lanplcallfoid;
8405 "lanname, lanpltrusted, lanplcallfoid, "
8406 "laninline, lanvalidator, "
8408 "acldefault('l', lanowner) AS acldefault, "
8418 *numProcLangs = ntups;
8433 for (
i = 0;
i < ntups;
i++)
8494 "castsource, casttarget, castfunc, castcontext, "
8497 "WHERE NOT EXISTS ( "
8498 "SELECT 1 FROM pg_range r "
8499 "WHERE c.castsource = r.rngtypid "
8500 "AND c.casttarget = r.rngmultitypid "
8507 "castsource, casttarget, castfunc, castcontext, "
8509 "FROM pg_cast ORDER BY 3,4");
8528 for (
i = 0;
i < ntups;
i++)
8552 if (sTypeInfo && tTypeInfo)
8576 appendPQExpBuffer(query,
"SELECT lanname FROM pg_language WHERE oid = %u", langid);
8616 "trftype, trflang, trffromsql::oid, trftosql::oid "
8617 "FROM pg_transform "
8624 *numTransforms = ntups;
8635 for (
i = 0;
i < ntups;
i++)
8658 if (typeInfo && lanname)
8672 return transforminfo;
8696 int i_attstattarget;
8706 int i_notnull_noinherit;
8707 int i_notnull_is_pk;
8711 int i_attcompression;
8712 int i_attfdwoptions;
8713 int i_attmissingval;
8728 for (
int i = 0;
i < numTables;
i++)
8733 if (tbinfo->
relkind == RELKIND_SEQUENCE)
8741 if (tbloids->
len > 1)
8748 if (checkoids->
len > 1)
8768 "a.attstattarget,\n"
8776 "pg_catalog.format_type(t.oid, a.atttypmod) AS atttypname,\n"
8777 "array_to_string(a.attoptions, ', ') AS attoptions,\n"
8778 "CASE WHEN a.attcollation <> t.typcollation "
8779 "THEN a.attcollation ELSE 0 END AS attcollation,\n"
8780 "pg_catalog.array_to_string(ARRAY("
8781 "SELECT pg_catalog.quote_ident(option_name) || "
8782 "' ' || pg_catalog.quote_literal(option_value) "
8783 "FROM pg_catalog.pg_options_to_table(attfdwoptions) "
8784 "ORDER BY option_name"
8785 "), E',\n ') AS attfdwoptions,\n");
8814 "CASE WHEN co.conname IS NOT NULL THEN co.conname "
8815 " WHEN a.attnotnull AND copk.conname IS NULL THEN '' ELSE NULL END AS notnull_name,\n"
8816 "CASE WHEN co.conname IS NOT NULL THEN co.connoinherit "
8817 " WHEN a.attnotnull THEN false ELSE NULL END AS notnull_noinherit,\n"
8818 "copk.conname IS NOT NULL as notnull_is_pk,\n"
8819 "CASE WHEN co.conname IS NOT NULL THEN "
8820 " coalesce(NOT co.conislocal, true) "
8821 "ELSE false END as notnull_inh,\n");
8824 "CASE WHEN a.attnotnull THEN '' ELSE NULL END AS notnull_name,\n"
8825 "false AS notnull_noinherit,\n"
8826 "copk.conname IS NOT NULL AS notnull_is_pk,\n"
8827 "NOT a.attislocal AS notnull_inh,\n");
8831 "a.attcompression AS attcompression,\n");
8834 "'' AS attcompression,\n");
8838 "a.attidentity,\n");
8841 "'' AS attidentity,\n");
8845 "CASE WHEN a.atthasmissing AND NOT a.attisdropped "
8846 "THEN a.attmissingval ELSE null END AS attmissingval,\n");
8849 "NULL AS attmissingval,\n");
8853 "a.attgenerated\n");
8856 "'' AS attgenerated\n");
8860 "FROM unnest('%s'::pg_catalog.oid[]) AS src(tbloid)\n"
8861 "JOIN pg_catalog.pg_attribute a ON (src.tbloid = a.attrelid) "
8862 "LEFT JOIN pg_catalog.pg_type t "
8863 "ON (a.atttypid = t.oid)\n",
8873 " LEFT JOIN pg_catalog.pg_constraint co ON "
8874 "(a.attrelid = co.conrelid\n"
8875 " AND co.contype = 'n' AND "
8876 "co.conkey = array[a.attnum])\n");
8879 "LEFT JOIN pg_catalog.pg_constraint copk ON "
8880 "(copk.conrelid = src.tbloid\n"
8881 " AND copk.contype = 'p' AND "
8882 "copk.conkey @> array[a.attnum])\n"
8883 "WHERE a.attnum > 0::pg_catalog.int2\n"
8884 "ORDER BY a.attrelid, a.attnum");
8904 i_notnull_noinherit =
PQfnumber(
res,
"notnull_noinherit");
8923 for (
int r = 0; r < ntups;)
8932 for (numatts = 1; numatts < ntups - r; numatts++)
8940 while (++curtblindx < numTables)
8942 tbinfo = &tblinfo[curtblindx];
8946 if (curtblindx >= numTables)
8947 pg_fatal(
"unrecognized table OID %u", attrelid);
8949 if (tbinfo->
relkind == RELKIND_SEQUENCE ||
8951 pg_fatal(
"unexpected column data for table \"%s\"",
8979 hasdefaults =
false;
8981 for (
int j = 0;
j < numatts;
j++, r++)
8983 bool use_named_notnull =
false;
8984 bool use_unnamed_notnull =
false;
8985 bool use_throwaway_notnull =
false;
8988 pg_fatal(
"invalid column numbering in table \"%s\"",
9048 use_named_notnull =
true;
9055 use_throwaway_notnull =
true;
9057 use_unnamed_notnull =
true;
9071 use_named_notnull =
true;
9083 if (strcmp(default_name,
9085 use_unnamed_notnull =
true;
9088 use_named_notnull =
true;
9095 use_throwaway_notnull =
true;
9098 if (use_unnamed_notnull)
9103 else if (use_named_notnull)
9108 else if (use_throwaway_notnull)
9114 psprintf(
"pgdump_throwaway_notnull_%d", notnullcount++);
9144 if (tbloids->
len > 1)
9167 "pg_catalog.pg_get_expr(adbin, adrelid) AS adsrc\n"
9168 "FROM unnest('%s'::pg_catalog.oid[]) AS src(tbloid)\n"
9169 "JOIN pg_catalog.pg_attrdef a ON (src.tbloid = a.adrelid)\n"
9170 "ORDER BY a.adrelid, a.adnum",
9179 for (
int j = 0;
j < numDefaults;
j++)
9191 if (tbinfo == NULL || tbinfo->
dobj.
catId.
oid != adrelid)
9193 while (++curtblindx < numTables)
9195 tbinfo = &tblinfo[curtblindx];
9199 if (curtblindx >= numTables)
9200 pg_fatal(
"unrecognized table OID %u", adrelid);
9203 if (adnum <= 0 || adnum > tbinfo->
numatts)
9204 pg_fatal(
"invalid adnum value %d for table \"%s\"",
9219 attrdefs[
j].
adnum = adnum;
9223 attrdefs[
j].
dobj.namespace = tbinfo->
dobj.namespace;
9246 else if (tbinfo->
relkind == RELKIND_VIEW)
9264 if (!attrdefs[
j].separate)
9276 tbinfo->
attrdefs[adnum - 1] = &attrdefs[
j];
9302 "SELECT c.tableoid, c.oid, conrelid, conname, "
9303 "pg_catalog.pg_get_constraintdef(c.oid) AS consrc, "
9304 "conislocal, convalidated "
9305 "FROM unnest('%s'::pg_catalog.oid[]) AS src(tbloid)\n"
9306 "JOIN pg_catalog.pg_constraint c ON (src.tbloid = c.conrelid)\n"
9307 "WHERE contype = 'c' "
9308 "ORDER BY c.conrelid, c.conname",
9326 for (
int j = 0;
j < numConstrs;)
9333 for (numcons = 1; numcons < numConstrs -
j; numcons++)
9341 while (++curtblindx < numTables)
9343 tbinfo = &tblinfo[curtblindx];
9347 if (curtblindx >= numTables)
9348 pg_fatal(
"unrecognized table OID %u", conrelid);
9350 if (numcons != tbinfo->
ncheck)
9353 "expected %d check constraints on table \"%s\" but found %d",
9362 for (
int c = 0;
c < numcons;
c++,
j++)
9371 constrs[
j].
dobj.namespace = tbinfo->
dobj.namespace;
9400 if (!constrs[
j].separate)
9480 "prsstart::oid, prstoken::oid, "
9481 "prsend::oid, prsheadline::oid, prslextype::oid "
9482 "FROM pg_ts_parser");
9487 *numTSParsers = ntups;
9501 for (
i = 0;
i < ntups;
i++)
9508 prsinfo[
i].
dobj.namespace =
9545 int i_dictnamespace;
9548 int i_dictinitoption;
9553 "dictnamespace, dictowner, "
9554 "dicttemplate, dictinitoption "
9560 *numTSDicts = ntups;
9572 for (
i = 0;
i < ntups;
i++)
9579 dictinfo[
i].
dobj.namespace =
9617 int i_tmplnamespace;
9624 "tmplnamespace, tmplinit::oid, tmpllexize::oid "
9625 "FROM pg_ts_template");
9630 *numTSTemplates = ntups;
9641 for (
i = 0;
i < ntups;
i++)
9648 tmplinfo[
i].
dobj.namespace =
9689 "cfgnamespace, cfgowner, cfgparser "
9690 "FROM pg_ts_config");
9695 *numTSConfigs = ntups;
9706 for (
i = 0;
i < ntups;
i++)
9713 cfginfo[
i].
dobj.namespace =
9758 "fdwhandler::pg_catalog.regproc, "
9759 "fdwvalidator::pg_catalog.regproc, "
9761 "acldefault('F', fdwowner) AS acldefault, "
9762 "array_to_string(ARRAY("
9763 "SELECT quote_ident(option_name) || ' ' || "
9764 "quote_literal(option_value) "
9765 "FROM pg_options_to_table(fdwoptions) "
9766 "ORDER BY option_name"
9767 "), E',\n ') AS fdwoptions "
9768 "FROM pg_foreign_data_wrapper");
9773 *numForeignDataWrappers = ntups;
9787 for (
i = 0;
i < ntups;
i++)
9794 fdwinfo[
i].
dobj.namespace = NULL;
9849 "srvfdw, srvtype, srvversion, srvacl, "
9850 "acldefault('S', srvowner) AS acldefault, "
9851 "array_to_string(ARRAY("
9852 "SELECT quote_ident(option_name) || ' ' || "
9853 "quote_literal(option_value) "
9854 "FROM pg_options_to_table(srvoptions) "
9855 "ORDER BY option_name"
9856 "), E',\n ') AS srvoptions "
9857 "FROM pg_foreign_server");
9862 *numForeignServers = ntups;
9877 for (
i = 0;
i < ntups;
i++)
9884 srvinfo[
i].
dobj.namespace = NULL;
9930 int i_defaclnamespace;
9931 int i_defaclobjtype;
9952 "SELECT oid, tableoid, "
9957 "CASE WHEN defaclnamespace = 0 THEN "
9958 "acldefault(CASE WHEN defaclobjtype = 'S' "
9959 "THEN 's'::\"char\" ELSE defaclobjtype END, "
9960 "defaclrole) ELSE '{}' END AS acldefault "
9961 "FROM pg_default_acl");
9966 *numDefaultACLs = ntups;
9978 for (
i = 0;
i < ntups;
i++)
9992 daclinfo[
i].
dobj.namespace = NULL;
10020 static const char *
10033 while (low <= high)
10037 if (roleoid < middle->roleoid)
10039 else if (roleoid > middle->
roleoid)
10046 pg_fatal(
"role with OID %u does not exist", roleoid);
10063 query =
"SELECT oid, rolname FROM pg_catalog.pg_roles ORDER BY 1";
10101 "SELECT DISTINCT attrelid FROM pg_attribute "
10102 "WHERE attacl IS NOT NULL");
10107 for (
i = 0;
i < ntups;
i++)
10126 "SELECT objoid, classoid, objsubid, privtype, initprivs "
10127 "FROM pg_init_privs");
10132 for (
i = 0;
i < ntups;
i++)
10143 objId.
oid = objoid;
10155 ((
TableInfo *) dobj)->hascolumnACLs =
true;
10159 classoid, objoid, objsubid);
10168 strcmp(dobj->
name,
"public") == 0)
10188 classoid, objoid, objsubid);
10222 const char *
name,
const char *
namespace,
10223 const char *owner,
CatalogId catalogId,
10224 int subid,
DumpId dumpId,
10225 const char *initdb_comment)
10236 if (strcmp(
type,
"LARGE OBJECT") != 0)
10261 if (initdb_comment != NULL)
10287 if (
namespace && *
namespace)
10302 .namespace =
namespace,
10304 .description =
"COMMENT",
10306 .createStmt = query->
data,
10322 const char *
name,
const char *
namespace,
10323 const char *owner,
CatalogId catalogId,
10324 int subid,
DumpId dumpId)
10327 catalogId, subid, dumpId, NULL);
10338 const char *reltypename)
10385 .namespace = tbinfo->
dobj.namespace->dobj.
name,
10387 .description =
"COMMENT",
10389 .createStmt = query->
data,
10393 else if (objsubid > 0 && objsubid <= tbinfo->numatts)
10410 .namespace = tbinfo->
dobj.namespace->dobj.
name,
10412 .description =
"COMMENT",
10414 .createStmt = query->
data,
10447 while (low <= high)
10449 middle = low + (high - low) / 2;
10451 if (classoid < middle->classoid)
10453 else if (classoid > middle->
classoid)
10455 else if (objoid < middle->objoid)
10457 else if (objoid > middle->
objoid)
10475 while (middle > low)
10477 if (classoid != middle[-1].classoid ||
10478 objoid != middle[-1].objoid)
10487 while (middle <= high)
10489 if (classoid != middle->
classoid ||
10490 objoid != middle->
objoid)
10527 "FROM pg_catalog.pg_description "
10528 "ORDER BY classoid, objoid, objsubid");
10545 for (
i = 0;
i < ntups;
i++)
10555 if (dobj == NULL ||
10568 ((
TableInfo *) dobj)->relkind == RELKIND_COMPOSITE_TYPE)
10607 if (dobj->
dump == 0)
10733 if (loinfo == NULL)
10734 pg_fatal(
"missing metadata for large objects \"%s\"",
10740 .description =
"BLOBS",
10742 .deps = dobj->dependencies,
10743 .nDeps = dobj->nDeps,
10745 .dumpArg = loinfo));
10815 "-- *not* dropping schema, since initdb creates it\n");
10817 "-- *not* creating schema, since initdb creates it\n");
10822 "SCHEMA", qnspname, NULL);
10828 .description =
"SCHEMA",
10830 .createStmt = q->
data,
10831 .dropStmt = delq->
data));
10836 const char *initdb_comment = NULL;
10838 if (!nspinfo->
create && strcmp(qnspname,
"public") == 0)
10839 initdb_comment =
"standard public schema";
10853 qnspname, NULL, NULL,
10898 qextname,
fmtId(extinfo->namespace));
10913 appendPQExpBufferStr(q,
"-- For binary upgrade, create an empty extension and insert objects into it\n");
10923 "SELECT pg_catalog.binary_upgrade_create_empty_extension(");
10968 .description =
"EXTENSION",
10970 .createStmt = q->
data,
10971 .dropStmt = delq->
data));
11004 if (tyinfo->
typtype == TYPTYPE_BASE)
11006 else if (tyinfo->
typtype == TYPTYPE_DOMAIN)
11008 else if (tyinfo->
typtype == TYPTYPE_COMPOSITE)
11010 else if (tyinfo->
typtype == TYPTYPE_ENUM)
11012 else if (tyinfo->
typtype == TYPTYPE_RANGE)
11017 pg_log_warning(
"typtype of data type \"%s\" appears to be invalid",
11046 "PREPARE dumpEnumType(pg_catalog.oid) AS\n"
11047 "SELECT oid, enumlabel "
11048 "FROM pg_catalog.pg_enum "
11049 "WHERE enumtypid = $1 "
11050 "ORDER BY enumsortorder");
11058 "EXECUTE dumpEnumType('%u')",
11087 for (
i = 0;
i < num;
i++)
11105 for (
i = 0;
i < num;
i++)
11113 "SELECT pg_catalog.binary_upgrade_set_next_pg_enum_oid('%u'::pg_catalog.oid);\n",
11124 tyinfo->
dobj.namespace->dobj.
name);
11129 .namespace = tyinfo->
dobj.namespace->dobj.
name,
11131 .description =
"TYPE",
11133 .createStmt = q->
data,
11134 .dropStmt = delq->
data));
11150 tyinfo->
dobj.namespace->dobj.
name,
11182 "PREPARE dumpRangeType(pg_catalog.oid) AS\n");
11189 "pg_catalog.format_type(rngmultitypid, NULL) AS rngmultitype, ");
11192 "NULL AS rngmultitype, ");
11195 "pg_catalog.format_type(rngsubtype, NULL) AS rngsubtype, "
11196 "opc.opcname AS opcname, "
11197 "(SELECT nspname FROM pg_catalog.pg_namespace nsp "
11198 " WHERE nsp.oid = opc.opcnamespace) AS opcnsp, "
11200 "CASE WHEN rngcollation = st.typcollation THEN 0 "
11201 " ELSE rngcollation END AS collation, "
11202 "rngcanonical, rngsubdiff "
11203 "FROM pg_catalog.pg_range r, pg_catalog.pg_type st, "
11204 " pg_catalog.pg_opclass opc "
11205 "WHERE st.oid = rngsubtype AND opc.oid = rngsubopc AND "
11214 "EXECUTE dumpRangeType('%u')",
11265 if (strcmp(procname,
"-") != 0)
11269 if (strcmp(procname,
"-") != 0)
11277 tyinfo->
dobj.namespace->dobj.
name);
11282 .namespace = tyinfo->
dobj.namespace->dobj.
name,
11284 .description =
"TYPE",
11286 .createStmt = q->
data,
11287 .dropStmt = delq->
data));
11303 tyinfo->
dobj.namespace->dobj.
name,
11348 tyinfo->
dobj.namespace->dobj.
name);
11353 .namespace = tyinfo->
dobj.namespace->dobj.
name,
11355 .description =
"TYPE",
11357 .createStmt = q->
data,
11358 .dropStmt = delq->
data));
11374 tyinfo->
dobj.namespace->dobj.
name,
11405 char *typsubscript;
11411 Oid typsubscriptoid;
11413 char *typispreferred;
11418 char *typcollatable;
11420 bool typdefault_is_literal =
false;
11426 "PREPARE dumpBaseType(pg_catalog.oid) AS\n"
11428 "typinput, typoutput, typreceive, typsend, "
11429 "typreceive::pg_catalog.oid AS typreceiveoid, "
11430 "typsend::pg_catalog.oid AS typsendoid, "
11432 "typanalyze::pg_catalog.oid AS typanalyzeoid, "
11433 "typdelim, typbyval, typalign, typstorage, "
11434 "typmodin, typmodout, "
11435 "typmodin::pg_catalog.oid AS typmodinoid, "
11436 "typmodout::pg_catalog.oid AS typmodoutoid, "
11437 "typcategory, typispreferred, "
11438 "(typcollation <> 0) AS typcollatable, "
11439 "pg_catalog.pg_get_expr(typdefaultbin, 0) AS typdefaultbin, typdefault, ");
11444 "typsubscript::pg_catalog.oid AS typsubscriptoid ");
11447 "'-' AS typsubscript, 0 AS typsubscriptoid ");
11458 "EXECUTE dumpBaseType('%u')",
11490 typdefault_is_literal =
true;
11515 "CREATE TYPE %s (\n"
11516 " INTERNALLENGTH = %s",
11518 (strcmp(typlen,
"-1") == 0) ?
"variable" : typlen);
11534 if (strcmp(typcollatable,
"t") == 0)
11537 if (typdefault != NULL)
11540 if (typdefault_is_literal)
11554 if (strcmp(typcategory,
"U") != 0)
11560 if (strcmp(typispreferred,
"t") == 0)
11563 if (typdelim && strcmp(typdelim,
",") != 0)
11571 else if (*
typalign == TYPALIGN_SHORT)
11573 else if (*
typalign == TYPALIGN_INT)
11575 else if (*
typalign == TYPALIGN_DOUBLE)
11578 if (*typstorage == TYPSTORAGE_PLAIN)
11580 else if (*typstorage == TYPSTORAGE_EXTERNAL)
11582 else if (*typstorage == TYPSTORAGE_EXTENDED)
11584 else if (*typstorage == TYPSTORAGE_MAIN)
11587 if (strcmp(typbyval,
"t") == 0)
11595 tyinfo->
dobj.namespace->dobj.
name);
11600 .namespace = tyinfo->
dobj.namespace->dobj.
name,
11602 .description =
"TYPE",
11604 .createStmt = q->
data,
11605 .dropStmt = delq->
data));
11621 tyinfo->
dobj.namespace->dobj.
name,
11651 bool typdefault_is_literal =
false;
11657 "PREPARE dumpDomain(pg_catalog.oid) AS\n");
11660 "pg_catalog.format_type(t.typbasetype, t.typtypmod) AS typdefn, "
11661 "pg_catalog.pg_get_expr(t.typdefaultbin, 'pg_catalog.pg_type'::pg_catalog.regclass) AS typdefaultbin, "
11663 "CASE WHEN t.typcollation <> u.typcollation "
11664 "THEN t.typcollation ELSE 0 END AS typcollation "
11665 "FROM pg_catalog.pg_type t "
11666 "LEFT JOIN pg_catalog.pg_type u ON (t.typbasetype = u.oid) "
11667 "WHERE t.oid = $1");
11675 "EXECUTE dumpDomain('%u')",
11687 typdefault_is_literal =
true;
11703 "CREATE DOMAIN %s AS %s",
11717 if (typnotnull[0] ==
't')
11720 if (typdefault != NULL)
11723 if (typdefault_is_literal)
11749 "DOMAIN", qtypname,
11750 tyinfo->
dobj.namespace->dobj.
name);
11755 .namespace = tyinfo->
dobj.namespace->dobj.
name,
11757 .description =
"DOMAIN",
11759 .createStmt = q->
data,
11760 .dropStmt = delq->
data));
11776 tyinfo->
dobj.namespace->dobj.
name,
11790 tyinfo->
dobj.namespace->dobj.
name,
11825 int i_attisdropped;
11826 int i_attcollation;
11841 "PREPARE dumpCompositeType(pg_catalog.oid) AS\n"
11842 "SELECT a.attname, a.attnum, "
11843 "pg_catalog.format_type(a.atttypid, a.atttypmod) AS atttypdefn, "
11844 "a.attlen, a.attalign, a.attisdropped, "
11845 "CASE WHEN a.attcollation <> at.typcollation "
11846 "THEN a.attcollation ELSE 0 END AS attcollation "
11847 "FROM pg_catalog.pg_type ct "
11848 "JOIN pg_catalog.pg_attribute a ON a.attrelid = ct.typrelid "
11849 "LEFT JOIN pg_catalog.pg_type at ON at.oid = a.atttypid "
11850 "WHERE ct.oid = $1 "
11851 "ORDER BY a.attnum");
11859 "EXECUTE dumpCompositeType('%u')",
11888 for (
i = 0;
i < ntups;
i++)
11908 if (actual_atts++ > 0)
11939 "\n-- For binary upgrade, recreate dropped column.\n");
11941 "SET attlen = %s, "
11942 "attalign = '%s', attbyval = false\n"
11963 tyinfo->
dobj.namespace->dobj.
name);
11968 .namespace = tyinfo->
dobj.namespace->dobj.
name,
11970 .description =
"TYPE",
11972 .createStmt = q->
data,
11973 .dropStmt = delq->
data));
11990 tyinfo->
dobj.namespace->dobj.
name,
12027 int i_attisdropped;
12054 for (
i = 0;
i < ntups;
i++)
12081 .namespace = tyinfo->
dobj.namespace->dobj.
name,
12083 .description =
"COMMENT",
12085 .createStmt = query->
data,
12136 .namespace = stinfo->
dobj.namespace->dobj.
name,
12138 .description =
"SHELL TYPE",
12140 .createStmt = q->
data));
12175 if (funcInfo != NULL && !funcInfo->
dobj.
dump)
12181 if (inlineInfo != NULL && !inlineInfo->
dobj.
dump)
12188 if (validatorInfo != NULL && !validatorInfo->
dobj.
dump)
12189 validatorInfo = NULL;
12197 useParams = (funcInfo != NULL &&
12241 "LANGUAGE", qlanname, NULL);
12247 .description =
"PROCEDURAL LANGUAGE",
12249 .createStmt = defqry->
data,
12250 .dropStmt = delqry->
data,
12266 qlanname, NULL, NULL,
12289 if (is_agg && finfo->
nargs == 0)
12316 for (
j = 0;
j < finfo->
nargs;
j++)
12344 char *funcfullsig = NULL;
12346 char *qual_funcsig;
12359 char *proleakproof;
12366 char **configitems = NULL;
12367 int nconfigitems = 0;
12368 const char *keyword;
12383 "PREPARE dumpFunc(pg_catalog.oid) AS\n");
12397 "pg_catalog.pg_get_function_arguments(p.oid) AS funcargs,\n"
12398 "pg_catalog.pg_get_function_identity_arguments(p.oid) AS funciargs,\n"
12399 "pg_catalog.pg_get_function_result(p.oid) AS funcresult,\n"
12400 "proleakproof,\n");
12404 "array_to_string(protrftypes, ' ') AS protrftypes,\n");
12407 "NULL AS protrftypes,\n");
12414 "'u' AS proparallel,\n");
12421 "CASE WHEN proiswindow THEN 'w' ELSE 'f' END AS prokind,\n");
12428 "'-' AS prosupport,\n");
12432 "pg_get_function_sqlbody(p.oid) AS prosqlbody\n");
12435 "NULL AS prosqlbody\n");
12438 "FROM pg_catalog.pg_proc p, pg_catalog.pg_language l\n"
12439 "WHERE p.oid = $1 "
12440 "AND l.oid = p.prolang");
12448 "EXECUTE dumpFunc('%u')",
12490 else if (probin[0] !=
'\0')
12494 if (prosrc[0] !=
'\0')
12503 (strchr(prosrc,
'\'') == NULL && strchr(prosrc,
'\\') == NULL))
12521 if (!
parsePGArray(proconfig, &configitems, &nconfigitems))
12522 pg_fatal(
"could not parse %s array",
"proconfig");
12526 configitems = NULL;
12539 if (prokind[0] == PROKIND_PROCEDURE)
12540 keyword =
"PROCEDURE";
12542 keyword =
"FUNCTION";
12545 keyword, qual_funcsig);
12550 funcfullsig ? funcfullsig :
12553 if (prokind[0] == PROKIND_PROCEDURE)
12555 else if (funcresult)
12559 (proretset[0] ==
't') ?
"SETOF " :
"",
12572 for (
i = 0; typeids[
i];
i++)
12581 if (prokind[0] == PROKIND_WINDOW)
12584 if (provolatile[0] != PROVOLATILE_VOLATILE)
12586 if (provolatile[0] == PROVOLATILE_IMMUTABLE)
12588 else if (provolatile[0] == PROVOLATILE_STABLE)
12590 else if (provolatile[0] != PROVOLATILE_VOLATILE)
12591 pg_fatal(
"unrecognized provolatile value for function \"%s\"",
12595 if (proisstrict[0] ==
't')
12598 if (prosecdef[0] ==
't')
12601 if (proleakproof[0] ==
't')
12609 if (strcmp(procost,
"0") != 0)
12611 if (strcmp(lanname,
"internal") == 0 || strcmp(lanname,
"c") == 0)
12614 if (strcmp(procost,
"1") != 0)
12620 if (strcmp(procost,
"100") != 0)
12624 if (proretset[0] ==
't' &&
12625 strcmp(prorows,
"0") != 0 && strcmp(prorows,
"1000") != 0)
12628 if (strcmp(prosupport,
"-") != 0)
12634 if (proparallel[0] != PROPARALLEL_UNSAFE)
12636 if (proparallel[0] == PROPARALLEL_SAFE)
12638 else if (proparallel[0] == PROPARALLEL_RESTRICTED)
12640 else if (proparallel[0] != PROPARALLEL_UNSAFE)
12641 pg_fatal(
"unrecognized proparallel value for function \"%s\"",
12645 for (
int i = 0;
i < nconfigitems;
i++)
12648 char *configitem = configitems[
i];
12651 pos = strchr(configitem,
'=');
12681 for (nameptr = namelist; *nameptr; nameptr++)
12683 if (nameptr != namelist)
12697 "pg_catalog.pg_proc", keyword,
12703 finfo->
dobj.namespace->dobj.
name);
12708 .
namespace = finfo->
dobj.namespace->dobj.
name,
12710 .description = keyword,
12713 .createStmt = q->
data,
12714 .dropStmt = delqry->
data));
12742 free(qual_funcsig);
12759 const char *sourceType;
12760 const char *targetType;
12770 if (funcInfo == NULL)
12771 pg_fatal(
"could not find function definition for function with OID %u",
12783 sourceType, targetType);
12786 sourceType, targetType);
12790 case COERCION_METHOD_BINARY:
12793 case COERCION_METHOD_INOUT:
12796 case COERCION_METHOD_FUNCTION:
12810 pg_log_warning(
"bogus value in pg_cast.castfunc or pg_cast.castmethod field");
12823 sourceType, targetType);
12826 sourceType, targetType);
12830 "CAST", castargs->
data, NULL);
12835 .description =
"CAST",
12837 .createStmt = defqry->
data,
12838 .dropStmt = delqry->
data));
12866 const char *transformType;
12876 if (fromsqlFuncInfo == NULL)
12877 pg_fatal(
"could not find function definition for function with OID %u",
12883 if (tosqlFuncInfo == NULL)
12884 pg_fatal(
"could not find function definition for function with OID %u",
12897 transformType, lanname);
12900 transformType, lanname);
12903 pg_log_warning(
"bogus transform definition, at least one of trffromsql and trftosql should be nonzero");
12907 if (fromsqlFuncInfo)
12947 transformType, lanname);
12950 transformType, lanname);
12954 "TRANSFORM", transformargs->
data, NULL);
12959 .description =
"TRANSFORM",
12961 .createStmt = defqry->
data,
12962 .dropStmt = delqry->
data,
13038 "PREPARE dumpOpr(pg_catalog.oid) AS\n"
13040 "oprcode::pg_catalog.regprocedure, "
13041 "oprleft::pg_catalog.regtype, "
13042 "oprright::pg_catalog.regtype, "
13045 "oprrest::pg_catalog.regprocedure, "
13046 "oprjoin::pg_catalog.regprocedure, "
13047 "oprcanmerge, oprcanhash "
13048 "FROM pg_catalog.pg_operator "
13057 "EXECUTE dumpOpr('%u')",
13085 if (strcmp(oprkind,
"r") == 0)
13086 pg_log_warning(
"postfix operators are not supported anymore (operator \"%s\")",
13104 if (strcmp(oprkind,
"r") == 0 ||
13105 strcmp(oprkind,
"b") == 0)
13113 if (strcmp(oprkind,
"l") == 0 ||
13114 strcmp(oprkind,
"b") == 0)
13136 if (strcmp(oprcanmerge,
"t") == 0)
13139 if (strcmp(oprcanhash,
"t") == 0)
13166 "OPERATOR",
oprid->data,
13167 oprinfo->
dobj.namespace->dobj.
name);
13172 .namespace = oprinfo->
dobj.namespace->dobj.
name,
13174 .description =
"OPERATOR",
13176 .createStmt = q->
data,
13177 .dropStmt = delq->
data));
13211 if (strcmp(proc,
"-") == 0)
13217 for (paren =
name; *paren; paren++)
13219 if (*paren ==
'(' && !inquote)
13225 inquote = !inquote;
13250 if (strcmp(oproid,
"0") == 0)
13254 if (oprInfo == NULL)
13261 return psprintf(
"OPERATOR(%s.%s)",
13282 "SELECT '%u'::pg_catalog.regproc", funcOid);
13325 aminfo->
amtype, qamname);
13339 "ACCESS METHOD", qamname, NULL);
13344 .description =
"ACCESS METHOD",
13346 .createStmt = q->
data,
13347 .dropStmt = delq->
data));
13378 int i_opcfamilyname;
13379 int i_opcfamilynsp;
13381 int i_amopstrategy;
13384 int i_sortfamilynsp;
13387 int i_amproclefttype;
13388 int i_amprocrighttype;
13393 char *opcfamilyname;
13394 char *opcfamilynsp;
13396 char *amopstrategy;
13399 char *sortfamilynsp;
13402 char *amproclefttype;
13403 char *amprocrighttype;
13418 "opckeytype::pg_catalog.regtype, "
13419 "opcdefault, opcfamily, "
13420 "opfname AS opcfamilyname, "
13421 "nspname AS opcfamilynsp, "
13422 "(SELECT amname FROM pg_catalog.pg_am WHERE oid = opcmethod) AS amname "
13423 "FROM pg_catalog.pg_opclass c "
13424 "LEFT JOIN pg_catalog.pg_opfamily f ON f.oid = opcfamily "
13425 "LEFT JOIN pg_catalog.pg_namespace n ON n.oid = opfnamespace "
13426 "WHERE c.oid = '%u'::pg_catalog.oid",
13458 if (strcmp(opcdefault,
"t") == 0)
13463 if (strlen(opcfamilyname) > 0)
13473 if (strcmp(opckeytype,
"-") != 0)
13490 "amopopr::pg_catalog.regoperator, "
13491 "opfname AS sortfamily, "
13492 "nspname AS sortfamilynsp "
13493 "FROM pg_catalog.pg_amop ao JOIN pg_catalog.pg_depend ON "
13494 "(classid = 'pg_catalog.pg_amop'::pg_catalog.regclass AND objid = ao.oid) "
13495 "LEFT JOIN pg_catalog.pg_opfamily f ON f.oid = amopsortfamily "
13496 "LEFT JOIN pg_catalog.pg_namespace n ON n.oid = opfnamespace "
13497 "WHERE refclassid = 'pg_catalog.pg_opclass'::pg_catalog.regclass "
13498 "AND refobjid = '%u'::pg_catalog.oid "
13499 "AND amopfamily = '%s'::pg_catalog.oid "
13500 "ORDER BY amopstrategy",
13513 for (
i = 0;
i < ntups;
i++)
13524 amopstrategy, amopopr);
13526 if (strlen(sortfamily) > 0)
13551 "amproc::pg_catalog.regprocedure, "
13552 "amproclefttype::pg_catalog.regtype, "
13553 "amprocrighttype::pg_catalog.regtype "
13554 "FROM pg_catalog.pg_amproc ap, pg_catalog.pg_depend "
13555 "WHERE refclassid = 'pg_catalog.pg_opclass'::pg_catalog.regclass "
13556 "AND refobjid = '%u'::pg_catalog.oid "
13557 "AND classid = 'pg_catalog.pg_amproc'::pg_catalog.regclass "
13558 "AND objid = ap.oid "
13559 "ORDER BY amprocnum",
13569 i_amprocrighttype =
PQfnumber(
res,
"amprocrighttype");
13571 for (
i = 0;
i < ntups;
i++)
13583 if (*amproclefttype && *amprocrighttype)
13610 "OPERATOR CLASS", nameusing->
data,
13611 opcinfo->
dobj.namespace->dobj.
name);
13616 .namespace = opcinfo->
dobj.namespace->dobj.
name,
13618 .description =
"OPERATOR CLASS",
13620 .createStmt = q->
data,
13621 .dropStmt = delq->
data));
13658 int i_amopstrategy;
13661 int i_sortfamilynsp;
13664 int i_amproclefttype;
13665 int i_amprocrighttype;
13667 char *amopstrategy;
13670 char *sortfamilynsp;
13673 char *amproclefttype;
13674 char *amprocrighttype;
13692 "amopopr::pg_catalog.regoperator, "
13693 "opfname AS sortfamily, "
13694 "nspname AS sortfamilynsp "
13695 "FROM pg_catalog.pg_amop ao JOIN pg_catalog.pg_depend ON "
13696 "(classid = 'pg_catalog.pg_amop'::pg_catalog.regclass AND objid = ao.oid) "
13697 "LEFT JOIN pg_catalog.pg_opfamily f ON f.oid = amopsortfamily "
13698 "LEFT JOIN pg_catalog.pg_namespace n ON n.oid = opfnamespace "
13699 "WHERE refclassid = 'pg_catalog.pg_opfamily'::pg_catalog.regclass "
13700 "AND refobjid = '%u'::pg_catalog.oid "
13701 "AND amopfamily = '%u'::pg_catalog.oid "
13702 "ORDER BY amopstrategy",
13711 "amproc::pg_catalog.regprocedure, "
13712 "amproclefttype::pg_catalog.regtype, "
13713 "amprocrighttype::pg_catalog.regtype "
13714 "FROM pg_catalog.pg_amproc ap, pg_catalog.pg_depend "
13715 "WHERE refclassid = 'pg_catalog.pg_opfamily'::pg_catalog.regclass "
13716 "AND refobjid = '%u'::pg_catalog.oid "
13717 "AND classid = 'pg_catalog.pg_amproc'::pg_catalog.regclass "
13718 "AND objid = ap.oid "
13719 "ORDER BY amprocnum",
13728 "(SELECT amname FROM pg_catalog.pg_am WHERE oid = opfmethod) AS amname "
13729 "FROM pg_catalog.pg_opfamily "
13730 "WHERE oid = '%u'::pg_catalog.oid",
13768 i_amopstrategy =
PQfnumber(res_ops,
"amopstrategy");
13769 i_amopopr =
PQfnumber(res_ops,
"amopopr");
13770 i_sortfamily =
PQfnumber(res_ops,
"sortfamily");
13771 i_sortfamilynsp =
PQfnumber(res_ops,
"sortfamilynsp");
13773 for (
i = 0;
i < ntups;
i++)
13775 amopstrategy =
PQgetvalue(res_ops,
i, i_amopstrategy);
13777 sortfamily =
PQgetvalue(res_ops,
i, i_sortfamily);
13778 sortfamilynsp =
PQgetvalue(res_ops,
i, i_sortfamilynsp);
13784 amopstrategy, amopopr);
13786 if (strlen(sortfamily) > 0)
13801 i_amprocnum =
PQfnumber(res_procs,
"amprocnum");
13802 i_amproc =
PQfnumber(res_procs,
"amproc");
13803 i_amproclefttype =
PQfnumber(res_procs,
"amproclefttype");
13804 i_amprocrighttype =
PQfnumber(res_procs,
"amprocrighttype");
13806 for (
i = 0;
i < ntups;
i++)
13808 amprocnum =
PQgetvalue(res_procs,
i, i_amprocnum);
13810 amproclefttype =
PQgetvalue(res_procs,
i, i_amproclefttype);
13811 amprocrighttype =
PQgetvalue(res_procs,
i, i_amprocrighttype);
13817 amprocnum, amproclefttype, amprocrighttype,
13832 "OPERATOR FAMILY", nameusing->
data,
13833 opfinfo->
dobj.namespace->dobj.
name);
13838 .namespace = opfinfo->
dobj.namespace->dobj.
name,
13840 .description =
"OPERATOR FAMILY",
13842 .createStmt = q->
data,
13843 .dropStmt = delq->
data));
13873 int i_collprovider;
13874 int i_collisdeterministic;
13878 int i_collicurules;
13879 const char *collprovider;
13880 const char *collcollate;
13881 const char *collctype;
13882 const char *colllocale;
13883 const char *collicurules;
13904 "'c' AS collprovider, "
13905 "NULL AS collversion, ");
13909 "collisdeterministic, ");
13912 "true AS collisdeterministic, ");
13919 "colliculocale AS colllocale, ");
13922 "NULL AS colllocale, ");
13929 "NULL AS collicurules, ");
13934 "FROM pg_catalog.pg_collation c "
13935 "WHERE c.oid = '%u'::pg_catalog.oid",
13941 i_collisdeterministic =
PQfnumber(
res,
"collisdeterministic");
13952 collcollate = NULL;
13965 if (collcollate[0] ==
'\0')
13966 collcollate = NULL;
13967 if (collctype[0] ==
'\0')
13979 collicurules = NULL;
13988 if (collprovider[0] ==
'b')
13990 else if (collprovider[0] ==
'c')
13992 else if (collprovider[0] ==
'i')
13994 else if (collprovider[0] ==
'd')
13998 pg_fatal(
"unrecognized collation provider: %s",
14001 if (strcmp(
PQgetvalue(
res, 0, i_collisdeterministic),
"f") == 0)
14004 if (collprovider[0] ==
'd')
14006 if (collcollate || collctype || colllocale || collicurules)
14011 else if (collprovider[0] ==
'b')
14013 if (collcollate || collctype || !colllocale || collicurules)
14020 else if (collprovider[0] ==
'i')
14024 if (collcollate || collctype || !colllocale)
14033 if (!collcollate || !collctype || colllocale ||
14034 strcmp(collcollate, collctype) != 0)
14047 else if (collprovider[0] ==
'c')
14049 if (colllocale || collicurules || !collcollate || !collctype)
14052 if (collcollate && collctype && strcmp(collcollate, collctype) == 0)
14066 pg_fatal(
"unrecognized collation provider: %s", collprovider);
14090 "COLLATION", qcollname,
14091 collinfo->
dobj.namespace->dobj.
name);
14096 .namespace = collinfo->
dobj.namespace->dobj.
name,
14098 .description =
"COLLATION",
14100 .createStmt = q->
data,
14101 .dropStmt = delq->
data));
14130 int i_conforencoding;
14131 int i_contoencoding;
14134 const char *conforencoding;
14135 const char *contoencoding;
14136 const char *conproc;
14151 "pg_catalog.pg_encoding_to_char(conforencoding) AS conforencoding, "
14152 "pg_catalog.pg_encoding_to_char(contoencoding) AS contoencoding, "
14153 "conproc, condefault "
14154 "FROM pg_catalog.pg_conversion c "
14155 "WHERE c.oid = '%u'::pg_catalog.oid",
14174 (condefault) ?
"DEFAULT " :
"",
14184 "CONVERSION", qconvname,
14185 convinfo->
dobj.namespace->dobj.
name);
14190 .namespace = convinfo->
dobj.namespace->dobj.
name,
14192 .description =
"CONVERSION",
14194 .createStmt = q->
data,
14195 .dropStmt = delq->
data));
14229 if (agginfo->aggfn.nargs == 0)
14234 for (
j = 0;
j < agginfo->aggfn.nargs;
j++)
14236 (
j > 0) ?
", " :
"",
14238 agginfo->aggfn.argtypes[
j],
14258 char *aggfullsig = NULL;
14263 const char *aggtransfn;
14264 const char *aggfinalfn;
14265 const char *aggcombinefn;
14266 const char *aggserialfn;
14267 const char *aggdeserialfn;
14268 const char *aggmtransfn;
14269 const char *aggminvtransfn;
14270 const char *aggmfinalfn;
14271 bool aggfinalextra;
14272 bool aggmfinalextra;
14273 char aggfinalmodify;
14274 char aggmfinalmodify;
14275 const char *aggsortop;
14276 char *aggsortconvop;
14278 const char *aggtranstype;
14279 const char *aggtransspace;
14280 const char *aggmtranstype;
14281 const char *aggmtransspace;
14282 const char *agginitval;
14283 const char *aggminitval;
14284 const char *proparallel;
14285 char defaultfinalmodify;
14300 "PREPARE dumpAgg(pg_catalog.oid) AS\n");
14306 "aggtranstype::pg_catalog.regtype,\n"
14309 "pg_catalog.pg_get_function_arguments(p.oid) AS funcargs,\n"
14310 "pg_catalog.pg_get_function_identity_arguments(p.oid) AS funciargs,\n");
14316 "aggminvtransfn,\n"
14318 "aggmtranstype::pg_catalog.regtype,\n"
14320 "aggmfinalextra,\n"
14322 "aggmtransspace,\n"
14326 "'n' AS aggkind,\n"
14327 "'-' AS aggmtransfn,\n"
14328 "'-' AS aggminvtransfn,\n"
14329 "'-' AS aggmfinalfn,\n"
14330 "0 AS aggmtranstype,\n"
14331 "false AS aggfinalextra,\n"
14332 "false AS aggmfinalextra,\n"
14333 "0 AS aggtransspace,\n"
14334 "0 AS aggmtransspace,\n"
14335 "NULL AS aggminitval,\n");
14345 "'-' AS aggcombinefn,\n"
14346 "'-' AS aggserialfn,\n"
14347 "'-' AS aggdeserialfn,\n"
14348 "'u' AS proparallel,\n");
14352 "aggfinalmodify,\n"
14353 "aggmfinalmodify\n");
14356 "'0' AS aggfinalmodify,\n"
14357 "'0' AS aggmfinalmodify\n");
14360 "FROM pg_catalog.pg_aggregate a, pg_catalog.pg_proc p "
14361 "WHERE a.aggfnoid = p.oid "
14370 "EXECUTE dumpAgg('%u')",
14371 agginfo->aggfn.dobj.catId.oid);
14413 defaultfinalmodify = (aggkind == AGGKIND_NORMAL) ? AGGMODIFY_READ_ONLY : AGGMODIFY_READ_WRITE;
14415 if (aggfinalmodify ==
'0')
14416 aggfinalmodify = defaultfinalmodify;
14417 if (aggmfinalmodify ==
'0')
14418 aggmfinalmodify = defaultfinalmodify;
14422 aggtransfn, aggtranstype);
14424 if (strcmp(aggtransspace,
"0") != 0)
14436 if (strcmp(aggfinalfn,
"-") != 0)
14442 if (aggfinalmodify != defaultfinalmodify)
14444 switch (aggfinalmodify)
14446 case AGGMODIFY_READ_ONLY:
14449 case AGGMODIFY_SHAREABLE:
14452 case AGGMODIFY_READ_WRITE:
14456 pg_fatal(
"unrecognized aggfinalmodify value for aggregate \"%s\"",
14457 agginfo->aggfn.dobj.name);
14463 if (strcmp(aggcombinefn,
"-") != 0)
14466 if (strcmp(aggserialfn,
"-") != 0)
14469 if (strcmp(aggdeserialfn,
"-") != 0)
14472 if (strcmp(aggmtransfn,
"-") != 0)
14480 if (strcmp(aggmtransspace,
"0") != 0)
14492 if (strcmp(aggmfinalfn,
"-") != 0)
14496 if (aggmfinalextra)
14498 if (aggmfinalmodify != defaultfinalmodify)
14500 switch (aggmfinalmodify)
14502 case AGGMODIFY_READ_ONLY:
14505 case AGGMODIFY_SHAREABLE:
14508 case AGGMODIFY_READ_WRITE:
14512 pg_fatal(
"unrecognized aggmfinalmodify value for aggregate \"%s\"",
14513 agginfo->aggfn.dobj.name);
14524 free(aggsortconvop);
14527 if (aggkind == AGGKIND_HYPOTHETICAL)
14530 if (proparallel[0] != PROPARALLEL_UNSAFE)
14532 if (proparallel[0] == PROPARALLEL_SAFE)
14534 else if (proparallel[0] == PROPARALLEL_RESTRICTED)
14536 else if (proparallel[0] != PROPARALLEL_UNSAFE)
14537 pg_fatal(
"unrecognized proparallel value for function \"%s\"",
14538 agginfo->aggfn.dobj.name);
14542 fmtId(agginfo->aggfn.dobj.namespace->dobj.name),
14546 fmtId(agginfo->aggfn.dobj.namespace->dobj.name),
14547 aggfullsig ? aggfullsig : aggsig, details->
data);
14551 "AGGREGATE", aggsig,
14552 agginfo->aggfn.dobj.namespace->dobj.name);
14556 agginfo->aggfn.dobj.dumpId,
14558 .
namespace = agginfo->aggfn.dobj.namespace->dobj.name,
14559 .owner = agginfo->aggfn.rolname,
14560 .description =
"AGGREGATE",
14562 .createStmt = q->
data,
14563 .dropStmt = delq->
data));
14568 agginfo->aggfn.dobj.namespace->dobj.name,
14569 agginfo->aggfn.rolname,
14570 agginfo->aggfn.dobj.catId, 0, agginfo->aggfn.dobj.dumpId);
14574 agginfo->aggfn.dobj.namespace->dobj.name,
14575 agginfo->aggfn.rolname,
14576 agginfo->aggfn.dobj.catId, 0, agginfo->aggfn.dobj.dumpId);
14589 "FUNCTION", aggsig, NULL,
14590 agginfo->aggfn.dobj.namespace->dobj.name,
14591 NULL, agginfo->aggfn.rolname, &agginfo->aggfn.dacl);
14646 "TEXT SEARCH PARSER", qprsname,
14647 prsinfo->
dobj.namespace->dobj.
name);
14652 .namespace = prsinfo->
dobj.namespace->dobj.
name,
14653 .description =
"TEXT SEARCH PARSER",
14655 .createStmt = q->
data,
14656 .dropStmt = delq->
data));
14660 dumpComment(fout,
"TEXT SEARCH PARSER", qprsname,
14661 prsinfo->
dobj.namespace->dobj.
name,
"",
14697 "FROM pg_ts_template p, pg_namespace n "
14698 "WHERE p.oid = '%u' AND n.oid = tmplnamespace",
14724 "TEXT SEARCH DICTIONARY", qdictname,
14725 dictinfo->
dobj.namespace->dobj.
name);
14730 .namespace = dictinfo->
dobj.namespace->dobj.
name,
14732 .description =
"TEXT SEARCH DICTIONARY",
14734 .createStmt = q->
data,
14735 .dropStmt = delq->
data));
14739 dumpComment(fout,
"TEXT SEARCH DICTIONARY", qdictname,
14784 "TEXT SEARCH TEMPLATE", qtmplname,
14785 tmplinfo->
dobj.namespace->dobj.
name);
14790 .namespace = tmplinfo->
dobj.namespace->dobj.
name,
14791 .description =
"TEXT SEARCH TEMPLATE",
14793 .createStmt = q->
data,
14794 .dropStmt = delq->
data));
14798 dumpComment(fout,
"TEXT SEARCH TEMPLATE", qtmplname,
14799 tmplinfo->
dobj.namespace->dobj.
name,
"",
14839 "FROM pg_ts_parser p, pg_namespace n "
14840 "WHERE p.oid = '%u' AND n.oid = prsnamespace",
14857 " ( SELECT alias FROM pg_catalog.ts_token_type('%u'::pg_catalog.oid) AS t\n"
14858 " WHERE t.tokid = m.maptokentype ) AS tokenname,\n"
14859 " m.mapdict::pg_catalog.regdictionary AS dictname\n"
14860 "FROM pg_catalog.pg_ts_config_map AS m\n"
14861 "WHERE m.mapcfg = '%u'\n"
14862 "ORDER BY m.mapcfg, m.maptokentype, m.mapseqno",
14871 for (
i = 0;
i < ntups;
i++)
14886 fmtId(tokenname), dictname);
14902 "TEXT SEARCH CONFIGURATION", qcfgname,
14903 cfginfo->
dobj.namespace->dobj.
name);
14908 .namespace = cfginfo->
dobj.namespace->dobj.
name,
14910 .description =
"TEXT SEARCH CONFIGURATION",
14912 .createStmt = q->
data,
14913 .dropStmt = delq->
data));
14917 dumpComment(fout,
"TEXT SEARCH CONFIGURATION", qcfgname,
14967 "FOREIGN DATA WRAPPER", qfdwname,
14974 .description =
"FOREIGN DATA WRAPPER",
14976 .createStmt = q->
data,
14977 .dropStmt = delq->
data));
14981 dumpComment(fout,
"FOREIGN DATA WRAPPER", qfdwname,
14988 "FOREIGN DATA WRAPPER", qfdwname, NULL, NULL,
15024 "FROM pg_foreign_data_wrapper w "
15025 "WHERE w.oid = '%u'",
15055 "SERVER", qsrvname, NULL);
15061 .description =
"SERVER",
15063 .createStmt = q->
data,
15064 .dropStmt = delq->
data));
15075 "FOREIGN SERVER", qsrvname, NULL, NULL,
15103 const char *servername,
const char *
namespace,
15132 "array_to_string(ARRAY("
15133 "SELECT quote_ident(option_name) || ' ' || "
15134 "quote_literal(option_value) "
15135 "FROM pg_options_to_table(umoptions) "
15136 "ORDER BY option_name"
15137 "), E',\n ') AS umoptions "
15138 "FROM pg_user_mappings "
15139 "WHERE srvid = '%u' "
15140 "ORDER BY usename",
15149 for (
i = 0;
i < ntups;
i++)
15161 if (umoptions && strlen(umoptions) > 0)
15172 usename, servername);
15176 .namespace =
namespace,
15178 .description =
"USER MAPPING",
15180 .createStmt = q->
data,
15181 .dropStmt = delq->
data));
15212 case DEFACLOBJ_RELATION:
15215 case DEFACLOBJ_SEQUENCE:
15216 type =
"SEQUENCES";
15218 case DEFACLOBJ_FUNCTION:
15219 type =
"FUNCTIONS";
15221 case DEFACLOBJ_TYPE:
15224 case DEFACLOBJ_NAMESPACE:
15229 pg_fatal(
"unrecognized object type in default privileges: %d",
15238 daclinfo->
dobj.namespace != NULL ?
15239 daclinfo->
dobj.namespace->dobj.
name : NULL,
15245 pg_fatal(
"could not parse default ACL list (%s)",
15251 .namespace = daclinfo->
dobj.namespace ?
15252 daclinfo->
dobj.namespace->dobj.
name : NULL,
15254 .description =
"DEFAULT ACL",
15256 .createStmt = q->
data));
15287 const char *nspname,
const char *tag,
const char *owner,
15292 const char *acls = dacl->
acl;
15295 const char *initprivs = dacl->
initprivs;
15296 const char *baseacls;
15304 if (dopt->
dataOnly && strcmp(
type,
"LARGE OBJECT") != 0)
15323 initprivs && *initprivs !=
'\0')
15329 pg_fatal(
"could not parse initial ACL list (%s) or default (%s) for object \"%s\" (%s)",
15331 appendPQExpBufferStr(sql,
"SELECT pg_catalog.binary_upgrade_set_record_init_privs(false);\n");
15342 if (initprivs && *initprivs !=
'\0')
15344 baseacls = initprivs;
15345 if (acls == NULL || *acls ==
'\0')
15352 acls, baseacls, owner,
15354 pg_fatal(
"could not parse ACL list (%s) or default (%s) for object \"%s\" (%s)",
15370 aclDeps[nDeps++] = objDumpId;
15372 aclDeps[nDeps++] = altDumpId;
15378 .namespace = nspname,
15380 .description =
"ACL",
15382 .createStmt = sql->
data,
15414 const char *
namespace,
const char *owner,
15431 if (strcmp(
type,
"LARGE OBJECT") != 0)
15448 for (
i = 0;
i < nlabels;
i++)
15453 if (labels[
i].objsubid != subid)
15457 "SECURITY LABEL FOR %s ON %s ",
15459 if (
namespace && *
namespace)
15466 if (query->
len > 0)
15473 .namespace =
namespace,
15475 .description =
"SECURITY LABEL",
15477 .createStmt = query->
data,
15522 for (
i = 0;
i < nlabels;
i++)
15524 const char *colname;
15548 if (query->
len > 0)
15555 .namespace = tbinfo->
dobj.namespace->dobj.
name,
15557 .description =
"SECURITY LABEL",
15559 .createStmt = query->
data,
15593 while (low <= high)
15595 middle = low + (high - low) / 2;
15597 if (classoid < middle->classoid)
15599 else if (classoid > middle->
classoid)
15601 else if (objoid < middle->objoid)
15603 else if (objoid > middle->
objoid)
15621 while (middle > low)
15623 if (classoid != middle[-1].classoid ||
15624 objoid != middle[-1].objoid)
15633 while (middle <= high)
15635 if (classoid != middle->
classoid ||
15636 objoid != middle->
objoid)
15670 "SELECT label, provider, classoid, objoid, objsubid "
15671 "FROM pg_catalog.pg_seclabel "
15672 "ORDER BY classoid, objoid, objsubid");
15689 for (
i = 0;
i < ntups;
i++)
15699 if (dobj == NULL ||
15712 ((
TableInfo *) dobj)->relkind == RELKIND_COMPOSITE_TYPE)
15752 if (tbinfo->
relkind == RELKIND_SEQUENCE)
15762 const char *objtype =
15763 (tbinfo->
relkind == RELKIND_SEQUENCE) ?
"SEQUENCE" :
"TABLE";
15767 objtype, namecopy, NULL,
15768 tbinfo->
dobj.namespace->dobj.
name,
15788 "PREPARE getColumnACLs(pg_catalog.oid) AS\n");
15803 "SELECT at.attname, "
15805 "'{}' AS acldefault, "
15806 "pip.privtype, pip.initprivs "
15807 "FROM pg_catalog.pg_attribute at "
15808 "LEFT JOIN pg_catalog.pg_init_privs pip ON "
15809 "(at.attrelid = pip.objoid "
15810 "AND pip.classoid = 'pg_catalog.pg_class'::pg_catalog.regclass "
15811 "AND at.attnum = pip.objsubid) "
15812 "WHERE at.attrelid = $1 AND "
15813 "NOT at.attisdropped "
15814 "AND (at.attacl IS NOT NULL OR pip.initprivs IS NOT NULL) "
15815 "ORDER BY at.attnum");
15820 "SELECT attname, attacl, '{}' AS acldefault, "
15821 "NULL AS privtype, NULL AS initprivs "
15822 "FROM pg_catalog.pg_attribute "
15823 "WHERE attrelid = $1 AND NOT attisdropped "
15824 "AND attacl IS NOT NULL "
15825 "ORDER BY attnum");
15834 "EXECUTE getColumnACLs('%u')",
15849 coldacl.
acl = attacl;
15861 "TABLE", namecopy, attnamecopy,
15862 tbinfo->
dobj.namespace->dobj.
name,
15863 NULL, tbinfo->
rolname, &coldacl);
15889 "SELECT pg_catalog.pg_get_viewdef('%u'::pg_catalog.oid) AS viewdef",
15897 pg_fatal(
"query to obtain definition of view \"%s\" returned no data",
15900 pg_fatal(
"query to obtain definition of view \"%s\" returned more than one definition",
15907 pg_fatal(
"definition of view \"%s\" appears to be empty (length zero)",
15979 const char *reltypename;
15991 pg_log_warning(
"WITH OIDS is not supported anymore (table \"%s\")",
15998 if (tbinfo->
relkind == RELKIND_VIEW)
16006 reltypename =
"VIEW";
16037 char *partkeydef = NULL;
16038 char *ftoptions = NULL;
16039 char *srvname = NULL;
16040 char *foreign =
"";
16048 case RELKIND_PARTITIONED_TABLE:
16053 reltypename =
"TABLE";
16057 "SELECT pg_get_partkeydef('%u')",
16065 case RELKIND_FOREIGN_TABLE:
16072 reltypename =
"FOREIGN TABLE";
16076 "SELECT fs.srvname, "
16077 "pg_catalog.array_to_string(ARRAY("
16078 "SELECT pg_catalog.quote_ident(option_name) || "
16079 "' ' || pg_catalog.quote_literal(option_value) "
16080 "FROM pg_catalog.pg_options_to_table(ftoptions) "
16081 "ORDER BY option_name"
16082 "), E',\n ') AS ftoptions "
16083 "FROM pg_catalog.pg_foreign_table ft "
16084 "JOIN pg_catalog.pg_foreign_server fs "
16085 "ON (fs.oid = ft.ftserver) "
16086 "WHERE ft.ftrelid = '%u'",
16096 foreign =
"FOREIGN ";
16099 case RELKIND_MATVIEW:
16100 reltypename =
"MATERIALIZED VIEW";
16103 reltypename =
"TABLE";
16131 if (tbinfo->
relkind != RELKIND_MATVIEW)
16145 bool print_default;
16146 bool print_notnull;
16152 print_default = (tbinfo->
attrdefs[
j] != NULL &&
16171 !print_default && !print_notnull &&
16176 if (actual_atts == 0)
16262 if (actual_atts == 0)
16293 for (k = 0; k < numParents; k++)
16304 if (tbinfo->
relkind == RELKIND_PARTITIONED_TABLE)
16307 if (tbinfo->
relkind == RELKIND_FOREIGN_TABLE)
16314 bool addcomma =
false;
16333 if (ftoptions && ftoptions[0])
16340 if (tbinfo->
relkind == RELKIND_MATVIEW)
16353 if (tbinfo->
relkind == RELKIND_MATVIEW)
16355 "pg_catalog.pg_class",
16356 "MATERIALIZED VIEW",
16371 "SELECT pg_catalog.binary_upgrade_set_missing_value(");
16404 (tbinfo->
relkind == RELKIND_RELATION ||
16405 tbinfo->
relkind == RELKIND_FOREIGN_TABLE ||
16406 tbinfo->
relkind == RELKIND_PARTITIONED_TABLE))
16414 "SET attlen = %d, "
16415 "attalign = '%c', attbyval = false\n"
16416 "WHERE attname = ",
16424 if (tbinfo->
relkind == RELKIND_RELATION ||
16425 tbinfo->
relkind == RELKIND_PARTITIONED_TABLE)
16438 "SET attislocal = false\n"
16439 "WHERE attname = ");
16455 "SET conislocal = false\n"
16456 "WHERE contype = 'n' AND conrelid = ");
16472 for (k = 0; k < tbinfo->
ncheck; k++)
16481 foreign, qualrelname,
16485 "SET conislocal = false\n"
16486 "WHERE contype = 'c' AND conname = ");
16496 for (k = 0; k < numParents; k++)
16524 (tbinfo->
relkind == RELKIND_RELATION ||
16525 tbinfo->
relkind == RELKIND_MATVIEW))
16529 "SET relfrozenxid = '%u', relminmxid = '%u'\n"
16541 appendPQExpBufferStr(q,
"\n-- For binary upgrade, set toast's relfrozenxid and relminmxid\n");
16543 "SET relfrozenxid = '%u', relminmxid = '%u'\n"
16544 "WHERE oid = '%u';\n",
16562 "SET relispopulated = 't'\n"
16590 "ALTER %sTABLE ONLY %s ALTER COLUMN %s SET NOT NULL;\n",
16591 foreign, qualrelname,
16595 "ALTER %sTABLE ONLY %s ADD CONSTRAINT %s NOT NULL %s;\n",
16596 foreign, qualrelname,
16607 appendPQExpBuffer(q,
"ALTER %sTABLE ONLY %s ALTER COLUMN %s SET STATISTICS %d;\n",
16608 foreign, qualrelname,
16620 case TYPSTORAGE_PLAIN:
16623 case TYPSTORAGE_EXTERNAL:
16626 case TYPSTORAGE_EXTENDED:
16629 case TYPSTORAGE_MAIN:
16640 appendPQExpBuffer(q,
"ALTER %sTABLE ONLY %s ALTER COLUMN %s SET STORAGE %s;\n",
16641 foreign, qualrelname,
16651 const char *cmname;
16666 if (cmname != NULL)
16667 appendPQExpBuffer(q,
"ALTER %sTABLE ONLY %s ALTER COLUMN %s SET COMPRESSION %s;\n",
16668 foreign, qualrelname,
16678 foreign, qualrelname,
16685 if (tbinfo->
relkind == RELKIND_FOREIGN_TABLE &&
16688 "ALTER FOREIGN TABLE %s ALTER COLUMN %s OPTIONS (\n"
16704 if ((tbinfo->
relkind == RELKIND_RELATION ||
16705 tbinfo->
relkind == RELKIND_PARTITIONED_TABLE ||
16706 tbinfo->
relkind == RELKIND_MATVIEW) &&
16713 else if (tbinfo->
relreplident == REPLICA_IDENTITY_NOTHING)
16718 else if (tbinfo->
relreplident == REPLICA_IDENTITY_FULL)
16731 reltypename, qrelname,
16732 tbinfo->
dobj.namespace->dobj.
name);
16737 char *tableam = NULL;
16746 if (RELKIND_HAS_TABLESPACE(tbinfo->
relkind))
16749 if (RELKIND_HAS_TABLE_AM(tbinfo->
relkind) ||
16750 tbinfo->
relkind == RELKIND_PARTITIONED_TABLE)
16751 tableam = tbinfo->
amname;
16755 .namespace = tbinfo->
dobj.namespace->dobj.
name,
16757 .tableam = tableam,
16760 .description = reltypename,
16763 .createStmt = q->
data,
16764 .dropStmt = delq->
data));
16826 "PREPARE dumpTableAttach(pg_catalog.oid) AS\n");
16829 "SELECT pg_get_expr(c.relpartbound, c.oid) "
16831 "WHERE c.oid = $1");
16839 "EXECUTE dumpTableAttach('%u')",
16847 "ALTER TABLE ONLY %s ",
16850 "ATTACH PARTITION %s %s;\n",
16863 .namespace = attachinfo->
dobj.namespace->dobj.
name,
16865 .description =
"TABLE ATTACH",
16867 .createStmt = q->
data));
16881 int adnum = adinfo->
adnum;
16901 foreign = tbinfo->
relkind == RELKIND_FOREIGN_TABLE ?
"FOREIGN " :
"";
16904 "ALTER %sTABLE ONLY %s ALTER COLUMN %s SET DEFAULT %s;\n",
16909 foreign, qualrelname,
16917 .
namespace = tbinfo->
dobj.namespace->dobj.
name,
16919 .description =
"DEFAULT",
16921 .createStmt = q->
data,
16922 .dropStmt = delq->
data));
16937 static const char *
16940 if (attrnum > 0 && attrnum <= tblInfo->numatts)
16941 return tblInfo->
attnames[attrnum - 1];
16957 pg_fatal(
"invalid column number %d for table \"%s\"",
16994 if (!is_constraint)
16998 char **indstatcolsarray = NULL;
16999 char **indstatvalsarray = NULL;
17030 if (strlen(indstatcols) != 0 || strlen(indstatvals) != 0)
17034 if (!
parsePGArray(indstatcols, &indstatcolsarray, &nstatcols))
17035 pg_fatal(
"could not parse index statistic columns");
17036 if (!
parsePGArray(indstatvals, &indstatvalsarray, &nstatvals))
17037 pg_fatal(
"could not parse index statistic values");
17038 if (nstatcols != nstatvals)
17039 pg_fatal(
"mismatched number of columns and values for index statistics");
17041 for (
j = 0;
j < nstatcols;
j++)
17050 indstatcolsarray[
j]);
17052 indstatvalsarray[
j]);
17058 "pg_catalog.pg_class",
17059 "INDEX", qqindxname);
17076 .namespace = tbinfo->
dobj.namespace->dobj.
name,
17079 .description =
"INDEX",
17081 .createStmt = q->
data,
17082 .dropStmt = delq->
data));
17084 free(indstatcolsarray);
17085 free(indstatvalsarray);
17091 tbinfo->
dobj.namespace->dobj.
name,
17132 .namespace = attachinfo->
dobj.namespace->dobj.
name,
17134 .description =
"INDEX ATTACH",
17136 .createStmt = q->
data));
17153 char *qstatsextname;
17168 "pg_catalog.pg_get_statisticsobjdef('%u'::pg_catalog.oid)",
17197 .namespace = statsextinfo->
dobj.namespace->dobj.
name,
17198 .owner = statsextinfo->
rolname,
17199 .description =
"STATISTICS",
17201 .createStmt = q->
data,
17202 .dropStmt = delq->
data));
17207 statsextinfo->
dobj.namespace->dobj.
name,
17216 free(qstatsextname);
17240 foreign = tbinfo &&
17241 tbinfo->
relkind == RELKIND_FOREIGN_TABLE ?
"FOREIGN " :
"";
17243 if (coninfo->
contype ==
'p' ||
17253 if (indxinfo == NULL)
17254 pg_fatal(
"missing index for constraint \"%s\"",
17274 coninfo->
contype ==
'p' ?
"PRIMARY KEY" :
"UNIQUE");
17287 int indkey = (int) indxinfo->
indkeys[k];
17295 (k == 0) ?
"" :
", ",
17304 for (k = indxinfo->
indnkeyattrs; k < indxinfo->indnattrs; k++)
17306 int indkey = (int) indxinfo->
indkeys[k];
17378 "pg_catalog.pg_class",
"INDEX",
17391 .
namespace = tbinfo->
dobj.namespace->dobj.
name,
17394 .description =
"CONSTRAINT",
17396 .createStmt = q->
data,
17397 .dropStmt = delq->
data));
17399 else if (coninfo->
contype ==
'f')
17409 only = tbinfo->
relkind == RELKIND_PARTITIONED_TABLE ?
"" :
"ONLY ";
17431 .
namespace = tbinfo->
dobj.namespace->dobj.
name,
17433 .description =
"FK CONSTRAINT",
17435 .createStmt = q->
data,
17436 .dropStmt = delq->
data));
17438 else if (coninfo->
contype ==
'c' && tbinfo)
17462 .
namespace = tbinfo->
dobj.namespace->dobj.
name,
17464 .description =
"CHECK CONSTRAINT",
17466 .createStmt = q->
data,
17467 .dropStmt = delq->
data));
17470 else if (coninfo->
contype ==
'c' && tbinfo == NULL)
17494 .
namespace = tyinfo->
dobj.namespace->dobj.
name,
17496 .description =
"CHECK CONSTRAINT",
17498 .createStmt = q->
data,
17499 .dropStmt = delq->
data));
17504 pg_fatal(
"unrecognized constraint type: %c",
17509 if (tbinfo && coninfo->
separate &&
17539 tbinfo->
dobj.namespace->dobj.
name,
17565 int64 default_minv,
17579 "SELECT format_type(seqtypid, NULL), "
17580 "seqstart, seqincrement, "
17582 "seqcache, seqcycle "
17583 "FROM pg_catalog.pg_sequence "
17584 "WHERE seqrelid = '%u'::oid",
17596 "SELECT 'bigint' AS sequence_type, "
17597 "start_value, increment_by, max_value, min_value, "
17598 "cache_value, is_cycled FROM %s",
17605 pg_fatal(
ngettext(
"query to get data of sequence \"%s\" returned %d row (expected 1)",
17606 "query to get data of sequence \"%s\" returned %d rows (expected 1)",
17619 is_ascending = (incby[0] !=
'-');
17620 if (strcmp(seqtype,
"smallint") == 0)
17625 else if (strcmp(seqtype,
"integer") == 0)
17630 else if (strcmp(seqtype,
"bigint") == 0)
17637 pg_fatal(
"unrecognized sequence type: %s", seqtype);
17638 default_minv = default_maxv = 0;
17649 if (strcmp(minv, bufm) == 0)
17651 if (strcmp(maxv, bufx) == 0)
17684 "ALTER COLUMN %s ADD GENERATED ",
17696 "CREATE %sSEQUENCE %s\n",
17701 if (strcmp(seqtype,
"bigint") != 0)
17721 cache, (cycled ?
"\n CYCLE" :
""));
17728 "ALTER SEQUENCE %s SET %s;\n",
17731 "UNLOGGED" :
"LOGGED");
17740 "SEQUENCE", qseqname,
17741 tbinfo->
dobj.namespace->dobj.
name);
17746 .namespace = tbinfo->
dobj.namespace->dobj.
name,
17748 .description =
"SEQUENCE",
17750 .createStmt = query->
data,
17751 .dropStmt = delqry->
data));
17769 if (owning_tab == NULL)
17770 pg_fatal(
"failed sanity check, parent table with OID %u of sequence with OID %u not found",
17786 .namespace = tbinfo->
dobj.namespace->dobj.
name,
17788 .description =
"SEQUENCE OWNED BY",
17790 .createStmt = query->
data,
17828 "SELECT last_value, is_called FROM %s",
17834 pg_fatal(
ngettext(
"query to get data of sequence \"%s\" returned %d row (expected 1)",
17835 "query to get data of sequence \"%s\" returned %d rows (expected 1)",
17846 last, (called ?
"true" :
"false"));
17851 .namespace = tbinfo->
dobj.namespace->dobj.
name,
17853 .description =
"SEQUENCE SET",
17855 .createStmt = query->
data,
17899 "pg_catalog.pg_trigger",
"TRIGGER",
17900 trigidentity->
data);
17915 tbinfo->
relkind == RELKIND_FOREIGN_TABLE ?
"FOREIGN " :
"",
17940 tbinfo->
relkind == RELKIND_FOREIGN_TABLE ?
"FOREIGN " :
"",
17970 .
namespace = tbinfo->
dobj.namespace->dobj.
name,
17972 .description =
"TRIGGER",
17974 .createStmt = query->
data,
17975 .dropStmt = delqry->
data));
18016 if (strcmp(
"", evtinfo->
evttags) != 0)
18054 "EVENT TRIGGER", qevtname, NULL);
18060 .description =
"EVENT TRIGGER",
18062 .createStmt = query->
data,
18063 .dropStmt = delqry->
data));
18145 "SELECT pg_catalog.pg_get_ruledef('%u'::pg_catalog.oid)",
18151 pg_fatal(
"query to get rule \"%s\" for table \"%s\" failed: wrong number of rows returned",
18214 .
namespace = tbinfo->
dobj.namespace->dobj.
name,
18216 .description =
"RULE",
18218 .createStmt = cmd->
data,
18219 .dropStmt = delcmd->
data));
18224 tbinfo->
dobj.namespace->dobj.
name,
18260 if (numExtensions == 0)
18267 "classid, objid, refobjid "
18269 "WHERE refclassid = 'pg_extension'::regclass "
18270 "AND deptype = 'e' "
18288 for (
i = 0;
i < ntups;
i++)
18304 pg_log_warning(
"could not find referenced extension %u", extId);
18352 if (numExtensions == 0)
18366 for (
i = 0;
i < numExtensions;
i++)
18371 char **extconfigarray = NULL;
18372 char **extconditionarray = NULL;
18373 int nconfigitems = 0;
18374 int nconditionitems = 0;
18394 if (strlen(extconfig) != 0 || strlen(extcondition) != 0)
18398 if (!
parsePGArray(extconfig, &extconfigarray, &nconfigitems))
18399 pg_fatal(
"could not parse %s array",
"extconfig");
18400 if (!
parsePGArray(extcondition, &extconditionarray, &nconditionitems))
18401 pg_fatal(
"could not parse %s array",
"extcondition");
18402 if (nconfigitems != nconditionitems)
18403 pg_fatal(
"mismatched number of configurations and conditions for extension");
18405 for (
j = 0;
j < nconfigitems;
j++)
18408 Oid configtbloid =
atooid(extconfigarray[
j]);
18413 if (configtbl == NULL)
18429 if (configtbl->
dobj.namespace->dobj.
dump &
18448 if (configtbl->
dataObj != NULL)
18450 if (strlen(extconditionarray[
j]) > 0)
18456 if (extconfigarray)
18457 free(extconfigarray);
18458 if (extconditionarray)
18459 free(extconditionarray);
18474 "SELECT conrelid, confrelid "
18475 "FROM pg_constraint "
18476 "JOIN pg_depend ON (objid = confrelid) "
18477 "WHERE contype = 'f' "
18478 "AND refclassid = 'pg_extension'::regclass "
18479 "AND classid = 'pg_class'::regclass;");
18488 for (
i = 0;
i < ntups;
i++)
18500 if (reftable == NULL ||
18502 contable == NULL ||
18548 "classid, objid, refclassid, refobjid, deptype "
18550 "WHERE deptype != 'p' AND deptype != 'e'\n");
18563 "SELECT 'pg_opfamily'::regclass AS classid, amopfamily AS objid, refclassid, refobjid, deptype "
18564 "FROM pg_depend d, pg_amop o "
18565 "WHERE deptype NOT IN ('p', 'e', 'i') AND "
18566 "classid = 'pg_amop'::regclass AND objid = o.oid "
18567 "AND NOT (refclassid = 'pg_opfamily'::regclass AND amopfamily = refobjid)\n");
18571 "SELECT 'pg_opfamily'::regclass AS classid, amprocfamily AS objid, refclassid, refobjid, deptype "
18572 "FROM pg_depend d, pg_amproc p "
18573 "WHERE deptype NOT IN ('p', 'e', 'i') AND "
18574 "classid = 'pg_amproc'::regclass AND objid = p.oid "
18575 "AND NOT (refclassid = 'pg_opfamily'::regclass AND amprocfamily = refobjid)\n");
18597 for (
i = 0;
i < ntups;
i++)
18609 if (dobj == NULL ||
18629 if (refdobj == NULL)
18644 if (deptype ==
'x')
18654 if (deptype ==
'i' &&
18705 for (
i = 0;
i < numObjs;
i++)
18769 if (((
RuleInfo *) dobj)->separate)
18838 if (dobj->
nDeps <= 0)
18846 &dependencies, &nDeps, &allocDeps);
18851 nDeps *
sizeof(
DumpId));
18856 free(dependencies);
18863 DumpId **dependencies,
int *nDeps,
int *allocDeps)
18882 if (*nDeps >= *allocDeps)
18886 *allocDeps *
sizeof(
DumpId));
18888 (*dependencies)[*nDeps] = depid;
18902 dependencies, nDeps, allocDeps);
18917 static const char *
18935 if (typeInfo && typeInfo->
ftypname)
18939 appendPQExpBuffer(query,
"SELECT pg_catalog.format_type('%u'::pg_catalog.oid, NULL)",
18968 static const char *
18980 for (
i = 0;
i < numatts;
i++)
18982 if (attisdropped[
i])
18984 if (attgenerated[
i])
18996 return buffer->
data;
19006 return (reloptions != NULL && strlen(reloptions) > 2);
19016 const char *prefix,
Archive *fout)
Acl * acldefault(ObjectType objtype, Oid ownerId)
#define InvalidAttrNumber
int lo_read(int fd, char *buf, int len)
void recordAdditionalCatalogID(CatalogId catId, DumpableObject *dobj)
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 Assert(condition)
#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
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 DumpId dumpACL(Archive *fout, DumpId objDumpId, DumpId altDumpId, const char *type, const char *name, const char *subname, const char *nspname, const char *tag, const char *owner, const DumpableAcl *dacl)
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 SimpleOidList extension_exclude_oids
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)
#define MAX_BLOBS_PER_ARCHIVE_ENTRY
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
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 SimpleStringList extension_exclude_patterns
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
Oid looids[FLEXIBLE_ARRAY_MEMBER]
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)