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_constraint_d.h"
51#include "catalog/pg_default_acl_d.h"
52#include "catalog/pg_largeobject_d.h"
53#include "catalog/pg_largeobject_metadata_d.h"
54#include "catalog/pg_proc_d.h"
55#include "catalog/pg_publication_d.h"
56#include "catalog/pg_shdepend_d.h"
57#include "catalog/pg_subscription_d.h"
58#include "catalog/pg_type_d.h"
127 "array length mismatch");
218#define MAX_ATTR_STATS_RELS 64
224#define DUMP_DEFAULT_ROWS_PER_INSERT 1
231#define MAX_BLOBS_PER_ARCHIVE_ENTRY 1000
236#define fmtQualifiedDumpable(obj) \
237 fmtQualifiedId((obj)->dobj.namespace->dobj.name, \
262 const char *pattern);
271 const char *
name,
const char *
namespace,
276 const char *
name,
const char *
namespace,
278 int subid,
DumpId dumpId);
282 const char *
namespace,
const char *owner,
333 const char *servername,
const char *
namespace,
339 const char *nspname,
const char *tag,
const char *owner,
345 DumpId **dependencies,
int *nDeps,
int *allocDeps);
435 char *use_role =
NULL;
469 {
"jobs", 1,
NULL,
'j'},
556 if (
strcmp(argv[1],
"--help") == 0 ||
strcmp(argv[1],
"-?") == 0)
561 if (
strcmp(argv[1],
"--version") == 0 ||
strcmp(argv[1],
"-V") == 0)
570 while ((
c =
getopt_long(argc, argv,
"abBcCd:e:E:f:F:h:j:n:N:Op:RsS:t:T:U:vwWxXZ:",
819 pg_log_error(
"too many command-line arguments (first is \"%s\")",
856 pg_fatal(
"option %s is not supported with parallel backup",
857 "--include-foreign-data");
864 pg_fatal(
"option %s requires option %s",
865 "--if-exists",
"-c/--clean");
885 pg_fatal(
"option %s requires option %s, %s, or %s",
886 "--on-conflict-do-nothing",
887 "--inserts",
"--rows-per-insert",
"--column-inserts");
903 pg_fatal(
"could not generate restrict key");
908 pg_fatal(
"option %s can only be used with %s",
909 "--restrict-key",
"--format=plain");
931 pg_fatal(
"unrecognized compression algorithm: \"%s\"",
938 pg_fatal(
"invalid compression specification: %s",
951 pg_log_warning(
"compression option \"%s\" is not currently supported by pg_dump",
963 pg_fatal(
"parallel backup only supported by the directory format");
983 fout->minRemoteVersion = 100000;
986 fout->numWorkers = numWorkers;
1018 pg_fatal(
"no matching schemas were found");
1035 pg_fatal(
"no matching tables were found");
1063 pg_fatal(
"no matching extensions were found");
1120 shdepend->dataObj->filtercond =
"WHERE classid = 'pg_largeobject'::regclass "
1121 "AND dbid = (SELECT oid FROM pg_database "
1122 " WHERE datname = current_database())";
1131 if (
fout->remoteVersion < 160000)
1293 printf(
_(
"%s exports a PostgreSQL database as an SQL script or to other formats.\n\n"),
progname);
1297 printf(
_(
"\nGeneral options:\n"));
1298 printf(
_(
" -f, --file=FILENAME output file or directory name\n"));
1299 printf(
_(
" -F, --format=c|d|t|p output file format (custom, directory, tar,\n"
1300 " plain text (default))\n"));
1301 printf(
_(
" -j, --jobs=NUM use this many parallel jobs to dump\n"));
1302 printf(
_(
" -v, --verbose verbose mode\n"));
1303 printf(
_(
" -V, --version output version information, then exit\n"));
1304 printf(
_(
" -Z, --compress=METHOD[:DETAIL]\n"
1305 " compress as specified\n"));
1306 printf(
_(
" --lock-wait-timeout=TIMEOUT fail after waiting TIMEOUT for a table lock\n"));
1307 printf(
_(
" --no-sync do not wait for changes to be written safely to disk\n"));
1308 printf(
_(
" --sync-method=METHOD set method for syncing files to disk\n"));
1309 printf(
_(
" -?, --help show this help, then exit\n"));
1311 printf(
_(
"\nOptions controlling the output content:\n"));
1312 printf(
_(
" -a, --data-only dump only the data, not the schema or statistics\n"));
1313 printf(
_(
" -b, --large-objects include large objects in dump\n"));
1314 printf(
_(
" --blobs (same as --large-objects, deprecated)\n"));
1315 printf(
_(
" -B, --no-large-objects exclude large objects in dump\n"));
1316 printf(
_(
" --no-blobs (same as --no-large-objects, deprecated)\n"));
1317 printf(
_(
" -c, --clean clean (drop) database objects before recreating\n"));
1318 printf(
_(
" -C, --create include commands to create database in dump\n"));
1319 printf(
_(
" -e, --extension=PATTERN dump the specified extension(s) only\n"));
1320 printf(
_(
" -E, --encoding=ENCODING dump the data in encoding ENCODING\n"));
1321 printf(
_(
" -n, --schema=PATTERN dump the specified schema(s) only\n"));
1322 printf(
_(
" -N, --exclude-schema=PATTERN do NOT dump the specified schema(s)\n"));
1323 printf(
_(
" -O, --no-owner skip restoration of object ownership in\n"
1324 " plain-text format\n"));
1325 printf(
_(
" -s, --schema-only dump only the schema, no data or statistics\n"));
1326 printf(
_(
" -S, --superuser=NAME superuser user name to use in plain-text format\n"));
1327 printf(
_(
" -t, --table=PATTERN dump only the specified table(s)\n"));
1328 printf(
_(
" -T, --exclude-table=PATTERN do NOT dump the specified table(s)\n"));
1329 printf(
_(
" -x, --no-privileges do not dump privileges (grant/revoke)\n"));
1330 printf(
_(
" --binary-upgrade for use by upgrade utilities only\n"));
1331 printf(
_(
" --column-inserts dump data as INSERT commands with column names\n"));
1332 printf(
_(
" --disable-dollar-quoting disable dollar quoting, use SQL standard quoting\n"));
1333 printf(
_(
" --disable-triggers disable triggers during data-only restore\n"));
1334 printf(
_(
" --enable-row-security enable row security (dump only content user has\n"
1336 printf(
_(
" --exclude-extension=PATTERN do NOT dump the specified extension(s)\n"));
1337 printf(
_(
" --exclude-table-and-children=PATTERN\n"
1338 " do NOT dump the specified table(s), including\n"
1339 " child and partition tables\n"));
1340 printf(
_(
" --exclude-table-data=PATTERN do NOT dump data for the specified table(s)\n"));
1341 printf(
_(
" --exclude-table-data-and-children=PATTERN\n"
1342 " do NOT dump data for the specified table(s),\n"
1343 " including child and partition tables\n"));
1344 printf(
_(
" --extra-float-digits=NUM override default setting for extra_float_digits\n"));
1345 printf(
_(
" --filter=FILENAME include or exclude objects and data from dump\n"
1346 " based on expressions in FILENAME\n"));
1347 printf(
_(
" --if-exists use IF EXISTS when dropping objects\n"));
1348 printf(
_(
" --include-foreign-data=PATTERN\n"
1349 " include data of foreign tables on foreign\n"
1350 " servers matching PATTERN\n"));
1351 printf(
_(
" --inserts dump data as INSERT commands, rather than COPY\n"));
1352 printf(
_(
" --load-via-partition-root load partitions via the root table\n"));
1353 printf(
_(
" --no-comments do not dump comment commands\n"));
1354 printf(
_(
" --no-data do not dump data\n"));
1355 printf(
_(
" --no-policies do not dump row security policies\n"));
1356 printf(
_(
" --no-publications do not dump publications\n"));
1357 printf(
_(
" --no-schema do not dump schema\n"));
1358 printf(
_(
" --no-security-labels do not dump security label assignments\n"));
1359 printf(
_(
" --no-statistics do not dump statistics\n"));
1360 printf(
_(
" --no-subscriptions do not dump subscriptions\n"));
1361 printf(
_(
" --no-table-access-method do not dump table access methods\n"));
1362 printf(
_(
" --no-tablespaces do not dump tablespace assignments\n"));
1363 printf(
_(
" --no-toast-compression do not dump TOAST compression methods\n"));
1364 printf(
_(
" --no-unlogged-table-data do not dump unlogged table data\n"));
1365 printf(
_(
" --on-conflict-do-nothing add ON CONFLICT DO NOTHING to INSERT commands\n"));
1366 printf(
_(
" --quote-all-identifiers quote all identifiers, even if not key words\n"));
1367 printf(
_(
" --restrict-key=RESTRICT_KEY use provided string as psql \\restrict key\n"));
1368 printf(
_(
" --rows-per-insert=NROWS number of rows per INSERT; implies --inserts\n"));
1369 printf(
_(
" --section=SECTION dump named section (pre-data, data, or post-data)\n"));
1370 printf(
_(
" --sequence-data include sequence data in dump\n"));
1371 printf(
_(
" --serializable-deferrable wait until the dump can run without anomalies\n"));
1372 printf(
_(
" --snapshot=SNAPSHOT use given snapshot for the dump\n"));
1373 printf(
_(
" --statistics dump the statistics\n"));
1374 printf(
_(
" --statistics-only dump only the statistics, not schema or data\n"));
1375 printf(
_(
" --strict-names require table and/or schema include patterns to\n"
1376 " match at least one entity each\n"));
1377 printf(
_(
" --table-and-children=PATTERN dump only the specified table(s), including\n"
1378 " child and partition tables\n"));
1379 printf(
_(
" --use-set-session-authorization\n"
1380 " use SET SESSION AUTHORIZATION commands instead of\n"
1381 " ALTER OWNER commands to set ownership\n"));
1383 printf(
_(
"\nConnection options:\n"));
1384 printf(
_(
" -d, --dbname=DBNAME database to dump\n"));
1385 printf(
_(
" -h, --host=HOSTNAME database server host or socket directory\n"));
1386 printf(
_(
" -p, --port=PORT database server port number\n"));
1387 printf(
_(
" -U, --username=NAME connect as specified database user\n"));
1388 printf(
_(
" -w, --no-password never prompt for password\n"));
1389 printf(
_(
" -W, --password force password prompt (should happen automatically)\n"));
1390 printf(
_(
" --role=ROLENAME do SET ROLE before dump\n"));
1392 printf(
_(
"\nIf no database name is supplied, then the PGDATABASE environment\n"
1393 "variable value is used.\n\n"));
1413 pg_fatal(
"invalid client encoding \"%s\" specified",
1541 "SET TRANSACTION ISOLATION LEVEL "
1542 "SERIALIZABLE, READ ONLY, DEFERRABLE");
1545 "SET TRANSACTION ISOLATION LEVEL "
1546 "REPEATABLE READ, READ ONLY");
1588 char *query =
"SELECT pg_catalog.pg_export_snapshot()";
1664 "SELECT oid FROM pg_catalog.pg_namespace n\n");
1670 pg_fatal(
"improper qualified name (too many dotted names): %s",
1678 pg_fatal(
"no matching schemas were found for pattern \"%s\"", cell->
val);
1721 "SELECT oid FROM pg_catalog.pg_extension e\n");
1726 pg_fatal(
"improper qualified name (too many dotted names): %s",
1731 pg_fatal(
"no matching extensions were found for pattern \"%s\"", cell->
val);
1774 "SELECT oid FROM pg_catalog.pg_foreign_server s\n");
1779 pg_fatal(
"improper qualified name (too many dotted names): %s",
1784 pg_fatal(
"no matching foreign servers were found for pattern \"%s\"", cell->
val);
1841 "\nFROM pg_catalog.pg_class c"
1842 "\n LEFT JOIN pg_catalog.pg_namespace n"
1843 "\n ON n.oid OPERATOR(pg_catalog.=) c.relnamespace"
1844 "\nWHERE c.relkind OPERATOR(pg_catalog.=) ANY"
1845 "\n (array['%c', '%c', '%c', '%c', '%c', '%c', '%c'])\n",
1851 false,
"n.nspname",
"c.relname",
NULL,
1852 "pg_catalog.pg_table_is_visible(c.oid)", &
dbbuf,
1855 pg_fatal(
"improper relation name (too many dotted names): %s",
1864 "\nSELECT i.inhrelid"
1865 "\nFROM partition_tree p"
1866 "\n JOIN pg_catalog.pg_inherits i"
1867 "\n ON p.relid OPERATOR(pg_catalog.=) i.inhparent"
1869 "\nSELECT relid FROM partition_tree");
1877 pg_fatal(
"no matching tables were found for pattern \"%s\"", cell->
val);
1904 pg_fatal(
"You are currently not connected to a database.");
1907 pg_fatal(
"cross-database references are not implemented: %s",
1952 if (
fout->dopt->binary_upgrade)
1984 nsinfo->dobj.catId.oid) ?
2030 if (
nsinfo->dobj.dump_contains &&
2061 tbinfo->dobj.catId.oid) ?
2064 tbinfo->dobj.dump =
tbinfo->dobj.namespace->dobj.dump_contains;
2122 tyinfo->dobj.dump =
tyinfo->dobj.namespace->dobj.dump_contains;
2138 if (
dinfo->dobj.namespace)
2140 dinfo->dobj.dump =
dinfo->dobj.namespace->dobj.dump_contains;
2168 cast->dobj.dump =
fout->dopt->include_everything ?
2193 if (!
fout->dopt->include_everything)
2285 dobj->
dump =
fout->dopt->include_everything ?
2303 sobj->dobj.dump =
sobj->dobj.namespace->dobj.dump_contains;
2325 if (dobj->namespace)
2328 dobj->
dump =
fout->dopt->include_everything ?
2356 pg_log_info(
"dumping contents of table \"%s.%s\"",
2357 tbinfo->dobj.namespace->dobj.name, classname);
2374 (
fout->dopt->binary_upgrade &&
fout->remoteVersion < 120000 &&
2469 pg_log_error(
"Dumping the contents of table \"%s\" failed: PQgetCopyData() failed.", classname);
2479 pg_log_error(
"Dumping the contents of table \"%s\" failed: PQgetResult() failed.", classname);
2488 pg_log_warning(
"unexpected extra results during COPY of table \"%s\"",
2549 attgenerated[nfields] =
tbinfo->attgenerated[
i];
2570 pg_fatal(
"wrong number of fields retrieved from table \"%s\"",
2591 if (
tbinfo->ispartition &&
2612 for (
int field = 0; field < nfields; field++)
2622 if (
tbinfo->needs_override)
2629 for (
int tuple = 0; tuple <
PQntuples(res); tuple++)
2655 for (
int field = 0; field < nfields; field++)
2659 if (attgenerated[field])
2692 const char *s =
PQgetvalue(res, tuple, field);
2851 if (
tbinfo->ispartition &&
2898 .namespace =
tbinfo->dobj.namespace->dobj.name,
2899 .owner =
tbinfo->rolname,
2900 .description =
"TABLE DATA",
2903 .copyStmt = copyStmt,
2904 .deps = &(
tbinfo->dobj.dumpId),
2952 if (!
tbinfo->relispopulated)
2965 .namespace =
tbinfo->dobj.namespace->dobj.name,
2966 .owner =
tbinfo->rolname,
2967 .description =
"MATERIALIZED VIEW DATA",
2969 .createStmt = q->
data,
2970 .deps =
tdinfo->dobj.dependencies,
2971 .nDeps =
tdinfo->dobj.nDeps));
2988 (!relkind || tblinfo[
i].
relkind == relkind))
3021 tbinfo->foreign_server)))
3051 tdinfo->dobj.catId.tableoid = 0;
3079 tbinfo->interesting =
true;
3104 "SELECT d1.objid, d2.refobjid, c2.relkind AS refrelkind "
3105 "FROM pg_depend d1 "
3106 "JOIN pg_class c1 ON c1.oid = d1.objid "
3108 " JOIN pg_rewrite r1 ON r1.ev_class = d1.objid "
3109 "JOIN pg_depend d2 ON d2.classid = 'pg_rewrite'::regclass "
3110 "AND d2.objid = r1.oid "
3111 "AND d2.refobjid <> d1.objid "
3112 "JOIN pg_class c2 ON c2.oid = d2.refobjid "
3115 "WHERE d1.classid = 'pg_class'::regclass "
3117 "SELECT w.objid, d3.refobjid, c3.relkind "
3119 "JOIN pg_rewrite r3 ON r3.ev_class = w.refobjid "
3120 "JOIN pg_depend d3 ON d3.classid = 'pg_rewrite'::regclass "
3121 "AND d3.objid = r3.oid "
3122 "AND d3.refobjid <> w.refobjid "
3123 "JOIN pg_class c3 ON c3.oid = d3.refobjid "
3127 "SELECT 'pg_class'::regclass::oid AS classid, objid, refobjid "
3139 for (
i = 0;
i < ntups;
i++)
3180 tbinfo->relispopulated =
false;
3230 ftable->dataObj->dobj.dumpId);
3294 "pg_encoding_to_char(encoding) AS encoding, "
3295 "datcollate, datctype, datfrozenxid, "
3296 "datacl, acldefault('d', datdba) AS acldefault, "
3297 "datistemplate, datconnlimit, ");
3299 if (
fout->remoteVersion >= 170000)
3301 else if (
fout->remoteVersion >= 150000)
3305 if (
fout->remoteVersion >= 160000)
3310 "(SELECT spcname FROM pg_tablespace t WHERE t.oid = dattablespace) AS tablespace, "
3311 "shobj_description(oid, 'pg_database') AS description "
3313 "WHERE datname = current_database()");
3376 "CREATE DATABASE %s WITH TEMPLATE = template0 "
3377 "OID = %u STRATEGY = FILE_COPY",
3399 pg_fatal(
"unrecognized locale provider: %s",
3402 if (
strlen(collate) > 0 &&
strcmp(collate, ctype) == 0)
3478 .dropStmt =
delQry->data));
3507 .description =
"COMMENT",
3509 .createStmt =
dbQry->data,
3531 .description =
"SECURITY LABEL",
3579 "SET datistemplate = false WHERE datname = ");
3600 "SET datfrozenxid = '%u', datminmxid = '%u'\n"
3602 frozenxid, minmxid);
3614 .dropStmt =
delQry->data,
3641 "FROM pg_catalog.pg_class\n"
3642 "WHERE oid IN (%u, %u, %u, %u);\n",
3680 "SET relfrozenxid = '%u', relminmxid = '%u'\n"
3681 "WHERE oid = %u;\n",
3689 "SELECT pg_catalog.binary_upgrade_set_next_heap_relfilenode('%u'::pg_catalog.oid);\n",
3694 "SELECT pg_catalog.binary_upgrade_set_next_index_relfilenode('%u'::pg_catalog.oid);\n",
3699 "TRUNCATE pg_catalog.pg_largeobject;\n");
3701 "TRUNCATE pg_catalog.pg_largeobject_metadata;\n");
3712 if (
fout->remoteVersion >= 160000)
3751 "WHERE setrole = 0 AND setdatabase = '%u'::oid",
3765 "FROM pg_db_role_setting s, pg_roles r "
3766 "WHERE setrole = r.oid AND setdatabase = '%u'::oid",
3801 .createStmt = qry->
data));
3816 pg_log_info(
"saving \"standard_conforming_strings = %s\"",
3826 .createStmt = qry->
data));
3852 "SELECT pg_catalog.current_schemas(false)");
3855 pg_fatal(
"could not parse result of current_schemas()");
3880 .createStmt = qry->
data));
3917 "SELECT oid, lomowner, lomacl, "
3918 "acldefault('L', lomowner) AS acldefault "
3919 "FROM pg_largeobject_metadata ");
3931 "(SELECT objoid FROM pg_description "
3933 "UNION SELECT objoid FROM pg_seclabel "
3937 "ORDER BY lomowner, lomacl::pg_catalog.text, oid");
3956 for (
i = 0;
i < ntups;
i += n)
3991 loinfo->dacl.privtype = 0;
3997 for (
int k = 1; k < n; k++)
4059 for (
int i = 0;
i <
loinfo->numlos;
i++)
4065 .owner =
loinfo->rolname,
4066 .description =
"BLOB METADATA",
4068 .createStmt =
cquery->data,
4069 .dropStmt =
"-- dummy"));
4078 for (
int i = 0;
i <
loinfo->numlos;
i++)
4091 catId, 0,
loinfo->dobj.dumpId);
4096 catId, 0,
loinfo->dobj.dumpId);
4149 for (
int i = 0;
i <
loinfo->numlos;
i++)
4158 pg_fatal(
"could not open large object %u: %s",
4168 pg_fatal(
"error reading large object %u: %s",
4250 polinfo->dobj.catId.tableoid = 0;
4272 pg_log_info(
"reading row-level security policies");
4275 "SELECT pol.oid, pol.tableoid, pol.polrelid, pol.polname, pol.polcmd, ");
4278 "CASE WHEN pol.polroles = '{0}' THEN NULL ELSE "
4279 " 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, "
4280 "pg_catalog.pg_get_expr(pol.polqual, pol.polrelid) AS polqual, "
4281 "pg_catalog.pg_get_expr(pol.polwithcheck, pol.polrelid) AS polwithcheck "
4282 "FROM unnest('%s'::pg_catalog.oid[]) AS src(tbloid)\n"
4283 "JOIN pg_catalog.pg_policy pol ON (src.tbloid = pol.polrelid)",
4303 for (
j = 0;
j < ntups;
j++)
4387 .namespace =
polinfo->dobj.namespace->dobj.name,
4388 .owner =
tbinfo->rolname,
4389 .description =
"ROW SECURITY",
4391 .createStmt = query->
data,
4392 .deps = &(
tbinfo->dobj.dumpId),
4401 else if (
polinfo->polcmd ==
'r')
4402 cmd =
" FOR SELECT";
4403 else if (
polinfo->polcmd ==
'a')
4404 cmd =
" FOR INSERT";
4405 else if (
polinfo->polcmd ==
'w')
4406 cmd =
" FOR UPDATE";
4407 else if (
polinfo->polcmd ==
'd')
4408 cmd =
" FOR DELETE";
4410 pg_fatal(
"unexpected policy command type: %c",
4422 !
polinfo->polpermissive ?
" AS RESTRICTIVE" :
"", cmd);
4446 .
namespace =
polinfo->dobj.namespace->dobj.name,
4447 .owner =
tbinfo->rolname,
4448 .description =
"POLICY",
4450 .createStmt = query->
data,
4451 .dropStmt =
delqry->data));
4498 "p.pubowner, p.puballtables, p.pubinsert, "
4499 "p.pubupdate, p.pubdelete, ");
4501 if (
fout->remoteVersion >= 110000)
4506 if (
fout->remoteVersion >= 130000)
4511 if (
fout->remoteVersion >= 180000)
4516 if (
fout->remoteVersion >= 190000)
4545 for (
i = 0;
i < ntups;
i++)
4592 if (
fout->remoteVersion >= 190000)
4600 "FROM pg_catalog.pg_publication_rel\n"
4601 "WHERE prpubid = %u AND prexcept",
4682 else if (
pubinfo->puballsequences)
4733 .description =
"PUBLICATION",
4735 .createStmt = query->
data,
4736 .dropStmt =
delq->data));
4779 "SELECT tableoid, oid, pnpubid, pnnspid "
4780 "FROM pg_catalog.pg_publication_namespace");
4794 for (
i = 0;
i < ntups;
i++)
4860 if (
fout->remoteVersion >= 150000)
4863 "SELECT tableoid, oid, prpubid, prrelid, "
4864 "pg_catalog.pg_get_expr(prqual, prrelid) AS prrelqual, "
4866 " WHEN pr.prattrs IS NOT NULL THEN\n"
4867 " (SELECT array_agg(attname)\n"
4869 " pg_catalog.generate_series(0, pg_catalog.array_upper(pr.prattrs::pg_catalog.int2[], 1)) s,\n"
4870 " pg_catalog.pg_attribute\n"
4871 " WHERE attrelid = pr.prrelid AND attnum = prattrs[s])\n"
4872 " ELSE NULL END) prattrs "
4873 "FROM pg_catalog.pg_publication_rel pr");
4874 if (
fout->remoteVersion >= 190000)
4879 "SELECT tableoid, oid, prpubid, prrelid, "
4880 "NULL AS prrelqual, NULL AS prattrs "
4881 "FROM pg_catalog.pg_publication_rel");
4897 for (
i = 0;
i < ntups;
i++)
4938 pg_fatal(
"could not parse %s array",
"prattrs");
4997 .description =
"PUBLICATION TABLES IN SCHEMA",
4999 .createStmt = query->
data));
5057 .
namespace =
tbinfo->dobj.namespace->dobj.name,
5059 .description =
"PUBLICATION TABLE",
5061 .createStmt = query->
data));
5098 "SELECT set_config(name, '%s', false) "
5100 "WHERE name = 'restrict_nonsystem_relation_kind'",
5152 "SELECT count(*) FROM pg_subscription "
5153 "WHERE subdbid = (SELECT oid FROM pg_database"
5154 " WHERE datname = current_database())",
5158 pg_log_warning(
"subscriptions not dumped because current user is not a superuser");
5167 "SELECT s.tableoid, s.oid, s.subname,\n"
5169 " s.subconninfo, s.subslotname, s.subsynccommit,\n"
5170 " s.subpublications,\n");
5172 if (
fout->remoteVersion >= 140000)
5177 if (
fout->remoteVersion >= 140000)
5182 if (
fout->remoteVersion >= 150000)
5184 " s.subtwophasestate,\n"
5185 " s.subdisableonerr,\n");
5188 " '%c' AS subtwophasestate,\n"
5189 " false AS subdisableonerr,\n",
5192 if (
fout->remoteVersion >= 160000)
5194 " s.subpasswordrequired,\n"
5195 " s.subrunasowner,\n"
5199 " 't' AS subpasswordrequired,\n"
5200 " 't' AS subrunasowner,\n"
5201 " '%s' AS suborigin,\n",
5206 " s.subenabled,\n");
5209 " false AS subenabled,\n");
5211 if (
fout->remoteVersion >= 170000)
5213 " s.subfailover,\n");
5216 " false AS subfailover,\n");
5218 if (
fout->remoteVersion >= 190000)
5220 " s.subretaindeadtuples,\n");
5223 " false AS subretaindeadtuples,\n");
5225 if (
fout->remoteVersion >= 190000)
5227 " s.submaxretention,\n");
5231 if (
fout->remoteVersion >= 190000)
5233 " s.subwalrcvtimeout,\n");
5236 " '-1' AS subwalrcvtimeout,\n");
5238 if (
fout->remoteVersion >= 190000)
5244 "FROM pg_subscription s\n");
5246 if (
fout->remoteVersion >= 190000)
5248 "LEFT JOIN pg_catalog.pg_foreign_server fs \n"
5249 " ON fs.oid = s.subserver \n");
5253 "LEFT JOIN pg_catalog.pg_replication_origin_status o \n"
5254 " ON o.external_id = 'pg_' || s.oid::text \n");
5257 "WHERE s.subdbid = (SELECT oid FROM pg_database\n"
5258 " WHERE datname = current_database())");
5293 for (
i = 0;
i < ntups;
i++)
5306 subinfo[
i].subservername =
NULL;
5376 fout->remoteVersion < 170000)
5380 "SELECT srsubid, srrelid, srsubstate, srsublsn "
5381 "FROM pg_catalog.pg_subscription_rel "
5395 for (
int i = 0;
i < ntups;
i++)
5408 if (subinfo ==
NULL)
5415 if (tblinfo ==
NULL)
5416 pg_fatal(
"failed sanity check, relation with OID %u not found",
5421 subrinfo[
i].dobj.catId.tableoid = relid;
5459 Assert(
fout->dopt->binary_upgrade &&
fout->remoteVersion >= 170000);
5473 "\n-- For binary upgrade, must preserve the subscriber table.\n");
5475 "SELECT pg_catalog.binary_upgrade_add_sub_rel_state(");
5500 .
namespace =
subrinfo->tblinfo->dobj.namespace->dobj.name,
5502 .description =
"SUBSCRIPTION TABLE",
5504 .createStmt = query->
data));
5554 pg_fatal(
"could not parse %s array",
"subpublications");
5565 appendPQExpBuffer(query,
" PUBLICATION %s WITH (connect = false, slot_name = ", publications->
data);
5631 "\n-- For binary upgrade, must preserve the remote_lsn for the subscriber's replication origin.\n");
5633 "SELECT pg_catalog.binary_upgrade_replorigin_advance(");
5645 "\n-- For binary upgrade, must preserve the subscriber's running state.\n");
5654 .description =
"SUBSCRIPTION",
5656 .createStmt = query->
data,
5657 .dropStmt =
delq->data));
5686 const char *keyword,
5687 const char *objname)
5704 "FROM pg_catalog.pg_depend d, pg_catalog.pg_extension e "
5705 "WHERE d.refobjid = e.oid AND classid = '%s'::pg_catalog.regclass "
5706 "AND objid = '%u'::pg_catalog.oid AND deptype = 'x' "
5707 "AND refclassid = 'pg_catalog.pg_extension'::pg_catalog.regclass",
5713 for (
i = 0;
i < ntups;
i++)
5745 "SELECT EXISTS(SELECT 1 "
5746 "FROM pg_catalog.pg_type "
5747 "WHERE oid = '%u'::pg_catalog.oid);",
5773 "SELECT pg_catalog.binary_upgrade_set_next_pg_type_oid('%u'::pg_catalog.oid);\n\n",
5788 "\n-- For binary upgrade, must preserve pg_type array oid\n");
5790 "SELECT pg_catalog.binary_upgrade_set_next_array_pg_type_oid('%u'::pg_catalog.oid);\n\n",
5799 if (
fout->remoteVersion >= 140000)
5802 "SELECT t.oid, t.typarray "
5803 "FROM pg_catalog.pg_type t "
5804 "JOIN pg_catalog.pg_range r "
5805 "ON t.oid = r.rngmultitypid "
5806 "WHERE r.rngtypid = '%u'::pg_catalog.oid;",
5823 "\n-- For binary upgrade, must preserve multirange pg_type oid\n");
5825 "SELECT pg_catalog.binary_upgrade_set_next_multirange_pg_type_oid('%u'::pg_catalog.oid);\n\n",
5828 "\n-- For binary upgrade, must preserve multirange pg_type array oid\n");
5830 "SELECT pg_catalog.binary_upgrade_set_next_multirange_array_pg_type_oid('%u'::pg_catalog.oid);\n\n",
5874 query =
"SELECT c.oid, c.relkind, c.relfilenode, c.reltoastrelid, "
5875 "ct.relfilenode, i.indexrelid, cti.relfilenode "
5876 "FROM pg_catalog.pg_class c LEFT JOIN pg_catalog.pg_index i "
5877 "ON (c.reltoastrelid = i.indrelid AND i.indisvalid) "
5878 "LEFT JOIN pg_catalog.pg_class ct ON (c.reltoastrelid = ct.oid) "
5879 "LEFT JOIN pg_catalog.pg_class AS cti ON (i.indexrelid = cti.oid) "
5928 "\n-- For binary upgrade, must preserve pg_class oids and relfilenodes\n");
5934 "SELECT pg_catalog.binary_upgrade_set_next_heap_pg_class_oid('%u'::pg_catalog.oid);\n",
5945 "SELECT pg_catalog.binary_upgrade_set_next_heap_relfilenode('%u'::pg_catalog.oid);\n",
5956 "SELECT pg_catalog.binary_upgrade_set_next_toast_pg_class_oid('%u'::pg_catalog.oid);\n",
5959 "SELECT pg_catalog.binary_upgrade_set_next_toast_relfilenode('%u'::pg_catalog.oid);\n",
5964 "SELECT pg_catalog.binary_upgrade_set_next_index_pg_class_oid('%u'::pg_catalog.oid);\n",
5967 "SELECT pg_catalog.binary_upgrade_set_next_index_relfilenode('%u'::pg_catalog.oid);\n",
5975 "SELECT pg_catalog.binary_upgrade_set_next_index_pg_class_oid('%u'::pg_catalog.oid);\n",
5978 "SELECT pg_catalog.binary_upgrade_set_next_index_relfilenode('%u'::pg_catalog.oid);\n",
5995 const char *objtype,
5996 const char *objname,
6019 pg_fatal(
"could not find parent extension for %s %s",
6023 "\n-- For binary upgrade, handle extension membership the hard way\n");
6060 "acldefault('n', n.nspowner) AS acldefault "
6061 "FROM pg_namespace n");
6076 for (
i = 0;
i < ntups;
i++)
6078 const char *nspowner;
6133 nsinfo[
i].dacl.privtype =
'i';
6189 "x.extname, n.nspname, x.extrelocatable, x.extversion, x.extconfig, x.extcondition "
6190 "FROM pg_extension x "
6191 "JOIN pg_namespace n ON n.oid = x.extnamespace");
6210 for (
i = 0;
i < ntups;
i++)
6283 "typnamespace, typacl, "
6284 "acldefault('T', typowner) AS acldefault, "
6286 "typelem, typrelid, typarray, "
6287 "CASE WHEN typrelid = 0 THEN ' '::\"char\" "
6288 "ELSE (SELECT relkind FROM pg_class WHERE oid = typrelid) END AS typrelkind, "
6289 "typtype, typisdefined, "
6290 "typname[0] = '_' AND typelem != 0 AND "
6291 "(SELECT typarray FROM pg_type te WHERE oid = pg_type.typelem) = oid AS isarray "
6315 for (
i = 0;
i < ntups;
i++)
6349 tyinfo[
i].isMultirange =
true;
6351 tyinfo[
i].isMultirange =
false;
6440 "oprcode::oid AS oprcode "
6441 "FROM pg_operator");
6459 for (
i = 0;
i < ntups;
i++)
6513 "FROM pg_collation");
6528 for (
i = 0;
i < ntups;
i++)
6577 "FROM pg_conversion");
6591 for (
i = 0;
i < ntups;
i++)
6637 "amhandler::pg_catalog.regproc AS amhandler ");
6652 for (
i = 0;
i < ntups;
i++)
6715 for (
i = 0;
i < ntups;
i++)
6765 "FROM pg_opfamily");
6780 for (
i = 0;
i < ntups;
i++)
6829 agg_check = (
fout->remoteVersion >= 110000 ?
"p.prokind = 'a'"
6833 "p.proname AS aggname, "
6834 "p.pronamespace AS aggnamespace, "
6835 "p.pronargs, p.proargtypes, "
6837 "p.proacl AS aggacl, "
6838 "acldefault('f', p.proowner) AS acldefault "
6840 "LEFT JOIN pg_init_privs pip ON "
6841 "(p.oid = pip.objoid "
6842 "AND pip.classoid = 'pg_proc'::regclass "
6843 "AND pip.objsubid = 0) "
6845 "p.pronamespace != "
6846 "(SELECT oid FROM pg_namespace "
6847 "WHERE nspname = 'pg_catalog') OR "
6848 "p.proacl IS DISTINCT FROM pip.initprivs",
6852 " OR EXISTS(SELECT 1 FROM pg_depend WHERE "
6853 "classid = 'pg_proc'::regclass AND "
6854 "objid = p.oid AND "
6855 "refclassid = 'pg_extension'::regclass AND "
6875 for (
i = 0;
i < ntups;
i++)
6886 agginfo[
i].aggfn.dacl.privtype = 0;
6901 agginfo[
i].aggfn.postponed_def =
false;
6964 :
"NOT p.proisagg");
6967 "SELECT p.tableoid, p.oid, p.proname, p.prolang, "
6968 "p.pronargs, p.proargtypes, p.prorettype, "
6970 "acldefault('f', p.proowner) AS acldefault, "
6974 "LEFT JOIN pg_init_privs pip ON "
6975 "(p.oid = pip.objoid "
6976 "AND pip.classoid = 'pg_proc'::regclass "
6977 "AND pip.objsubid = 0) "
6979 "\n AND NOT EXISTS (SELECT 1 FROM pg_depend "
6980 "WHERE classid = 'pg_proc'::regclass AND "
6981 "objid = p.oid AND deptype = 'i')"
6983 "\n pronamespace != "
6984 "(SELECT oid FROM pg_namespace "
6985 "WHERE nspname = 'pg_catalog')"
6986 "\n OR EXISTS (SELECT 1 FROM pg_cast"
6987 "\n WHERE pg_cast.oid > %u "
6988 "\n AND p.oid = pg_cast.castfunc)"
6989 "\n OR EXISTS (SELECT 1 FROM pg_transform"
6990 "\n WHERE pg_transform.oid > %u AND "
6991 "\n (p.oid = pg_transform.trffromsql"
6992 "\n OR p.oid = pg_transform.trftosql))",
6998 "\n OR EXISTS(SELECT 1 FROM pg_depend WHERE "
6999 "classid = 'pg_proc'::regclass AND "
7000 "objid = p.oid AND "
7001 "refclassid = 'pg_extension'::regclass AND "
7004 "\n OR p.proacl IS DISTINCT FROM pip.initprivs");
7025 for (
i = 0;
i < ntups;
i++)
7032 finfo[
i].
dobj.namespace =
7042 if (finfo[
i].nargs == 0)
7048 finfo[
i].argtypes, finfo[
i].nargs);
7074 char *reltuples,
int32 relallvisible,
7075 int32 relallfrozen,
char relkind,
7076 char **indAttNames,
int nindAttNames)
7078 if (!
fout->dopt->dumpStatistics)
7101 dobj->namespace = rel->namespace;
7134 pg_fatal(
"cannot dump statistics for relation kind \"%c\"",
7218 "SELECT c.tableoid, c.oid, c.relname, "
7219 "c.relnamespace, c.relkind, c.reltype, "
7222 "c.relhasindex, c.relhasrules, c.relpages, "
7223 "c.reltuples, c.relallvisible, ");
7225 if (
fout->remoteVersion >= 180000)
7231 "c.relhastriggers, c.relpersistence, "
7238 fout->remoteVersion >= 200000 ?
7239 " THEN 'g'::\"char\"" :
7243 " THEN 's'::\"char\""
7244 " ELSE 'r'::\"char\" END, c.relowner) AS acldefault, "
7246 "(SELECT ftserver FROM pg_catalog.pg_foreign_table WHERE ftrelid = c.oid) "
7247 "ELSE 0 END AS foreignserver, "
7248 "c.relfrozenxid, tc.relfrozenxid AS tfrozenxid, "
7250 "tc.relpages AS toastpages, "
7251 "tc.reloptions AS toast_reloptions, "
7252 "d.refobjid AS owning_tab, "
7253 "d.refobjsubid AS owning_col, "
7254 "tsp.spcname AS reltablespace, ");
7256 if (
fout->remoteVersion >= 120000)
7258 "false AS relhasoids, ");
7264 "c.relispopulated, ");
7267 "c.relreplident, ");
7270 "c.relrowsecurity, c.relforcerowsecurity, ");
7273 "c.relminmxid, tc.relminmxid AS tminmxid, ");
7276 "array_remove(array_remove(c.reloptions,'check_option=local'),'check_option=cascaded') AS reloptions, "
7277 "CASE WHEN 'check_option=local' = ANY (c.reloptions) THEN 'LOCAL'::text "
7278 "WHEN 'check_option=cascaded' = ANY (c.reloptions) THEN 'CASCADED'::text ELSE NULL END AS checkoption, ");
7284 "(d.deptype = 'i') IS TRUE AS is_identity_sequence, ");
7287 "c.relispartition AS ispartition ");
7296 "\nFROM pg_class c\n"
7297 "LEFT JOIN pg_depend d ON "
7299 "d.classid = 'pg_class'::regclass AND d.objid = c.oid AND "
7300 "d.objsubid = 0 AND "
7301 "d.refclassid = 'pg_class'::regclass AND d.deptype IN ('a', 'i'))\n"
7302 "LEFT JOIN pg_tablespace tsp ON (tsp.oid = c.reltablespace)\n");
7308 "LEFT JOIN pg_am am ON (c.relam = am.oid)\n");
7316 "LEFT JOIN pg_class tc ON (c.reltoastrelid = tc.oid"
7331 "WHERE c.relkind IN ("
7417 for (
i = 0;
i < ntups;
i++)
7427 tblinfo[
i].
dobj.namespace =
7483 !(
fout->remoteVersion >= 200000))
7542 if (tblinfo[
i].interesting)
7547 tblinfo[
i].relpages,
7549 relallvisible, relallfrozen,
7550 tblinfo[
i].relkind,
NULL, 0);
7552 tblinfo[
i].
stats = stats;
7579 if (query->
len == 0)
7588 if (query->
len >= 100000)
7599 if (query->
len != 0)
7643 if (owning_tab ==
NULL)
7644 pg_fatal(
"failed sanity check, parent table with OID %u of sequence with OID %u not found",
7669 if (
seqinfo->is_identity_sequence)
7716 for (
i = 0;
i < ntups;
i++)
7754 if (
fout->remoteVersion < 110000)
7757 if (!
fout->dopt->dumpData)
7771 "SELECT partrelid FROM pg_partitioned_table WHERE\n"
7772 "(SELECT c.oid FROM pg_opclass c JOIN pg_am a "
7773 "ON c.opcmethod = a.oid\n"
7774 "WHERE opcname = 'enum_ops' "
7775 "AND opcnamespace = 'pg_catalog'::regnamespace "
7776 "AND amname = 'hash') = ANY(partclass)");
7782 for (
int i = 0;
i < ntups;
i++)
7789 pg_fatal(
"failed sanity check, table OID %u appearing in pg_partitioned_table not found",
7791 tbinfo->unsafe_partitions =
true;
7864 if (!
tbinfo->interesting)
7875 "SELECT t.tableoid, t.oid, i.indrelid, "
7876 "t.relname AS indexname, "
7877 "t.relpages, t.reltuples, t.relallvisible, ");
7879 if (
fout->remoteVersion >= 180000)
7885 "pg_catalog.pg_get_indexdef(i.indexrelid) AS indexdef, "
7886 "i.indkey, i.indisclustered, "
7887 "c.contype, c.conname, "
7888 "c.condeferrable, c.condeferred, "
7889 "c.tableoid AS contableoid, "
7891 "pg_catalog.pg_get_constraintdef(c.oid, false) AS condef, "
7892 "CASE WHEN i.indexprs IS NOT NULL THEN "
7893 "(SELECT pg_catalog.array_agg(attname ORDER BY attnum)"
7894 " FROM pg_catalog.pg_attribute "
7895 " WHERE attrelid = i.indexrelid) "
7896 "ELSE NULL END AS indattnames, "
7897 "(SELECT spcname FROM pg_catalog.pg_tablespace s WHERE s.oid = t.reltablespace) AS tablespace, "
7898 "t.reloptions AS indreloptions, ");
7902 "i.indisreplident, ");
7904 if (
fout->remoteVersion >= 110000)
7906 "inh.inhparent AS parentidx, "
7907 "i.indnkeyatts AS indnkeyatts, "
7908 "i.indnatts AS indnatts, "
7909 "(SELECT pg_catalog.array_agg(attnum ORDER BY attnum) "
7910 " FROM pg_catalog.pg_attribute "
7911 " WHERE attrelid = i.indexrelid AND "
7912 " attstattarget >= 0) AS indstatcols, "
7913 "(SELECT pg_catalog.array_agg(attstattarget ORDER BY attnum) "
7914 " FROM pg_catalog.pg_attribute "
7915 " WHERE attrelid = i.indexrelid AND "
7916 " attstattarget >= 0) AS indstatvals, ");
7920 "i.indnatts AS indnkeyatts, "
7921 "i.indnatts AS indnatts, "
7922 "'' AS indstatcols, "
7923 "'' AS indstatvals, ");
7925 if (
fout->remoteVersion >= 150000)
7927 "i.indnullsnotdistinct, ");
7930 "false AS indnullsnotdistinct, ");
7932 if (
fout->remoteVersion >= 180000)
7937 "NULL AS conperiod ");
7948 if (
fout->remoteVersion >= 110000)
7951 "FROM unnest('%s'::pg_catalog.oid[]) AS src(tbloid)\n"
7952 "JOIN pg_catalog.pg_index i ON (src.tbloid = i.indrelid) "
7953 "JOIN pg_catalog.pg_class t ON (t.oid = i.indexrelid) "
7954 "JOIN pg_catalog.pg_class t2 ON (t2.oid = i.indrelid) "
7955 "LEFT JOIN pg_catalog.pg_constraint c "
7956 "ON (i.indrelid = c.conrelid AND "
7957 "i.indexrelid = c.conindid AND "
7958 "c.contype IN ('p','u','x')) "
7959 "LEFT JOIN pg_catalog.pg_inherits inh "
7960 "ON (inh.inhrelid = indexrelid) "
7961 "WHERE (i.indisvalid OR t2.relkind = 'p') "
7963 "ORDER BY i.indrelid, indexname",
7973 "FROM unnest('%s'::pg_catalog.oid[]) AS src(tbloid)\n"
7974 "JOIN pg_catalog.pg_index i ON (src.tbloid = i.indrelid) "
7975 "JOIN pg_catalog.pg_class t ON (t.oid = i.indexrelid) "
7976 "LEFT JOIN pg_catalog.pg_constraint c "
7977 "ON (i.indrelid = c.conrelid AND "
7978 "i.indexrelid = c.conindid AND "
7979 "c.contype IN ('p','u','x')) "
7980 "WHERE i.indisvalid AND i.indisready "
7981 "ORDER BY i.indrelid, indexname",
8026 for (
int j = 0;
j < ntups;)
8052 pg_fatal(
"unexpected index data for table \"%s\"",
8063 char **indAttNames =
NULL;
8064 int nindAttNames = 0;
8105 &indAttNames, &nindAttNames))
8106 pg_fatal(
"could not parse %s array",
"indattnames");
8112 indAttNames, nindAttNames);
8115 if (contype ==
'p' || contype ==
'u' || contype ==
'x')
8189 if (
fout->remoteVersion < 130000)
8191 "stxnamespace, stxowner, stxrelid, NULL AS stxstattarget "
8192 "FROM pg_catalog.pg_statistic_ext");
8195 "stxnamespace, stxowner, stxrelid, stxstattarget "
8196 "FROM pg_catalog.pg_statistic_ext");
8212 for (
i = 0;
i < ntups;
i++)
8232 if (
fout->dopt->dumpStatistics)
8291 "SELECT c.tableoid, c.oid, "
8292 "conrelid, conname, confrelid, ");
8293 if (
fout->remoteVersion >= 110000)
8298 "pg_catalog.pg_get_constraintdef(c.oid) AS condef\n"
8299 "FROM unnest('%s'::pg_catalog.oid[]) AS src(tbloid)\n"
8300 "JOIN pg_catalog.pg_constraint c ON (src.tbloid = c.conrelid)\n"
8301 "WHERE contype = 'f' ",
8303 if (
fout->remoteVersion >= 110000)
8305 "AND conparentid = 0 ");
8307 "ORDER BY conrelid, conname");
8324 for (
int j = 0;
j < ntups;
j++)
8338 if (
tbinfo->dobj.catId.oid == conrelid)
8342 pg_fatal(
"unrecognized table OID %u", conrelid);
8375 for (
int k = 0; k <
reftable->numIndexes; k++)
8380 if (
reftable->indexes[k].dobj.catId.oid != indexOid)
8415 for (cell =
refidx->partattaches.head; cell; cell = cell->
next)
8421 if (
attach->partitionIdx->partattaches.head !=
NULL)
8453 "PREPARE getDomainConstraints(pg_catalog.oid) AS\n"
8454 "SELECT tableoid, oid, conname, "
8455 "pg_catalog.pg_get_constraintdef(oid) AS consrc, "
8456 "convalidated, contype "
8457 "FROM pg_catalog.pg_constraint "
8458 "WHERE contypid = $1 AND contype IN (%s) "
8460 fout->remoteVersion < 170000 ?
"'c'" :
"'c', 'n'");
8468 "EXECUTE getDomainConstraints('%u')",
8486 for (
int i = 0,
j = 0;
i < ntups;
i++)
8503 constraint =
tyinfo->notnull;
8511 constraint->
dobj.namespace =
tyinfo->dobj.namespace;
8514 constraint->
contype = contype;
8560 "tableoid, oid, rulename, "
8561 "ev_class AS ruletable, ev_type, is_instead, "
8580 for (
i = 0;
i < ntups;
i++)
8592 pg_fatal(
"failed sanity check, parent table with OID %u of pg_rewrite entry with OID %u not found",
8670 if (!
tbinfo->hastriggers ||
8681 if (
fout->remoteVersion >= 150000)
8692 "SELECT t.tgrelid, t.tgname, "
8693 "pg_catalog.pg_get_triggerdef(t.oid, false) AS tgdef, "
8694 "t.tgenabled, t.tableoid, t.oid, "
8695 "t.tgparentid <> 0 AS tgispartition\n"
8696 "FROM unnest('%s'::pg_catalog.oid[]) AS src(tbloid)\n"
8697 "JOIN pg_catalog.pg_trigger t ON (src.tbloid = t.tgrelid) "
8698 "LEFT JOIN pg_catalog.pg_trigger u ON (u.oid = t.tgparentid) "
8699 "WHERE ((NOT t.tgisinternal AND t.tgparentid = 0) "
8700 "OR t.tgenabled != u.tgenabled) "
8701 "ORDER BY t.tgrelid, t.tgname",
8704 else if (
fout->remoteVersion >= 130000)
8715 "SELECT t.tgrelid, t.tgname, "
8716 "pg_catalog.pg_get_triggerdef(t.oid, false) AS tgdef, "
8717 "t.tgenabled, t.tableoid, t.oid, t.tgisinternal as tgispartition\n"
8718 "FROM unnest('%s'::pg_catalog.oid[]) AS src(tbloid)\n"
8719 "JOIN pg_catalog.pg_trigger t ON (src.tbloid = t.tgrelid) "
8720 "LEFT JOIN pg_catalog.pg_trigger u ON (u.oid = t.tgparentid) "
8721 "WHERE (NOT t.tgisinternal OR t.tgenabled != u.tgenabled) "
8722 "ORDER BY t.tgrelid, t.tgname",
8725 else if (
fout->remoteVersion >= 110000)
8735 "SELECT t.tgrelid, t.tgname, "
8736 "pg_catalog.pg_get_triggerdef(t.oid, false) AS tgdef, "
8737 "t.tgenabled, t.tableoid, t.oid, t.tgisinternal as tgispartition "
8738 "FROM unnest('%s'::pg_catalog.oid[]) AS src(tbloid)\n"
8739 "JOIN pg_catalog.pg_trigger t ON (src.tbloid = t.tgrelid) "
8740 "LEFT JOIN pg_catalog.pg_depend AS d ON "
8741 " d.classid = 'pg_catalog.pg_trigger'::pg_catalog.regclass AND "
8742 " d.refclassid = 'pg_catalog.pg_trigger'::pg_catalog.regclass AND "
8744 "LEFT JOIN pg_catalog.pg_trigger AS pt ON pt.oid = refobjid "
8745 "WHERE (NOT t.tgisinternal OR t.tgenabled != pt.tgenabled) "
8746 "ORDER BY t.tgrelid, t.tgname",
8753 "SELECT t.tgrelid, t.tgname, "
8754 "pg_catalog.pg_get_triggerdef(t.oid, false) AS tgdef, "
8755 "t.tgenabled, false as tgispartition, "
8756 "t.tableoid, t.oid "
8757 "FROM unnest('%s'::pg_catalog.oid[]) AS src(tbloid)\n"
8758 "JOIN pg_catalog.pg_trigger t ON (src.tbloid = t.tgrelid) "
8759 "WHERE NOT tgisinternal "
8760 "ORDER BY t.tgrelid, t.tgname",
8783 for (
int j = 0;
j < ntups;)
8856 "SELECT e.tableoid, e.oid, evtname, evtenabled, "
8857 "evtevent, evtowner, "
8858 "array_to_string(array("
8859 "select quote_literal(x) "
8860 " from unnest(evttags) as t(x)), ', ') as evttags, "
8861 "e.evtfoid::regproc as evtfname "
8862 "FROM pg_event_trigger e "
8880 for (
i = 0;
i < ntups;
i++)
8930 "lanname, lanpltrusted, lanplcallfoid, "
8931 "laninline, lanvalidator, "
8933 "acldefault('l', lanowner) AS acldefault, "
8956 for (
i = 0;
i < ntups;
i++)
9010 if (
fout->remoteVersion >= 140000)
9013 "castsource, casttarget, castfunc, castcontext, "
9016 "WHERE NOT EXISTS ( "
9017 "SELECT 1 FROM pg_range r "
9018 "WHERE c.castsource = r.rngtypid "
9019 "AND c.casttarget = r.rngmultitypid "
9026 "castsource, casttarget, castfunc, castcontext, "
9028 "FROM pg_cast ORDER BY 3,4");
9045 for (
i = 0;
i < ntups;
i++)
9091 appendPQExpBuffer(query,
"SELECT lanname FROM pg_language WHERE oid = %u", langid);
9122 "trftype, trflang, trffromsql::oid, trftosql::oid "
9123 "FROM pg_transform "
9139 for (
i = 0;
i < ntups;
i++)
9248 if (!
tbinfo->interesting &&
9249 !(
fout->dopt->binary_upgrade &&
9282 "a.attstattarget,\n"
9290 "pg_catalog.format_type(t.oid, a.atttypmod) AS atttypname,\n"
9291 "array_to_string(a.attoptions, ', ') AS attoptions,\n"
9292 "CASE WHEN a.attcollation <> t.typcollation "
9293 "THEN a.attcollation ELSE 0 END AS attcollation,\n"
9294 "pg_catalog.array_to_string(ARRAY("
9295 "SELECT pg_catalog.quote_ident(option_name) || "
9296 "' ' || pg_catalog.quote_literal(option_value) "
9297 "FROM pg_catalog.pg_options_to_table(attfdwoptions) "
9298 "ORDER BY option_name"
9299 "), E',\n ') AS attfdwoptions,\n");
9319 if (
fout->remoteVersion >= 180000)
9321 "co.conname AS notnull_name,\n"
9322 "CASE WHEN co.convalidated THEN pt.description"
9323 " ELSE NULL END AS notnull_comment,\n"
9324 "CASE WHEN NOT co.convalidated THEN co.oid "
9325 "ELSE NULL END AS notnull_invalidoid,\n"
9326 "co.connoinherit AS notnull_noinherit,\n"
9327 "co.conislocal AS notnull_islocal,\n");
9330 "CASE WHEN a.attnotnull THEN '' ELSE NULL END AS notnull_name,\n"
9331 "NULL AS notnull_comment,\n"
9332 "NULL AS notnull_invalidoid,\n"
9333 "false AS notnull_noinherit,\n"
9334 "CASE WHEN a.attislocal THEN true\n"
9335 " WHEN a.attnotnull AND NOT a.attislocal THEN true\n"
9337 "END AS notnull_islocal,\n");
9339 if (
fout->remoteVersion >= 140000)
9341 "a.attcompression AS attcompression,\n");
9344 "'' AS attcompression,\n");
9347 "a.attidentity,\n");
9349 if (
fout->remoteVersion >= 110000)
9351 "CASE WHEN a.atthasmissing AND NOT a.attisdropped "
9352 "THEN a.attmissingval ELSE null END AS attmissingval,\n");
9355 "NULL AS attmissingval,\n");
9357 if (
fout->remoteVersion >= 120000)
9359 "a.attgenerated\n");
9362 "'' AS attgenerated\n");
9366 "FROM unnest('%s'::pg_catalog.oid[]) AS src(tbloid)\n"
9367 "JOIN pg_catalog.pg_attribute a ON (src.tbloid = a.attrelid) "
9368 "LEFT JOIN pg_catalog.pg_type t "
9369 "ON (a.atttypid = t.oid)\n",
9376 if (
fout->remoteVersion >= 180000)
9378 " LEFT JOIN pg_catalog.pg_constraint co ON "
9379 "(a.attrelid = co.conrelid\n"
9380 " AND co.contype = 'n' AND "
9381 "co.conkey = array[a.attnum])\n"
9382 " LEFT JOIN pg_catalog.pg_description pt ON "
9383 "(pt.classoid = co.tableoid AND pt.objoid = co.oid)\n");
9386 "WHERE a.attnum > 0::pg_catalog.int2\n");
9392 if (
fout->dopt->binary_upgrade &&
fout->remoteVersion < 120000)
9394 "OR (a.attnum = -2::pg_catalog.int2 AND src.tbloid = "
9398 "ORDER BY a.attrelid, a.attnum");
9438 for (
int r = 0; r < ntups;)
9446 for (numatts = 1; numatts < ntups - r; numatts++)
9457 if (
tbinfo->dobj.catId.oid == attrelid)
9461 pg_fatal(
"unrecognized table OID %u", attrelid);
9465 !(
fout->dopt->binary_upgrade &&
9468 pg_fatal(
"unexpected column data for table \"%s\"",
9472 tbinfo->numatts = numatts;
9497 for (
int j = 0;
j < numatts;
j++, r++)
9500 !(
fout->dopt->binary_upgrade &&
fout->remoteVersion < 120000 &&
9502 pg_fatal(
"invalid column numbering in table \"%s\"",
9507 tbinfo->attstattarget[
j] = -1;
9572 "pg_catalog.pg_get_expr(adbin, adrelid) AS adsrc\n"
9573 "FROM unnest('%s'::pg_catalog.oid[]) AS src(tbloid)\n"
9574 "JOIN pg_catalog.pg_attrdef a ON (src.tbloid = a.adrelid)\n"
9575 "ORDER BY a.adrelid, a.adnum",
9609 pg_fatal(
"invalid adnum value %d for table \"%s\"",
9610 adnum,
tbinfo->dobj.name);
9616 if (
tbinfo->attisdropped[adnum - 1])
9624 attrdefs[
j].
adnum = adnum;
9628 attrdefs[
j].
dobj.namespace =
tbinfo->dobj.namespace;
9639 if (
tbinfo->attgenerated[adnum - 1])
9669 if (!attrdefs[
j].separate)
9681 tbinfo->attrdefs[adnum - 1] = &attrdefs[
j];
9702 pg_log_info(
"finding invalid not-null constraints");
9706 "SELECT c.tableoid, c.oid, conrelid, conname, "
9707 "pg_catalog.pg_get_constraintdef(c.oid) AS consrc, "
9708 "conislocal, convalidated "
9709 "FROM unnest('%s'::pg_catalog.oid[]) AS src(conoid)\n"
9710 "JOIN pg_catalog.pg_constraint c ON (src.conoid = c.oid)\n"
9711 "ORDER BY c.conrelid, c.conname",
9746 if (
tbinfo->dobj.catId.oid == conrelid)
9750 pg_fatal(
"unrecognized table OID %u", conrelid);
9804 "SELECT c.tableoid, c.oid, conrelid, conname, "
9805 "pg_catalog.pg_get_constraintdef(c.oid) AS consrc, "
9806 "conislocal, convalidated "
9807 "FROM unnest('%s'::pg_catalog.oid[]) AS src(tbloid)\n"
9808 "JOIN pg_catalog.pg_constraint c ON (src.tbloid = c.conrelid)\n"
9809 "WHERE contype = 'c' "
9810 "ORDER BY c.conrelid, c.conname",
9846 if (
tbinfo->dobj.catId.oid == conrelid)
9850 pg_fatal(
"unrecognized table OID %u", conrelid);
9855 "expected %d check constraints on table \"%s\" but found %d",
10006 tbinfo->notnull_invalid[
j] =
true;
10019 tbinfo->notnull_invalid[
j] =
false;
10027 if (
fout->remoteVersion < 180000)
10036 tbinfo->notnull_constrs[
j] =
"";
10051 !
tbinfo->notnull_islocal[
j]) ||
10066 tbinfo->notnull_constrs[
j] =
"";
10100 if (
tbinfo->attisdropped[colno])
10102 return (
tbinfo->attislocal[colno] ||
tbinfo->ispartition);
10136 "prsstart::oid, prstoken::oid, "
10137 "prsend::oid, prsheadline::oid, prslextype::oid "
10138 "FROM pg_ts_parser");
10156 for (
i = 0;
i < ntups;
i++)
10203 "dictnamespace, dictowner, "
10204 "dicttemplate, dictinitoption "
10205 "FROM pg_ts_dict");
10221 for (
i = 0;
i < ntups;
i++)
10268 "tmplnamespace, tmplinit::oid, tmpllexize::oid "
10269 "FROM pg_ts_template");
10284 for (
i = 0;
i < ntups;
i++)
10327 "cfgnamespace, cfgowner, cfgparser "
10328 "FROM pg_ts_config");
10343 for (
i = 0;
i < ntups;
i++)
10391 "fdwhandler::pg_catalog.regproc, "
10392 "fdwvalidator::pg_catalog.regproc, ");
10394 if (
fout->remoteVersion >= 190000)
10401 "acldefault('F', fdwowner) AS acldefault, "
10402 "array_to_string(ARRAY("
10403 "SELECT quote_ident(option_name) || ' ' || "
10404 "quote_literal(option_value) "
10405 "FROM pg_options_to_table(fdwoptions) "
10406 "ORDER BY option_name"
10407 "), E',\n ') AS fdwoptions "
10408 "FROM pg_foreign_data_wrapper");
10427 for (
i = 0;
i < ntups;
i++)
10485 "srvfdw, srvtype, srvversion, srvacl, "
10486 "acldefault('S', srvowner) AS acldefault, "
10487 "array_to_string(ARRAY("
10488 "SELECT quote_ident(option_name) || ' ' || "
10489 "quote_literal(option_value) "
10490 "FROM pg_options_to_table(srvoptions) "
10491 "ORDER BY option_name"
10492 "), E',\n ') AS srvoptions "
10493 "FROM pg_foreign_server");
10512 for (
i = 0;
i < ntups;
i++)
10582 "SELECT oid, tableoid, "
10584 "defaclnamespace, "
10587 "CASE WHEN defaclnamespace = 0 THEN "
10588 "acldefault(CASE WHEN defaclobjtype = 'S' "
10589 "THEN 's'::\"char\" ELSE defaclobjtype END, "
10590 "defaclrole) ELSE '{}' END AS acldefault "
10591 "FROM pg_default_acl");
10607 for (
i = 0;
i < ntups;
i++)
10660 while (low <= high)
10666 else if (roleoid >
middle->roleoid)
10673 pg_fatal(
"role with OID %u does not exist", roleoid);
10690 query =
"SELECT oid, rolname FROM pg_catalog.pg_roles ORDER BY 1";
10728 "SELECT DISTINCT attrelid FROM pg_attribute "
10729 "WHERE attacl IS NOT NULL");
10734 for (
i = 0;
i < ntups;
i++)
10751 "SELECT objoid, classoid, objsubid, privtype, initprivs "
10752 "FROM pg_init_privs");
10757 for (
i = 0;
i < ntups;
i++)
10768 objId.
oid = objoid;
10780 ((
TableInfo *) dobj)->hascolumnACLs =
true;
10784 classoid, objoid, objsubid);
10808 daobj->dacl.privtype = privtype;
10813 classoid, objoid, objsubid);
10846 const char *
name,
const char *
namespace,
10847 const char *owner,
CatalogId catalogId,
10848 int subid,
DumpId dumpId,
10911 if (
namespace && *
namespace)
10926 .namespace =
namespace,
10928 .description =
"COMMENT",
10930 .createStmt = query->
data,
10946 const char *
name,
const char *
namespace,
10947 const char *owner,
CatalogId catalogId,
10948 int subid,
DumpId dumpId)
10951 catalogId, subid, dumpId,
NULL);
10962 const char *argtype,
const char *
argval)
11025 if (
fout->remoteVersion >= 190000)
11053 if (
fout->remoteVersion >= 190000)
11124 pg_fatal(
"statistics dumped out of order (current: %d %s %s, expected: %d %s %s)",
11131 if (
fout->remoteVersion >= 190000)
11133 "PREPARE getAttributeStats(pg_catalog.oid[]) AS\n");
11136 "PREPARE getAttributeStats(pg_catalog.name[], pg_catalog.name[]) AS\n");
11139 "SELECT s.schemaname, s.tablename, s.attname, s.inherited, "
11140 "s.null_frac, s.avg_width, s.n_distinct, "
11141 "s.most_common_vals, s.most_common_freqs, "
11142 "s.histogram_bounds, s.correlation, "
11143 "s.most_common_elems, s.most_common_elem_freqs, "
11144 "s.elem_count_histogram, ");
11146 if (
fout->remoteVersion >= 170000)
11148 "s.range_length_histogram, "
11149 "s.range_empty_frac, "
11150 "s.range_bounds_histogram ");
11153 "NULL AS range_length_histogram,"
11154 "NULL AS range_empty_frac,"
11155 "NULL AS range_bounds_histogram ");
11167 if (
fout->remoteVersion >= 190000)
11169 "FROM pg_catalog.pg_stats s "
11170 "JOIN unnest($1) WITH ORDINALITY AS u (tableid, ord) "
11171 "ON s.tableid = u.tableid "
11172 "ORDER BY u.ord, s.attname, s.inherited");
11175 "FROM pg_catalog.pg_stats s "
11176 "JOIN unnest($1, $2) WITH ORDINALITY AS u (schemaname, tablename, ord) "
11177 "ON s.schemaname = u.schemaname "
11178 "AND s.tablename = u.tablename "
11179 "WHERE s.tablename = ANY($2) "
11180 "ORDER BY u.ord, s.attname, s.inherited");
11193 fout->remoteVersion);
11218 if (
fout->remoteVersion >= 180000)
11250 for (; rownum <
PQntuples(res); rownum++)
11261 fout->remoteVersion);
11268 pg_fatal(
"unexpected null attname");
11276 if (
rsinfo->nindAttNames == 0)
11283 bool found =
false;
11285 for (
int i = 0;
i <
rsinfo->nindAttNames;
i++)
11333 if (
fout->remoteVersion >= 170000)
11365 if (!
fout->dopt->dumpStatistics)
11370 .namespace = dobj->namespace->dobj.
name,
11371 .description =
"STATISTICS DATA",
11372 .section =
rsinfo->section,
11376 .nDeps = dobj->
nDeps));
11434 .namespace =
tbinfo->dobj.namespace->dobj.name,
11435 .owner =
tbinfo->rolname,
11436 .description =
"COMMENT",
11438 .createStmt = query->
data,
11439 .deps = &(
tbinfo->dobj.dumpId),
11459 .namespace =
tbinfo->dobj.namespace->dobj.name,
11460 .owner =
tbinfo->rolname,
11461 .description =
"COMMENT",
11463 .createStmt = query->
data,
11464 .deps = &(
tbinfo->dobj.dumpId),
11496 while (low <= high)
11498 middle = low + (high - low) / 2;
11502 else if (classoid >
middle->classoid)
11506 else if (objoid >
middle->objoid)
11526 if (classoid !=
middle[-1].classoid ||
11527 objoid !=
middle[-1].objoid)
11538 if (classoid !=
middle->classoid ||
11539 objoid !=
middle->objoid)
11576 "FROM pg_catalog.pg_description "
11577 "ORDER BY classoid, objoid, objsubid");
11594 for (
i = 0;
i < ntups;
i++)
11604 if (dobj ==
NULL ||
11656 if (dobj->
dump == 0)
11784 pg_fatal(
"missing metadata for large objects \"%s\"",
11790 .description =
"BLOBS",
11792 .deps = dobj->dependencies,
11793 .nDeps = dobj->nDeps,
11868 "-- *not* dropping schema, since initdb creates it\n");
11870 "-- *not* creating schema, since initdb creates it\n");
11881 .description =
"SCHEMA",
11883 .createStmt = q->
data,
11884 .dropStmt =
delq->data));
11966 appendPQExpBufferStr(q,
"-- For binary upgrade, create an empty extension and insert objects into it\n");
11976 "SELECT pg_catalog.binary_upgrade_create_empty_extension(");
12021 .description =
"EXTENSION",
12023 .createStmt = q->
data,
12024 .dropStmt =
delq->data));
12065 pg_log_warning(
"typtype of data type \"%s\" appears to be invalid",
12094 "PREPARE dumpEnumType(pg_catalog.oid) AS\n"
12095 "SELECT oid, enumlabel "
12096 "FROM pg_catalog.pg_enum "
12097 "WHERE enumtypid = $1 "
12098 "ORDER BY enumsortorder");
12106 "EXECUTE dumpEnumType('%u')",
12107 tyinfo->dobj.catId.oid);
12135 for (
i = 0;
i < num;
i++)
12153 for (
i = 0;
i < num;
i++)
12161 "SELECT pg_catalog.binary_upgrade_set_next_pg_enum_oid('%u'::pg_catalog.oid);\n",
12172 tyinfo->dobj.namespace->dobj.name);
12177 .namespace =
tyinfo->dobj.namespace->dobj.name,
12178 .owner =
tyinfo->rolname,
12179 .description =
"TYPE",
12181 .createStmt = q->
data,
12182 .dropStmt =
delq->data));
12198 tyinfo->dobj.namespace->dobj.name,
12230 "PREPARE dumpRangeType(pg_catalog.oid) AS\n");
12235 if (
fout->remoteVersion >= 140000)
12237 "pg_catalog.format_type(rngmultitypid, NULL) AS rngmultitype, ");
12240 "NULL AS rngmultitype, ");
12243 "pg_catalog.format_type(rngsubtype, NULL) AS rngsubtype, "
12244 "opc.opcname AS opcname, "
12245 "(SELECT nspname FROM pg_catalog.pg_namespace nsp "
12246 " WHERE nsp.oid = opc.opcnamespace) AS opcnsp, "
12248 "CASE WHEN rngcollation = st.typcollation THEN 0 "
12249 " ELSE rngcollation END AS collation, "
12250 "rngcanonical, rngsubdiff "
12251 "FROM pg_catalog.pg_range r, pg_catalog.pg_type st, "
12252 " pg_catalog.pg_opclass opc "
12253 "WHERE st.oid = rngsubtype AND opc.oid = rngsubopc AND "
12262 "EXECUTE dumpRangeType('%u')",
12263 tyinfo->dobj.catId.oid);
12313 if (
strcmp(procname,
"-") != 0)
12317 if (
strcmp(procname,
"-") != 0)
12325 tyinfo->dobj.namespace->dobj.name);
12330 .namespace =
tyinfo->dobj.namespace->dobj.name,
12331 .owner =
tyinfo->rolname,
12332 .description =
"TYPE",
12334 .createStmt = q->
data,
12335 .dropStmt =
delq->data));
12351 tyinfo->dobj.namespace->dobj.name,
12396 tyinfo->dobj.namespace->dobj.name);
12401 .namespace =
tyinfo->dobj.namespace->dobj.name,
12402 .owner =
tyinfo->rolname,
12403 .description =
"TYPE",
12405 .createStmt = q->
data,
12406 .dropStmt =
delq->data));
12422 tyinfo->dobj.namespace->dobj.name,
12453 char *typsubscript;
12474 "PREPARE dumpBaseType(pg_catalog.oid) AS\n"
12476 "typinput, typoutput, typreceive, typsend, "
12477 "typreceive::pg_catalog.oid AS typreceiveoid, "
12478 "typsend::pg_catalog.oid AS typsendoid, "
12480 "typanalyze::pg_catalog.oid AS typanalyzeoid, "
12481 "typdelim, typbyval, typalign, typstorage, "
12482 "typmodin, typmodout, "
12483 "typmodin::pg_catalog.oid AS typmodinoid, "
12484 "typmodout::pg_catalog.oid AS typmodoutoid, "
12485 "typcategory, typispreferred, "
12486 "(typcollation <> 0) AS typcollatable, "
12487 "pg_catalog.pg_get_expr(typdefaultbin, 0) AS typdefaultbin, typdefault, ");
12489 if (
fout->remoteVersion >= 140000)
12492 "typsubscript::pg_catalog.oid AS typsubscriptoid ");
12495 "'-' AS typsubscript, 0 AS typsubscriptoid ");
12506 "EXECUTE dumpBaseType('%u')",
12507 tyinfo->dobj.catId.oid);
12563 "CREATE TYPE %s (\n"
12564 " INTERNALLENGTH = %s",
12566 (
strcmp(typlen,
"-1") == 0) ?
"variable" : typlen);
12611 if (typdelim &&
strcmp(typdelim,
",") != 0)
12635 if (
strcmp(typbyval,
"t") == 0)
12643 tyinfo->dobj.namespace->dobj.name);
12648 .namespace =
tyinfo->dobj.namespace->dobj.name,
12649 .owner =
tyinfo->rolname,
12650 .description =
"TYPE",
12652 .createStmt = q->
data,
12653 .dropStmt =
delq->data));
12669 tyinfo->dobj.namespace->dobj.name,
12705 "PREPARE dumpDomain(pg_catalog.oid) AS\n");
12708 "pg_catalog.format_type(t.typbasetype, t.typtypmod) AS typdefn, "
12709 "pg_catalog.pg_get_expr(t.typdefaultbin, 'pg_catalog.pg_type'::pg_catalog.regclass) AS typdefaultbin, "
12711 "CASE WHEN t.typcollation <> u.typcollation "
12712 "THEN t.typcollation ELSE 0 END AS typcollation "
12713 "FROM pg_catalog.pg_type t "
12714 "LEFT JOIN pg_catalog.pg_type u ON (t.typbasetype = u.oid) "
12715 "WHERE t.oid = $1");
12723 "EXECUTE dumpDomain('%u')",
12724 tyinfo->dobj.catId.oid);
12751 "CREATE DOMAIN %s AS %s",
12810 for (
i = 0;
i <
tyinfo->nDomChecks;
i++)
12826 tyinfo->dobj.namespace->dobj.name);
12831 .namespace =
tyinfo->dobj.namespace->dobj.name,
12832 .owner =
tyinfo->rolname,
12833 .description =
"DOMAIN",
12835 .createStmt = q->
data,
12836 .dropStmt =
delq->data));
12852 tyinfo->dobj.namespace->dobj.name,
12856 for (
i = 0;
i <
tyinfo->nDomChecks;
i++)
12871 tyinfo->dobj.namespace->dobj.name,
12891 tyinfo->dobj.namespace->dobj.name,
12941 "PREPARE dumpCompositeType(pg_catalog.oid) AS\n"
12942 "SELECT a.attname, a.attnum, "
12943 "pg_catalog.format_type(a.atttypid, a.atttypmod) AS atttypdefn, "
12944 "a.attlen, a.attalign, a.attisdropped, "
12945 "CASE WHEN a.attcollation <> at.typcollation "
12946 "THEN a.attcollation ELSE 0 END AS attcollation "
12947 "FROM pg_catalog.pg_type ct "
12948 "JOIN pg_catalog.pg_attribute a ON a.attrelid = ct.typrelid "
12949 "LEFT JOIN pg_catalog.pg_type at ON at.oid = a.atttypid "
12950 "WHERE ct.oid = $1 "
12951 "ORDER BY a.attnum");
12959 "EXECUTE dumpCompositeType('%u')",
12960 tyinfo->dobj.catId.oid);
12988 for (
i = 0;
i < ntups;
i++)
13039 "\n-- For binary upgrade, recreate dropped column.\n");
13041 "SET attlen = %s, "
13042 "attalign = '%s', attbyval = false\n"
13063 tyinfo->dobj.namespace->dobj.name);
13068 .namespace =
tyinfo->dobj.namespace->dobj.name,
13069 .owner =
tyinfo->rolname,
13070 .description =
"TYPE",
13072 .createStmt = q->
data,
13073 .dropStmt =
delq->data));
13090 tyinfo->dobj.namespace->dobj.name,
13130 if (
fout->dopt->no_comments)
13154 for (
i = 0;
i < ntups;
i++)
13181 .namespace =
tyinfo->dobj.namespace->dobj.name,
13182 .owner =
tyinfo->rolname,
13183 .description =
"COMMENT",
13185 .createStmt = query->
data,
13186 .deps = &(
tyinfo->dobj.dumpId),
13227 stinfo->baseType->dobj.catId.oid,
13236 .namespace =
stinfo->dobj.namespace->dobj.name,
13237 .owner =
stinfo->baseType->rolname,
13238 .description =
"SHELL TYPE",
13240 .createStmt = q->
data));
13312 plang->lanpltrusted ?
"TRUSTED " :
"",
13346 .owner =
plang->lanowner,
13347 .description =
"PROCEDURAL LANGUAGE",
13349 .createStmt =
defqry->data,
13350 .dropStmt =
delqry->data,
13416 for (
j = 0;
j < finfo->
nargs;
j++)
13468 const char *keyword;
13483 "PREPARE dumpFunc(pg_catalog.oid) AS\n");
13497 "pg_catalog.pg_get_function_arguments(p.oid) AS funcargs,\n"
13498 "pg_catalog.pg_get_function_identity_arguments(p.oid) AS funciargs,\n"
13499 "pg_catalog.pg_get_function_result(p.oid) AS funcresult,\n"
13500 "proleakproof,\n");
13503 "array_to_string(protrftypes, ' ') AS protrftypes,\n");
13508 if (
fout->remoteVersion >= 110000)
13513 "CASE WHEN proiswindow THEN 'w' ELSE 'f' END AS prokind,\n");
13515 if (
fout->remoteVersion >= 120000)
13520 "'-' AS prosupport,\n");
13522 if (
fout->remoteVersion >= 140000)
13524 "pg_get_function_sqlbody(p.oid) AS prosqlbody\n");
13527 "NULL AS prosqlbody\n");
13530 "FROM pg_catalog.pg_proc p, pg_catalog.pg_language l\n"
13531 "WHERE p.oid = $1 "
13532 "AND l.oid = p.prolang");
13540 "EXECUTE dumpFunc('%u')",
13582 else if (
probin[0] !=
'\0')
13586 if (prosrc[0] !=
'\0')
13614 pg_fatal(
"could not parse %s array",
"proconfig");
13632 keyword =
"PROCEDURE";
13634 keyword =
"FUNCTION";
13685 pg_fatal(
"unrecognized provolatile value for function \"%s\"",
13735 pg_fatal(
"unrecognized proparallel value for function \"%s\"",
13795 "pg_catalog.pg_proc", keyword,
13801 finfo->
dobj.namespace->dobj.
name);
13806 .
namespace = finfo->
dobj.namespace->dobj.
name,
13808 .description = keyword,
13811 .createStmt = q->
data,
13812 .dropStmt =
delqry->data));
13869 pg_fatal(
"could not find function definition for function with OID %u",
13886 switch (
cast->castmethod)
13908 pg_log_warning(
"bogus value in pg_cast.castfunc or pg_cast.castmethod field");
13914 if (
cast->castcontext ==
'a')
13916 else if (
cast->castcontext ==
'i')
13933 .description =
"CAST",
13935 .createStmt =
defqry->data,
13936 .dropStmt =
delqry->data));
13942 cast->dobj.catId, 0,
cast->dobj.dumpId);
13975 pg_fatal(
"could not find function definition for function with OID %u",
13982 pg_fatal(
"could not find function definition for function with OID %u",
14001 pg_log_warning(
"bogus transform definition, at least one of trffromsql and trftosql should be nonzero");
14057 .description =
"TRANSFORM",
14059 .createStmt =
defqry->data,
14060 .dropStmt =
delqry->data,
14136 "PREPARE dumpOpr(pg_catalog.oid) AS\n"
14138 "oprcode::pg_catalog.regprocedure, "
14139 "oprleft::pg_catalog.regtype, "
14140 "oprright::pg_catalog.regtype, "
14143 "oprrest::pg_catalog.regprocedure, "
14144 "oprjoin::pg_catalog.regprocedure, "
14145 "oprcanmerge, oprcanhash "
14146 "FROM pg_catalog.pg_operator "
14155 "EXECUTE dumpOpr('%u')",
14183 if (
strcmp(oprkind,
"r") == 0)
14184 pg_log_warning(
"postfix operators are not supported anymore (operator \"%s\")",
14202 if (
strcmp(oprkind,
"r") == 0 ||
14203 strcmp(oprkind,
"b") == 0)
14211 if (
strcmp(oprkind,
"l") == 0 ||
14212 strcmp(oprkind,
"b") == 0)
14265 oprinfo->dobj.namespace->dobj.name);
14270 .namespace =
oprinfo->dobj.namespace->dobj.name,
14272 .description =
"OPERATOR",
14274 .createStmt = q->
data,
14275 .dropStmt =
delq->data));
14309 if (
strcmp(proc,
"-") == 0)
14359 return psprintf(
"OPERATOR(%s.%s)",
14380 "SELECT '%u'::pg_catalog.regproc", funcOid);
14442 .description =
"ACCESS METHOD",
14444 .createStmt = q->
data,
14445 .dropStmt =
delq->data));
14516 "opckeytype::pg_catalog.regtype, "
14517 "opcdefault, opcfamily, "
14518 "opfname AS opcfamilyname, "
14519 "nspname AS opcfamilynsp, "
14520 "(SELECT amname FROM pg_catalog.pg_am WHERE oid = opcmethod) AS amname "
14521 "FROM pg_catalog.pg_opclass c "
14522 "LEFT JOIN pg_catalog.pg_opfamily f ON f.oid = opcfamily "
14523 "LEFT JOIN pg_catalog.pg_namespace n ON n.oid = opfnamespace "
14524 "WHERE c.oid = '%u'::pg_catalog.oid",
14588 "amopopr::pg_catalog.regoperator, "
14589 "opfname AS sortfamily, "
14590 "nspname AS sortfamilynsp "
14591 "FROM pg_catalog.pg_amop ao JOIN pg_catalog.pg_depend ON "
14592 "(classid = 'pg_catalog.pg_amop'::pg_catalog.regclass AND objid = ao.oid) "
14593 "LEFT JOIN pg_catalog.pg_opfamily f ON f.oid = amopsortfamily "
14594 "LEFT JOIN pg_catalog.pg_namespace n ON n.oid = opfnamespace "
14595 "WHERE refclassid = 'pg_catalog.pg_opclass'::pg_catalog.regclass "
14596 "AND refobjid = '%u'::pg_catalog.oid "
14597 "AND amopfamily = '%s'::pg_catalog.oid "
14598 "ORDER BY amopstrategy",
14611 for (
i = 0;
i < ntups;
i++)
14624 if (
strlen(sortfamily) > 0)
14649 "amproc::pg_catalog.regprocedure, "
14650 "amproclefttype::pg_catalog.regtype, "
14651 "amprocrighttype::pg_catalog.regtype "
14652 "FROM pg_catalog.pg_amproc ap, pg_catalog.pg_depend "
14653 "WHERE refclassid = 'pg_catalog.pg_opclass'::pg_catalog.regclass "
14654 "AND refobjid = '%u'::pg_catalog.oid "
14655 "AND classid = 'pg_catalog.pg_amproc'::pg_catalog.regclass "
14656 "AND objid = ap.oid "
14657 "ORDER BY amprocnum",
14669 for (
i = 0;
i < ntups;
i++)
14709 opcinfo->dobj.namespace->dobj.name);
14714 .namespace =
opcinfo->dobj.namespace->dobj.name,
14716 .description =
"OPERATOR CLASS",
14718 .createStmt = q->
data,
14719 .dropStmt =
delq->data));
14790 "amopopr::pg_catalog.regoperator, "
14791 "opfname AS sortfamily, "
14792 "nspname AS sortfamilynsp "
14793 "FROM pg_catalog.pg_amop ao JOIN pg_catalog.pg_depend ON "
14794 "(classid = 'pg_catalog.pg_amop'::pg_catalog.regclass AND objid = ao.oid) "
14795 "LEFT JOIN pg_catalog.pg_opfamily f ON f.oid = amopsortfamily "
14796 "LEFT JOIN pg_catalog.pg_namespace n ON n.oid = opfnamespace "
14797 "WHERE refclassid = 'pg_catalog.pg_opfamily'::pg_catalog.regclass "
14798 "AND refobjid = '%u'::pg_catalog.oid "
14799 "AND amopfamily = '%u'::pg_catalog.oid "
14800 "ORDER BY amopstrategy",
14809 "amproc::pg_catalog.regprocedure, "
14810 "amproclefttype::pg_catalog.regtype, "
14811 "amprocrighttype::pg_catalog.regtype "
14812 "FROM pg_catalog.pg_amproc ap, pg_catalog.pg_depend "
14813 "WHERE refclassid = 'pg_catalog.pg_opfamily'::pg_catalog.regclass "
14814 "AND refobjid = '%u'::pg_catalog.oid "
14815 "AND classid = 'pg_catalog.pg_amproc'::pg_catalog.regclass "
14816 "AND objid = ap.oid "
14817 "ORDER BY amprocnum",
14826 "(SELECT amname FROM pg_catalog.pg_am WHERE oid = opfmethod) AS amname "
14827 "FROM pg_catalog.pg_opfamily "
14828 "WHERE oid = '%u'::pg_catalog.oid",
14871 for (
i = 0;
i < ntups;
i++)
14884 if (
strlen(sortfamily) > 0)
14904 for (
i = 0;
i < ntups;
i++)
14931 opfinfo->dobj.namespace->dobj.name);
14936 .namespace =
opfinfo->dobj.namespace->dobj.name,
14938 .description =
"OPERATOR FAMILY",
14940 .createStmt = q->
data,
14941 .dropStmt =
delq->data));
15000 if (
fout->remoteVersion >= 120000)
15002 "collisdeterministic, ");
15005 "true AS collisdeterministic, ");
15007 if (
fout->remoteVersion >= 170000)
15010 else if (
fout->remoteVersion >= 150000)
15012 "colliculocale AS colllocale, ");
15015 "NULL AS colllocale, ");
15017 if (
fout->remoteVersion >= 160000)
15022 "NULL AS collicurules, ");
15027 "FROM pg_catalog.pg_collation c "
15028 "WHERE c.oid = '%u'::pg_catalog.oid",
15056 if (
fout->remoteVersion < 150000)
15091 pg_fatal(
"unrecognized collation provider: %s",
15115 if (
fout->remoteVersion >= 150000)
15184 collinfo->dobj.namespace->dobj.name);
15189 .namespace =
collinfo->dobj.namespace->dobj.name,
15191 .description =
"COLLATION",
15193 .createStmt = q->
data,
15194 .dropStmt =
delq->data));
15244 "pg_catalog.pg_encoding_to_char(conforencoding) AS conforencoding, "
15245 "pg_catalog.pg_encoding_to_char(contoencoding) AS contoencoding, "
15246 "conproc, condefault "
15247 "FROM pg_catalog.pg_conversion c "
15248 "WHERE c.oid = '%u'::pg_catalog.oid",
15278 convinfo->dobj.namespace->dobj.name);
15283 .namespace =
convinfo->dobj.namespace->dobj.name,
15285 .description =
"CONVERSION",
15287 .createStmt = q->
data,
15288 .dropStmt =
delq->data));
15322 if (
agginfo->aggfn.nargs == 0)
15329 (
j > 0) ?
", " :
"",
15368 const char *aggsortop;
15371 const char *aggtranstype;
15372 const char *aggtransspace;
15393 "PREPARE dumpAgg(pg_catalog.oid) AS\n");
15399 "aggtranstype::pg_catalog.regtype,\n"
15402 "pg_catalog.pg_get_function_arguments(p.oid) AS funcargs,\n"
15403 "pg_catalog.pg_get_function_identity_arguments(p.oid) AS funciargs,\n");
15408 "aggminvtransfn,\n"
15410 "aggmtranstype::pg_catalog.regtype,\n"
15412 "aggmfinalextra,\n"
15414 "aggmtransspace,\n"
15423 if (
fout->remoteVersion >= 110000)
15425 "aggfinalmodify,\n"
15426 "aggmfinalmodify\n");
15429 "'0' AS aggfinalmodify,\n"
15430 "'0' AS aggmfinalmodify\n");
15433 "FROM pg_catalog.pg_aggregate a, pg_catalog.pg_proc p "
15434 "WHERE a.aggfnoid = p.oid "
15443 "EXECUTE dumpAgg('%u')",
15444 agginfo->aggfn.dobj.catId.oid);
15497 if (
strcmp(aggtransspace,
"0") != 0)
15529 pg_fatal(
"unrecognized aggfinalmodify value for aggregate \"%s\"",
15585 pg_fatal(
"unrecognized aggmfinalmodify value for aggregate \"%s\"",
15610 pg_fatal(
"unrecognized proparallel value for function \"%s\"",
15625 agginfo->aggfn.dobj.namespace->dobj.name);
15631 .
namespace =
agginfo->aggfn.dobj.namespace->dobj.name,
15632 .owner =
agginfo->aggfn.rolname,
15633 .description =
"AGGREGATE",
15635 .createStmt = q->
data,
15636 .dropStmt =
delq->data));
15641 agginfo->aggfn.dobj.namespace->dobj.name,
15647 agginfo->aggfn.dobj.namespace->dobj.name,
15663 agginfo->aggfn.dobj.namespace->dobj.name,
15720 prsinfo->dobj.namespace->dobj.name);
15725 .namespace =
prsinfo->dobj.namespace->dobj.name,
15726 .description =
"TEXT SEARCH PARSER",
15728 .createStmt = q->
data,
15729 .dropStmt =
delq->data));
15734 prsinfo->dobj.namespace->dobj.name,
"",
15770 "FROM pg_ts_template p, pg_namespace n "
15771 "WHERE p.oid = '%u' AND n.oid = tmplnamespace",
15798 dictinfo->dobj.namespace->dobj.name);
15803 .namespace =
dictinfo->dobj.namespace->dobj.name,
15805 .description =
"TEXT SEARCH DICTIONARY",
15807 .createStmt = q->
data,
15808 .dropStmt =
delq->data));
15858 tmplinfo->dobj.namespace->dobj.name);
15863 .namespace =
tmplinfo->dobj.namespace->dobj.name,
15864 .description =
"TEXT SEARCH TEMPLATE",
15866 .createStmt = q->
data,
15867 .dropStmt =
delq->data));
15872 tmplinfo->dobj.namespace->dobj.name,
"",
15912 "FROM pg_ts_parser p, pg_namespace n "
15913 "WHERE p.oid = '%u' AND n.oid = prsnamespace",
15930 " ( SELECT alias FROM pg_catalog.ts_token_type('%u'::pg_catalog.oid) AS t\n"
15931 " WHERE t.tokid = m.maptokentype ) AS tokenname,\n"
15932 " m.mapdict::pg_catalog.regdictionary AS dictname\n"
15933 "FROM pg_catalog.pg_ts_config_map AS m\n"
15934 "WHERE m.mapcfg = '%u'\n"
15935 "ORDER BY m.mapcfg, m.maptokentype, m.mapseqno",
15944 for (
i = 0;
i < ntups;
i++)
15975 "TEXT SEARCH CONFIGURATION",
qcfgname,
15976 cfginfo->dobj.namespace->dobj.name);
15981 .namespace =
cfginfo->dobj.namespace->dobj.name,
15983 .description =
"TEXT SEARCH CONFIGURATION",
15985 .createStmt = q->
data,
15986 .dropStmt =
delq->data));
16050 .description =
"FOREIGN DATA WRAPPER",
16052 .createStmt = q->
data,
16053 .dropStmt =
delq->data));
16100 "FROM pg_foreign_data_wrapper w "
16101 "WHERE w.oid = '%u'",
16137 .description =
"SERVER",
16139 .createStmt = q->
data,
16140 .dropStmt =
delq->data));
16179 const char *servername,
const char *
namespace,
16208 "array_to_string(ARRAY("
16209 "SELECT quote_ident(option_name) || ' ' || "
16210 "quote_literal(option_value) "
16211 "FROM pg_options_to_table(umoptions) "
16212 "ORDER BY option_name"
16213 "), E',\n ') AS umoptions "
16214 "FROM pg_user_mappings "
16215 "WHERE srvid = '%u' "
16216 "ORDER BY usename",
16225 for (
i = 0;
i < ntups;
i++)
16252 .namespace =
namespace,
16254 .description =
"USER MAPPING",
16256 .createStmt = q->
data,
16257 .dropStmt =
delq->data));
16292 type =
"SEQUENCES";
16295 type =
"FUNCTIONS";
16304 type =
"LARGE OBJECTS";
16308 pg_fatal(
"unrecognized object type in default privileges: %d",
16322 fout->remoteVersion,
16324 pg_fatal(
"could not parse default ACL list (%s)",
16330 .namespace =
daclinfo->dobj.namespace ?
16333 .description =
"DEFAULT ACL",
16335 .createStmt = q->
data));
16366 const char *nspname,
const char *tag,
const char *owner,
16371 const char *
acls = dacl->
acl;
16374 const char *initprivs = dacl->
initprivs;
16402 initprivs && *initprivs !=
'\0')
16407 "",
fout->remoteVersion, sql))
16408 pg_fatal(
"could not parse initial ACL list (%s) or default (%s) for object \"%s\" (%s)",
16410 appendPQExpBufferStr(sql,
"SELECT pg_catalog.binary_upgrade_set_record_init_privs(false);\n");
16421 if (initprivs && *initprivs !=
'\0')
16432 "",
fout->remoteVersion, sql))
16433 pg_fatal(
"could not parse ACL list (%s) or default (%s) for object \"%s\" (%s)",
16457 .namespace = nspname,
16459 .description =
"ACL",
16461 .createStmt = sql->
data,
16493 const char *
namespace,
const char *owner,
16532 if (labels[
i].objsubid != subid)
16536 "SECURITY LABEL FOR %s ON %s ",
16538 if (
namespace && *
namespace)
16545 if (query->
len > 0)
16552 .namespace =
namespace,
16554 .description =
"SECURITY LABEL",
16556 .createStmt = query->
data,
16603 const char *colname;
16627 if (query->
len > 0)
16634 .namespace =
tbinfo->dobj.namespace->dobj.name,
16635 .owner =
tbinfo->rolname,
16636 .description =
"SECURITY LABEL",
16638 .createStmt = query->
data,
16639 .deps = &(
tbinfo->dobj.dumpId),
16672 while (low <= high)
16674 middle = low + (high - low) / 2;
16678 else if (classoid >
middle->classoid)
16682 else if (objoid >
middle->objoid)
16702 if (classoid !=
middle[-1].classoid ||
16703 objoid !=
middle[-1].objoid)
16714 if (classoid !=
middle->classoid ||
16715 objoid !=
middle->objoid)
16749 "SELECT label, provider, classoid, objoid, objsubid "
16750 "FROM pg_catalog.pg_seclabels "
16751 "ORDER BY classoid, objoid, objsubid");
16768 for (
i = 0;
i < ntups;
i++)
16778 if (dobj ==
NULL ||
16841 const char *objtype;
16843 switch (
tbinfo->relkind)
16846 objtype =
"SEQUENCE";
16849 objtype =
"PROPERTY GRAPH";
16859 tbinfo->dobj.namespace->dobj.name,
16879 "PREPARE getColumnACLs(pg_catalog.oid) AS\n");
16892 "SELECT at.attname, "
16894 "'{}' AS acldefault, "
16895 "pip.privtype, pip.initprivs "
16896 "FROM pg_catalog.pg_attribute at "
16897 "LEFT JOIN pg_catalog.pg_init_privs pip ON "
16898 "(at.attrelid = pip.objoid "
16899 "AND pip.classoid = 'pg_catalog.pg_class'::pg_catalog.regclass "
16900 "AND at.attnum = pip.objsubid) "
16901 "WHERE at.attrelid = $1 AND "
16902 "NOT at.attisdropped "
16903 "AND (at.attacl IS NOT NULL OR pip.initprivs IS NOT NULL) "
16904 "ORDER BY at.attnum");
16912 "EXECUTE getColumnACLs('%u')",
16913 tbinfo->dobj.catId.oid);
16930 coldacl.initprivs = initprivs;
16940 tbinfo->dobj.namespace->dobj.name,
16967 "SELECT pg_catalog.pg_get_viewdef('%u'::pg_catalog.oid) AS viewdef",
16968 tbinfo->dobj.catId.oid);
16975 pg_fatal(
"query to obtain definition of view \"%s\" returned no data",
16978 pg_fatal(
"query to obtain definition of view \"%s\" returned more than one definition",
16985 pg_fatal(
"definition of view \"%s\" appears to be empty (length zero)",
17070 pg_log_warning(
"WITH OIDS is not supported anymore (table \"%s\")",
17089 tbinfo->dobj.catId.oid);
17122 tbinfo->dobj.catId.oid);
17125 "SELECT pg_catalog.pg_get_propgraphdef('%u'::pg_catalog.oid) AS pgdef",
17126 tbinfo->dobj.catId.oid);
17133 pg_fatal(
"query to obtain definition of property graph \"%s\" returned no data",
17136 pg_fatal(
"query to obtain definition of property graph \"%s\" returned more than one definition",
17143 pg_fatal(
"definition of property graph \"%s\" appears to be empty (length zero)",
17164 switch (
tbinfo->relkind)
17175 "SELECT pg_get_partkeydef('%u')",
17176 tbinfo->dobj.catId.oid);
17194 "SELECT fs.srvname, "
17195 "pg_catalog.array_to_string(ARRAY("
17196 "SELECT pg_catalog.quote_ident(option_name) || "
17197 "' ' || pg_catalog.quote_literal(option_value) "
17198 "FROM pg_catalog.pg_options_to_table(ftoptions) "
17199 "ORDER BY option_name"
17200 "), E',\n ') AS ftoptions "
17201 "FROM pg_catalog.pg_foreign_table ft "
17202 "JOIN pg_catalog.pg_foreign_server fs "
17203 "ON (fs.oid = ft.ftserver) "
17204 "WHERE ft.ftrelid = '%u'",
17205 tbinfo->dobj.catId.oid);
17225 numParents =
tbinfo->numParents;
17230 tbinfo->dobj.catId.oid);
17274 tbinfo->attrdefs[
j]->dobj.dump &&
17275 !
tbinfo->attrdefs[
j]->separate);
17283 (
tbinfo->notnull_islocal[
j] ||
17335 tbinfo->attrdefs[
j]->adef_expr);
17338 tbinfo->attrdefs[
j]->adef_expr);
17341 tbinfo->attrdefs[
j]->adef_expr);
17346 if (
tbinfo->notnull_constrs[
j][0] ==
'\0')
17352 if (
tbinfo->notnull_noinh[
j])
17391 if (
tbinfo->notnull_constrs[
j][0] ==
'\0')
17399 if (
tbinfo->notnull_noinh[
j])
17447 if (numParents > 0 && !
tbinfo->ispartition &&
17451 for (k = 0; k < numParents; k++)
17513 "pg_catalog.pg_class",
17514 "MATERIALIZED VIEW",
17525 if (
tbinfo->attmissingval[
j][0] !=
'\0')
17529 "SELECT pg_catalog.binary_upgrade_set_missing_value(");
17584 "UPDATE pg_catalog.pg_attribute\n"
17585 "SET attlen = v.dlen, "
17586 "attalign = v.dalign, "
17587 "attbyval = false\n"
17608 "WHERE attrelid = ");
17611 " AND attname = v.dname;\n");
17623 if (!
tbinfo->attisdropped[
j] &&
17630 "SET attislocal = false\n"
17631 "WHERE attrelid = ");
17634 " AND attname IN (");
17668 if (
tbinfo->notnull_constrs[
j][0] !=
'\0')
17673 "SET conislocal = false\n"
17674 "WHERE contype = 'n' AND conrelid = ");
17689 "SET conislocal = false\n"
17690 "WHERE contype = 'n' AND conrelid = ");
17707 if (extra->
len > 0)
17724 for (k = 0; k <
tbinfo->ncheck; k++)
17741 "SET conislocal = false\n"
17742 "WHERE contype = 'c' AND conrelid = ");
17758 if (numParents > 0 && !
tbinfo->ispartition)
17761 for (k = 0; k < numParents; k++)
17794 "SET relfrozenxid = '%u', relminmxid = '%u'\n"
17806 appendPQExpBufferStr(q,
"\n-- For binary upgrade, set toast's relfrozenxid and relminmxid\n");
17808 "SET relfrozenxid = '%u', relminmxid = '%u'\n"
17809 "WHERE oid = '%u';\n",
17810 tbinfo->toast_frozenxid,
17827 "SET relispopulated = 't'\n"
17848 if (
tbinfo->attstattarget[
j] >= 0)
17849 appendPQExpBuffer(q,
"ALTER %sTABLE ONLY %s ALTER COLUMN %s SET STATISTICS %d;\n",
17860 switch (
tbinfo->attstorage[
j])
17882 appendPQExpBuffer(q,
"ALTER %sTABLE ONLY %s ALTER COLUMN %s SET STORAGE %s;\n",
17895 switch (
tbinfo->attcompression[
j])
17909 appendPQExpBuffer(q,
"ALTER %sTABLE ONLY %s ALTER COLUMN %s SET COMPRESSION %s;\n",
17918 if (
tbinfo->attoptions[
j][0] !=
'\0')
17928 tbinfo->attfdwoptions[
j][0] !=
'\0')
17930 "ALTER FOREIGN TABLE ONLY %s ALTER COLUMN %s OPTIONS (\n"
17967 if (
tbinfo->forcerowsec)
17976 tbinfo->dobj.namespace->dobj.name);
17981 char *tableam =
NULL;
17995 tableam =
tbinfo->amname;
17999 .namespace =
tbinfo->dobj.namespace->dobj.name,
18001 .tableam = tableam,
18002 .relkind =
tbinfo->relkind,
18003 .owner =
tbinfo->rolname,
18005 .section =
tbinfo->postponed_def ?
18007 .createStmt = q->
data,
18008 .dropStmt =
delq->data));
18024 fout->remoteVersion >= 180000)
18055 .namespace =
tbinfo->dobj.namespace->dobj.name,
18056 .owner =
tbinfo->rolname,
18057 .description =
"COMMENT",
18060 .deps = &(
tbinfo->dobj.dumpId),
18121 "PREPARE dumpTableAttach(pg_catalog.oid) AS\n");
18124 "SELECT pg_get_expr(c.relpartbound, c.oid) "
18126 "WHERE c.oid = $1");
18134 "EXECUTE dumpTableAttach('%u')",
18142 "ALTER TABLE ONLY %s ",
18145 "ATTACH PARTITION %s %s;\n",
18158 .namespace =
attachinfo->dobj.namespace->dobj.name,
18160 .description =
"TABLE ATTACH",
18162 .createStmt = q->
data));
18176 int adnum =
adinfo->adnum;
18199 "ALTER %sTABLE ONLY %s ALTER COLUMN %s SET DEFAULT %s;\n",
18212 .
namespace =
tbinfo->dobj.namespace->dobj.name,
18213 .owner =
tbinfo->rolname,
18214 .description =
"DEFAULT",
18216 .createStmt = q->
data,
18217 .dropStmt =
delq->data));
18236 return tblInfo->attnames[attrnum - 1];
18252 pg_fatal(
"invalid column number %d for table \"%s\"",
18253 attrnum,
tblInfo->dobj.name);
18291 char *indstatcols =
indxinfo->indstatcols;
18292 char *indstatvals =
indxinfo->indstatvals;
18325 if (
strlen(indstatcols) != 0 ||
strlen(indstatvals) != 0)
18330 pg_fatal(
"could not parse index statistic columns");
18332 pg_fatal(
"could not parse index statistic values");
18334 pg_fatal(
"mismatched number of columns and values for index statistics");
18353 "pg_catalog.pg_class",
18381 .namespace =
tbinfo->dobj.namespace->dobj.name,
18382 .tablespace =
indxinfo->tablespace,
18383 .owner =
tbinfo->rolname,
18384 .description =
"INDEX",
18386 .createStmt = q->
data,
18387 .dropStmt =
delq->data));
18396 tbinfo->dobj.namespace->dobj.name,
18416 if (!
fout->dopt->dumpSchema)
18441 .namespace =
attachinfo->dobj.namespace->dobj.name,
18442 .owner =
attachinfo->parentIdx->indextable->rolname,
18443 .description =
"INDEX ATTACH",
18445 .createStmt = q->
data));
18477 "pg_catalog.pg_get_statisticsobjdef('%u'::pg_catalog.oid)",
18508 .description =
"STATISTICS",
18510 .createStmt = q->
data,
18511 .dropStmt =
delq->data));
18563 "PREPARE getExtStatsStats(pg_catalog.name, pg_catalog.name) AS\n"
18572 if (
fout->remoteVersion >= 150000)
18603 if (
fout->remoteVersion >= 190000)
18608 "SELECT json_agg( "
18609 " json_build_object( "
18611 " string_to_array(kv.key, ', ')::integer[], "
18613 " kv.value::bigint )) "
18614 "FROM json_each_text(e.n_distinct::text::json) AS kv"
18615 ") AS n_distinct, "
18617 "SELECT json_agg( "
18618 " json_build_object( "
18620 " string_to_array( "
18621 " split_part(kv.key, ' => ', 1), "
18622 " ', ')::integer[], "
18624 " split_part(kv.key, ' => ', 2)::integer, "
18626 " kv.value::double precision )) "
18627 "FROM json_each_text(e.dependencies::text::json) AS kv "
18628 ") AS dependencies, ");
18631 if (
fout->remoteVersion >= 130000)
18633 "e.most_common_vals, e.most_common_freqs, "
18634 "e.most_common_base_freqs, ");
18637 "NULL AS most_common_vals, NULL AS most_common_freqs, "
18638 "NULL AS most_common_base_freqs, ");
18641 if (
fout->remoteVersion >= 140000)
18650 "SELECT jsonb_pretty(jsonb_agg("
18651 "nullif(j.obj, '{}'::jsonb))) "
18652 "FROM pg_stats_ext_exprs AS ee "
18653 "CROSS JOIN LATERAL jsonb_strip_nulls("
18654 " jsonb_build_object( "
18655 " 'null_frac', ee.null_frac::text, "
18656 " 'avg_width', ee.avg_width::text, "
18657 " 'n_distinct', ee.n_distinct::text, "
18658 " 'most_common_vals', ee.most_common_vals::text, "
18659 " 'most_common_freqs', ee.most_common_freqs::text, "
18660 " 'histogram_bounds', ee.histogram_bounds::text, "
18661 " 'correlation', ee.correlation::text, "
18662 " 'most_common_elems', ee.most_common_elems::text, "
18663 " 'most_common_elem_freqs', ee.most_common_elem_freqs::text, "
18664 " 'elem_count_histogram', ee.elem_count_histogram::text");
18667 if (
fout->remoteVersion >= 190000)
18670 " 'range_length_histogram', ee.range_length_histogram::text, "
18671 " 'range_empty_frac', ee.range_empty_frac::text, "
18672 " 'range_bounds_histogram', ee.range_bounds_histogram::text");
18676 "WHERE ee.statistics_schemaname = $1 "
18677 "AND ee.statistics_name = $2 ");
18679 if (
fout->remoteVersion >= 150000)
18688 if (
fout->remoteVersion >= 120000)
18690 "FROM pg_catalog.pg_stats_ext AS e "
18691 "WHERE e.statistics_schemaname = $1 "
18692 "AND e.statistics_name = $2 ");
18696 "SELECT s.stxndistinct AS n_distinct, "
18697 " s.stxdependencies AS dependencies "
18698 "FROM pg_catalog.pg_statistic_ext AS s "
18699 "JOIN pg_catalog.pg_namespace AS n "
18700 "ON n.oid = s.stxnamespace "
18701 "WHERE n.nspname = $1 "
18702 "AND s.stxname = $2 "
18741 for (
int i = 0;
i < nstats;
i++)
18746 pg_fatal(
"inherited cannot be NULL");
18749 "SELECT * FROM pg_catalog.pg_restore_extended_stats(\n");
18751 fout->remoteVersion);
18798 .description =
"EXTENDED STATISTICS DATA",
18800 .createStmt = out->
data,
18832 if (
coninfo->contype ==
'p' ||
18843 pg_fatal(
"missing index for constraint \"%s\"",
18863 coninfo->contype ==
'p' ?
"PRIMARY KEY" :
"UNIQUE");
18874 for (k = 0; k <
indxinfo->indnkeyattrs; k++)
18884 (k == 0) ?
"" :
", ",
18903 (k ==
indxinfo->indnkeyattrs) ?
"" :
", ",
18954 "pg_catalog.pg_class",
"INDEX",
18967 .
namespace =
tbinfo->dobj.namespace->dobj.name,
18968 .tablespace =
indxinfo->tablespace,
18969 .owner =
tbinfo->rolname,
18970 .description =
"CONSTRAINT",
18972 .createStmt = q->
data,
18973 .dropStmt =
delq->data));
18975 else if (
coninfo->contype ==
'f')
19007 .
namespace =
tbinfo->dobj.namespace->dobj.name,
19008 .owner =
tbinfo->rolname,
19009 .description =
"FK CONSTRAINT",
19011 .createStmt = q->
data,
19012 .dropStmt =
delq->data));
19021 const char *keyword;
19024 keyword =
"CHECK CONSTRAINT";
19026 keyword =
"CONSTRAINT";
19045 .
namespace =
tbinfo->dobj.namespace->dobj.name,
19046 .owner =
tbinfo->rolname,
19047 .description = keyword,
19049 .createStmt = q->
data,
19050 .dropStmt =
delq->data));
19063 const char *keyword;
19066 keyword =
"CHECK CONSTRAINT";
19068 keyword =
"CONSTRAINT";
19086 .
namespace =
tyinfo->dobj.namespace->dobj.name,
19087 .owner =
tyinfo->rolname,
19088 .description = keyword,
19090 .createStmt = q->
data,
19091 .dropStmt =
delq->data));
19102 tyinfo->dobj.namespace->dobj.name,
19112 pg_fatal(
"unrecognized constraint type: %c",
19147 tbinfo->dobj.namespace->dobj.name,
19197 if (
fout->remoteVersion < 180000 ||
19198 (!
fout->dopt->dumpData && !
fout->dopt->sequence_data))
19199 query =
"SELECT seqrelid, format_type(seqtypid, NULL), "
19200 "seqstart, seqincrement, "
19202 "seqcache, seqcycle, "
19204 "FROM pg_catalog.pg_sequence "
19205 "ORDER BY seqrelid";
19207 query =
"SELECT seqrelid, format_type(seqtypid, NULL), "
19208 "seqstart, seqincrement, "
19210 "seqcache, seqcycle, "
19211 "last_value, is_called "
19212 "FROM pg_catalog.pg_sequence, "
19213 "pg_get_sequence_data(seqrelid) "
19214 "ORDER BY seqrelid;";
19265 key.oid =
tbinfo->dobj.catId.oid;
19288 pg_fatal(
"unrecognized sequence type: %d",
seq->seqtype);
19295 if (!
tbinfo->is_identity_sequence)
19306 tbinfo->dobj.catId.oid);
19314 if (
tbinfo->is_identity_sequence)
19322 "ALTER COLUMN %s ADD GENERATED ",
19338 "UNLOGGED" :
"LOGGED");
19343 "CREATE %sSEQUENCE %s\n",
19368 seq->cache, (
seq->cycled ?
"\n CYCLE" :
""));
19370 if (
tbinfo->is_identity_sequence)
19380 tbinfo->dobj.namespace->dobj.name);
19385 .namespace =
tbinfo->dobj.namespace->dobj.name,
19386 .owner =
tbinfo->rolname,
19387 .description =
"SEQUENCE",
19389 .createStmt = query->
data,
19390 .dropStmt =
delqry->data));
19408 if (owning_tab ==
NULL)
19409 pg_fatal(
"failed sanity check, parent table with OID %u of sequence with OID %u not found",
19425 .namespace =
tbinfo->dobj.namespace->dobj.name,
19426 .owner =
tbinfo->rolname,
19427 .description =
"SEQUENCE OWNED BY",
19429 .createStmt = query->
data,
19430 .deps = &(
tbinfo->dobj.dumpId),
19464 if (!
fout->dopt->dumpData && !
fout->dopt->sequence_data)
19477 if (
fout->remoteVersion < 180000)
19482 "SELECT last_value, is_called FROM %s",
19488 pg_fatal(
ngettext(
"query to get data of sequence \"%s\" returned %d row (expected 1)",
19489 "query to get data of sequence \"%s\" returned %d rows (expected 1)",
19506 key.oid =
tbinfo->dobj.catId.oid;
19511 pg_fatal(
"failed to get data for sequence \"%s\"; user may lack "
19512 "SELECT privilege on the sequence or the sequence may "
19513 "have been concurrently dropped",
19524 last, (
called ?
"true" :
"false"));
19529 .namespace =
tbinfo->dobj.namespace->dobj.name,
19530 .owner =
tbinfo->rolname,
19531 .description =
"SEQUENCE SET",
19533 .createStmt = query->
data,
19534 .deps = &(
tbinfo->dobj.dumpId),
19575 "pg_catalog.pg_trigger",
"TRIGGER",
19578 if (
tginfo->tgispartition)
19593 switch (
tginfo->tgenabled)
19613 else if (
tginfo->tgenabled !=
't' &&
tginfo->tgenabled !=
'O')
19618 switch (
tginfo->tgenabled)
19646 .
namespace =
tbinfo->dobj.namespace->dobj.name,
19647 .owner =
tbinfo->rolname,
19648 .description =
"TRIGGER",
19650 .createStmt = query->
data,
19651 .dropStmt =
delqry->data));
19703 if (
evtinfo->evtenabled !=
'O')
19736 .description =
"EVENT TRIGGER",
19738 .createStmt = query->
data,
19739 .dropStmt =
delqry->data));
19826 "SELECT pg_catalog.pg_get_ruledef('%u'::pg_catalog.oid)",
19832 pg_fatal(
"query to get rule \"%s\" for table \"%s\" failed: wrong number of rows returned",
19895 .
namespace =
tbinfo->dobj.namespace->dobj.name,
19896 .owner =
tbinfo->rolname,
19897 .description =
"RULE",
19899 .createStmt = cmd->
data,
19900 .dropStmt =
delcmd->data));
19905 tbinfo->dobj.namespace->dobj.name,
19948 "classid, objid, refobjid "
19950 "WHERE refclassid = 'pg_extension'::regclass "
19951 "AND deptype = 'e' "
19969 for (
i = 0;
i < ntups;
i++)
20051 char *extcondition =
curext->extcondition;
20063 curext->dobj.catId.oid))
20072 curext->dobj.catId.oid))
20075 if (
strlen(extconfig) != 0 ||
strlen(extcondition) != 0)
20080 pg_fatal(
"could not parse %s array",
"extconfig");
20082 pg_fatal(
"could not parse %s array",
"extcondition");
20084 pg_fatal(
"mismatched number of configurations and conditions for extension");
20110 if (
configtbl->dobj.namespace->dobj.dump &
20123 configtbl->dobj.namespace->dobj.catId.oid))
20155 "SELECT conrelid, confrelid "
20156 "FROM pg_constraint "
20157 "JOIN pg_depend ON (objid = confrelid) "
20158 "WHERE contype = 'f' "
20159 "AND refclassid = 'pg_extension'::regclass "
20160 "AND classid = 'pg_class'::regclass;");
20169 for (
i = 0;
i < ntups;
i++)
20183 contable ==
NULL ||
20229 "classid, objid, refclassid, refobjid, deptype "
20231 "WHERE deptype != 'p' AND deptype != 'e'\n");
20244 "SELECT 'pg_opfamily'::regclass AS classid, amopfamily AS objid, refclassid, refobjid, deptype "
20245 "FROM pg_depend d, pg_amop o "
20246 "WHERE deptype NOT IN ('p', 'e', 'i') AND "
20247 "classid = 'pg_amop'::regclass AND objid = o.oid "
20248 "AND NOT (refclassid = 'pg_opfamily'::regclass AND amopfamily = refobjid)\n");
20252 "SELECT 'pg_opfamily'::regclass AS classid, amprocfamily AS objid, refclassid, refobjid, deptype "
20253 "FROM pg_depend d, pg_amproc p "
20254 "WHERE deptype NOT IN ('p', 'e', 'i') AND "
20255 "classid = 'pg_amproc'::regclass AND objid = p.oid "
20256 "AND NOT (refclassid = 'pg_opfamily'::regclass AND amprocfamily = refobjid)\n");
20262 if (
fout->remoteVersion >= 190000)
20264 "SELECT 'pg_class'::regclass AS classid, pgepgid AS objid, refclassid, refobjid, deptype "
20265 "FROM pg_depend d, pg_propgraph_element pge "
20266 "WHERE deptype NOT IN ('p', 'e', 'i') AND "
20267 "classid = 'pg_propgraph_element'::regclass AND objid = pge.oid\n");
20289 for (
i = 0;
i < ntups;
i++)
20301 if (dobj ==
NULL ||
20336 if (deptype ==
'x')
20346 if (deptype ==
'i' &&
20461 if (((
RuleInfo *) dobj)->separate)
20540 if (dobj->
nDeps <= 0)
20548 &dependencies, &nDeps, &allocDeps);
20564 DumpId **dependencies,
int *nDeps,
int *allocDeps)
20583 if (*nDeps >= *allocDeps)
20588 (*dependencies)[*nDeps] =
depid;
20602 dependencies, nDeps, allocDeps);
20639 appendPQExpBuffer(query,
"SELECT pg_catalog.format_type('%u'::pg_catalog.oid, NULL)",
20671 int numatts =
ti->numatts;
20672 char **attnames =
ti->attnames;
20673 bool *attisdropped =
ti->attisdropped;
20674 char *attgenerated =
ti->attgenerated;
20680 for (
i = 0;
i < numatts;
i++)
20682 if (attisdropped[
i])
20684 if (attgenerated[
i])
20696 return buffer->
data;
20706 return (reloptions !=
NULL &&
strlen(reloptions) > 2);
20721 fout->std_strings);
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)
TableInfo * findTableByOid(Oid oid)
ExtensionInfo * findExtensionByOid(Oid oid)
CollInfo * findCollationByOid(Oid oid)
SubscriptionInfo * findSubscriptionByOid(Oid oid)
OprInfo * findOprByOid(Oid oid)
NamespaceInfo * findNamespaceByOid(Oid oid)
void addObjectDependency(DumpableObject *dobj, DumpId refId)
DumpableObject * findObjectByDumpId(DumpId dumpId)
void parseOidArray(const char *str, Oid *array, int arraysize)
ExtensionInfo * findOwningExtension(CatalogId catalogId)
TableInfo * getSchemaData(Archive *fout, int *numTablesPtr)
TypeInfo * findTypeByOid(Oid oid)
DumpId createDumpId(void)
DumpableObject * findObjectByCatalogId(CatalogId catalogId)
void AssignDumpId(DumpableObject *dobj)
void getDumpableObjects(DumpableObject ***objs, int *numObjs)
PublicationInfo * findPublicationByOid(Oid oid)
void on_exit_close_archive(Archive *AHX)
void init_parallel_dump_utils(void)
static void cleanup(void)
static const gbtree_vinfo tinfo
#define ngettext(s, p, n)
#define Assert(condition)
#define PG_TEXTDOMAIN(domain)
#define StaticAssertDecl(condition, errmessage)
#define OidIsValid(objectId)
void set_pglocale_pgservice(const char *argv0, const char *app)
char * supports_compression(const pg_compress_specification compression_spec)
char * validate_compress_specification(pg_compress_specification *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)
#define PG_COMPRESSION_OPTION_WORKERS
void parse_compress_options(const char *option, char **algorithm, char **detail)
#define ALWAYS_SECURE_SEARCH_PATH_SQL
char * generate_restrict_key(void)
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)
bool valid_restrict_key(const char *restrict_key)
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)
char * sanitize_line(const char *str, bool want_hyphen)
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)
char * PQdb(const PGconn *conn)
const char * PQparameterStatus(const PGconn *conn, const char *paramName)
int PQclientEncoding(const PGconn *conn)
char * PQerrorMessage(const PGconn *conn)
int PQsetClientEncoding(PGconn *conn, const char *encoding)
void PQfreemem(void *ptr)
Oid PQftype(const PGresult *res, int field_num)
int PQfnumber(const PGresult *res, const char *field_name)
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_malloc(size_t size)
char * pg_strdup(const char *in)
#define pg_realloc_array(pointer, type, count)
#define pg_malloc_array(type, count)
#define pg_malloc0_object(type)
#define pg_malloc_object(type)
#define pg_malloc0_array(type, count)
@ DATA_DIR_SYNC_METHOD_FSYNC
void filter_init(FilterStateData *fstate, const char *filename, exit_function f_exit)
void filter_free(FilterStateData *fstate)
const char * filter_object_type_name(FilterObjectType fot)
bool filter_read_item(FilterStateData *fstate, char **objname, FilterCommandType *comtype, FilterObjectType *objtype)
void pg_log_filter_error(FilterStateData *fstate, const char *fmt,...)
@ 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)
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)
void pfree(void *pointer)
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)
#define check_mut_excl_opts(set, opt,...)
static AmcheckOptions opts
int EndLO(Archive *AHX, Oid oid)
void ProcessArchiveRestoreOptions(Archive *AHX)
RestoreOptions * NewRestoreOptions(void)
#define appendStringLiteralAH(buf, str, AH)
int StartLO(Archive *AHX, Oid oid)
enum _archiveFormat ArchiveFormat
void ConnectDatabaseAhx(Archive *AHX, const ConnParams *cparams, bool isReconnect)
void CloseArchive(Archive *AHX)
Archive * CreateArchive(const char *FileSpec, const ArchiveFormat fmt, const pg_compress_specification compression_spec, bool dosync, ArchiveMode mode, SetupWorkerPtrType setupDumpWorker, DataDirSyncMethod sync_method)
@ PREPQUERY_DUMPTABLEATTACH
@ PREPQUERY_DUMPRANGETYPE
@ PREPQUERY_DUMPEXTSTATSOBJSTATS
@ PREPQUERY_GETATTRIBUTESTATS
@ 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 TocIDRequired(ArchiveHandle *AH, DumpId id)
TocEntry * ArchiveEntry(Archive *AHX, CatalogId catalogId, DumpId dumpId, ArchiveOpts *opts)
#define ARCHIVE_OPTS(...)
int(* DataDumperPtr)(Archive *AH, const void *userArg)
void ExecuteSqlStatement(Archive *AHX, const char *query)
PGresult * ExecuteSqlQuery(Archive *AHX, const char *query, ExecStatusType status)
PGresult * ExecuteSqlQueryForSingleRow(Archive *fout, const char *query)
void exit_nicely(int code)
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)
ExtensionInfo * getExtensions(Archive *fout, int *numExtensions)
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 char * dumpRelationStats_dumper(Archive *fout, const void *userArg, const TocEntry *te)
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 dumpRelationStats(Archive *fout, const RelStatsInfo *rsinfo)
static void dumpTableComment(Archive *fout, const TableInfo *tbinfo, const char *reltypename)
static SimpleStringList extension_include_patterns
static void selectDumpableNamespace(NamespaceInfo *nsinfo, Archive *fout)
InhInfo * getInherits(Archive *fout, int *numInherits)
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)
void getTypes(Archive *fout)
static void dumpAccessMethod(Archive *fout, const AccessMethodInfo *aminfo)
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 RelStatsInfo * getRelationStatistics(Archive *fout, DumpableObject *rel, int32 relpages, char *reltuples, int32 relallvisible, int32 relallfrozen, char relkind, char **indAttNames, int nindAttNames)
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 PGresult * fetchAttributeStats(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 void selectDumpableCast(CastInfo *cast, Archive *fout)
void getCasts(Archive *fout)
static void dumpPublication(Archive *fout, const PublicationInfo *pubinfo)
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)
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)
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 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 determineNotNullFlags(Archive *fout, PGresult *res, int r, TableInfo *tbinfo, int j, int i_notnull_name, int i_notnull_comment, int i_notnull_invalidoid, int i_notnull_noinherit, int i_notnull_islocal, PQExpBuffer *invalidnotnulloids)
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)
TableInfo * getTables(Archive *fout, int *numTables)
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
static void dumpStatisticsExtStats(Archive *fout, const StatsExtInfo *statsextinfo)
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)
static void appendNamedArgument(PQExpBuffer out, Archive *fout, const char *argname, const char *argtype, const char *argval)
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
#define MAX_ATTR_STATS_RELS
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 char * get_language_name(Archive *fout, Oid langid)
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
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)
static char * format_aggregate_signature(const AggInfo *agginfo, Archive *fout, bool honor_quotes)
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 getSubscriptionRelations(Archive *fout)
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 DUMP_COMPONENT_STATISTICS
static int statistics_only
static int with_statistics
PGDLLIMPORT char * optarg
static char buf[DEFAULT_XLOG_SEG_SIZE]
#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)
void simple_ptr_list_append(SimplePtrList *list, void *ptr)
bool simple_oid_list_member(SimpleOidList *list, Oid val)
void simple_oid_list_append(SimpleOidList *list, Oid val)
PGconn * GetConnection(void)
const char * fmtId(const char *rawid)
void setFmtEncoding(int encoding)
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)
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
char * suboriginremotelsn
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
pg_compress_specification compression_spec
int disable_dollar_quoting
const char * lockWaitTimeout
struct _relStatsInfo * stats
bool is_identity_sequence
struct _tableInfo ** parents
struct _tableDataInfo * dataObj
const void * defnDumperArg
#define MinTransactionIdAttributeNumber
#define MaxCommandIdAttributeNumber
#define MaxTransactionIdAttributeNumber
#define TableOidAttributeNumber
#define SelfItemPointerAttributeNumber
#define MinCommandIdAttributeNumber
static StringInfo copybuf
static void * fn(void *arg)
#define FirstNormalObjectId
static char * error_detail
bool SplitGUCList(char *rawstring, char separator, List **namelist)