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_proc_d.h"
54 #include "catalog/pg_type_d.h"
121 "array length mismatch");
214 #define DUMP_DEFAULT_ROWS_PER_INSERT 1
221 #define MAX_BLOBS_PER_ARCHIVE_ENTRY 1000
226 #define fmtQualifiedDumpable(obj) \
227 fmtQualifiedId((obj)->dobj.namespace->dobj.name, \
232 const char *dumpencoding,
const char *dumpsnapshot,
250 bool with_child_tables);
252 const char *pattern);
257 static const char *
getRoleName(
const char *roleoid_str);
261 const char *
name,
const char *
namespace,
264 const char *initdb_comment);
266 const char *
name,
const char *
namespace,
268 int subid,
DumpId dumpId);
272 const char *
namespace,
const char *owner,
322 const char *servername,
const char *
namespace,
328 const char *nspname,
const char *tag,
const char *owner,
334 DumpId **dependencies,
int *nDeps,
int *allocDeps);
348 int i_notnull_name,
int i_notnull_noinherit,
349 int i_notnull_islocal);
353 const FuncInfo *finfo,
bool honor_quotes);
375 bool force_array_type,
376 bool include_multirange_type);
388 const char *objnamespace);
393 const char *prefix,
Archive *fout);
417 bool g_verbose =
false;
418 const char *dumpencoding = NULL;
419 const char *dumpsnapshot = NULL;
420 char *use_role = NULL;
426 char *compression_detail = NULL;
427 char *compression_algorithm_str =
"none";
428 char *error_detail = NULL;
429 bool user_compression_defined =
false;
434 static struct option long_options[] = {
447 {
"jobs", 1, NULL,
'j'},
526 if (strcmp(argv[1],
"--help") == 0 || strcmp(argv[1],
"-?") == 0)
531 if (strcmp(argv[1],
"--version") == 0 || strcmp(argv[1],
"-V") == 0)
533 puts(
"pg_dump (PostgreSQL) " PG_VERSION);
540 while ((
c =
getopt_long(argc, argv,
"abBcCd:e:E:f:F:h:j:n:N:Op:RsS:t:T:U:vwWxZ:",
541 long_options, &optindex)) != -1)
658 &compression_detail);
659 user_compression_defined =
true;
765 pg_log_error(
"too many command-line arguments (first is \"%s\")",
784 pg_fatal(
"options -s/--schema-only and -a/--data-only cannot be used together");
787 pg_fatal(
"options -s/--schema-only and --include-foreign-data cannot be used together");
790 pg_fatal(
"option --include-foreign-data is not supported with parallel backup");
793 pg_fatal(
"options -c/--clean and -a/--data-only cannot be used together");
796 pg_fatal(
"option --if-exists requires option -c/--clean");
803 pg_fatal(
"option --on-conflict-do-nothing requires option --inserts, --rows-per-insert, or --column-inserts");
818 !user_compression_defined)
821 compression_algorithm_str =
"gzip";
823 compression_algorithm_str =
"none";
832 pg_fatal(
"unrecognized compression algorithm: \"%s\"",
833 compression_algorithm_str);
838 if (error_detail != NULL)
839 pg_fatal(
"invalid compression specification: %s",
843 if (error_detail != NULL)
852 pg_log_warning(
"compression option \"%s\" is not currently supported by pg_dump",
864 pg_fatal(
"parallel backup only supported by the directory format");
919 pg_fatal(
"no matching schemas were found");
936 pg_fatal(
"no matching tables were found");
964 pg_fatal(
"no matching extensions were found");
1003 getTableData(&dopt, tblinfo, numTables, RELKIND_SEQUENCE);
1059 boundaryObjs[0].dumpId, boundaryObjs[1].dumpId);
1078 for (
i = 0;
i < numObjs;
i++)
1155 printf(
_(
"%s dumps a database as a text file or to other formats.\n\n"),
progname);
1159 printf(
_(
"\nGeneral options:\n"));
1160 printf(
_(
" -f, --file=FILENAME output file or directory name\n"));
1161 printf(
_(
" -F, --format=c|d|t|p output file format (custom, directory, tar,\n"
1162 " plain text (default))\n"));
1163 printf(
_(
" -j, --jobs=NUM use this many parallel jobs to dump\n"));
1164 printf(
_(
" -v, --verbose verbose mode\n"));
1165 printf(
_(
" -V, --version output version information, then exit\n"));
1166 printf(
_(
" -Z, --compress=METHOD[:DETAIL]\n"
1167 " compress as specified\n"));
1168 printf(
_(
" --lock-wait-timeout=TIMEOUT fail after waiting TIMEOUT for a table lock\n"));
1169 printf(
_(
" --no-sync do not wait for changes to be written safely to disk\n"));
1170 printf(
_(
" --sync-method=METHOD set method for syncing files to disk\n"));
1171 printf(
_(
" -?, --help show this help, then exit\n"));
1173 printf(
_(
"\nOptions controlling the output content:\n"));
1174 printf(
_(
" -a, --data-only dump only the data, not the schema\n"));
1175 printf(
_(
" -b, --large-objects include large objects in dump\n"));
1176 printf(
_(
" --blobs (same as --large-objects, deprecated)\n"));
1177 printf(
_(
" -B, --no-large-objects exclude large objects in dump\n"));
1178 printf(
_(
" --no-blobs (same as --no-large-objects, deprecated)\n"));
1179 printf(
_(
" -c, --clean clean (drop) database objects before recreating\n"));
1180 printf(
_(
" -C, --create include commands to create database in dump\n"));
1181 printf(
_(
" -e, --extension=PATTERN dump the specified extension(s) only\n"));
1182 printf(
_(
" -E, --encoding=ENCODING dump the data in encoding ENCODING\n"));
1183 printf(
_(
" -n, --schema=PATTERN dump the specified schema(s) only\n"));
1184 printf(
_(
" -N, --exclude-schema=PATTERN do NOT dump the specified schema(s)\n"));
1185 printf(
_(
" -O, --no-owner skip restoration of object ownership in\n"
1186 " plain-text format\n"));
1187 printf(
_(
" -s, --schema-only dump only the schema, no data\n"));
1188 printf(
_(
" -S, --superuser=NAME superuser user name to use in plain-text format\n"));
1189 printf(
_(
" -t, --table=PATTERN dump only the specified table(s)\n"));
1190 printf(
_(
" -T, --exclude-table=PATTERN do NOT dump the specified table(s)\n"));
1191 printf(
_(
" -x, --no-privileges do not dump privileges (grant/revoke)\n"));
1192 printf(
_(
" --binary-upgrade for use by upgrade utilities only\n"));
1193 printf(
_(
" --column-inserts dump data as INSERT commands with column names\n"));
1194 printf(
_(
" --disable-dollar-quoting disable dollar quoting, use SQL standard quoting\n"));
1195 printf(
_(
" --disable-triggers disable triggers during data-only restore\n"));
1196 printf(
_(
" --enable-row-security enable row security (dump only content user has\n"
1198 printf(
_(
" --exclude-extension=PATTERN do NOT dump the specified extension(s)\n"));
1199 printf(
_(
" --exclude-table-and-children=PATTERN\n"
1200 " do NOT dump the specified table(s), including\n"
1201 " child and partition tables\n"));
1202 printf(
_(
" --exclude-table-data=PATTERN do NOT dump data for the specified table(s)\n"));
1203 printf(
_(
" --exclude-table-data-and-children=PATTERN\n"
1204 " do NOT dump data for the specified table(s),\n"
1205 " including child and partition tables\n"));
1206 printf(
_(
" --extra-float-digits=NUM override default setting for extra_float_digits\n"));
1207 printf(
_(
" --filter=FILENAME include or exclude objects and data from dump\n"
1208 " based on expressions in FILENAME\n"));
1209 printf(
_(
" --if-exists use IF EXISTS when dropping objects\n"));
1210 printf(
_(
" --include-foreign-data=PATTERN\n"
1211 " include data of foreign tables on foreign\n"
1212 " servers matching PATTERN\n"));
1213 printf(
_(
" --inserts dump data as INSERT commands, rather than COPY\n"));
1214 printf(
_(
" --load-via-partition-root load partitions via the root table\n"));
1215 printf(
_(
" --no-comments do not dump comment commands\n"));
1216 printf(
_(
" --no-publications do not dump publications\n"));
1217 printf(
_(
" --no-security-labels do not dump security label assignments\n"));
1218 printf(
_(
" --no-subscriptions do not dump subscriptions\n"));
1219 printf(
_(
" --no-table-access-method do not dump table access methods\n"));
1220 printf(
_(
" --no-tablespaces do not dump tablespace assignments\n"));
1221 printf(
_(
" --no-toast-compression do not dump TOAST compression methods\n"));
1222 printf(
_(
" --no-unlogged-table-data do not dump unlogged table data\n"));
1223 printf(
_(
" --on-conflict-do-nothing add ON CONFLICT DO NOTHING to INSERT commands\n"));
1224 printf(
_(
" --quote-all-identifiers quote all identifiers, even if not key words\n"));
1225 printf(
_(
" --rows-per-insert=NROWS number of rows per INSERT; implies --inserts\n"));
1226 printf(
_(
" --section=SECTION dump named section (pre-data, data, or post-data)\n"));
1227 printf(
_(
" --serializable-deferrable wait until the dump can run without anomalies\n"));
1228 printf(
_(
" --snapshot=SNAPSHOT use given snapshot for the dump\n"));
1229 printf(
_(
" --strict-names require table and/or schema include patterns to\n"
1230 " match at least one entity each\n"));
1231 printf(
_(
" --table-and-children=PATTERN dump only the specified table(s), including\n"
1232 " child and partition tables\n"));
1233 printf(
_(
" --use-set-session-authorization\n"
1234 " use SET SESSION AUTHORIZATION commands instead of\n"
1235 " ALTER OWNER commands to set ownership\n"));
1237 printf(
_(
"\nConnection options:\n"));
1238 printf(
_(
" -d, --dbname=DBNAME database to dump\n"));
1239 printf(
_(
" -h, --host=HOSTNAME database server host or socket directory\n"));
1240 printf(
_(
" -p, --port=PORT database server port number\n"));
1241 printf(
_(
" -U, --username=NAME connect as specified database user\n"));
1242 printf(
_(
" -w, --no-password never prompt for password\n"));
1243 printf(
_(
" -W, --password force password prompt (should happen automatically)\n"));
1244 printf(
_(
" --role=ROLENAME do SET ROLE before dump\n"));
1246 printf(
_(
"\nIf no database name is supplied, then the PGDATABASE environment\n"
1247 "variable value is used.\n\n"));
1248 printf(
_(
"Report bugs to <%s>.\n"), PACKAGE_BUGREPORT);
1249 printf(
_(
"%s home page: <%s>\n"), PACKAGE_NAME, PACKAGE_URL);
1254 const char *dumpsnapshot,
char *use_role)
1258 const char *std_strings;
1268 pg_fatal(
"invalid client encoding \"%s\" specified",
1279 AH->
std_strings = (std_strings && strcmp(std_strings,
"on") == 0);
1388 "SET TRANSACTION ISOLATION LEVEL "
1389 "SERIALIZABLE, READ ONLY, DEFERRABLE");
1392 "SET TRANSACTION ISOLATION LEVEL "
1393 "REPEATABLE READ, READ ONLY");
1415 pg_fatal(
"parallel dumps from standby servers are not supported by this server version");
1439 char *query =
"SELECT pg_catalog.pg_export_snapshot()";
1481 return archiveFormat;
1499 if (patterns->
head == NULL)
1509 for (cell = patterns->
head; cell; cell = cell->
next)
1515 "SELECT oid FROM pg_catalog.pg_namespace n\n");
1518 false, NULL,
"n.nspname", NULL, NULL, &dbbuf,
1521 pg_fatal(
"improper qualified name (too many dotted names): %s",
1523 else if (dotcnt == 1)
1529 pg_fatal(
"no matching schemas were found for pattern \"%s\"", cell->
val);
1558 if (patterns->
head == NULL)
1567 for (cell = patterns->
head; cell; cell = cell->
next)
1572 "SELECT oid FROM pg_catalog.pg_extension e\n");
1574 false, NULL,
"e.extname", NULL, NULL, NULL,
1577 pg_fatal(
"improper qualified name (too many dotted names): %s",
1582 pg_fatal(
"no matching extensions were found for pattern \"%s\"", cell->
val);
1610 if (patterns->
head == NULL)
1620 for (cell = patterns->
head; cell; cell = cell->
next)
1625 "SELECT oid FROM pg_catalog.pg_foreign_server s\n");
1627 false, NULL,
"s.srvname", NULL, NULL, NULL,
1630 pg_fatal(
"improper qualified name (too many dotted names): %s",
1635 pg_fatal(
"no matching foreign servers were found for pattern \"%s\"", cell->
val);
1662 if (patterns->
head == NULL)
1672 for (cell = patterns->
head; cell; cell = cell->
next)
1685 if (with_child_tables)
1692 "\nFROM pg_catalog.pg_class c"
1693 "\n LEFT JOIN pg_catalog.pg_namespace n"
1694 "\n ON n.oid OPERATOR(pg_catalog.=) c.relnamespace"
1695 "\nWHERE c.relkind OPERATOR(pg_catalog.=) ANY"
1696 "\n (array['%c', '%c', '%c', '%c', '%c', '%c'])\n",
1697 RELKIND_RELATION, RELKIND_SEQUENCE, RELKIND_VIEW,
1698 RELKIND_MATVIEW, RELKIND_FOREIGN_TABLE,
1699 RELKIND_PARTITIONED_TABLE);
1702 false,
"n.nspname",
"c.relname", NULL,
1703 "pg_catalog.pg_table_is_visible(c.oid)", &dbbuf,
1706 pg_fatal(
"improper relation name (too many dotted names): %s",
1708 else if (dotcnt == 2)
1712 if (with_child_tables)
1715 "\nSELECT i.inhrelid"
1716 "\nFROM partition_tree p"
1717 "\n JOIN pg_catalog.pg_inherits i"
1718 "\n ON p.relid OPERATOR(pg_catalog.=) i.inhparent"
1720 "\nSELECT relid FROM partition_tree");
1728 pg_fatal(
"no matching tables were found for pattern \"%s\"", cell->
val);
1755 pg_fatal(
"You are currently not connected to a database.");
1757 if (strcmp(db,
dbname) != 0)
1758 pg_fatal(
"cross-database references are not implemented: %s",
1846 strcmp(nsinfo->
dobj.
name,
"pg_catalog") == 0)
1855 else if (strncmp(nsinfo->
dobj.
name,
"pg_", 3) == 0 ||
1856 strcmp(nsinfo->
dobj.
name,
"information_schema") == 0)
1861 else if (strcmp(nsinfo->
dobj.
name,
"public") == 0)
1873 if (nsinfo->
nspowner == ROLE_PG_DATABASE_OWNER)
1953 tyinfo->
typrelkind != RELKIND_COMPOSITE_TYPE)
1958 if (tytable != NULL)
1998 if (dinfo->
dobj.namespace)
2186 if (dobj->namespace)
2203 const char *classname = tbinfo->
dobj.
name;
2215 const char *column_list;
2217 pg_log_info(
"dumping contents of table \"%s.%s\"",
2218 tbinfo->
dobj.namespace->dobj.
name, classname);
2236 if (tbinfo->
relkind == RELKIND_FOREIGN_TABLE)
2241 if (strlen(column_list) > 2)
2327 pg_log_error(
"Dumping the contents of table \"%s\" failed: PQgetCopyData() failed.", classname);
2337 pg_log_error(
"Dumping the contents of table \"%s\" failed: PQgetResult() failed.", classname);
2346 pg_log_warning(
"unexpected extra results during COPY of table \"%s\"",
2352 if (tbinfo->
relkind == RELKIND_FOREIGN_TABLE)
2379 int rows_this_statement = 0;
2382 if (tbinfo->
relkind == RELKIND_FOREIGN_TABLE)
2428 pg_fatal(
"wrong number of fields retrieved from table \"%s\"",
2438 if (insertStmt == NULL)
2470 for (
int field = 0; field < nfields; field++)
2490 if (rows_this_statement == 0)
2506 if (rows_per_statement == 1)
2508 else if (rows_this_statement > 0)
2513 for (
int field = 0; field < nfields; field++)
2517 if (attgenerated[field])
2552 if (strspn(s,
"0123456789 +-eE.") == strlen(s))
2587 if (++rows_this_statement >= rows_per_statement)
2590 archputs(
" ON CONFLICT DO NOTHING;\n", fout);
2594 rows_this_statement = 0;
2607 if (rows_this_statement > 0)
2610 archputs(
" ON CONFLICT DO NOTHING;\n", fout);
2620 if (insertStmt != NULL)
2625 if (tbinfo->
relkind == RELKIND_FOREIGN_TABLE)
2643 parentTbinfo = tbinfo->
parents[0];
2647 parentTbinfo = parentTbinfo->
parents[0];
2650 return parentTbinfo;
2668 parentTbinfo = tbinfo->
parents[0];
2674 parentTbinfo = parentTbinfo->
parents[0];
2696 char *tdDefn = NULL;
2698 const char *copyFrom;
2733 copyStmt = copyBuf->
data;
2753 .namespace = tbinfo->
dobj.namespace->dobj.
name,
2755 .description =
"TABLE DATA",
2757 .createStmt = tdDefn,
2758 .copyStmt = copyStmt,
2762 .dumpArg = tdinfo));
2820 .namespace = tbinfo->
dobj.namespace->dobj.
name,
2822 .description =
"MATERIALIZED VIEW DATA",
2824 .createStmt = q->
data,
2840 for (
i = 0;
i < numTables;
i++)
2843 (!relkind || tblinfo[
i].
relkind == relkind))
2867 if (tbinfo->
relkind == RELKIND_VIEW)
2870 if (tbinfo->
relkind == RELKIND_FOREIGN_TABLE &&
2876 if (tbinfo->
relkind == RELKIND_PARTITIONED_TABLE)
2892 if (tbinfo->
relkind == RELKIND_MATVIEW)
2894 else if (tbinfo->
relkind == RELKIND_SEQUENCE)
2907 tdinfo->
dobj.namespace = tbinfo->
dobj.namespace;
2947 "SELECT d1.objid, d2.refobjid, c2.relkind AS refrelkind "
2948 "FROM pg_depend d1 "
2949 "JOIN pg_class c1 ON c1.oid = d1.objid "
2951 " JOIN pg_rewrite r1 ON r1.ev_class = d1.objid "
2952 "JOIN pg_depend d2 ON d2.classid = 'pg_rewrite'::regclass "
2953 "AND d2.objid = r1.oid "
2954 "AND d2.refobjid <> d1.objid "
2955 "JOIN pg_class c2 ON c2.oid = d2.refobjid "
2956 "AND c2.relkind IN (" CppAsString2(RELKIND_MATVIEW)
","
2958 "WHERE d1.classid = 'pg_class'::regclass "
2960 "SELECT w.objid, d3.refobjid, c3.relkind "
2962 "JOIN pg_rewrite r3 ON r3.ev_class = w.refobjid "
2963 "JOIN pg_depend d3 ON d3.classid = 'pg_rewrite'::regclass "
2964 "AND d3.objid = r3.oid "
2965 "AND d3.refobjid <> w.refobjid "
2966 "JOIN pg_class c3 ON c3.oid = d3.refobjid "
2967 "AND c3.relkind IN (" CppAsString2(RELKIND_MATVIEW)
","
2970 "SELECT 'pg_class'::regclass::oid AS classid, objid, refobjid "
2982 for (
i = 0;
i < ntups;
i++)
3009 if (refdobj == NULL)
3016 if (refdobj == NULL)
3052 for (
i = 0;
i < numObjs;
i++)
3064 if (ftable == NULL ||
3137 "pg_encoding_to_char(encoding) AS encoding, "
3138 "datcollate, datctype, datfrozenxid, "
3139 "datacl, acldefault('d', datdba) AS acldefault, "
3140 "datistemplate, datconnlimit, ");
3150 appendPQExpBufferStr(dbQry,
"'c' AS datlocprovider, NULL AS datlocale, NULL AS datcollversion, ");
3156 "(SELECT spcname FROM pg_tablespace t WHERE t.oid = dattablespace) AS tablespace, "
3157 "shobj_description(oid, 'pg_database') AS description "
3159 "WHERE datname = current_database()");
3222 "CREATE DATABASE %s WITH TEMPLATE = template0 "
3223 "OID = %u STRATEGY = FILE_COPY",
3224 qdatname, dbCatId.
oid);
3245 pg_fatal(
"unrecognized locale provider: %s",
3248 if (strlen(collate) > 0 && strcmp(collate, ctype) == 0)
3255 if (strlen(collate) > 0)
3260 if (strlen(ctype) > 0)
3323 .createStmt = creaQry->
data,
3324 .dropStmt = delQry->
data));
3353 .description =
"COMMENT",
3355 .createStmt = dbQry->
data,
3373 if (seclabelQry->
len > 0)
3377 .description =
"SECURITY LABEL",
3379 .createStmt = seclabelQry->
data,
3394 qdatname, NULL, NULL,
3395 NULL, dba, &dbdacl);
3425 "SET datistemplate = false WHERE datname = ");
3446 "SET datfrozenxid = '%u', datminmxid = '%u'\n"
3448 frozenxid, minmxid);
3453 if (creaQry->
len > 0)
3459 .createStmt = creaQry->
data,
3460 .dropStmt = delQry->
data,
3461 .deps = &dbDumpId));
3473 int ii_relfrozenxid,
3482 appendPQExpBuffer(loFrozenQry,
"SELECT relfrozenxid, relminmxid, relfilenode, oid\n"
3483 "FROM pg_catalog.pg_class\n"
3484 "WHERE oid IN (%u, %u);\n",
3485 LargeObjectRelationId, LargeObjectLOidPNIndexId);
3487 appendPQExpBuffer(loFrozenQry,
"SELECT relfrozenxid, 0 AS relminmxid, relfilenode, oid\n"
3488 "FROM pg_catalog.pg_class\n"
3489 "WHERE oid IN (%u, %u);\n",
3490 LargeObjectRelationId, LargeObjectLOidPNIndexId);
3494 ii_relfrozenxid =
PQfnumber(lo_res,
"relfrozenxid");
3495 ii_relminmxid =
PQfnumber(lo_res,
"relminmxid");
3496 ii_relfilenode =
PQfnumber(lo_res,
"relfilenode");
3499 appendPQExpBufferStr(loHorizonQry,
"\n-- For binary upgrade, set pg_largeobject relfrozenxid and relminmxid\n");
3500 appendPQExpBufferStr(loOutQry,
"\n-- For binary upgrade, preserve pg_largeobject and index relfilenodes\n");
3507 "SET relfrozenxid = '%u', relminmxid = '%u'\n"
3508 "WHERE oid = %u;\n",
3516 if (oid == LargeObjectRelationId)
3518 "SELECT pg_catalog.binary_upgrade_set_next_heap_relfilenode('%u'::pg_catalog.oid);\n",
3520 else if (oid == LargeObjectLOidPNIndexId)
3522 "SELECT pg_catalog.binary_upgrade_set_next_index_relfilenode('%u'::pg_catalog.oid);\n",
3527 "TRUNCATE pg_catalog.pg_largeobject;\n");
3534 .createStmt = loOutQry->
data));
3566 "WHERE setrole = 0 AND setdatabase = '%u'::oid",
3573 "DATABASE",
dbname, NULL, NULL,
3580 "FROM pg_db_role_setting s, pg_roles r "
3581 "WHERE setrole = r.oid AND setdatabase = '%u'::oid",
3616 .createStmt = qry->
data));
3628 const char *stdstrings = AH->
std_strings ?
"on" :
"off";
3631 pg_log_info(
"saving \"standard_conforming_strings = %s\"",
3641 .createStmt = qry->
data));
3655 char **schemanames = NULL;
3656 int nschemanames = 0;
3667 "SELECT pg_catalog.current_schemas(false)");
3670 pg_fatal(
"could not parse result of current_schemas()");
3678 for (
i = 0;
i < nschemanames;
i++)
3695 .createStmt = qry->
data));
3732 "SELECT oid, lomowner, lomacl, "
3733 "acldefault('L', lomowner) AS acldefault "
3734 "FROM pg_largeobject_metadata "
3735 "ORDER BY lomowner, lomacl::pg_catalog.text, oid");
3754 for (
i = 0;
i < ntups;
i += n)
3767 if (strcmp(thisowner,
PQgetvalue(
res,
i + n, i_lomowner)) != 0 ||
3782 snprintf(namebuf,
sizeof(namebuf),
"%u..%u", thisoid,
3785 snprintf(namebuf,
sizeof(namebuf),
"%u", thisoid);
3793 loinfo->
looids[0] = thisoid;
3795 for (
int k = 1; k < n; k++)
3802 extraID.
tableoid = LargeObjectRelationId;
3858 for (
int i = 0;
i < loinfo->
numlos;
i++)
3865 .description =
"BLOB METADATA",
3867 .createStmt = cquery->
data,
3868 .dropStmt =
"-- dummy"));
3877 for (
int i = 0;
i < loinfo->
numlos;
i++)
3917 snprintf(tagbuf,
sizeof(tagbuf),
"LARGE OBJECTS %u..%u",
3921 "LARGE OBJECT", namebuf, NULL, NULL,
3927 "LARGE OBJECT", namebuf, NULL, NULL,
3948 for (
int i = 0;
i < loinfo->
numlos;
i++)
3957 pg_fatal(
"could not open large object %u: %s",
3967 pg_fatal(
"error reading large object %u: %s",
3997 int i_polpermissive;
4016 for (
i = 0;
i < numTables;
i++)
4025 if (tbinfo->
relkind != RELKIND_RELATION &&
4026 tbinfo->
relkind != RELKIND_PARTITIONED_TABLE)
4030 if (tbloids->
len > 1)
4051 polinfo->
dobj.namespace = tbinfo->
dobj.namespace;
4070 pg_log_info(
"reading row-level security policies");
4073 "SELECT pol.oid, pol.tableoid, pol.polrelid, pol.polname, pol.polcmd, ");
4079 "CASE WHEN pol.polroles = '{0}' THEN NULL ELSE "
4080 " 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, "
4081 "pg_catalog.pg_get_expr(pol.polqual, pol.polrelid) AS polqual, "
4082 "pg_catalog.pg_get_expr(pol.polwithcheck, pol.polrelid) AS polwithcheck "
4083 "FROM unnest('%s'::pg_catalog.oid[]) AS src(tbloid)\n"
4084 "JOIN pg_catalog.pg_policy pol ON (src.tbloid = pol.polrelid)",
4104 for (
j = 0;
j < ntups;
j++)
4116 polinfo[
j].
dobj.namespace = tbinfo->
dobj.namespace;
4125 polinfo[
j].polroles = NULL;
4188 .namespace = polinfo->
dobj.namespace->dobj.
name,
4190 .description =
"ROW SECURITY",
4192 .createStmt = query->
data,
4200 if (polinfo->
polcmd ==
'*')
4202 else if (polinfo->
polcmd ==
'r')
4203 cmd =
" FOR SELECT";
4204 else if (polinfo->
polcmd ==
'a')
4205 cmd =
" FOR INSERT";
4206 else if (polinfo->
polcmd ==
'w')
4207 cmd =
" FOR UPDATE";
4208 else if (polinfo->
polcmd ==
'd')
4209 cmd =
" FOR DELETE";
4211 pg_fatal(
"unexpected policy command type: %c",
4247 .
namespace = polinfo->
dobj.namespace->dobj.
name,
4249 .description =
"POLICY",
4251 .createStmt = query->
data,
4252 .dropStmt = delqry->
data));
4298 "p.pubowner, p.puballtables, p.pubinsert, "
4299 "p.pubupdate, p.pubdelete, ");
4339 for (
i = 0;
i < ntups;
i++)
4452 .description =
"PUBLICATION",
4454 .createStmt = query->
data,
4455 .dropStmt = delq->
data));
4498 "SELECT tableoid, oid, pnpubid, pnnspid "
4499 "FROM pg_catalog.pg_publication_namespace");
4513 for (
i = 0;
i < ntups;
i++)
4525 if (pubinfo == NULL)
4528 if (nspinfo == NULL)
4544 pubsinfo[
j].
dobj.namespace = nspinfo->
dobj.namespace;
4588 "SELECT tableoid, oid, prpubid, prrelid, "
4589 "pg_catalog.pg_get_expr(prqual, prrelid) AS prrelqual, "
4591 " WHEN pr.prattrs IS NOT NULL THEN\n"
4592 " (SELECT array_agg(attname)\n"
4594 " pg_catalog.generate_series(0, pg_catalog.array_upper(pr.prattrs::pg_catalog.int2[], 1)) s,\n"
4595 " pg_catalog.pg_attribute\n"
4596 " WHERE attrelid = pr.prrelid AND attnum = prattrs[s])\n"
4597 " ELSE NULL END) prattrs "
4598 "FROM pg_catalog.pg_publication_rel pr");
4601 "SELECT tableoid, oid, prpubid, prrelid, "
4602 "NULL AS prrelqual, NULL AS prattrs "
4603 "FROM pg_catalog.pg_publication_rel");
4619 for (
i = 0;
i < ntups;
i++)
4631 if (pubinfo == NULL)
4646 pubrinfo[
j].dobj.catId.tableoid =
4650 pubrinfo[
j].dobj.namespace = tbinfo->
dobj.namespace;
4651 pubrinfo[
j].dobj.name = tbinfo->
dobj.
name;
4652 pubrinfo[
j].publication = pubinfo;
4653 pubrinfo[
j].pubtable = tbinfo;
4655 pubrinfo[
j].pubrelqual = NULL;
4666 &attnames, &nattnames))
4667 pg_fatal(
"could not parse %s array",
"prattrs");
4669 for (
int k = 0; k < nattnames; k++)
4676 pubrinfo[
j].pubrattrs = attribs->
data;
4679 pubrinfo[
j].pubrattrs = NULL;
4722 .
namespace = schemainfo->
dobj.
name,
4724 .description =
"PUBLICATION TABLES IN SCHEMA",
4726 .createStmt = query->
data));
4760 if (pubrinfo->pubrattrs)
4763 if (pubrinfo->pubrelqual)
4782 ArchiveEntry(fout, pubrinfo->dobj.catId, pubrinfo->dobj.dumpId,
4784 .
namespace = tbinfo->
dobj.namespace->dobj.
name,
4786 .description =
"PUBLICATION TABLE",
4788 .createStmt = query->
data));
4807 if (
val && strcmp(
val,
"on") == 0)
4825 "SELECT set_config(name, '%s', false) "
4827 "WHERE name = 'restrict_nonsystem_relation_kind'",
4852 int i_subtwophasestate;
4853 int i_subdisableonerr;
4854 int i_subpasswordrequired;
4855 int i_subrunasowner;
4858 int i_subsynccommit;
4859 int i_subpublications;
4861 int i_suboriginremotelsn;
4875 "SELECT count(*) FROM pg_subscription "
4876 "WHERE subdbid = (SELECT oid FROM pg_database"
4877 " WHERE datname = current_database())",
4881 pg_log_warning(
"subscriptions not dumped because current user is not a superuser");
4890 "SELECT s.tableoid, s.oid, s.subname,\n"
4892 " s.subconninfo, s.subslotname, s.subsynccommit,\n"
4893 " s.subpublications,\n");
4907 " s.subtwophasestate,\n"
4908 " s.subdisableonerr,\n");
4911 " '%c' AS subtwophasestate,\n"
4912 " false AS subdisableonerr,\n",
4917 " s.subpasswordrequired,\n"
4918 " s.subrunasowner,\n"
4922 " 't' AS subpasswordrequired,\n"
4923 " 't' AS subrunasowner,\n"
4924 " '%s' AS suborigin,\n",
4929 " s.subenabled,\n");
4932 " false AS subenabled,\n");
4936 " s.subfailover\n");
4939 " false AS subfailover\n");
4942 "FROM pg_subscription s\n");
4946 "LEFT JOIN pg_catalog.pg_replication_origin_status o \n"
4947 " ON o.external_id = 'pg_' || s.oid::text \n");
4950 "WHERE s.subdbid = (SELECT oid FROM pg_database\n"
4951 " WHERE datname = current_database())");
4967 i_subtwophasestate =
PQfnumber(
res,
"subtwophasestate");
4969 i_subpasswordrequired =
PQfnumber(
res,
"subpasswordrequired");
4976 i_suboriginremotelsn =
PQfnumber(
res,
"suboriginremotelsn");
4982 for (
i = 0;
i < ntups;
i++)
5058 "SELECT srsubid, srrelid, srsubstate, srsublsn "
5059 "FROM pg_catalog.pg_subscription_rel "
5073 for (
int i = 0;
i < ntups;
i++)
5083 if (cur_srsubid != last_srsubid)
5086 if (subinfo == NULL)
5087 pg_fatal(
"subscription with OID %u does not exist", cur_srsubid);
5089 last_srsubid = cur_srsubid;
5093 if (tblinfo == NULL)
5094 pg_fatal(
"failed sanity check, table with OID %u not found",
5151 "\n-- For binary upgrade, must preserve the subscriber table.\n");
5153 "SELECT pg_catalog.binary_upgrade_add_sub_rel_state(");
5180 .description =
"SUBSCRIPTION TABLE",
5182 .createStmt = query->
data));
5202 char **pubnames = NULL;
5225 pg_fatal(
"could not parse %s array",
"subpublications");
5228 for (
i = 0;
i < npubnames;
i++)
5236 appendPQExpBuffer(query,
" PUBLICATION %s WITH (connect = false, slot_name = ", publications->
data);
5242 if (strcmp(subinfo->
subbinary,
"t") == 0)
5245 if (strcmp(subinfo->
substream,
"t") == 0)
5247 else if (strcmp(subinfo->
substream,
"p") == 0)
5293 "\n-- For binary upgrade, must preserve the remote_lsn for the subscriber's replication origin.\n");
5295 "SELECT pg_catalog.binary_upgrade_replorigin_advance(");
5307 "\n-- For binary upgrade, must preserve the subscriber's running state.\n");
5316 .description =
"SUBSCRIPTION",
5318 .createStmt = query->
data,
5319 .dropStmt = delq->
data));
5347 const char *catalog,
5348 const char *keyword,
5349 const char *objname)
5366 "FROM pg_catalog.pg_depend d, pg_catalog.pg_extension e "
5367 "WHERE d.refobjid = e.oid AND classid = '%s'::pg_catalog.regclass "
5368 "AND objid = '%u'::pg_catalog.oid AND deptype = 'x' "
5369 "AND refclassid = 'pg_catalog.pg_extension'::pg_catalog.regclass",
5375 for (
i = 0;
i < ntups;
i++)
5405 ++next_possible_free_oid;
5407 "SELECT EXISTS(SELECT 1 "
5408 "FROM pg_catalog.pg_type "
5409 "WHERE oid = '%u'::pg_catalog.oid);",
5410 next_possible_free_oid);
5416 return next_possible_free_oid;
5423 bool force_array_type,
5424 bool include_multirange_type)
5428 Oid pg_type_array_oid;
5429 Oid pg_type_multirange_oid;
5430 Oid pg_type_multirange_array_oid;
5435 "SELECT pg_catalog.binary_upgrade_set_next_pg_type_oid('%u'::pg_catalog.oid);\n\n",
5440 pg_type_array_oid =
tinfo->typarray;
5444 if (!
OidIsValid(pg_type_array_oid) && force_array_type)
5450 "\n-- For binary upgrade, must preserve pg_type array oid\n");
5452 "SELECT pg_catalog.binary_upgrade_set_next_array_pg_type_oid('%u'::pg_catalog.oid);\n\n",
5459 if (include_multirange_type)
5464 "SELECT t.oid, t.typarray "
5465 "FROM pg_catalog.pg_type t "
5466 "JOIN pg_catalog.pg_range r "
5467 "ON t.oid = r.rngmultitypid "
5468 "WHERE r.rngtypid = '%u'::pg_catalog.oid;",
5485 "\n-- For binary upgrade, must preserve multirange pg_type oid\n");
5487 "SELECT pg_catalog.binary_upgrade_set_next_multirange_pg_type_oid('%u'::pg_catalog.oid);\n\n",
5488 pg_type_multirange_oid);
5490 "\n-- For binary upgrade, must preserve multirange pg_type array oid\n");
5492 "SELECT pg_catalog.binary_upgrade_set_next_multirange_array_pg_type_oid('%u'::pg_catalog.oid);\n\n",
5493 pg_type_multirange_array_oid);
5508 pg_type_oid,
false,
false);
5536 query =
"SELECT c.oid, c.relkind, c.relfilenode, c.reltoastrelid, "
5537 "ct.relfilenode, i.indexrelid, cti.relfilenode "
5538 "FROM pg_catalog.pg_class c LEFT JOIN pg_catalog.pg_index i "
5539 "ON (c.reltoastrelid = i.indrelid AND i.indisvalid) "
5540 "LEFT JOIN pg_catalog.pg_class ct ON (c.reltoastrelid = ct.oid) "
5541 "LEFT JOIN pg_catalog.pg_class AS cti ON (i.indexrelid = cti.oid) "
5584 key.oid = pg_class_oid;
5590 "\n-- For binary upgrade, must preserve pg_class oids and relfilenodes\n");
5592 if (entry->
relkind != RELKIND_INDEX &&
5593 entry->
relkind != RELKIND_PARTITIONED_INDEX)
5596 "SELECT pg_catalog.binary_upgrade_set_next_heap_pg_class_oid('%u'::pg_catalog.oid);\n",
5605 entry->
relkind != RELKIND_PARTITIONED_TABLE)
5607 "SELECT pg_catalog.binary_upgrade_set_next_heap_relfilenode('%u'::pg_catalog.oid);\n",
5615 entry->
relkind != RELKIND_PARTITIONED_TABLE)
5618 "SELECT pg_catalog.binary_upgrade_set_next_toast_pg_class_oid('%u'::pg_catalog.oid);\n",
5621 "SELECT pg_catalog.binary_upgrade_set_next_toast_relfilenode('%u'::pg_catalog.oid);\n",
5626 "SELECT pg_catalog.binary_upgrade_set_next_index_pg_class_oid('%u'::pg_catalog.oid);\n",
5629 "SELECT pg_catalog.binary_upgrade_set_next_index_relfilenode('%u'::pg_catalog.oid);\n",
5637 "SELECT pg_catalog.binary_upgrade_set_next_index_pg_class_oid('%u'::pg_catalog.oid);\n",
5640 "SELECT pg_catalog.binary_upgrade_set_next_index_relfilenode('%u'::pg_catalog.oid);\n",
5657 const char *objtype,
5658 const char *objname,
5659 const char *objnamespace)
5681 pg_fatal(
"could not find parent extension for %s %s",
5685 "\n-- For binary upgrade, handle extension membership the hard way\n");
5689 if (objnamespace && *objnamespace)
5722 "acldefault('n', n.nspowner) AS acldefault "
5723 "FROM pg_namespace n");
5738 for (
i = 0;
i < ntups;
i++)
5740 const char *nspowner;
5778 if (strcmp(nsinfo[
i].dobj.name,
"public") == 0)
5819 pg_fatal(
"schema with OID %u does not exist", nsoid);
5843 int i_extrelocatable;
5851 "x.extname, n.nspname, x.extrelocatable, x.extversion, x.extconfig, x.extcondition "
5852 "FROM pg_extension x "
5853 "JOIN pg_namespace n ON n.oid = x.extnamespace");
5872 for (
i = 0;
i < ntups;
i++)
5893 *numExtensions = ntups;
5945 "typnamespace, typacl, "
5946 "acldefault('T', typowner) AS acldefault, "
5948 "typelem, typrelid, typarray, "
5949 "CASE WHEN typrelid = 0 THEN ' '::\"char\" "
5950 "ELSE (SELECT relkind FROM pg_class WHERE oid = typrelid) END AS typrelkind, "
5951 "typtype, typisdefined, "
5952 "typname[0] = '_' AND typelem != 0 AND "
5953 "(SELECT typarray FROM pg_type te WHERE oid = pg_type.typelem) = oid AS isarray "
5977 for (
i = 0;
i < ntups;
i++)
5984 tyinfo[
i].
dobj.namespace =
6010 if (tyinfo[
i].typtype == TYPTYPE_MULTIRANGE)
6028 tyinfo[
i].
typtype == TYPTYPE_DOMAIN)
6042 (tyinfo[
i].
typtype == TYPTYPE_BASE ||
6043 tyinfo[
i].
typtype == TYPTYPE_RANGE))
6050 stinfo->
dobj.namespace = tyinfo[
i].
dobj.namespace;
6097 "oprcode::oid AS oprcode "
6098 "FROM pg_operator");
6114 for (
i = 0;
i < ntups;
i++)
6121 oprinfo[
i].
dobj.namespace =
6151 int i_collnamespace;
6164 "FROM pg_collation");
6178 for (
i = 0;
i < ntups;
i++)
6185 collinfo[
i].
dobj.namespace =
6226 "FROM pg_conversion");
6240 for (
i = 0;
i < ntups;
i++)
6247 convinfo[
i].
dobj.namespace =
6286 "amhandler::pg_catalog.regproc AS amhandler "
6301 for (
i = 0;
i < ntups;
i++)
6308 aminfo[
i].
dobj.namespace = NULL;
6362 for (
i = 0;
i < ntups;
i++)
6369 opcinfo[
i].
dobj.namespace =
6410 "FROM pg_opfamily");
6424 for (
i = 0;
i < ntups;
i++)
6431 opfinfo[
i].
dobj.namespace =
6473 const char *agg_check;
6475 agg_check = (fout->
remoteVersion >= 110000 ?
"p.prokind = 'a'"
6479 "p.proname AS aggname, "
6480 "p.pronamespace AS aggnamespace, "
6481 "p.pronargs, p.proargtypes, "
6483 "p.proacl AS aggacl, "
6484 "acldefault('f', p.proowner) AS acldefault "
6486 "LEFT JOIN pg_init_privs pip ON "
6487 "(p.oid = pip.objoid "
6488 "AND pip.classoid = 'pg_proc'::regclass "
6489 "AND pip.objsubid = 0) "
6491 "p.pronamespace != "
6492 "(SELECT oid FROM pg_namespace "
6493 "WHERE nspname = 'pg_catalog') OR "
6494 "p.proacl IS DISTINCT FROM pip.initprivs",
6498 " OR EXISTS(SELECT 1 FROM pg_depend WHERE "
6499 "classid = 'pg_proc'::regclass AND "
6500 "objid = p.oid AND "
6501 "refclassid = 'pg_extension'::regclass AND "
6508 "pronamespace AS aggnamespace, "
6509 "pronargs, proargtypes, "
6511 "proacl AS aggacl, "
6512 "acldefault('f', proowner) AS acldefault "
6514 "WHERE proisagg AND ("
6516 "(SELECT oid FROM pg_namespace "
6517 "WHERE nspname = 'pg_catalog')");
6520 " OR EXISTS(SELECT 1 FROM pg_depend WHERE "
6521 "classid = 'pg_proc'::regclass AND "
6522 "objid = p.oid AND "
6523 "refclassid = 'pg_extension'::regclass AND "
6544 for (
i = 0;
i < ntups;
i++)
6546 agginfo[
i].aggfn.dobj.objType =
DO_AGG;
6551 agginfo[
i].aggfn.dobj.namespace =
6555 agginfo[
i].aggfn.dacl.privtype = 0;
6556 agginfo[
i].aggfn.dacl.initprivs = NULL;
6561 if (agginfo[
i].aggfn.nargs == 0)
6562 agginfo[
i].aggfn.argtypes = NULL;
6565 agginfo[
i].aggfn.argtypes = (
Oid *)
pg_malloc(agginfo[
i].aggfn.nargs *
sizeof(
Oid));
6567 agginfo[
i].aggfn.argtypes,
6568 agginfo[
i].aggfn.nargs);
6570 agginfo[
i].aggfn.postponed_def =
false;
6633 const char *not_agg_check;
6635 not_agg_check = (fout->
remoteVersion >= 110000 ?
"p.prokind <> 'a'"
6636 :
"NOT p.proisagg");
6639 "SELECT p.tableoid, p.oid, p.proname, p.prolang, "
6640 "p.pronargs, p.proargtypes, p.prorettype, "
6642 "acldefault('f', p.proowner) AS acldefault, "
6646 "LEFT JOIN pg_init_privs pip ON "
6647 "(p.oid = pip.objoid "
6648 "AND pip.classoid = 'pg_proc'::regclass "
6649 "AND pip.objsubid = 0) "
6651 "\n AND NOT EXISTS (SELECT 1 FROM pg_depend "
6652 "WHERE classid = 'pg_proc'::regclass AND "
6653 "objid = p.oid AND deptype = 'i')"
6655 "\n pronamespace != "
6656 "(SELECT oid FROM pg_namespace "
6657 "WHERE nspname = 'pg_catalog')"
6658 "\n OR EXISTS (SELECT 1 FROM pg_cast"
6659 "\n WHERE pg_cast.oid > %u "
6660 "\n AND p.oid = pg_cast.castfunc)"
6661 "\n OR EXISTS (SELECT 1 FROM pg_transform"
6662 "\n WHERE pg_transform.oid > %u AND "
6663 "\n (p.oid = pg_transform.trffromsql"
6664 "\n OR p.oid = pg_transform.trftosql))",
6670 "\n OR EXISTS(SELECT 1 FROM pg_depend WHERE "
6671 "classid = 'pg_proc'::regclass AND "
6672 "objid = p.oid AND "
6673 "refclassid = 'pg_extension'::regclass AND "
6676 "\n OR p.proacl IS DISTINCT FROM pip.initprivs");
6682 "SELECT tableoid, oid, proname, prolang, "
6683 "pronargs, proargtypes, prorettype, proacl, "
6684 "acldefault('f', proowner) AS acldefault, "
6688 "WHERE NOT proisagg"
6689 "\n AND NOT EXISTS (SELECT 1 FROM pg_depend "
6690 "WHERE classid = 'pg_proc'::regclass AND "
6691 "objid = p.oid AND deptype = 'i')"
6693 "\n pronamespace != "
6694 "(SELECT oid FROM pg_namespace "
6695 "WHERE nspname = 'pg_catalog')"
6696 "\n OR EXISTS (SELECT 1 FROM pg_cast"
6697 "\n WHERE pg_cast.oid > '%u'::oid"
6698 "\n AND p.oid = pg_cast.castfunc)",
6703 "\n OR EXISTS (SELECT 1 FROM pg_transform"
6704 "\n WHERE pg_transform.oid > '%u'::oid"
6705 "\n AND (p.oid = pg_transform.trffromsql"
6706 "\n OR p.oid = pg_transform.trftosql))",
6711 "\n OR EXISTS(SELECT 1 FROM pg_depend WHERE "
6712 "classid = 'pg_proc'::regclass AND "
6713 "objid = p.oid AND "
6714 "refclassid = 'pg_extension'::regclass AND "
6737 for (
i = 0;
i < ntups;
i++)
6744 finfo[
i].
dobj.namespace =
6754 if (finfo[
i].nargs == 0)
6760 finfo[
i].argtypes, finfo[
i].nargs);
6807 int i_reltablespace;
6809 int i_relhastriggers;
6810 int i_relpersistence;
6811 int i_relispopulated;
6814 int i_relforcerowsec;
6816 int i_toastfrozenxid;
6822 int i_toastreloptions;
6824 int i_foreignserver;
6826 int i_is_identity_sequence;
6849 "SELECT c.tableoid, c.oid, c.relname, "
6850 "c.relnamespace, c.relkind, c.reltype, "
6853 "c.relhasindex, c.relhasrules, c.relpages, "
6854 "c.relhastriggers, "
6855 "c.relpersistence, "
6858 "acldefault(CASE WHEN c.relkind = " CppAsString2(RELKIND_SEQUENCE)
6859 " THEN 's'::\"char\" ELSE 'r'::\"char\" END, c.relowner) AS acldefault, "
6860 "CASE WHEN c.relkind = " CppAsString2(RELKIND_FOREIGN_TABLE)
" THEN "
6861 "(SELECT ftserver FROM pg_catalog.pg_foreign_table WHERE ftrelid = c.oid) "
6862 "ELSE 0 END AS foreignserver, "
6863 "c.relfrozenxid, tc.relfrozenxid AS tfrozenxid, "
6865 "tc.relpages AS toastpages, "
6866 "tc.reloptions AS toast_reloptions, "
6867 "d.refobjid AS owning_tab, "
6868 "d.refobjsubid AS owning_col, "
6869 "tsp.spcname AS reltablespace, ");
6873 "false AS relhasoids, ");
6880 "c.relispopulated, ");
6883 "'t' as relispopulated, ");
6887 "c.relreplident, ");
6890 "'d' AS relreplident, ");
6894 "c.relrowsecurity, c.relforcerowsecurity, ");
6897 "false AS relrowsecurity, "
6898 "false AS relforcerowsecurity, ");
6902 "c.relminmxid, tc.relminmxid AS tminmxid, ");
6905 "0 AS relminmxid, 0 AS tminmxid, ");
6909 "array_remove(array_remove(c.reloptions,'check_option=local'),'check_option=cascaded') AS reloptions, "
6910 "CASE WHEN 'check_option=local' = ANY (c.reloptions) THEN 'LOCAL'::text "
6911 "WHEN 'check_option=cascaded' = ANY (c.reloptions) THEN 'CASCADED'::text ELSE NULL END AS checkoption, ");
6914 "c.reloptions, NULL AS checkoption, ");
6921 "NULL AS amname, ");
6925 "(d.deptype = 'i') IS TRUE AS is_identity_sequence, ");
6928 "false AS is_identity_sequence, ");
6932 "c.relispartition AS ispartition ");
6935 "false AS ispartition ");
6944 "\nFROM pg_class c\n"
6945 "LEFT JOIN pg_depend d ON "
6947 "d.classid = 'pg_class'::regclass AND d.objid = c.oid AND "
6948 "d.objsubid = 0 AND "
6949 "d.refclassid = 'pg_class'::regclass AND d.deptype IN ('a', 'i'))\n"
6950 "LEFT JOIN pg_tablespace tsp ON (tsp.oid = c.reltablespace)\n");
6957 "LEFT JOIN pg_am am ON (c.relam = am.oid)\n");
6965 "LEFT JOIN pg_class tc ON (c.reltoastrelid = tc.oid"
6967 " AND c.relkind <> " CppAsString2(RELKIND_PARTITIONED_TABLE)
")\n");
6980 "WHERE c.relkind IN ("
7028 i_relforcerowsec =
PQfnumber(
res,
"relforcerowsecurity");
7036 i_toastreloptions =
PQfnumber(
res,
"toast_reloptions");
7040 i_is_identity_sequence =
PQfnumber(
res,
"is_identity_sequence");
7062 for (
i = 0;
i < ntups;
i++)
7069 tblinfo[
i].
dobj.namespace =
7129 if (tblinfo[
i].relkind == RELKIND_COMPOSITE_TYPE)
7176 (tblinfo[
i].
relkind == RELKIND_RELATION ||
7177 tblinfo[
i].
relkind == RELKIND_PARTITIONED_TABLE))
7184 if (query->
len == 0)
7193 if (query->
len >= 100000)
7204 if (query->
len != 0)
7239 for (
i = 0;
i < numTables;
i++)
7248 if (owning_tab == NULL)
7249 pg_fatal(
"failed sanity check, parent table with OID %u of sequence with OID %u not found",
7312 *numInherits = ntups;
7319 for (
i = 0;
i < ntups;
i++)
7374 "SELECT partrelid FROM pg_partitioned_table WHERE\n"
7375 "(SELECT c.oid FROM pg_opclass c JOIN pg_am a "
7376 "ON c.opcmethod = a.oid\n"
7377 "WHERE opcname = 'enum_ops' "
7378 "AND opcnamespace = 'pg_catalog'::regnamespace "
7379 "AND amname = 'hash') = ANY(partclass)");
7385 for (
int i = 0;
i < ntups;
i++)
7392 pg_fatal(
"failed sanity check, table OID %u appearing in pg_partitioned_table not found",
7429 i_indnullsnotdistinct,
7452 for (
int i = 0;
i < numTables;
i++)
7466 if (tbloids->
len > 1)
7473 "SELECT t.tableoid, t.oid, i.indrelid, "
7474 "t.relname AS indexname, "
7475 "pg_catalog.pg_get_indexdef(i.indexrelid) AS indexdef, "
7476 "i.indkey, i.indisclustered, "
7477 "c.contype, c.conname, "
7478 "c.condeferrable, c.condeferred, "
7479 "c.tableoid AS contableoid, "
7481 "pg_catalog.pg_get_constraintdef(c.oid, false) AS condef, "
7482 "(SELECT spcname FROM pg_catalog.pg_tablespace s WHERE s.oid = t.reltablespace) AS tablespace, "
7483 "t.reloptions AS indreloptions, ");
7488 "i.indisreplident, ");
7491 "false AS indisreplident, ");
7495 "inh.inhparent AS parentidx, "
7496 "i.indnkeyatts AS indnkeyatts, "
7497 "i.indnatts AS indnatts, "
7498 "(SELECT pg_catalog.array_agg(attnum ORDER BY attnum) "
7499 " FROM pg_catalog.pg_attribute "
7500 " WHERE attrelid = i.indexrelid AND "
7501 " attstattarget >= 0) AS indstatcols, "
7502 "(SELECT pg_catalog.array_agg(attstattarget ORDER BY attnum) "
7503 " FROM pg_catalog.pg_attribute "
7504 " WHERE attrelid = i.indexrelid AND "
7505 " attstattarget >= 0) AS indstatvals, ");
7509 "i.indnatts AS indnkeyatts, "
7510 "i.indnatts AS indnatts, "
7511 "'' AS indstatcols, "
7512 "'' AS indstatvals, ");
7516 "i.indnullsnotdistinct, ");
7519 "false AS indnullsnotdistinct, ");
7526 "NULL AS conperiod ");
7540 "FROM unnest('%s'::pg_catalog.oid[]) AS src(tbloid)\n"
7541 "JOIN pg_catalog.pg_index i ON (src.tbloid = i.indrelid) "
7542 "JOIN pg_catalog.pg_class t ON (t.oid = i.indexrelid) "
7543 "JOIN pg_catalog.pg_class t2 ON (t2.oid = i.indrelid) "
7544 "LEFT JOIN pg_catalog.pg_constraint c "
7545 "ON (i.indrelid = c.conrelid AND "
7546 "i.indexrelid = c.conindid AND "
7547 "c.contype IN ('p','u','x')) "
7548 "LEFT JOIN pg_catalog.pg_inherits inh "
7549 "ON (inh.inhrelid = indexrelid) "
7550 "WHERE (i.indisvalid OR t2.relkind = 'p') "
7552 "ORDER BY i.indrelid, indexname",
7562 "FROM unnest('%s'::pg_catalog.oid[]) AS src(tbloid)\n"
7563 "JOIN pg_catalog.pg_index i ON (src.tbloid = i.indrelid) "
7564 "JOIN pg_catalog.pg_class t ON (t.oid = i.indexrelid) "
7565 "LEFT JOIN pg_catalog.pg_constraint c "
7566 "ON (i.indrelid = c.conrelid AND "
7567 "i.indexrelid = c.conindid AND "
7568 "c.contype IN ('p','u','x')) "
7569 "WHERE i.indisvalid AND i.indisready "
7570 "ORDER BY i.indrelid, indexname",
7589 i_indnullsnotdistinct =
PQfnumber(
res,
"indnullsnotdistinct");
7610 for (
int j = 0;
j < ntups;)
7617 for (numinds = 1; numinds < ntups -
j; numinds++)
7625 while (++curtblindx < numTables)
7627 tbinfo = &tblinfo[curtblindx];
7631 if (curtblindx >= numTables)
7632 pg_fatal(
"unrecognized table OID %u", indrelid);
7636 pg_fatal(
"unexpected index data for table \"%s\"",
7643 for (
int c = 0;
c < numinds;
c++,
j++)
7653 indxinfo[
j].
dobj.namespace = tbinfo->
dobj.namespace;
7664 indxinfo[
j].indkeys, indxinfo[
j].indnattrs);
7675 if (contype ==
'p' || contype ==
'u' || contype ==
'x')
7690 constrinfo->
dobj.namespace = tbinfo->
dobj.namespace;
7693 constrinfo->
contype = contype;
7697 constrinfo->
condef = NULL;
7753 "stxnamespace, stxowner, stxrelid, NULL AS stxstattarget "
7754 "FROM pg_catalog.pg_statistic_ext");
7757 "stxnamespace, stxowner, stxrelid, stxstattarget "
7758 "FROM pg_catalog.pg_statistic_ext");
7774 for (
i = 0;
i < ntups;
i++)
7781 statsextinfo[
i].
dobj.namespace =
7835 for (
int i = 0;
i < numTables;
i++)
7843 if ((!
tinfo->hastriggers &&
7844 tinfo->relkind != RELKIND_PARTITIONED_TABLE) ||
7849 if (tbloids->
len > 1)
7856 "SELECT c.tableoid, c.oid, "
7857 "conrelid, conname, confrelid, ");
7863 "pg_catalog.pg_get_constraintdef(c.oid) AS condef\n"
7864 "FROM unnest('%s'::pg_catalog.oid[]) AS src(tbloid)\n"
7865 "JOIN pg_catalog.pg_constraint c ON (src.tbloid = c.conrelid)\n"
7866 "WHERE contype = 'f' ",
7870 "AND conparentid = 0 ");
7872 "ORDER BY conrelid, conname");
7889 for (
int j = 0;
j < ntups;
j++)
7898 if (tbinfo == NULL || tbinfo->
dobj.
catId.
oid != conrelid)
7900 while (++curtblindx < numTables)
7902 tbinfo = &tblinfo[curtblindx];
7906 if (curtblindx >= numTables)
7907 pg_fatal(
"unrecognized table OID %u", conrelid);
7915 constrinfo[
j].
dobj.namespace = tbinfo->
dobj.namespace;
7934 if (reftable && reftable->
relkind == RELKIND_PARTITIONED_TABLE)
7940 for (
int k = 0; k < reftable->
numIndexes; k++)
7948 refidx = &reftable->
indexes[k];
8013 "PREPARE getDomainConstraints(pg_catalog.oid) AS\n"
8014 "SELECT tableoid, oid, conname, "
8015 "pg_catalog.pg_get_constraintdef(oid) AS consrc, "
8017 "FROM pg_catalog.pg_constraint "
8018 "WHERE contypid = $1 AND contype = 'c' "
8019 "ORDER BY conname");
8027 "EXECUTE getDomainConstraints('%u')",
8044 for (
i = 0;
i < ntups;
i++)
8053 constrinfo[
i].
dobj.namespace = tyinfo->
dobj.namespace;
8103 "tableoid, oid, rulename, "
8104 "ev_class AS ruletable, ev_type, is_instead, "
8123 for (
i = 0;
i < ntups;
i++)
8134 if (ruleinfo[
i].ruletable == NULL)
8135 pg_fatal(
"failed sanity check, parent table with OID %u of pg_rewrite entry with OID %u not found",
8136 ruletableoid, ruleinfo[
i].dobj.catId.oid);
8142 if (ruleinfo[
i].ruletable)
8151 if ((ruleinfo[
i].ruletable->relkind == RELKIND_VIEW ||
8209 for (
int i = 0;
i < numTables;
i++)
8218 if (tbloids->
len > 1)
8235 "SELECT t.tgrelid, t.tgname, "
8236 "pg_catalog.pg_get_triggerdef(t.oid, false) AS tgdef, "
8237 "t.tgenabled, t.tableoid, t.oid, "
8238 "t.tgparentid <> 0 AS tgispartition\n"
8239 "FROM unnest('%s'::pg_catalog.oid[]) AS src(tbloid)\n"
8240 "JOIN pg_catalog.pg_trigger t ON (src.tbloid = t.tgrelid) "
8241 "LEFT JOIN pg_catalog.pg_trigger u ON (u.oid = t.tgparentid) "
8242 "WHERE ((NOT t.tgisinternal AND t.tgparentid = 0) "
8243 "OR t.tgenabled != u.tgenabled) "
8244 "ORDER BY t.tgrelid, t.tgname",
8258 "SELECT t.tgrelid, t.tgname, "
8259 "pg_catalog.pg_get_triggerdef(t.oid, false) AS tgdef, "
8260 "t.tgenabled, t.tableoid, t.oid, t.tgisinternal as tgispartition\n"
8261 "FROM unnest('%s'::pg_catalog.oid[]) AS src(tbloid)\n"
8262 "JOIN pg_catalog.pg_trigger t ON (src.tbloid = t.tgrelid) "
8263 "LEFT JOIN pg_catalog.pg_trigger u ON (u.oid = t.tgparentid) "
8264 "WHERE (NOT t.tgisinternal OR t.tgenabled != u.tgenabled) "
8265 "ORDER BY t.tgrelid, t.tgname",
8278 "SELECT t.tgrelid, t.tgname, "
8279 "pg_catalog.pg_get_triggerdef(t.oid, false) AS tgdef, "
8280 "t.tgenabled, t.tableoid, t.oid, t.tgisinternal as tgispartition "
8281 "FROM unnest('%s'::pg_catalog.oid[]) AS src(tbloid)\n"
8282 "JOIN pg_catalog.pg_trigger t ON (src.tbloid = t.tgrelid) "
8283 "LEFT JOIN pg_catalog.pg_depend AS d ON "
8284 " d.classid = 'pg_catalog.pg_trigger'::pg_catalog.regclass AND "
8285 " d.refclassid = 'pg_catalog.pg_trigger'::pg_catalog.regclass AND "
8287 "LEFT JOIN pg_catalog.pg_trigger AS pt ON pt.oid = refobjid "
8288 "WHERE (NOT t.tgisinternal OR t.tgenabled != pt.tgenabled) "
8289 "ORDER BY t.tgrelid, t.tgname",
8296 "SELECT t.tgrelid, t.tgname, "
8297 "pg_catalog.pg_get_triggerdef(t.oid, false) AS tgdef, "
8298 "t.tgenabled, false as tgispartition, "
8299 "t.tableoid, t.oid "
8300 "FROM unnest('%s'::pg_catalog.oid[]) AS src(tbloid)\n"
8301 "JOIN pg_catalog.pg_trigger t ON (src.tbloid = t.tgrelid) "
8302 "WHERE NOT tgisinternal "
8303 "ORDER BY t.tgrelid, t.tgname",
8326 for (
int j = 0;
j < ntups;)
8333 for (numtrigs = 1; numtrigs < ntups -
j; numtrigs++)
8341 while (++curtblindx < numTables)
8343 tbinfo = &tblinfo[curtblindx];
8347 if (curtblindx >= numTables)
8348 pg_fatal(
"unrecognized table OID %u", tgrelid);
8354 for (
int c = 0;
c < numtrigs;
c++,
j++)
8361 tginfo[
j].
dobj.namespace = tbinfo->
dobj.namespace;
8403 "SELECT e.tableoid, e.oid, evtname, evtenabled, "
8404 "evtevent, evtowner, "
8405 "array_to_string(array("
8406 "select quote_literal(x) "
8407 " from unnest(evttags) as t(x)), ', ') as evttags, "
8408 "e.evtfoid::regproc as evtfname "
8409 "FROM pg_event_trigger e "
8427 for (
i = 0;
i < ntups;
i++)
8469 int i_lanplcallfoid;
8477 "lanname, lanpltrusted, lanplcallfoid, "
8478 "laninline, lanvalidator, "
8480 "acldefault('l', lanowner) AS acldefault, "
8503 for (
i = 0;
i < ntups;
i++)
8560 "castsource, casttarget, castfunc, castcontext, "
8563 "WHERE NOT EXISTS ( "
8564 "SELECT 1 FROM pg_range r "
8565 "WHERE c.castsource = r.rngtypid "
8566 "AND c.casttarget = r.rngmultitypid "
8573 "castsource, casttarget, castfunc, castcontext, "
8575 "FROM pg_cast ORDER BY 3,4");
8592 for (
i = 0;
i < ntups;
i++)
8616 if (sTypeInfo && tTypeInfo)
8638 appendPQExpBuffer(query,
"SELECT lanname FROM pg_language WHERE oid = %u", langid);
8673 "trftype, trflang, trffromsql::oid, trftosql::oid "
8674 "FROM pg_transform "
8690 for (
i = 0;
i < ntups;
i++)
8713 if (typeInfo && lanname)
8749 int i_attstattarget;
8759 int i_notnull_noinherit;
8760 int i_notnull_islocal;
8763 int i_attcompression;
8764 int i_attfdwoptions;
8765 int i_attmissingval;
8780 for (
int i = 0;
i < numTables;
i++)
8785 if (tbinfo->
relkind == RELKIND_SEQUENCE)
8793 if (tbloids->
len > 1)
8800 if (checkoids->
len > 1)
8820 "a.attstattarget,\n"
8828 "pg_catalog.format_type(t.oid, a.atttypmod) AS atttypname,\n"
8829 "array_to_string(a.attoptions, ', ') AS attoptions,\n"
8830 "CASE WHEN a.attcollation <> t.typcollation "
8831 "THEN a.attcollation ELSE 0 END AS attcollation,\n"
8832 "pg_catalog.array_to_string(ARRAY("
8833 "SELECT pg_catalog.quote_ident(option_name) || "
8834 "' ' || pg_catalog.quote_literal(option_value) "
8835 "FROM pg_catalog.pg_options_to_table(attfdwoptions) "
8836 "ORDER BY option_name"
8837 "), E',\n ') AS attfdwoptions,\n");
8854 "co.conname AS notnull_name,\n"
8855 "co.connoinherit AS notnull_noinherit,\n"
8856 "co.conislocal AS notnull_islocal,\n");
8859 "CASE WHEN a.attnotnull THEN '' ELSE NULL END AS notnull_name,\n"
8860 "false AS notnull_noinherit,\n"
8861 "a.attislocal AS notnull_islocal,\n");
8865 "a.attcompression AS attcompression,\n");
8868 "'' AS attcompression,\n");
8872 "a.attidentity,\n");
8875 "'' AS attidentity,\n");
8879 "CASE WHEN a.atthasmissing AND NOT a.attisdropped "
8880 "THEN a.attmissingval ELSE null END AS attmissingval,\n");
8883 "NULL AS attmissingval,\n");
8887 "a.attgenerated\n");
8890 "'' AS attgenerated\n");
8894 "FROM unnest('%s'::pg_catalog.oid[]) AS src(tbloid)\n"
8895 "JOIN pg_catalog.pg_attribute a ON (src.tbloid = a.attrelid) "
8896 "LEFT JOIN pg_catalog.pg_type t "
8897 "ON (a.atttypid = t.oid)\n",
8907 " LEFT JOIN pg_catalog.pg_constraint co ON "
8908 "(a.attrelid = co.conrelid\n"
8909 " AND co.contype = 'n' AND "
8910 "co.conkey = array[a.attnum])\n");
8913 "WHERE a.attnum > 0::pg_catalog.int2\n"
8914 "ORDER BY a.attrelid, a.attnum");
8934 i_notnull_noinherit =
PQfnumber(
res,
"notnull_noinherit");
8952 for (
int r = 0; r < ntups;)
8960 for (numatts = 1; numatts < ntups - r; numatts++)
8968 while (++curtblindx < numTables)
8970 tbinfo = &tblinfo[curtblindx];
8974 if (curtblindx >= numTables)
8975 pg_fatal(
"unrecognized table OID %u", attrelid);
8977 if (tbinfo->
relkind == RELKIND_SEQUENCE ||
8979 pg_fatal(
"unexpected column data for table \"%s\"",
9004 hasdefaults =
false;
9006 for (
int j = 0;
j < numatts;
j++, r++)
9009 pg_fatal(
"invalid column numbering in table \"%s\"",
9030 i_notnull_name, i_notnull_noinherit,
9046 if (tbloids->
len > 1)
9069 "pg_catalog.pg_get_expr(adbin, adrelid) AS adsrc\n"
9070 "FROM unnest('%s'::pg_catalog.oid[]) AS src(tbloid)\n"
9071 "JOIN pg_catalog.pg_attrdef a ON (src.tbloid = a.adrelid)\n"
9072 "ORDER BY a.adrelid, a.adnum",
9081 for (
int j = 0;
j < numDefaults;
j++)
9093 if (tbinfo == NULL || tbinfo->
dobj.
catId.
oid != adrelid)
9095 while (++curtblindx < numTables)
9097 tbinfo = &tblinfo[curtblindx];
9101 if (curtblindx >= numTables)
9102 pg_fatal(
"unrecognized table OID %u", adrelid);
9105 if (adnum <= 0 || adnum > tbinfo->
numatts)
9106 pg_fatal(
"invalid adnum value %d for table \"%s\"",
9121 attrdefs[
j].
adnum = adnum;
9125 attrdefs[
j].
dobj.namespace = tbinfo->
dobj.namespace;
9148 else if (tbinfo->
relkind == RELKIND_VIEW)
9166 if (!attrdefs[
j].separate)
9178 tbinfo->
attrdefs[adnum - 1] = &attrdefs[
j];
9204 "SELECT c.tableoid, c.oid, conrelid, conname, "
9205 "pg_catalog.pg_get_constraintdef(c.oid) AS consrc, "
9206 "conislocal, convalidated "
9207 "FROM unnest('%s'::pg_catalog.oid[]) AS src(tbloid)\n"
9208 "JOIN pg_catalog.pg_constraint c ON (src.tbloid = c.conrelid)\n"
9209 "WHERE contype = 'c' "
9210 "ORDER BY c.conrelid, c.conname",
9228 for (
int j = 0;
j < numConstrs;)
9235 for (numcons = 1; numcons < numConstrs -
j; numcons++)
9243 while (++curtblindx < numTables)
9245 tbinfo = &tblinfo[curtblindx];
9249 if (curtblindx >= numTables)
9250 pg_fatal(
"unrecognized table OID %u", conrelid);
9252 if (numcons != tbinfo->
ncheck)
9255 "expected %d check constraints on table \"%s\" but found %d",
9264 for (
int c = 0;
c < numcons;
c++,
j++)
9273 constrs[
j].
dobj.namespace = tbinfo->
dobj.namespace;
9302 if (!constrs[
j].separate)
9359 int i_notnull_name,
int i_notnull_noinherit,
9360 int i_notnull_islocal)
9412 if (strcmp(default_name,
9483 "prsstart::oid, prstoken::oid, "
9484 "prsend::oid, prsheadline::oid, prslextype::oid "
9485 "FROM pg_ts_parser");
9503 for (
i = 0;
i < ntups;
i++)
9510 prsinfo[
i].
dobj.namespace =
9542 int i_dictnamespace;
9545 int i_dictinitoption;
9550 "dictnamespace, dictowner, "
9551 "dicttemplate, dictinitoption "
9568 for (
i = 0;
i < ntups;
i++)
9575 dictinfo[
i].
dobj.namespace =
9608 int i_tmplnamespace;
9615 "tmplnamespace, tmplinit::oid, tmpllexize::oid "
9616 "FROM pg_ts_template");
9631 for (
i = 0;
i < ntups;
i++)
9638 tmplinfo[
i].
dobj.namespace =
9674 "cfgnamespace, cfgowner, cfgparser "
9675 "FROM pg_ts_config");
9690 for (
i = 0;
i < ntups;
i++)
9697 cfginfo[
i].
dobj.namespace =
9737 "fdwhandler::pg_catalog.regproc, "
9738 "fdwvalidator::pg_catalog.regproc, "
9740 "acldefault('F', fdwowner) AS acldefault, "
9741 "array_to_string(ARRAY("
9742 "SELECT quote_ident(option_name) || ' ' || "
9743 "quote_literal(option_value) "
9744 "FROM pg_options_to_table(fdwoptions) "
9745 "ORDER BY option_name"
9746 "), E',\n ') AS fdwoptions "
9747 "FROM pg_foreign_data_wrapper");
9765 for (
i = 0;
i < ntups;
i++)
9772 fdwinfo[
i].
dobj.namespace = NULL;
9822 "srvfdw, srvtype, srvversion, srvacl, "
9823 "acldefault('S', srvowner) AS acldefault, "
9824 "array_to_string(ARRAY("
9825 "SELECT quote_ident(option_name) || ' ' || "
9826 "quote_literal(option_value) "
9827 "FROM pg_options_to_table(srvoptions) "
9828 "ORDER BY option_name"
9829 "), E',\n ') AS srvoptions "
9830 "FROM pg_foreign_server");
9849 for (
i = 0;
i < ntups;
i++)
9856 srvinfo[
i].
dobj.namespace = NULL;
9897 int i_defaclnamespace;
9898 int i_defaclobjtype;
9919 "SELECT oid, tableoid, "
9924 "CASE WHEN defaclnamespace = 0 THEN "
9925 "acldefault(CASE WHEN defaclobjtype = 'S' "
9926 "THEN 's'::\"char\" ELSE defaclobjtype END, "
9927 "defaclrole) ELSE '{}' END AS acldefault "
9928 "FROM pg_default_acl");
9944 for (
i = 0;
i < ntups;
i++)
9958 daclinfo[
i].
dobj.namespace = NULL;
10001 if (roleoid < middle->roleoid)
10003 else if (roleoid > middle->
roleoid)
10010 pg_fatal(
"role with OID %u does not exist", roleoid);
10027 query =
"SELECT oid, rolname FROM pg_catalog.pg_roles ORDER BY 1";
10065 "SELECT DISTINCT attrelid FROM pg_attribute "
10066 "WHERE attacl IS NOT NULL");
10071 for (
i = 0;
i < ntups;
i++)
10090 "SELECT objoid, classoid, objsubid, privtype, initprivs "
10091 "FROM pg_init_privs");
10096 for (
i = 0;
i < ntups;
i++)
10107 objId.
oid = objoid;
10119 ((
TableInfo *) dobj)->hascolumnACLs =
true;
10123 classoid, objoid, objsubid);
10132 strcmp(dobj->
name,
"public") == 0)
10152 classoid, objoid, objsubid);
10186 const char *
name,
const char *
namespace,
10187 const char *owner,
CatalogId catalogId,
10188 int subid,
DumpId dumpId,
10189 const char *initdb_comment)
10200 if (strcmp(
type,
"LARGE OBJECT") != 0)
10225 if (initdb_comment != NULL)
10251 if (
namespace && *
namespace)
10266 .namespace =
namespace,
10268 .description =
"COMMENT",
10270 .createStmt = query->
data,
10286 const char *
name,
const char *
namespace,
10287 const char *owner,
CatalogId catalogId,
10288 int subid,
DumpId dumpId)
10291 catalogId, subid, dumpId, NULL);
10302 const char *reltypename)
10349 .namespace = tbinfo->
dobj.namespace->dobj.
name,
10351 .description =
"COMMENT",
10353 .createStmt = query->
data,
10357 else if (objsubid > 0 && objsubid <= tbinfo->numatts)
10374 .namespace = tbinfo->
dobj.namespace->dobj.
name,
10376 .description =
"COMMENT",
10378 .createStmt = query->
data,
10411 while (low <= high)
10413 middle = low + (high - low) / 2;
10415 if (classoid < middle->classoid)
10417 else if (classoid > middle->
classoid)
10419 else if (objoid < middle->objoid)
10421 else if (objoid > middle->
objoid)
10439 while (middle > low)
10441 if (classoid != middle[-1].classoid ||
10442 objoid != middle[-1].objoid)
10451 while (middle <= high)
10453 if (classoid != middle->
classoid ||
10454 objoid != middle->
objoid)
10491 "FROM pg_catalog.pg_description "
10492 "ORDER BY classoid, objoid, objsubid");
10509 for (
i = 0;
i < ntups;
i++)
10519 if (dobj == NULL ||
10532 ((
TableInfo *) dobj)->relkind == RELKIND_COMPOSITE_TYPE)
10571 if (dobj->
dump == 0)
10697 if (loinfo == NULL)
10698 pg_fatal(
"missing metadata for large objects \"%s\"",
10704 .description =
"BLOBS",
10706 .deps = dobj->dependencies,
10707 .nDeps = dobj->nDeps,
10709 .dumpArg = loinfo));
10779 "-- *not* dropping schema, since initdb creates it\n");
10781 "-- *not* creating schema, since initdb creates it\n");
10786 "SCHEMA", qnspname, NULL);
10792 .description =
"SCHEMA",
10794 .createStmt = q->
data,
10795 .dropStmt = delq->
data));
10800 const char *initdb_comment = NULL;
10802 if (!nspinfo->
create && strcmp(qnspname,
"public") == 0)
10803 initdb_comment =
"standard public schema";
10817 qnspname, NULL, NULL,
10862 qextname,
fmtId(extinfo->namespace));
10877 appendPQExpBufferStr(q,
"-- For binary upgrade, create an empty extension and insert objects into it\n");
10887 "SELECT pg_catalog.binary_upgrade_create_empty_extension(");
10932 .description =
"EXTENSION",
10934 .createStmt = q->
data,
10935 .dropStmt = delq->
data));
10968 if (tyinfo->
typtype == TYPTYPE_BASE)
10970 else if (tyinfo->
typtype == TYPTYPE_DOMAIN)
10972 else if (tyinfo->
typtype == TYPTYPE_COMPOSITE)
10974 else if (tyinfo->
typtype == TYPTYPE_ENUM)
10976 else if (tyinfo->
typtype == TYPTYPE_RANGE)
10981 pg_log_warning(
"typtype of data type \"%s\" appears to be invalid",
11010 "PREPARE dumpEnumType(pg_catalog.oid) AS\n"
11011 "SELECT oid, enumlabel "
11012 "FROM pg_catalog.pg_enum "
11013 "WHERE enumtypid = $1 "
11014 "ORDER BY enumsortorder");
11022 "EXECUTE dumpEnumType('%u')",
11051 for (
i = 0;
i < num;
i++)
11069 for (
i = 0;
i < num;
i++)
11077 "SELECT pg_catalog.binary_upgrade_set_next_pg_enum_oid('%u'::pg_catalog.oid);\n",
11088 tyinfo->
dobj.namespace->dobj.
name);
11093 .namespace = tyinfo->
dobj.namespace->dobj.
name,
11095 .description =
"TYPE",
11097 .createStmt = q->
data,
11098 .dropStmt = delq->
data));
11114 tyinfo->
dobj.namespace->dobj.
name,
11146 "PREPARE dumpRangeType(pg_catalog.oid) AS\n");
11153 "pg_catalog.format_type(rngmultitypid, NULL) AS rngmultitype, ");
11156 "NULL AS rngmultitype, ");
11159 "pg_catalog.format_type(rngsubtype, NULL) AS rngsubtype, "
11160 "opc.opcname AS opcname, "
11161 "(SELECT nspname FROM pg_catalog.pg_namespace nsp "
11162 " WHERE nsp.oid = opc.opcnamespace) AS opcnsp, "
11164 "CASE WHEN rngcollation = st.typcollation THEN 0 "
11165 " ELSE rngcollation END AS collation, "
11166 "rngcanonical, rngsubdiff "
11167 "FROM pg_catalog.pg_range r, pg_catalog.pg_type st, "
11168 " pg_catalog.pg_opclass opc "
11169 "WHERE st.oid = rngsubtype AND opc.oid = rngsubopc AND "
11178 "EXECUTE dumpRangeType('%u')",
11229 if (strcmp(procname,
"-") != 0)
11233 if (strcmp(procname,
"-") != 0)
11241 tyinfo->
dobj.namespace->dobj.
name);
11246 .namespace = tyinfo->
dobj.namespace->dobj.
name,
11248 .description =
"TYPE",
11250 .createStmt = q->
data,
11251 .dropStmt = delq->
data));
11267 tyinfo->
dobj.namespace->dobj.
name,
11312 tyinfo->
dobj.namespace->dobj.
name);
11317 .namespace = tyinfo->
dobj.namespace->dobj.
name,
11319 .description =
"TYPE",
11321 .createStmt = q->
data,
11322 .dropStmt = delq->
data));
11338 tyinfo->
dobj.namespace->dobj.
name,
11369 char *typsubscript;
11375 Oid typsubscriptoid;
11377 char *typispreferred;
11382 char *typcollatable;
11384 bool typdefault_is_literal =
false;
11390 "PREPARE dumpBaseType(pg_catalog.oid) AS\n"
11392 "typinput, typoutput, typreceive, typsend, "
11393 "typreceive::pg_catalog.oid AS typreceiveoid, "
11394 "typsend::pg_catalog.oid AS typsendoid, "
11396 "typanalyze::pg_catalog.oid AS typanalyzeoid, "
11397 "typdelim, typbyval, typalign, typstorage, "
11398 "typmodin, typmodout, "
11399 "typmodin::pg_catalog.oid AS typmodinoid, "
11400 "typmodout::pg_catalog.oid AS typmodoutoid, "
11401 "typcategory, typispreferred, "
11402 "(typcollation <> 0) AS typcollatable, "
11403 "pg_catalog.pg_get_expr(typdefaultbin, 0) AS typdefaultbin, typdefault, ");
11408 "typsubscript::pg_catalog.oid AS typsubscriptoid ");
11411 "'-' AS typsubscript, 0 AS typsubscriptoid ");
11422 "EXECUTE dumpBaseType('%u')",
11454 typdefault_is_literal =
true;
11479 "CREATE TYPE %s (\n"
11480 " INTERNALLENGTH = %s",
11482 (strcmp(typlen,
"-1") == 0) ?
"variable" : typlen);
11498 if (strcmp(typcollatable,
"t") == 0)
11501 if (typdefault != NULL)
11504 if (typdefault_is_literal)
11518 if (strcmp(typcategory,
"U") != 0)
11524 if (strcmp(typispreferred,
"t") == 0)
11527 if (typdelim && strcmp(typdelim,
",") != 0)
11535 else if (*
typalign == TYPALIGN_SHORT)
11537 else if (*
typalign == TYPALIGN_INT)
11539 else if (*
typalign == TYPALIGN_DOUBLE)
11542 if (*typstorage == TYPSTORAGE_PLAIN)
11544 else if (*typstorage == TYPSTORAGE_EXTERNAL)
11546 else if (*typstorage == TYPSTORAGE_EXTENDED)
11548 else if (*typstorage == TYPSTORAGE_MAIN)
11551 if (strcmp(typbyval,
"t") == 0)
11559 tyinfo->
dobj.namespace->dobj.
name);
11564 .namespace = tyinfo->
dobj.namespace->dobj.
name,
11566 .description =
"TYPE",
11568 .createStmt = q->
data,
11569 .dropStmt = delq->
data));
11585 tyinfo->
dobj.namespace->dobj.
name,
11615 bool typdefault_is_literal =
false;
11621 "PREPARE dumpDomain(pg_catalog.oid) AS\n");
11624 "pg_catalog.format_type(t.typbasetype, t.typtypmod) AS typdefn, "
11625 "pg_catalog.pg_get_expr(t.typdefaultbin, 'pg_catalog.pg_type'::pg_catalog.regclass) AS typdefaultbin, "
11627 "CASE WHEN t.typcollation <> u.typcollation "
11628 "THEN t.typcollation ELSE 0 END AS typcollation "
11629 "FROM pg_catalog.pg_type t "
11630 "LEFT JOIN pg_catalog.pg_type u ON (t.typbasetype = u.oid) "
11631 "WHERE t.oid = $1");
11639 "EXECUTE dumpDomain('%u')",
11651 typdefault_is_literal =
true;
11667 "CREATE DOMAIN %s AS %s",
11681 if (typnotnull[0] ==
't')
11684 if (typdefault != NULL)
11687 if (typdefault_is_literal)
11713 "DOMAIN", qtypname,
11714 tyinfo->
dobj.namespace->dobj.
name);
11719 .namespace = tyinfo->
dobj.namespace->dobj.
name,
11721 .description =
"DOMAIN",
11723 .createStmt = q->
data,
11724 .dropStmt = delq->
data));
11740 tyinfo->
dobj.namespace->dobj.
name,
11754 tyinfo->
dobj.namespace->dobj.
name,
11789 int i_attisdropped;
11790 int i_attcollation;
11805 "PREPARE dumpCompositeType(pg_catalog.oid) AS\n"
11806 "SELECT a.attname, a.attnum, "
11807 "pg_catalog.format_type(a.atttypid, a.atttypmod) AS atttypdefn, "
11808 "a.attlen, a.attalign, a.attisdropped, "
11809 "CASE WHEN a.attcollation <> at.typcollation "
11810 "THEN a.attcollation ELSE 0 END AS attcollation "
11811 "FROM pg_catalog.pg_type ct "
11812 "JOIN pg_catalog.pg_attribute a ON a.attrelid = ct.typrelid "
11813 "LEFT JOIN pg_catalog.pg_type at ON at.oid = a.atttypid "
11814 "WHERE ct.oid = $1 "
11815 "ORDER BY a.attnum");
11823 "EXECUTE dumpCompositeType('%u')",
11852 for (
i = 0;
i < ntups;
i++)
11872 if (actual_atts++ > 0)
11903 "\n-- For binary upgrade, recreate dropped column.\n");
11905 "SET attlen = %s, "
11906 "attalign = '%s', attbyval = false\n"
11927 tyinfo->
dobj.namespace->dobj.
name);
11932 .namespace = tyinfo->
dobj.namespace->dobj.
name,
11934 .description =
"TYPE",
11936 .createStmt = q->
data,
11937 .dropStmt = delq->
data));
11954 tyinfo->
dobj.namespace->dobj.
name,
11991 int i_attisdropped;
12018 for (
i = 0;
i < ntups;
i++)
12045 .namespace = tyinfo->
dobj.namespace->dobj.
name,
12047 .description =
"COMMENT",
12049 .createStmt = query->
data,
12100 .namespace = stinfo->
dobj.namespace->dobj.
name,
12102 .description =
"SHELL TYPE",
12104 .createStmt = q->
data));
12139 if (funcInfo != NULL && !funcInfo->
dobj.
dump)
12145 if (inlineInfo != NULL && !inlineInfo->
dobj.
dump)
12152 if (validatorInfo != NULL && !validatorInfo->
dobj.
dump)
12153 validatorInfo = NULL;
12161 useParams = (funcInfo != NULL &&
12205 "LANGUAGE", qlanname, NULL);
12211 .description =
"PROCEDURAL LANGUAGE",
12213 .createStmt = defqry->
data,
12214 .dropStmt = delqry->
data,
12230 qlanname, NULL, NULL,
12253 if (is_agg && finfo->
nargs == 0)
12280 for (
j = 0;
j < finfo->
nargs;
j++)
12308 char *funcfullsig = NULL;
12310 char *qual_funcsig;
12323 char *proleakproof;
12330 char **configitems = NULL;
12331 int nconfigitems = 0;
12332 const char *keyword;
12347 "PREPARE dumpFunc(pg_catalog.oid) AS\n");
12361 "pg_catalog.pg_get_function_arguments(p.oid) AS funcargs,\n"
12362 "pg_catalog.pg_get_function_identity_arguments(p.oid) AS funciargs,\n"
12363 "pg_catalog.pg_get_function_result(p.oid) AS funcresult,\n"
12364 "proleakproof,\n");
12368 "array_to_string(protrftypes, ' ') AS protrftypes,\n");
12371 "NULL AS protrftypes,\n");
12378 "'u' AS proparallel,\n");
12385 "CASE WHEN proiswindow THEN 'w' ELSE 'f' END AS prokind,\n");
12392 "'-' AS prosupport,\n");
12396 "pg_get_function_sqlbody(p.oid) AS prosqlbody\n");
12399 "NULL AS prosqlbody\n");
12402 "FROM pg_catalog.pg_proc p, pg_catalog.pg_language l\n"
12403 "WHERE p.oid = $1 "
12404 "AND l.oid = p.prolang");
12412 "EXECUTE dumpFunc('%u')",
12454 else if (probin[0] !=
'\0')
12458 if (prosrc[0] !=
'\0')
12467 (strchr(prosrc,
'\'') == NULL && strchr(prosrc,
'\\') == NULL))
12485 if (!
parsePGArray(proconfig, &configitems, &nconfigitems))
12486 pg_fatal(
"could not parse %s array",
"proconfig");
12490 configitems = NULL;
12503 if (prokind[0] == PROKIND_PROCEDURE)
12504 keyword =
"PROCEDURE";
12506 keyword =
"FUNCTION";
12509 keyword, qual_funcsig);
12514 funcfullsig ? funcfullsig :
12517 if (prokind[0] == PROKIND_PROCEDURE)
12519 else if (funcresult)
12523 (proretset[0] ==
't') ?
"SETOF " :
"",
12536 for (
i = 0; typeids[
i];
i++)
12545 if (prokind[0] == PROKIND_WINDOW)
12548 if (provolatile[0] != PROVOLATILE_VOLATILE)
12550 if (provolatile[0] == PROVOLATILE_IMMUTABLE)
12552 else if (provolatile[0] == PROVOLATILE_STABLE)
12554 else if (provolatile[0] != PROVOLATILE_VOLATILE)
12555 pg_fatal(
"unrecognized provolatile value for function \"%s\"",
12559 if (proisstrict[0] ==
't')
12562 if (prosecdef[0] ==
't')
12565 if (proleakproof[0] ==
't')
12573 if (strcmp(procost,
"0") != 0)
12575 if (strcmp(lanname,
"internal") == 0 || strcmp(lanname,
"c") == 0)
12578 if (strcmp(procost,
"1") != 0)
12584 if (strcmp(procost,
"100") != 0)
12588 if (proretset[0] ==
't' &&
12589 strcmp(prorows,
"0") != 0 && strcmp(prorows,
"1000") != 0)
12592 if (strcmp(prosupport,
"-") != 0)
12598 if (proparallel[0] != PROPARALLEL_UNSAFE)
12600 if (proparallel[0] == PROPARALLEL_SAFE)
12602 else if (proparallel[0] == PROPARALLEL_RESTRICTED)
12604 else if (proparallel[0] != PROPARALLEL_UNSAFE)
12605 pg_fatal(
"unrecognized proparallel value for function \"%s\"",
12609 for (
int i = 0;
i < nconfigitems;
i++)
12612 char *configitem = configitems[
i];
12615 pos = strchr(configitem,
'=');
12645 for (nameptr = namelist; *nameptr; nameptr++)
12647 if (nameptr != namelist)
12661 "pg_catalog.pg_proc", keyword,
12667 finfo->
dobj.namespace->dobj.
name);
12672 .
namespace = finfo->
dobj.namespace->dobj.
name,
12674 .description = keyword,
12677 .createStmt = q->
data,
12678 .dropStmt = delqry->
data));
12706 free(qual_funcsig);
12723 const char *sourceType;
12724 const char *targetType;
12734 if (funcInfo == NULL)
12735 pg_fatal(
"could not find function definition for function with OID %u",
12747 sourceType, targetType);
12750 sourceType, targetType);
12754 case COERCION_METHOD_BINARY:
12757 case COERCION_METHOD_INOUT:
12760 case COERCION_METHOD_FUNCTION:
12774 pg_log_warning(
"bogus value in pg_cast.castfunc or pg_cast.castmethod field");
12787 sourceType, targetType);
12790 sourceType, targetType);
12794 "CAST", castargs->
data, NULL);
12799 .description =
"CAST",
12801 .createStmt = defqry->
data,
12802 .dropStmt = delqry->
data));
12830 const char *transformType;
12840 if (fromsqlFuncInfo == NULL)
12841 pg_fatal(
"could not find function definition for function with OID %u",
12847 if (tosqlFuncInfo == NULL)
12848 pg_fatal(
"could not find function definition for function with OID %u",
12861 transformType, lanname);
12864 transformType, lanname);
12867 pg_log_warning(
"bogus transform definition, at least one of trffromsql and trftosql should be nonzero");
12871 if (fromsqlFuncInfo)
12911 transformType, lanname);
12914 transformType, lanname);
12918 "TRANSFORM", transformargs->
data, NULL);
12923 .description =
"TRANSFORM",
12925 .createStmt = defqry->
data,
12926 .dropStmt = delqry->
data,
13002 "PREPARE dumpOpr(pg_catalog.oid) AS\n"
13004 "oprcode::pg_catalog.regprocedure, "
13005 "oprleft::pg_catalog.regtype, "
13006 "oprright::pg_catalog.regtype, "
13009 "oprrest::pg_catalog.regprocedure, "
13010 "oprjoin::pg_catalog.regprocedure, "
13011 "oprcanmerge, oprcanhash "
13012 "FROM pg_catalog.pg_operator "
13021 "EXECUTE dumpOpr('%u')",
13049 if (strcmp(oprkind,
"r") == 0)
13050 pg_log_warning(
"postfix operators are not supported anymore (operator \"%s\")",
13068 if (strcmp(oprkind,
"r") == 0 ||
13069 strcmp(oprkind,
"b") == 0)
13077 if (strcmp(oprkind,
"l") == 0 ||
13078 strcmp(oprkind,
"b") == 0)
13100 if (strcmp(oprcanmerge,
"t") == 0)
13103 if (strcmp(oprcanhash,
"t") == 0)
13130 "OPERATOR",
oprid->data,
13131 oprinfo->
dobj.namespace->dobj.
name);
13136 .namespace = oprinfo->
dobj.namespace->dobj.
name,
13138 .description =
"OPERATOR",
13140 .createStmt = q->
data,
13141 .dropStmt = delq->
data));
13175 if (strcmp(proc,
"-") == 0)
13181 for (paren =
name; *paren; paren++)
13183 if (*paren ==
'(' && !inquote)
13189 inquote = !inquote;
13214 if (strcmp(oproid,
"0") == 0)
13218 if (oprInfo == NULL)
13225 return psprintf(
"OPERATOR(%s.%s)",
13246 "SELECT '%u'::pg_catalog.regproc", funcOid);
13289 aminfo->
amtype, qamname);
13303 "ACCESS METHOD", qamname, NULL);
13308 .description =
"ACCESS METHOD",
13310 .createStmt = q->
data,
13311 .dropStmt = delq->
data));
13342 int i_opcfamilyname;
13343 int i_opcfamilynsp;
13345 int i_amopstrategy;
13348 int i_sortfamilynsp;
13351 int i_amproclefttype;
13352 int i_amprocrighttype;
13357 char *opcfamilyname;
13358 char *opcfamilynsp;
13360 char *amopstrategy;
13363 char *sortfamilynsp;
13366 char *amproclefttype;
13367 char *amprocrighttype;
13382 "opckeytype::pg_catalog.regtype, "
13383 "opcdefault, opcfamily, "
13384 "opfname AS opcfamilyname, "
13385 "nspname AS opcfamilynsp, "
13386 "(SELECT amname FROM pg_catalog.pg_am WHERE oid = opcmethod) AS amname "
13387 "FROM pg_catalog.pg_opclass c "
13388 "LEFT JOIN pg_catalog.pg_opfamily f ON f.oid = opcfamily "
13389 "LEFT JOIN pg_catalog.pg_namespace n ON n.oid = opfnamespace "
13390 "WHERE c.oid = '%u'::pg_catalog.oid",
13422 if (strcmp(opcdefault,
"t") == 0)
13427 if (strlen(opcfamilyname) > 0)
13437 if (strcmp(opckeytype,
"-") != 0)
13454 "amopopr::pg_catalog.regoperator, "
13455 "opfname AS sortfamily, "
13456 "nspname AS sortfamilynsp "
13457 "FROM pg_catalog.pg_amop ao JOIN pg_catalog.pg_depend ON "
13458 "(classid = 'pg_catalog.pg_amop'::pg_catalog.regclass AND objid = ao.oid) "
13459 "LEFT JOIN pg_catalog.pg_opfamily f ON f.oid = amopsortfamily "
13460 "LEFT JOIN pg_catalog.pg_namespace n ON n.oid = opfnamespace "
13461 "WHERE refclassid = 'pg_catalog.pg_opclass'::pg_catalog.regclass "
13462 "AND refobjid = '%u'::pg_catalog.oid "
13463 "AND amopfamily = '%s'::pg_catalog.oid "
13464 "ORDER BY amopstrategy",
13477 for (
i = 0;
i < ntups;
i++)
13488 amopstrategy, amopopr);
13490 if (strlen(sortfamily) > 0)
13515 "amproc::pg_catalog.regprocedure, "
13516 "amproclefttype::pg_catalog.regtype, "
13517 "amprocrighttype::pg_catalog.regtype "
13518 "FROM pg_catalog.pg_amproc ap, pg_catalog.pg_depend "
13519 "WHERE refclassid = 'pg_catalog.pg_opclass'::pg_catalog.regclass "
13520 "AND refobjid = '%u'::pg_catalog.oid "
13521 "AND classid = 'pg_catalog.pg_amproc'::pg_catalog.regclass "
13522 "AND objid = ap.oid "
13523 "ORDER BY amprocnum",
13533 i_amprocrighttype =
PQfnumber(
res,
"amprocrighttype");
13535 for (
i = 0;
i < ntups;
i++)
13547 if (*amproclefttype && *amprocrighttype)
13574 "OPERATOR CLASS", nameusing->
data,
13575 opcinfo->
dobj.namespace->dobj.
name);
13580 .namespace = opcinfo->
dobj.namespace->dobj.
name,
13582 .description =
"OPERATOR CLASS",
13584 .createStmt = q->
data,
13585 .dropStmt = delq->
data));
13622 int i_amopstrategy;
13625 int i_sortfamilynsp;
13628 int i_amproclefttype;
13629 int i_amprocrighttype;
13631 char *amopstrategy;
13634 char *sortfamilynsp;
13637 char *amproclefttype;
13638 char *amprocrighttype;
13656 "amopopr::pg_catalog.regoperator, "
13657 "opfname AS sortfamily, "
13658 "nspname AS sortfamilynsp "
13659 "FROM pg_catalog.pg_amop ao JOIN pg_catalog.pg_depend ON "
13660 "(classid = 'pg_catalog.pg_amop'::pg_catalog.regclass AND objid = ao.oid) "
13661 "LEFT JOIN pg_catalog.pg_opfamily f ON f.oid = amopsortfamily "
13662 "LEFT JOIN pg_catalog.pg_namespace n ON n.oid = opfnamespace "
13663 "WHERE refclassid = 'pg_catalog.pg_opfamily'::pg_catalog.regclass "
13664 "AND refobjid = '%u'::pg_catalog.oid "
13665 "AND amopfamily = '%u'::pg_catalog.oid "
13666 "ORDER BY amopstrategy",
13675 "amproc::pg_catalog.regprocedure, "
13676 "amproclefttype::pg_catalog.regtype, "
13677 "amprocrighttype::pg_catalog.regtype "
13678 "FROM pg_catalog.pg_amproc ap, pg_catalog.pg_depend "
13679 "WHERE refclassid = 'pg_catalog.pg_opfamily'::pg_catalog.regclass "
13680 "AND refobjid = '%u'::pg_catalog.oid "
13681 "AND classid = 'pg_catalog.pg_amproc'::pg_catalog.regclass "
13682 "AND objid = ap.oid "
13683 "ORDER BY amprocnum",
13692 "(SELECT amname FROM pg_catalog.pg_am WHERE oid = opfmethod) AS amname "
13693 "FROM pg_catalog.pg_opfamily "
13694 "WHERE oid = '%u'::pg_catalog.oid",
13732 i_amopstrategy =
PQfnumber(res_ops,
"amopstrategy");
13733 i_amopopr =
PQfnumber(res_ops,
"amopopr");
13734 i_sortfamily =
PQfnumber(res_ops,
"sortfamily");
13735 i_sortfamilynsp =
PQfnumber(res_ops,
"sortfamilynsp");
13737 for (
i = 0;
i < ntups;
i++)
13739 amopstrategy =
PQgetvalue(res_ops,
i, i_amopstrategy);
13741 sortfamily =
PQgetvalue(res_ops,
i, i_sortfamily);
13742 sortfamilynsp =
PQgetvalue(res_ops,
i, i_sortfamilynsp);
13748 amopstrategy, amopopr);
13750 if (strlen(sortfamily) > 0)
13765 i_amprocnum =
PQfnumber(res_procs,
"amprocnum");
13766 i_amproc =
PQfnumber(res_procs,
"amproc");
13767 i_amproclefttype =
PQfnumber(res_procs,
"amproclefttype");
13768 i_amprocrighttype =
PQfnumber(res_procs,
"amprocrighttype");
13770 for (
i = 0;
i < ntups;
i++)
13772 amprocnum =
PQgetvalue(res_procs,
i, i_amprocnum);
13774 amproclefttype =
PQgetvalue(res_procs,
i, i_amproclefttype);
13775 amprocrighttype =
PQgetvalue(res_procs,
i, i_amprocrighttype);
13781 amprocnum, amproclefttype, amprocrighttype,
13796 "OPERATOR FAMILY", nameusing->
data,
13797 opfinfo->
dobj.namespace->dobj.
name);
13802 .namespace = opfinfo->
dobj.namespace->dobj.
name,
13804 .description =
"OPERATOR FAMILY",
13806 .createStmt = q->
data,
13807 .dropStmt = delq->
data));
13837 int i_collprovider;
13838 int i_collisdeterministic;
13842 int i_collicurules;
13843 const char *collprovider;
13844 const char *collcollate;
13845 const char *collctype;
13846 const char *colllocale;
13847 const char *collicurules;
13868 "'c' AS collprovider, "
13869 "NULL AS collversion, ");
13873 "collisdeterministic, ");
13876 "true AS collisdeterministic, ");
13883 "colliculocale AS colllocale, ");
13886 "NULL AS colllocale, ");
13893 "NULL AS collicurules, ");
13898 "FROM pg_catalog.pg_collation c "
13899 "WHERE c.oid = '%u'::pg_catalog.oid",
13905 i_collisdeterministic =
PQfnumber(
res,
"collisdeterministic");
13916 collcollate = NULL;
13929 if (collcollate[0] ==
'\0')
13930 collcollate = NULL;
13931 if (collctype[0] ==
'\0')
13943 collicurules = NULL;
13952 if (collprovider[0] ==
'b')
13954 else if (collprovider[0] ==
'c')
13956 else if (collprovider[0] ==
'i')
13958 else if (collprovider[0] ==
'd')
13962 pg_fatal(
"unrecognized collation provider: %s",
13965 if (strcmp(
PQgetvalue(
res, 0, i_collisdeterministic),
"f") == 0)
13968 if (collprovider[0] ==
'd')
13970 if (collcollate || collctype || colllocale || collicurules)
13975 else if (collprovider[0] ==
'b')
13977 if (collcollate || collctype || !colllocale || collicurules)
13984 else if (collprovider[0] ==
'i')
13988 if (collcollate || collctype || !colllocale)
13997 if (!collcollate || !collctype || colllocale ||
13998 strcmp(collcollate, collctype) != 0)
14011 else if (collprovider[0] ==
'c')
14013 if (colllocale || collicurules || !collcollate || !collctype)
14016 if (collcollate && collctype && strcmp(collcollate, collctype) == 0)
14030 pg_fatal(
"unrecognized collation provider: %s", collprovider);
14054 "COLLATION", qcollname,
14055 collinfo->
dobj.namespace->dobj.
name);
14060 .namespace = collinfo->
dobj.namespace->dobj.
name,
14062 .description =
"COLLATION",
14064 .createStmt = q->
data,
14065 .dropStmt = delq->
data));
14094 int i_conforencoding;
14095 int i_contoencoding;
14098 const char *conforencoding;
14099 const char *contoencoding;
14100 const char *conproc;
14115 "pg_catalog.pg_encoding_to_char(conforencoding) AS conforencoding, "
14116 "pg_catalog.pg_encoding_to_char(contoencoding) AS contoencoding, "
14117 "conproc, condefault "
14118 "FROM pg_catalog.pg_conversion c "
14119 "WHERE c.oid = '%u'::pg_catalog.oid",
14138 (condefault) ?
"DEFAULT " :
"",
14148 "CONVERSION", qconvname,
14149 convinfo->
dobj.namespace->dobj.
name);
14154 .namespace = convinfo->
dobj.namespace->dobj.
name,
14156 .description =
"CONVERSION",
14158 .createStmt = q->
data,
14159 .dropStmt = delq->
data));
14193 if (agginfo->aggfn.nargs == 0)
14198 for (
j = 0;
j < agginfo->aggfn.nargs;
j++)
14200 (
j > 0) ?
", " :
"",
14202 agginfo->aggfn.argtypes[
j],
14222 char *aggfullsig = NULL;
14227 const char *aggtransfn;
14228 const char *aggfinalfn;
14229 const char *aggcombinefn;
14230 const char *aggserialfn;
14231 const char *aggdeserialfn;
14232 const char *aggmtransfn;
14233 const char *aggminvtransfn;
14234 const char *aggmfinalfn;
14235 bool aggfinalextra;
14236 bool aggmfinalextra;
14237 char aggfinalmodify;
14238 char aggmfinalmodify;
14239 const char *aggsortop;
14240 char *aggsortconvop;
14242 const char *aggtranstype;
14243 const char *aggtransspace;
14244 const char *aggmtranstype;
14245 const char *aggmtransspace;
14246 const char *agginitval;
14247 const char *aggminitval;
14248 const char *proparallel;
14249 char defaultfinalmodify;
14264 "PREPARE dumpAgg(pg_catalog.oid) AS\n");
14270 "aggtranstype::pg_catalog.regtype,\n"
14273 "pg_catalog.pg_get_function_arguments(p.oid) AS funcargs,\n"
14274 "pg_catalog.pg_get_function_identity_arguments(p.oid) AS funciargs,\n");
14280 "aggminvtransfn,\n"
14282 "aggmtranstype::pg_catalog.regtype,\n"
14284 "aggmfinalextra,\n"
14286 "aggmtransspace,\n"
14290 "'n' AS aggkind,\n"
14291 "'-' AS aggmtransfn,\n"
14292 "'-' AS aggminvtransfn,\n"
14293 "'-' AS aggmfinalfn,\n"
14294 "0 AS aggmtranstype,\n"
14295 "false AS aggfinalextra,\n"
14296 "false AS aggmfinalextra,\n"
14297 "0 AS aggtransspace,\n"
14298 "0 AS aggmtransspace,\n"
14299 "NULL AS aggminitval,\n");
14309 "'-' AS aggcombinefn,\n"
14310 "'-' AS aggserialfn,\n"
14311 "'-' AS aggdeserialfn,\n"
14312 "'u' AS proparallel,\n");
14316 "aggfinalmodify,\n"
14317 "aggmfinalmodify\n");
14320 "'0' AS aggfinalmodify,\n"
14321 "'0' AS aggmfinalmodify\n");
14324 "FROM pg_catalog.pg_aggregate a, pg_catalog.pg_proc p "
14325 "WHERE a.aggfnoid = p.oid "
14334 "EXECUTE dumpAgg('%u')",
14335 agginfo->aggfn.dobj.catId.oid);
14377 defaultfinalmodify = (aggkind == AGGKIND_NORMAL) ? AGGMODIFY_READ_ONLY : AGGMODIFY_READ_WRITE;
14379 if (aggfinalmodify ==
'0')
14380 aggfinalmodify = defaultfinalmodify;
14381 if (aggmfinalmodify ==
'0')
14382 aggmfinalmodify = defaultfinalmodify;
14386 aggtransfn, aggtranstype);
14388 if (strcmp(aggtransspace,
"0") != 0)
14400 if (strcmp(aggfinalfn,
"-") != 0)
14406 if (aggfinalmodify != defaultfinalmodify)
14408 switch (aggfinalmodify)
14410 case AGGMODIFY_READ_ONLY:
14413 case AGGMODIFY_SHAREABLE:
14416 case AGGMODIFY_READ_WRITE:
14420 pg_fatal(
"unrecognized aggfinalmodify value for aggregate \"%s\"",
14421 agginfo->aggfn.dobj.name);
14427 if (strcmp(aggcombinefn,
"-") != 0)
14430 if (strcmp(aggserialfn,
"-") != 0)
14433 if (strcmp(aggdeserialfn,
"-") != 0)
14436 if (strcmp(aggmtransfn,
"-") != 0)
14444 if (strcmp(aggmtransspace,
"0") != 0)
14456 if (strcmp(aggmfinalfn,
"-") != 0)
14460 if (aggmfinalextra)
14462 if (aggmfinalmodify != defaultfinalmodify)
14464 switch (aggmfinalmodify)
14466 case AGGMODIFY_READ_ONLY:
14469 case AGGMODIFY_SHAREABLE:
14472 case AGGMODIFY_READ_WRITE:
14476 pg_fatal(
"unrecognized aggmfinalmodify value for aggregate \"%s\"",
14477 agginfo->aggfn.dobj.name);
14488 free(aggsortconvop);
14491 if (aggkind == AGGKIND_HYPOTHETICAL)
14494 if (proparallel[0] != PROPARALLEL_UNSAFE)
14496 if (proparallel[0] == PROPARALLEL_SAFE)
14498 else if (proparallel[0] == PROPARALLEL_RESTRICTED)
14500 else if (proparallel[0] != PROPARALLEL_UNSAFE)
14501 pg_fatal(
"unrecognized proparallel value for function \"%s\"",
14502 agginfo->aggfn.dobj.name);
14506 fmtId(agginfo->aggfn.dobj.namespace->dobj.name),
14510 fmtId(agginfo->aggfn.dobj.namespace->dobj.name),
14511 aggfullsig ? aggfullsig : aggsig, details->
data);
14515 "AGGREGATE", aggsig,
14516 agginfo->aggfn.dobj.namespace->dobj.name);
14520 agginfo->aggfn.dobj.dumpId,
14522 .
namespace = agginfo->aggfn.dobj.namespace->dobj.name,
14523 .owner = agginfo->aggfn.rolname,
14524 .description =
"AGGREGATE",
14526 .createStmt = q->
data,
14527 .dropStmt = delq->
data));
14532 agginfo->aggfn.dobj.namespace->dobj.name,
14533 agginfo->aggfn.rolname,
14534 agginfo->aggfn.dobj.catId, 0, agginfo->aggfn.dobj.dumpId);
14538 agginfo->aggfn.dobj.namespace->dobj.name,
14539 agginfo->aggfn.rolname,
14540 agginfo->aggfn.dobj.catId, 0, agginfo->aggfn.dobj.dumpId);
14553 "FUNCTION", aggsig, NULL,
14554 agginfo->aggfn.dobj.namespace->dobj.name,
14555 NULL, agginfo->aggfn.rolname, &agginfo->aggfn.dacl);
14610 "TEXT SEARCH PARSER", qprsname,
14611 prsinfo->
dobj.namespace->dobj.
name);
14616 .namespace = prsinfo->
dobj.namespace->dobj.
name,
14617 .description =
"TEXT SEARCH PARSER",
14619 .createStmt = q->
data,
14620 .dropStmt = delq->
data));
14624 dumpComment(fout,
"TEXT SEARCH PARSER", qprsname,
14625 prsinfo->
dobj.namespace->dobj.
name,
"",
14661 "FROM pg_ts_template p, pg_namespace n "
14662 "WHERE p.oid = '%u' AND n.oid = tmplnamespace",
14688 "TEXT SEARCH DICTIONARY", qdictname,
14689 dictinfo->
dobj.namespace->dobj.
name);
14694 .namespace = dictinfo->
dobj.namespace->dobj.
name,
14696 .description =
"TEXT SEARCH DICTIONARY",
14698 .createStmt = q->
data,
14699 .dropStmt = delq->
data));
14703 dumpComment(fout,
"TEXT SEARCH DICTIONARY", qdictname,
14748 "TEXT SEARCH TEMPLATE", qtmplname,
14749 tmplinfo->
dobj.namespace->dobj.
name);
14754 .namespace = tmplinfo->
dobj.namespace->dobj.
name,
14755 .description =
"TEXT SEARCH TEMPLATE",
14757 .createStmt = q->
data,
14758 .dropStmt = delq->
data));
14762 dumpComment(fout,
"TEXT SEARCH TEMPLATE", qtmplname,
14763 tmplinfo->
dobj.namespace->dobj.
name,
"",
14803 "FROM pg_ts_parser p, pg_namespace n "
14804 "WHERE p.oid = '%u' AND n.oid = prsnamespace",
14821 " ( SELECT alias FROM pg_catalog.ts_token_type('%u'::pg_catalog.oid) AS t\n"
14822 " WHERE t.tokid = m.maptokentype ) AS tokenname,\n"
14823 " m.mapdict::pg_catalog.regdictionary AS dictname\n"
14824 "FROM pg_catalog.pg_ts_config_map AS m\n"
14825 "WHERE m.mapcfg = '%u'\n"
14826 "ORDER BY m.mapcfg, m.maptokentype, m.mapseqno",
14835 for (
i = 0;
i < ntups;
i++)
14850 fmtId(tokenname), dictname);
14866 "TEXT SEARCH CONFIGURATION", qcfgname,
14867 cfginfo->
dobj.namespace->dobj.
name);
14872 .namespace = cfginfo->
dobj.namespace->dobj.
name,
14874 .description =
"TEXT SEARCH CONFIGURATION",
14876 .createStmt = q->
data,
14877 .dropStmt = delq->
data));
14881 dumpComment(fout,
"TEXT SEARCH CONFIGURATION", qcfgname,
14931 "FOREIGN DATA WRAPPER", qfdwname,
14938 .description =
"FOREIGN DATA WRAPPER",
14940 .createStmt = q->
data,
14941 .dropStmt = delq->
data));
14945 dumpComment(fout,
"FOREIGN DATA WRAPPER", qfdwname,
14952 "FOREIGN DATA WRAPPER", qfdwname, NULL, NULL,
14988 "FROM pg_foreign_data_wrapper w "
14989 "WHERE w.oid = '%u'",
15019 "SERVER", qsrvname, NULL);
15025 .description =
"SERVER",
15027 .createStmt = q->
data,
15028 .dropStmt = delq->
data));
15039 "FOREIGN SERVER", qsrvname, NULL, NULL,
15067 const char *servername,
const char *
namespace,
15096 "array_to_string(ARRAY("
15097 "SELECT quote_ident(option_name) || ' ' || "
15098 "quote_literal(option_value) "
15099 "FROM pg_options_to_table(umoptions) "
15100 "ORDER BY option_name"
15101 "), E',\n ') AS umoptions "
15102 "FROM pg_user_mappings "
15103 "WHERE srvid = '%u' "
15104 "ORDER BY usename",
15113 for (
i = 0;
i < ntups;
i++)
15125 if (umoptions && strlen(umoptions) > 0)
15136 usename, servername);
15140 .namespace =
namespace,
15142 .description =
"USER MAPPING",
15144 .createStmt = q->
data,
15145 .dropStmt = delq->
data));
15176 case DEFACLOBJ_RELATION:
15179 case DEFACLOBJ_SEQUENCE:
15180 type =
"SEQUENCES";
15182 case DEFACLOBJ_FUNCTION:
15183 type =
"FUNCTIONS";
15185 case DEFACLOBJ_TYPE:
15188 case DEFACLOBJ_NAMESPACE:
15193 pg_fatal(
"unrecognized object type in default privileges: %d",
15202 daclinfo->
dobj.namespace != NULL ?
15203 daclinfo->
dobj.namespace->dobj.
name : NULL,
15209 pg_fatal(
"could not parse default ACL list (%s)",
15215 .namespace = daclinfo->
dobj.namespace ?
15216 daclinfo->
dobj.namespace->dobj.
name : NULL,
15218 .description =
"DEFAULT ACL",
15220 .createStmt = q->
data));
15251 const char *nspname,
const char *tag,
const char *owner,
15256 const char *acls = dacl->
acl;
15259 const char *initprivs = dacl->
initprivs;
15260 const char *baseacls;
15268 if (dopt->
dataOnly && strcmp(
type,
"LARGE OBJECT") != 0)
15287 initprivs && *initprivs !=
'\0')
15293 pg_fatal(
"could not parse initial ACL list (%s) or default (%s) for object \"%s\" (%s)",
15295 appendPQExpBufferStr(sql,
"SELECT pg_catalog.binary_upgrade_set_record_init_privs(false);\n");
15306 if (initprivs && *initprivs !=
'\0')
15308 baseacls = initprivs;
15309 if (acls == NULL || *acls ==
'\0')
15316 acls, baseacls, owner,
15318 pg_fatal(
"could not parse ACL list (%s) or default (%s) for object \"%s\" (%s)",
15334 aclDeps[nDeps++] = objDumpId;
15336 aclDeps[nDeps++] = altDumpId;
15342 .namespace = nspname,
15344 .description =
"ACL",
15346 .createStmt = sql->
data,
15378 const char *
namespace,
const char *owner,
15395 if (strcmp(
type,
"LARGE OBJECT") != 0)
15412 for (
i = 0;
i < nlabels;
i++)
15417 if (labels[
i].objsubid != subid)
15421 "SECURITY LABEL FOR %s ON %s ",
15423 if (
namespace && *
namespace)
15430 if (query->
len > 0)
15437 .namespace =
namespace,
15439 .description =
"SECURITY LABEL",
15441 .createStmt = query->
data,
15486 for (
i = 0;
i < nlabels;
i++)
15488 const char *colname;
15512 if (query->
len > 0)
15519 .namespace = tbinfo->
dobj.namespace->dobj.
name,
15521 .description =
"SECURITY LABEL",
15523 .createStmt = query->
data,
15557 while (low <= high)
15559 middle = low + (high - low) / 2;
15561 if (classoid < middle->classoid)
15563 else if (classoid > middle->
classoid)
15565 else if (objoid < middle->objoid)
15567 else if (objoid > middle->
objoid)
15585 while (middle > low)
15587 if (classoid != middle[-1].classoid ||
15588 objoid != middle[-1].objoid)
15597 while (middle <= high)
15599 if (classoid != middle->
classoid ||
15600 objoid != middle->
objoid)
15634 "SELECT label, provider, classoid, objoid, objsubid "
15635 "FROM pg_catalog.pg_seclabel "
15636 "ORDER BY classoid, objoid, objsubid");
15653 for (
i = 0;
i < ntups;
i++)
15663 if (dobj == NULL ||
15676 ((
TableInfo *) dobj)->relkind == RELKIND_COMPOSITE_TYPE)
15716 if (tbinfo->
relkind == RELKIND_SEQUENCE)
15726 const char *objtype =
15727 (tbinfo->
relkind == RELKIND_SEQUENCE) ?
"SEQUENCE" :
"TABLE";
15731 objtype, namecopy, NULL,
15732 tbinfo->
dobj.namespace->dobj.
name,
15752 "PREPARE getColumnACLs(pg_catalog.oid) AS\n");
15767 "SELECT at.attname, "
15769 "'{}' AS acldefault, "
15770 "pip.privtype, pip.initprivs "
15771 "FROM pg_catalog.pg_attribute at "
15772 "LEFT JOIN pg_catalog.pg_init_privs pip ON "
15773 "(at.attrelid = pip.objoid "
15774 "AND pip.classoid = 'pg_catalog.pg_class'::pg_catalog.regclass "
15775 "AND at.attnum = pip.objsubid) "
15776 "WHERE at.attrelid = $1 AND "
15777 "NOT at.attisdropped "
15778 "AND (at.attacl IS NOT NULL OR pip.initprivs IS NOT NULL) "
15779 "ORDER BY at.attnum");
15784 "SELECT attname, attacl, '{}' AS acldefault, "
15785 "NULL AS privtype, NULL AS initprivs "
15786 "FROM pg_catalog.pg_attribute "
15787 "WHERE attrelid = $1 AND NOT attisdropped "
15788 "AND attacl IS NOT NULL "
15789 "ORDER BY attnum");
15798 "EXECUTE getColumnACLs('%u')",
15813 coldacl.
acl = attacl;
15825 "TABLE", namecopy, attnamecopy,
15826 tbinfo->
dobj.namespace->dobj.
name,
15827 NULL, tbinfo->
rolname, &coldacl);
15853 "SELECT pg_catalog.pg_get_viewdef('%u'::pg_catalog.oid) AS viewdef",
15861 pg_fatal(
"query to obtain definition of view \"%s\" returned no data",
15864 pg_fatal(
"query to obtain definition of view \"%s\" returned more than one definition",
15871 pg_fatal(
"definition of view \"%s\" appears to be empty (length zero)",
15944 const char *reltypename;
15956 pg_log_warning(
"WITH OIDS is not supported anymore (table \"%s\")",
15963 if (tbinfo->
relkind == RELKIND_VIEW)
15971 reltypename =
"VIEW";
16002 char *partkeydef = NULL;
16003 char *ftoptions = NULL;
16004 char *srvname = NULL;
16005 const char *foreign =
"";
16013 case RELKIND_PARTITIONED_TABLE:
16018 reltypename =
"TABLE";
16022 "SELECT pg_get_partkeydef('%u')",
16030 case RELKIND_FOREIGN_TABLE:
16037 reltypename =
"FOREIGN TABLE";
16041 "SELECT fs.srvname, "
16042 "pg_catalog.array_to_string(ARRAY("
16043 "SELECT pg_catalog.quote_ident(option_name) || "
16044 "' ' || pg_catalog.quote_literal(option_value) "
16045 "FROM pg_catalog.pg_options_to_table(ftoptions) "
16046 "ORDER BY option_name"
16047 "), E',\n ') AS ftoptions "
16048 "FROM pg_catalog.pg_foreign_table ft "
16049 "JOIN pg_catalog.pg_foreign_server fs "
16050 "ON (fs.oid = ft.ftserver) "
16051 "WHERE ft.ftrelid = '%u'",
16061 foreign =
"FOREIGN ";
16064 case RELKIND_MATVIEW:
16065 reltypename =
"MATERIALIZED VIEW";
16068 reltypename =
"TABLE";
16087 tbinfo->
relkind != RELKIND_PARTITIONED_TABLE) ?
16101 if (tbinfo->
relkind != RELKIND_MATVIEW)
16115 bool print_default;
16116 bool print_notnull;
16122 print_default = (tbinfo->
attrdefs[
j] != NULL &&
16141 !print_default && !print_notnull &&
16146 if (actual_atts == 0)
16236 if (actual_atts == 0)
16267 for (k = 0; k < numParents; k++)
16278 if (tbinfo->
relkind == RELKIND_PARTITIONED_TABLE)
16281 if (tbinfo->
relkind == RELKIND_FOREIGN_TABLE)
16288 bool addcomma =
false;
16307 if (ftoptions && ftoptions[0])
16314 if (tbinfo->
relkind == RELKIND_MATVIEW)
16327 if (tbinfo->
relkind == RELKIND_MATVIEW)
16329 "pg_catalog.pg_class",
16330 "MATERIALIZED VIEW",
16345 "SELECT pg_catalog.binary_upgrade_set_missing_value(");
16378 (tbinfo->
relkind == RELKIND_RELATION ||
16379 tbinfo->
relkind == RELKIND_FOREIGN_TABLE ||
16380 tbinfo->
relkind == RELKIND_PARTITIONED_TABLE))
16383 bool firstitem_extra;
16400 "UPDATE pg_catalog.pg_attribute\n"
16401 "SET attlen = v.dlen, "
16402 "attalign = v.dalign, "
16403 "attbyval = false\n"
16416 foreign, qualrelname);
16424 "WHERE attrelid = ");
16427 " AND attname = v.dname;\n");
16446 "SET attislocal = false\n"
16447 "WHERE attrelid = ");
16450 " AND attname IN (");
16468 firstitem_extra =
true;
16489 "SET conislocal = false\n"
16490 "WHERE contype = 'n' AND conrelid = ");
16502 if (firstitem_extra)
16505 "SET conislocal = false\n"
16506 "WHERE contype = 'n' AND conrelid = ");
16510 firstitem_extra =
false;
16520 if (!firstitem_extra)
16523 if (extra->
len > 0)
16540 for (k = 0; k < tbinfo->
ncheck; k++)
16550 foreign, qualrelname,
16557 "SET conislocal = false\n"
16558 "WHERE contype = 'c' AND conrelid = ");
16577 for (k = 0; k < numParents; k++)
16605 (tbinfo->
relkind == RELKIND_RELATION ||
16606 tbinfo->
relkind == RELKIND_MATVIEW))
16610 "SET relfrozenxid = '%u', relminmxid = '%u'\n"
16622 appendPQExpBufferStr(q,
"\n-- For binary upgrade, set toast's relfrozenxid and relminmxid\n");
16624 "SET relfrozenxid = '%u', relminmxid = '%u'\n"
16625 "WHERE oid = '%u';\n",
16643 "SET relispopulated = 't'\n"
16671 "ALTER %sTABLE ONLY %s ALTER COLUMN %s SET NOT NULL;\n",
16672 foreign, qualrelname,
16676 "ALTER %sTABLE ONLY %s ADD CONSTRAINT %s NOT NULL %s;\n",
16677 foreign, qualrelname,
16688 appendPQExpBuffer(q,
"ALTER %sTABLE ONLY %s ALTER COLUMN %s SET STATISTICS %d;\n",
16689 foreign, qualrelname,
16701 case TYPSTORAGE_PLAIN:
16704 case TYPSTORAGE_EXTERNAL:
16707 case TYPSTORAGE_EXTENDED:
16710 case TYPSTORAGE_MAIN:
16721 appendPQExpBuffer(q,
"ALTER %sTABLE ONLY %s ALTER COLUMN %s SET STORAGE %s;\n",
16722 foreign, qualrelname,
16732 const char *cmname;
16747 if (cmname != NULL)
16748 appendPQExpBuffer(q,
"ALTER %sTABLE ONLY %s ALTER COLUMN %s SET COMPRESSION %s;\n",
16749 foreign, qualrelname,
16759 foreign, qualrelname,
16766 if (tbinfo->
relkind == RELKIND_FOREIGN_TABLE &&
16769 "ALTER FOREIGN TABLE ONLY %s ALTER COLUMN %s OPTIONS (\n"
16785 if ((tbinfo->
relkind == RELKIND_RELATION ||
16786 tbinfo->
relkind == RELKIND_PARTITIONED_TABLE ||
16787 tbinfo->
relkind == RELKIND_MATVIEW) &&
16794 else if (tbinfo->
relreplident == REPLICA_IDENTITY_NOTHING)
16799 else if (tbinfo->
relreplident == REPLICA_IDENTITY_FULL)
16812 reltypename, qrelname,
16813 tbinfo->
dobj.namespace->dobj.
name);
16818 char *tableam = NULL;
16827 if (RELKIND_HAS_TABLESPACE(tbinfo->
relkind))
16830 if (RELKIND_HAS_TABLE_AM(tbinfo->
relkind) ||
16831 tbinfo->
relkind == RELKIND_PARTITIONED_TABLE)
16832 tableam = tbinfo->
amname;
16836 .namespace = tbinfo->
dobj.namespace->dobj.
name,
16838 .tableam = tableam,
16841 .description = reltypename,
16844 .createStmt = q->
data,
16845 .dropStmt = delq->
data));
16908 "PREPARE dumpTableAttach(pg_catalog.oid) AS\n");
16911 "SELECT pg_get_expr(c.relpartbound, c.oid) "
16913 "WHERE c.oid = $1");
16921 "EXECUTE dumpTableAttach('%u')",
16929 "ALTER TABLE ONLY %s ",
16932 "ATTACH PARTITION %s %s;\n",
16945 .namespace = attachinfo->
dobj.namespace->dobj.
name,
16947 .description =
"TABLE ATTACH",
16949 .createStmt = q->
data));
16963 int adnum = adinfo->
adnum;
16983 foreign = tbinfo->
relkind == RELKIND_FOREIGN_TABLE ?
"FOREIGN " :
"";
16986 "ALTER %sTABLE ONLY %s ALTER COLUMN %s SET DEFAULT %s;\n",
16991 foreign, qualrelname,
16999 .
namespace = tbinfo->
dobj.namespace->dobj.
name,
17001 .description =
"DEFAULT",
17003 .createStmt = q->
data,
17004 .dropStmt = delq->
data));
17019 static const char *
17022 if (attrnum > 0 && attrnum <= tblInfo->numatts)
17023 return tblInfo->
attnames[attrnum - 1];
17039 pg_fatal(
"invalid column number %d for table \"%s\"",
17076 if (!is_constraint)
17080 char **indstatcolsarray = NULL;
17081 char **indstatvalsarray = NULL;
17112 if (strlen(indstatcols) != 0 || strlen(indstatvals) != 0)
17116 if (!
parsePGArray(indstatcols, &indstatcolsarray, &nstatcols))
17117 pg_fatal(
"could not parse index statistic columns");
17118 if (!
parsePGArray(indstatvals, &indstatvalsarray, &nstatvals))
17119 pg_fatal(
"could not parse index statistic values");
17120 if (nstatcols != nstatvals)
17121 pg_fatal(
"mismatched number of columns and values for index statistics");
17123 for (
j = 0;
j < nstatcols;
j++)
17132 indstatcolsarray[
j]);
17134 indstatvalsarray[
j]);
17140 "pg_catalog.pg_class",
17141 "INDEX", qqindxname);
17158 .namespace = tbinfo->
dobj.namespace->dobj.
name,
17161 .description =
"INDEX",
17163 .createStmt = q->
data,
17164 .dropStmt = delq->
data));
17166 free(indstatcolsarray);
17167 free(indstatvalsarray);
17173 tbinfo->
dobj.namespace->dobj.
name,
17214 .namespace = attachinfo->
dobj.namespace->dobj.
name,
17216 .description =
"INDEX ATTACH",
17218 .createStmt = q->
data));
17235 char *qstatsextname;
17250 "pg_catalog.pg_get_statisticsobjdef('%u'::pg_catalog.oid)",
17279 .namespace = statsextinfo->
dobj.namespace->dobj.
name,
17280 .owner = statsextinfo->
rolname,
17281 .description =
"STATISTICS",
17283 .createStmt = q->
data,
17284 .dropStmt = delq->
data));
17289 statsextinfo->
dobj.namespace->dobj.
name,
17298 free(qstatsextname);
17322 foreign = tbinfo &&
17323 tbinfo->
relkind == RELKIND_FOREIGN_TABLE ?
"FOREIGN " :
"";
17325 if (coninfo->
contype ==
'p' ||
17335 if (indxinfo == NULL)
17336 pg_fatal(
"missing index for constraint \"%s\"",
17356 coninfo->
contype ==
'p' ?
"PRIMARY KEY" :
"UNIQUE");
17369 int indkey = (int) indxinfo->
indkeys[k];
17377 (k == 0) ?
"" :
", ",
17386 for (k = indxinfo->
indnkeyattrs; k < indxinfo->indnattrs; k++)
17388 int indkey = (int) indxinfo->
indkeys[k];
17447 "pg_catalog.pg_class",
"INDEX",
17460 .
namespace = tbinfo->
dobj.namespace->dobj.
name,
17463 .description =
"CONSTRAINT",
17465 .createStmt = q->
data,
17466 .dropStmt = delq->
data));
17468 else if (coninfo->
contype ==
'f')
17478 only = tbinfo->
relkind == RELKIND_PARTITIONED_TABLE ?
"" :
"ONLY ";
17500 .
namespace = tbinfo->
dobj.namespace->dobj.
name,
17502 .description =
"FK CONSTRAINT",
17504 .createStmt = q->
data,
17505 .dropStmt = delq->
data));
17507 else if (coninfo->
contype ==
'c' && tbinfo)
17531 .
namespace = tbinfo->
dobj.namespace->dobj.
name,
17533 .description =
"CHECK CONSTRAINT",
17535 .createStmt = q->
data,
17536 .dropStmt = delq->
data));
17539 else if (coninfo->
contype ==
'c' && tbinfo == NULL)
17563 .
namespace = tyinfo->
dobj.namespace->dobj.
name,
17565 .description =
"CHECK CONSTRAINT",
17567 .createStmt = q->
data,
17568 .dropStmt = delq->
data));
17573 pg_fatal(
"unrecognized constraint type: %c",
17578 if (tbinfo && coninfo->
separate &&
17608 tbinfo->
dobj.namespace->dobj.
name,
17666 query =
"SELECT seqrelid, format_type(seqtypid, NULL), "
17667 "seqstart, seqincrement, "
17669 "seqcache, seqcycle, "
17671 "FROM pg_catalog.pg_sequence "
17672 "ORDER BY seqrelid";
17674 query =
"SELECT seqrelid, format_type(seqtypid, NULL), "
17675 "seqstart, seqincrement, "
17677 "seqcache, seqcycle, "
17678 "last_value, is_called "
17679 "FROM pg_catalog.pg_sequence, "
17680 "pg_get_sequence_data(seqrelid) "
17681 "ORDER BY seqrelid;";
17715 int64 default_minv,
17750 "SELECT 'bigint' AS sequence_type, "
17751 "start_value, increment_by, max_value, min_value, "
17752 "cache_value, is_cycled FROM %s",
17758 pg_fatal(
ngettext(
"query to get data of sequence \"%s\" returned %d row (expected 1)",
17759 "query to get data of sequence \"%s\" returned %d rows (expected 1)",
17776 is_ascending = (seq->
incby >= 0);
17795 default_minv = default_maxv = 0;
17828 "ALTER COLUMN %s ADD GENERATED ",
17844 "UNLOGGED" :
"LOGGED");
17849 "CREATE %sSEQUENCE %s\n",
17862 if (seq->
minv != default_minv)
17867 if (seq->
maxv != default_maxv)
17885 "SEQUENCE", qseqname,
17886 tbinfo->
dobj.namespace->dobj.
name);
17891 .namespace = tbinfo->
dobj.namespace->dobj.
name,
17893 .description =
"SEQUENCE",
17895 .createStmt = query->
data,
17896 .dropStmt = delqry->
data));
17914 if (owning_tab == NULL)
17915 pg_fatal(
"failed sanity check, parent table with OID %u of sequence with OID %u not found",
17931 .namespace = tbinfo->
dobj.namespace->dobj.
name,
17933 .description =
"SEQUENCE OWNED BY",
17935 .createStmt = query->
data,
17984 "SELECT last_value, is_called FROM %s",
17990 pg_fatal(
ngettext(
"query to get data of sequence \"%s\" returned %d row (expected 1)",
17991 "query to get data of sequence \"%s\" returned %d rows (expected 1)",
18020 last, (called ?
"true" :
"false"));
18025 .namespace = tbinfo->
dobj.namespace->dobj.
name,
18027 .description =
"SEQUENCE SET",
18029 .createStmt = query->
data,
18071 "pg_catalog.pg_trigger",
"TRIGGER",
18072 trigidentity->
data);
18087 tbinfo->
relkind == RELKIND_FOREIGN_TABLE ?
"FOREIGN " :
"",
18112 tbinfo->
relkind == RELKIND_FOREIGN_TABLE ?
"FOREIGN " :
"",
18142 .
namespace = tbinfo->
dobj.namespace->dobj.
name,
18144 .description =
"TRIGGER",
18146 .createStmt = query->
data,
18147 .dropStmt = delqry->
data));
18188 if (strcmp(
"", evtinfo->
evttags) != 0)
18226 "EVENT TRIGGER", qevtname, NULL);
18232 .description =
"EVENT TRIGGER",
18234 .createStmt = query->
data,
18235 .dropStmt = delqry->
data));
18317 "SELECT pg_catalog.pg_get_ruledef('%u'::pg_catalog.oid)",
18323 pg_fatal(
"query to get rule \"%s\" for table \"%s\" failed: wrong number of rows returned",
18386 .
namespace = tbinfo->
dobj.namespace->dobj.
name,
18388 .description =
"RULE",
18390 .createStmt = cmd->
data,
18391 .dropStmt = delcmd->
data));
18396 tbinfo->
dobj.namespace->dobj.
name,
18432 if (numExtensions == 0)
18439 "classid, objid, refobjid "
18441 "WHERE refclassid = 'pg_extension'::regclass "
18442 "AND deptype = 'e' "
18460 for (
i = 0;
i < ntups;
i++)
18476 pg_log_warning(
"could not find referenced extension %u", extId);
18524 if (numExtensions == 0)
18538 for (
i = 0;
i < numExtensions;
i++)
18543 char **extconfigarray = NULL;
18544 char **extconditionarray = NULL;
18545 int nconfigitems = 0;
18546 int nconditionitems = 0;
18566 if (strlen(extconfig) != 0 || strlen(extcondition) != 0)
18570 if (!
parsePGArray(extconfig, &extconfigarray, &nconfigitems))
18571 pg_fatal(
"could not parse %s array",
"extconfig");
18572 if (!
parsePGArray(extcondition, &extconditionarray, &nconditionitems))
18573 pg_fatal(
"could not parse %s array",
"extcondition");
18574 if (nconfigitems != nconditionitems)
18575 pg_fatal(
"mismatched number of configurations and conditions for extension");
18577 for (
j = 0;
j < nconfigitems;
j++)
18580 Oid configtbloid =
atooid(extconfigarray[
j]);
18585 if (configtbl == NULL)
18601 if (configtbl->
dobj.namespace->dobj.
dump &
18620 if (configtbl->
dataObj != NULL)
18622 if (strlen(extconditionarray[
j]) > 0)
18628 if (extconfigarray)
18629 free(extconfigarray);
18630 if (extconditionarray)
18631 free(extconditionarray);
18646 "SELECT conrelid, confrelid "
18647 "FROM pg_constraint "
18648 "JOIN pg_depend ON (objid = confrelid) "
18649 "WHERE contype = 'f' "
18650 "AND refclassid = 'pg_extension'::regclass "
18651 "AND classid = 'pg_class'::regclass;");
18660 for (
i = 0;
i < ntups;
i++)
18672 if (reftable == NULL ||
18674 contable == NULL ||
18720 "classid, objid, refclassid, refobjid, deptype "
18722 "WHERE deptype != 'p' AND deptype != 'e'\n");
18735 "SELECT 'pg_opfamily'::regclass AS classid, amopfamily AS objid, refclassid, refobjid, deptype "
18736 "FROM pg_depend d, pg_amop o "
18737 "WHERE deptype NOT IN ('p', 'e', 'i') AND "
18738 "classid = 'pg_amop'::regclass AND objid = o.oid "
18739 "AND NOT (refclassid = 'pg_opfamily'::regclass AND amopfamily = refobjid)\n");
18743 "SELECT 'pg_opfamily'::regclass AS classid, amprocfamily AS objid, refclassid, refobjid, deptype "
18744 "FROM pg_depend d, pg_amproc p "
18745 "WHERE deptype NOT IN ('p', 'e', 'i') AND "
18746 "classid = 'pg_amproc'::regclass AND objid = p.oid "
18747 "AND NOT (refclassid = 'pg_opfamily'::regclass AND amprocfamily = refobjid)\n");
18769 for (
i = 0;
i < ntups;
i++)
18781 if (dobj == NULL ||
18801 if (refdobj == NULL)
18816 if (deptype ==
'x')
18826 if (deptype ==
'i' &&
18877 for (
i = 0;
i < numObjs;
i++)
18941 if (((
RuleInfo *) dobj)->separate)
19010 if (dobj->
nDeps <= 0)
19018 &dependencies, &nDeps, &allocDeps);
19023 nDeps *
sizeof(
DumpId));
19028 free(dependencies);
19035 DumpId **dependencies,
int *nDeps,
int *allocDeps)
19054 if (*nDeps >= *allocDeps)
19058 *allocDeps *
sizeof(
DumpId));
19060 (*dependencies)[*nDeps] = depid;
19074 dependencies, nDeps, allocDeps);
19089 static const char *
19107 if (typeInfo && typeInfo->
ftypname)
19111 appendPQExpBuffer(query,
"SELECT pg_catalog.format_type('%u'::pg_catalog.oid, NULL)",
19140 static const char *
19152 for (
i = 0;
i < numatts;
i++)
19154 if (attisdropped[
i])
19156 if (attgenerated[
i])
19168 return buffer->
data;
19178 return (reloptions != NULL && strlen(reloptions) > 2);
19188 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 strtoi64(str, endptr, base)
#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 const char * p2
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
static int pg_cmp_u32(uint32 a, uint32 b)
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)
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 void collectBinaryUpgradeClassOids(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 int nbinaryUpgradeClassOids
static void dumpBaseType(Archive *fout, const TypeInfo *tyinfo)
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 int SequenceItemCmp(const void *p1, const void *p2)
static void dumpTableComment(Archive *fout, const TableInfo *tbinfo, const char *reltypename)
static SimpleStringList extension_include_patterns
static void selectDumpableNamespace(NamespaceInfo *nsinfo, Archive *fout)
void getForeignDataWrappers(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)
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)
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)
static void help(const char *progname)
void getTypes(Archive *fout)
static void dumpAccessMethod(Archive *fout, const AccessMethodInfo *aminfo)
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)
static const char *const SeqTypeNames[]
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)
void getOpclasses(Archive *fout)
void getForeignServers(Archive *fout)
void getFuncs(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)
void getTSDictionaries(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 SeqType parse_sequence_type(const char *name)
static const char * getRoleName(const char *roleoid_str)
static void dumpShellType(Archive *fout, const ShellTypeInfo *stinfo)
static SequenceItem * sequences
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)
void getCasts(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)
void getTSConfigurations(Archive *fout)
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)
StaticAssertDecl(lengthof(SeqTypeNames)==(SEQTYPE_BIGINT+1), "array length mismatch")
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
void getAccessMethods(Archive *fout)
void getConversions(Archive *fout)
void getRules(Archive *fout)
InhInfo * getInherits(Archive *fout, int *numInherits)
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)
static void determineNotNullFlags(Archive *fout, PGresult *res, int r, TableInfo *tbinfo, int j, int i_notnull_name, int i_notnull_noinherit, int i_notnull_islocal)
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)
void getCollations(Archive *fout)
static char * format_function_arguments(const FuncInfo *finfo, const char *funcargs, bool is_agg)
static void dumpTransform(Archive *fout, const TransformInfo *transform)
void getAggregates(Archive *fout)
static void dumpLO(Archive *fout, const LoInfo *loinfo)
void getNamespaces(Archive *fout)
static void dumpPublicationTable(Archive *fout, const PublicationRelInfo *pubrinfo)
void getPublications(Archive *fout)
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)
void getTSParsers(Archive *fout)
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)
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)
static void dumpRule(Archive *fout, const RuleInfo *rinfo)
static void dumpCompositeType(Archive *fout, const TypeInfo *tyinfo)
static void dumpEnumType(Archive *fout, const TypeInfo *tyinfo)
static void dumpExtension(Archive *fout, const ExtensionInfo *extinfo)
#define fmtQualifiedDumpable(obj)
static bool nonemptyReloptions(const char *reloptions)
static SimpleStringList extension_exclude_patterns
static BinaryUpgradeClassOidItem * binaryUpgradeClassOids
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 int BinaryUpgradeClassOidItemCmp(const void *p1, const void *p2)
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)
void getDefaultACLs(Archive *fout)
static SimpleStringList tabledata_exclude_patterns
static void dumpConversion(Archive *fout, const ConvInfo *convinfo)
static void dumpForeignDataWrapper(Archive *fout, const FdwInfo *fdwinfo)
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 void collectSequences(Archive *fout)
static Oid g_last_builtin_oid
ExtensionInfo * getExtensions(Archive *fout, int *numExtensions)
void getTriggers(Archive *fout, TableInfo tblinfo[], int numTables)
void getTransforms(Archive *fout)
void getEventTriggers(Archive *fout)
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)
static SecLabelItem * seclabels
static SimpleStringList tabledata_exclude_patterns_and_children
static bool checkExtensionMembership(DumpableObject *dobj, Archive *fout)
static CommentItem * comments
static int dumpTableData_insert(Archive *fout, const void *dcontext)
static SimpleOidList tabledata_exclude_oids
static SimpleStringList table_exclude_patterns_and_children
TableInfo * getTables(Archive *fout, int *numTables)
static void binary_upgrade_set_pg_class_oids(Archive *fout, PQExpBuffer upgrade_buffer, Oid pg_class_oid)
void getTSTemplates(Archive *fout)
static void set_restrict_relation_kind(Archive *AH, const char *value)
void getProcLangs(Archive *fout)
static void dumpSequence(Archive *fout, const TableInfo *tbinfo)
bool shouldPrintColumn(const DumpOptions *dopt, const TableInfo *tbinfo, int colno)
static TableInfo * getRootTableInfo(const TableInfo *tbinfo)
void getOperators(Archive *fout)
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)
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)
void getOpfamilies(Archive *fout)
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)
RelFileNumber toast_index_relfilenumber
RelFileNumber toast_relfilenumber
RelFileNumber relfilenumber
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)