44 #include "catalog/pg_aggregate_d.h"
45 #include "catalog/pg_am_d.h"
46 #include "catalog/pg_attribute_d.h"
47 #include "catalog/pg_authid_d.h"
48 #include "catalog/pg_cast_d.h"
49 #include "catalog/pg_class_d.h"
50 #include "catalog/pg_default_acl_d.h"
51 #include "catalog/pg_largeobject_d.h"
52 #include "catalog/pg_largeobject_metadata_d.h"
53 #include "catalog/pg_proc_d.h"
55 #include "catalog/pg_trigger_d.h"
56 #include "catalog/pg_type_d.h"
123 "array length mismatch");
216 #define DUMP_DEFAULT_ROWS_PER_INSERT 1
223 #define MAX_BLOBS_PER_ARCHIVE_ENTRY 1000
228 #define fmtQualifiedDumpable(obj) \
229 fmtQualifiedId((obj)->dobj.namespace->dobj.name, \
234 const char *dumpencoding,
const char *dumpsnapshot,
252 bool with_child_tables);
254 const char *pattern);
259 static const char *
getRoleName(
const char *roleoid_str);
263 const char *
name,
const char *
namespace,
266 const char *initdb_comment);
268 const char *
name,
const char *
namespace,
270 int subid,
DumpId dumpId);
274 const char *
namespace,
const char *owner,
324 const char *servername,
const char *
namespace,
330 const char *nspname,
const char *tag,
const char *owner,
336 DumpId **dependencies,
int *nDeps,
int *allocDeps);
351 const FuncInfo *finfo,
bool honor_quotes);
373 bool force_array_type,
374 bool include_multirange_type);
386 const char *objnamespace);
391 const char *prefix,
Archive *fout);
415 bool g_verbose =
false;
416 const char *dumpencoding = NULL;
417 const char *dumpsnapshot = NULL;
418 char *use_role = NULL;
424 char *compression_detail = NULL;
425 char *compression_algorithm_str =
"none";
426 char *error_detail = NULL;
427 bool user_compression_defined =
false;
432 static struct option long_options[] = {
445 {
"jobs", 1, NULL,
'j'},
524 if (strcmp(argv[1],
"--help") == 0 || strcmp(argv[1],
"-?") == 0)
529 if (strcmp(argv[1],
"--version") == 0 || strcmp(argv[1],
"-V") == 0)
531 puts(
"pg_dump (PostgreSQL) " PG_VERSION);
538 while ((
c =
getopt_long(argc, argv,
"abBcCd:e:E:f:F:h:j:n:N:Op:RsS:t:T:U:vwWxZ:",
539 long_options, &optindex)) != -1)
656 &compression_detail);
657 user_compression_defined =
true;
763 pg_log_error(
"too many command-line arguments (first is \"%s\")",
782 pg_fatal(
"options -s/--schema-only and -a/--data-only cannot be used together");
785 pg_fatal(
"options -s/--schema-only and --include-foreign-data cannot be used together");
788 pg_fatal(
"option --include-foreign-data is not supported with parallel backup");
791 pg_fatal(
"options -c/--clean and -a/--data-only cannot be used together");
794 pg_fatal(
"option --if-exists requires option -c/--clean");
801 pg_fatal(
"option --on-conflict-do-nothing requires option --inserts, --rows-per-insert, or --column-inserts");
816 !user_compression_defined)
819 compression_algorithm_str =
"gzip";
821 compression_algorithm_str =
"none";
830 pg_fatal(
"unrecognized compression algorithm: \"%s\"",
831 compression_algorithm_str);
836 if (error_detail != NULL)
837 pg_fatal(
"invalid compression specification: %s",
841 if (error_detail != NULL)
850 pg_log_warning(
"compression option \"%s\" is not currently supported by pg_dump",
862 pg_fatal(
"parallel backup only supported by the directory format");
917 pg_fatal(
"no matching schemas were found");
934 pg_fatal(
"no matching tables were found");
962 pg_fatal(
"no matching extensions were found");
1001 getTableData(&dopt, tblinfo, numTables, RELKIND_SEQUENCE);
1057 boundaryObjs[0].dumpId, boundaryObjs[1].dumpId);
1076 for (
i = 0;
i < numObjs;
i++)
1153 printf(
_(
"%s dumps a database as a text file or to other formats.\n\n"),
progname);
1157 printf(
_(
"\nGeneral options:\n"));
1158 printf(
_(
" -f, --file=FILENAME output file or directory name\n"));
1159 printf(
_(
" -F, --format=c|d|t|p output file format (custom, directory, tar,\n"
1160 " plain text (default))\n"));
1161 printf(
_(
" -j, --jobs=NUM use this many parallel jobs to dump\n"));
1162 printf(
_(
" -v, --verbose verbose mode\n"));
1163 printf(
_(
" -V, --version output version information, then exit\n"));
1164 printf(
_(
" -Z, --compress=METHOD[:DETAIL]\n"
1165 " compress as specified\n"));
1166 printf(
_(
" --lock-wait-timeout=TIMEOUT fail after waiting TIMEOUT for a table lock\n"));
1167 printf(
_(
" --no-sync do not wait for changes to be written safely to disk\n"));
1168 printf(
_(
" --sync-method=METHOD set method for syncing files to disk\n"));
1169 printf(
_(
" -?, --help show this help, then exit\n"));
1171 printf(
_(
"\nOptions controlling the output content:\n"));
1172 printf(
_(
" -a, --data-only dump only the data, not the schema\n"));
1173 printf(
_(
" -b, --large-objects include large objects in dump\n"));
1174 printf(
_(
" --blobs (same as --large-objects, deprecated)\n"));
1175 printf(
_(
" -B, --no-large-objects exclude large objects in dump\n"));
1176 printf(
_(
" --no-blobs (same as --no-large-objects, deprecated)\n"));
1177 printf(
_(
" -c, --clean clean (drop) database objects before recreating\n"));
1178 printf(
_(
" -C, --create include commands to create database in dump\n"));
1179 printf(
_(
" -e, --extension=PATTERN dump the specified extension(s) only\n"));
1180 printf(
_(
" -E, --encoding=ENCODING dump the data in encoding ENCODING\n"));
1181 printf(
_(
" -n, --schema=PATTERN dump the specified schema(s) only\n"));
1182 printf(
_(
" -N, --exclude-schema=PATTERN do NOT dump the specified schema(s)\n"));
1183 printf(
_(
" -O, --no-owner skip restoration of object ownership in\n"
1184 " plain-text format\n"));
1185 printf(
_(
" -s, --schema-only dump only the schema, no data\n"));
1186 printf(
_(
" -S, --superuser=NAME superuser user name to use in plain-text format\n"));
1187 printf(
_(
" -t, --table=PATTERN dump only the specified table(s)\n"));
1188 printf(
_(
" -T, --exclude-table=PATTERN do NOT dump the specified table(s)\n"));
1189 printf(
_(
" -x, --no-privileges do not dump privileges (grant/revoke)\n"));
1190 printf(
_(
" --binary-upgrade for use by upgrade utilities only\n"));
1191 printf(
_(
" --column-inserts dump data as INSERT commands with column names\n"));
1192 printf(
_(
" --disable-dollar-quoting disable dollar quoting, use SQL standard quoting\n"));
1193 printf(
_(
" --disable-triggers disable triggers during data-only restore\n"));
1194 printf(
_(
" --enable-row-security enable row security (dump only content user has\n"
1196 printf(
_(
" --exclude-extension=PATTERN do NOT dump the specified extension(s)\n"));
1197 printf(
_(
" --exclude-table-and-children=PATTERN\n"
1198 " do NOT dump the specified table(s), including\n"
1199 " child and partition tables\n"));
1200 printf(
_(
" --exclude-table-data=PATTERN do NOT dump data for the specified table(s)\n"));
1201 printf(
_(
" --exclude-table-data-and-children=PATTERN\n"
1202 " do NOT dump data for the specified table(s),\n"
1203 " including child and partition tables\n"));
1204 printf(
_(
" --extra-float-digits=NUM override default setting for extra_float_digits\n"));
1205 printf(
_(
" --filter=FILENAME include or exclude objects and data from dump\n"
1206 " based on expressions in FILENAME\n"));
1207 printf(
_(
" --if-exists use IF EXISTS when dropping objects\n"));
1208 printf(
_(
" --include-foreign-data=PATTERN\n"
1209 " include data of foreign tables on foreign\n"
1210 " servers matching PATTERN\n"));
1211 printf(
_(
" --inserts dump data as INSERT commands, rather than COPY\n"));
1212 printf(
_(
" --load-via-partition-root load partitions via the root table\n"));
1213 printf(
_(
" --no-comments do not dump comments\n"));
1214 printf(
_(
" --no-publications do not dump publications\n"));
1215 printf(
_(
" --no-security-labels do not dump security label assignments\n"));
1216 printf(
_(
" --no-subscriptions do not dump subscriptions\n"));
1217 printf(
_(
" --no-table-access-method do not dump table access methods\n"));
1218 printf(
_(
" --no-tablespaces do not dump tablespace assignments\n"));
1219 printf(
_(
" --no-toast-compression do not dump TOAST compression methods\n"));
1220 printf(
_(
" --no-unlogged-table-data do not dump unlogged table data\n"));
1221 printf(
_(
" --on-conflict-do-nothing add ON CONFLICT DO NOTHING to INSERT commands\n"));
1222 printf(
_(
" --quote-all-identifiers quote all identifiers, even if not key words\n"));
1223 printf(
_(
" --rows-per-insert=NROWS number of rows per INSERT; implies --inserts\n"));
1224 printf(
_(
" --section=SECTION dump named section (pre-data, data, or post-data)\n"));
1225 printf(
_(
" --serializable-deferrable wait until the dump can run without anomalies\n"));
1226 printf(
_(
" --snapshot=SNAPSHOT use given snapshot for the dump\n"));
1227 printf(
_(
" --strict-names require table and/or schema include patterns to\n"
1228 " match at least one entity each\n"));
1229 printf(
_(
" --table-and-children=PATTERN dump only the specified table(s), including\n"
1230 " child and partition tables\n"));
1231 printf(
_(
" --use-set-session-authorization\n"
1232 " use SET SESSION AUTHORIZATION commands instead of\n"
1233 " ALTER OWNER commands to set ownership\n"));
1235 printf(
_(
"\nConnection options:\n"));
1236 printf(
_(
" -d, --dbname=DBNAME database to dump\n"));
1237 printf(
_(
" -h, --host=HOSTNAME database server host or socket directory\n"));
1238 printf(
_(
" -p, --port=PORT database server port number\n"));
1239 printf(
_(
" -U, --username=NAME connect as specified database user\n"));
1240 printf(
_(
" -w, --no-password never prompt for password\n"));
1241 printf(
_(
" -W, --password force password prompt (should happen automatically)\n"));
1242 printf(
_(
" --role=ROLENAME do SET ROLE before dump\n"));
1244 printf(
_(
"\nIf no database name is supplied, then the PGDATABASE environment\n"
1245 "variable value is used.\n\n"));
1246 printf(
_(
"Report bugs to <%s>.\n"), PACKAGE_BUGREPORT);
1247 printf(
_(
"%s home page: <%s>\n"), PACKAGE_NAME, PACKAGE_URL);
1252 const char *dumpsnapshot,
char *use_role)
1256 const char *std_strings;
1266 pg_fatal(
"invalid client encoding \"%s\" specified",
1277 AH->
std_strings = (std_strings && strcmp(std_strings,
"on") == 0);
1386 "SET TRANSACTION ISOLATION LEVEL "
1387 "SERIALIZABLE, READ ONLY, DEFERRABLE");
1390 "SET TRANSACTION ISOLATION LEVEL "
1391 "REPEATABLE READ, READ ONLY");
1413 pg_fatal(
"parallel dumps from standby servers are not supported by this server version");
1437 char *query =
"SELECT pg_catalog.pg_export_snapshot()";
1479 return archiveFormat;
1497 if (patterns->
head == NULL)
1507 for (cell = patterns->
head; cell; cell = cell->
next)
1513 "SELECT oid FROM pg_catalog.pg_namespace n\n");
1516 false, NULL,
"n.nspname", NULL, NULL, &dbbuf,
1519 pg_fatal(
"improper qualified name (too many dotted names): %s",
1521 else if (dotcnt == 1)
1527 pg_fatal(
"no matching schemas were found for pattern \"%s\"", cell->
val);
1556 if (patterns->
head == NULL)
1565 for (cell = patterns->
head; cell; cell = cell->
next)
1570 "SELECT oid FROM pg_catalog.pg_extension e\n");
1572 false, NULL,
"e.extname", NULL, NULL, NULL,
1575 pg_fatal(
"improper qualified name (too many dotted names): %s",
1580 pg_fatal(
"no matching extensions were found for pattern \"%s\"", cell->
val);
1608 if (patterns->
head == NULL)
1618 for (cell = patterns->
head; cell; cell = cell->
next)
1623 "SELECT oid FROM pg_catalog.pg_foreign_server s\n");
1625 false, NULL,
"s.srvname", NULL, NULL, NULL,
1628 pg_fatal(
"improper qualified name (too many dotted names): %s",
1633 pg_fatal(
"no matching foreign servers were found for pattern \"%s\"", cell->
val);
1660 if (patterns->
head == NULL)
1670 for (cell = patterns->
head; cell; cell = cell->
next)
1683 if (with_child_tables)
1690 "\nFROM pg_catalog.pg_class c"
1691 "\n LEFT JOIN pg_catalog.pg_namespace n"
1692 "\n ON n.oid OPERATOR(pg_catalog.=) c.relnamespace"
1693 "\nWHERE c.relkind OPERATOR(pg_catalog.=) ANY"
1694 "\n (array['%c', '%c', '%c', '%c', '%c', '%c'])\n",
1695 RELKIND_RELATION, RELKIND_SEQUENCE, RELKIND_VIEW,
1696 RELKIND_MATVIEW, RELKIND_FOREIGN_TABLE,
1697 RELKIND_PARTITIONED_TABLE);
1700 false,
"n.nspname",
"c.relname", NULL,
1701 "pg_catalog.pg_table_is_visible(c.oid)", &dbbuf,
1704 pg_fatal(
"improper relation name (too many dotted names): %s",
1706 else if (dotcnt == 2)
1710 if (with_child_tables)
1713 "\nSELECT i.inhrelid"
1714 "\nFROM partition_tree p"
1715 "\n JOIN pg_catalog.pg_inherits i"
1716 "\n ON p.relid OPERATOR(pg_catalog.=) i.inhparent"
1718 "\nSELECT relid FROM partition_tree");
1726 pg_fatal(
"no matching tables were found for pattern \"%s\"", cell->
val);
1753 pg_fatal(
"You are currently not connected to a database.");
1755 if (strcmp(db,
dbname) != 0)
1756 pg_fatal(
"cross-database references are not implemented: %s",
1844 strcmp(nsinfo->
dobj.
name,
"pg_catalog") == 0)
1853 else if (strncmp(nsinfo->
dobj.
name,
"pg_", 3) == 0 ||
1854 strcmp(nsinfo->
dobj.
name,
"information_schema") == 0)
1859 else if (strcmp(nsinfo->
dobj.
name,
"public") == 0)
1871 if (nsinfo->
nspowner == ROLE_PG_DATABASE_OWNER)
1951 tyinfo->
typrelkind != RELKIND_COMPOSITE_TYPE)
1956 if (tytable != NULL)
1996 if (dinfo->
dobj.namespace)
2184 if (dobj->namespace)
2201 const char *classname = tbinfo->
dobj.
name;
2213 const char *column_list;
2215 pg_log_info(
"dumping contents of table \"%s.%s\"",
2216 tbinfo->
dobj.namespace->dobj.
name, classname);
2234 if (tbinfo->
relkind == RELKIND_FOREIGN_TABLE)
2239 if (strlen(column_list) > 2)
2325 pg_log_error(
"Dumping the contents of table \"%s\" failed: PQgetCopyData() failed.", classname);
2335 pg_log_error(
"Dumping the contents of table \"%s\" failed: PQgetResult() failed.", classname);
2344 pg_log_warning(
"unexpected extra results during COPY of table \"%s\"",
2350 if (tbinfo->
relkind == RELKIND_FOREIGN_TABLE)
2377 int rows_this_statement = 0;
2380 if (tbinfo->
relkind == RELKIND_FOREIGN_TABLE)
2426 pg_fatal(
"wrong number of fields retrieved from table \"%s\"",
2436 if (insertStmt == NULL)
2468 for (
int field = 0; field < nfields; field++)
2488 if (rows_this_statement == 0)
2504 if (rows_per_statement == 1)
2506 else if (rows_this_statement > 0)
2511 for (
int field = 0; field < nfields; field++)
2515 if (attgenerated[field])
2550 if (strspn(s,
"0123456789 +-eE.") == strlen(s))
2585 if (++rows_this_statement >= rows_per_statement)
2588 archputs(
" ON CONFLICT DO NOTHING;\n", fout);
2592 rows_this_statement = 0;
2605 if (rows_this_statement > 0)
2608 archputs(
" ON CONFLICT DO NOTHING;\n", fout);
2618 if (insertStmt != NULL)
2623 if (tbinfo->
relkind == RELKIND_FOREIGN_TABLE)
2641 parentTbinfo = tbinfo->
parents[0];
2645 parentTbinfo = parentTbinfo->
parents[0];
2648 return parentTbinfo;
2666 parentTbinfo = tbinfo->
parents[0];
2672 parentTbinfo = parentTbinfo->
parents[0];
2694 char *tdDefn = NULL;
2696 const char *copyFrom;
2731 copyStmt = copyBuf->
data;
2751 .namespace = tbinfo->
dobj.namespace->dobj.
name,
2753 .description =
"TABLE DATA",
2755 .createStmt = tdDefn,
2756 .copyStmt = copyStmt,
2760 .dumpArg = tdinfo));
2818 .namespace = tbinfo->
dobj.namespace->dobj.
name,
2820 .description =
"MATERIALIZED VIEW DATA",
2822 .createStmt = q->
data,
2838 for (
i = 0;
i < numTables;
i++)
2841 (!relkind || tblinfo[
i].
relkind == relkind))
2865 if (tbinfo->
relkind == RELKIND_VIEW)
2868 if (tbinfo->
relkind == RELKIND_FOREIGN_TABLE &&
2874 if (tbinfo->
relkind == RELKIND_PARTITIONED_TABLE)
2890 if (tbinfo->
relkind == RELKIND_MATVIEW)
2892 else if (tbinfo->
relkind == RELKIND_SEQUENCE)
2905 tdinfo->
dobj.namespace = tbinfo->
dobj.namespace;
2945 "SELECT d1.objid, d2.refobjid, c2.relkind AS refrelkind "
2946 "FROM pg_depend d1 "
2947 "JOIN pg_class c1 ON c1.oid = d1.objid "
2949 " JOIN pg_rewrite r1 ON r1.ev_class = d1.objid "
2950 "JOIN pg_depend d2 ON d2.classid = 'pg_rewrite'::regclass "
2951 "AND d2.objid = r1.oid "
2952 "AND d2.refobjid <> d1.objid "
2953 "JOIN pg_class c2 ON c2.oid = d2.refobjid "
2954 "AND c2.relkind IN (" CppAsString2(RELKIND_MATVIEW)
","
2956 "WHERE d1.classid = 'pg_class'::regclass "
2958 "SELECT w.objid, d3.refobjid, c3.relkind "
2960 "JOIN pg_rewrite r3 ON r3.ev_class = w.refobjid "
2961 "JOIN pg_depend d3 ON d3.classid = 'pg_rewrite'::regclass "
2962 "AND d3.objid = r3.oid "
2963 "AND d3.refobjid <> w.refobjid "
2964 "JOIN pg_class c3 ON c3.oid = d3.refobjid "
2965 "AND c3.relkind IN (" CppAsString2(RELKIND_MATVIEW)
","
2968 "SELECT 'pg_class'::regclass::oid AS classid, objid, refobjid "
2980 for (
i = 0;
i < ntups;
i++)
3007 if (refdobj == NULL)
3014 if (refdobj == NULL)
3050 for (
i = 0;
i < numObjs;
i++)
3062 if (ftable == NULL ||
3135 "pg_encoding_to_char(encoding) AS encoding, "
3136 "datcollate, datctype, datfrozenxid, "
3137 "datacl, acldefault('d', datdba) AS acldefault, "
3138 "datistemplate, datconnlimit, ");
3148 appendPQExpBufferStr(dbQry,
"'c' AS datlocprovider, NULL AS datlocale, NULL AS datcollversion, ");
3154 "(SELECT spcname FROM pg_tablespace t WHERE t.oid = dattablespace) AS tablespace, "
3155 "shobj_description(oid, 'pg_database') AS description "
3157 "WHERE datname = current_database()");
3220 "CREATE DATABASE %s WITH TEMPLATE = template0 "
3221 "OID = %u STRATEGY = FILE_COPY",
3222 qdatname, dbCatId.
oid);
3243 pg_fatal(
"unrecognized locale provider: %s",
3246 if (strlen(collate) > 0 && strcmp(collate, ctype) == 0)
3253 if (strlen(collate) > 0)
3258 if (strlen(ctype) > 0)
3321 .createStmt = creaQry->
data,
3322 .dropStmt = delQry->
data));
3351 .description =
"COMMENT",
3353 .createStmt = dbQry->
data,
3371 if (seclabelQry->
len > 0)
3375 .description =
"SECURITY LABEL",
3377 .createStmt = seclabelQry->
data,
3392 qdatname, NULL, NULL,
3393 NULL, dba, &dbdacl);
3423 "SET datistemplate = false WHERE datname = ");
3444 "SET datfrozenxid = '%u', datminmxid = '%u'\n"
3446 frozenxid, minmxid);
3451 if (creaQry->
len > 0)
3457 .createStmt = creaQry->
data,
3458 .dropStmt = delQry->
data,
3459 .deps = &dbDumpId));
3471 int ii_relfrozenxid,
3480 appendPQExpBuffer(loFrozenQry,
"SELECT relfrozenxid, relminmxid, relfilenode, oid\n"
3481 "FROM pg_catalog.pg_class\n"
3482 "WHERE oid IN (%u, %u);\n",
3483 LargeObjectRelationId, LargeObjectLOidPNIndexId);
3485 appendPQExpBuffer(loFrozenQry,
"SELECT relfrozenxid, 0 AS relminmxid, relfilenode, oid\n"
3486 "FROM pg_catalog.pg_class\n"
3487 "WHERE oid IN (%u, %u);\n",
3488 LargeObjectRelationId, LargeObjectLOidPNIndexId);
3492 ii_relfrozenxid =
PQfnumber(lo_res,
"relfrozenxid");
3493 ii_relminmxid =
PQfnumber(lo_res,
"relminmxid");
3494 ii_relfilenode =
PQfnumber(lo_res,
"relfilenode");
3497 appendPQExpBufferStr(loHorizonQry,
"\n-- For binary upgrade, set pg_largeobject relfrozenxid and relminmxid\n");
3498 appendPQExpBufferStr(loOutQry,
"\n-- For binary upgrade, preserve pg_largeobject and index relfilenodes\n");
3505 "SET relfrozenxid = '%u', relminmxid = '%u'\n"
3506 "WHERE oid = %u;\n",
3514 if (oid == LargeObjectRelationId)
3516 "SELECT pg_catalog.binary_upgrade_set_next_heap_relfilenode('%u'::pg_catalog.oid);\n",
3518 else if (oid == LargeObjectLOidPNIndexId)
3520 "SELECT pg_catalog.binary_upgrade_set_next_index_relfilenode('%u'::pg_catalog.oid);\n",
3525 "TRUNCATE pg_catalog.pg_largeobject;\n");
3532 .createStmt = loOutQry->
data));
3564 "WHERE setrole = 0 AND setdatabase = '%u'::oid",
3571 "DATABASE",
dbname, NULL, NULL,
3578 "FROM pg_db_role_setting s, pg_roles r "
3579 "WHERE setrole = r.oid AND setdatabase = '%u'::oid",
3614 .createStmt = qry->
data));
3626 const char *stdstrings = AH->
std_strings ?
"on" :
"off";
3629 pg_log_info(
"saving \"standard_conforming_strings = %s\"",
3639 .createStmt = qry->
data));
3653 char **schemanames = NULL;
3654 int nschemanames = 0;
3665 "SELECT pg_catalog.current_schemas(false)");
3668 pg_fatal(
"could not parse result of current_schemas()");
3676 for (
i = 0;
i < nschemanames;
i++)
3693 .createStmt = qry->
data));
3730 "SELECT oid, lomowner, lomacl, "
3731 "acldefault('L', lomowner) AS acldefault "
3732 "FROM pg_largeobject_metadata "
3733 "ORDER BY lomowner, lomacl::pg_catalog.text, oid");
3752 for (
i = 0;
i < ntups;
i += n)
3765 if (strcmp(thisowner,
PQgetvalue(
res,
i + n, i_lomowner)) != 0 ||
3780 snprintf(namebuf,
sizeof(namebuf),
"%u..%u", thisoid,
3783 snprintf(namebuf,
sizeof(namebuf),
"%u", thisoid);
3791 loinfo->
looids[0] = thisoid;
3793 for (
int k = 1; k < n; k++)
3800 extraID.
tableoid = LargeObjectRelationId;
3856 for (
int i = 0;
i < loinfo->
numlos;
i++)
3863 .description =
"BLOB METADATA",
3865 .createStmt = cquery->
data,
3866 .dropStmt =
"-- dummy"));
3875 for (
int i = 0;
i < loinfo->
numlos;
i++)
3915 snprintf(tagbuf,
sizeof(tagbuf),
"LARGE OBJECTS %u..%u",
3919 "LARGE OBJECT", namebuf, NULL, NULL,
3925 "LARGE OBJECT", namebuf, NULL, NULL,
3946 for (
int i = 0;
i < loinfo->
numlos;
i++)
3955 pg_fatal(
"could not open large object %u: %s",
3965 pg_fatal(
"error reading large object %u: %s",
3995 int i_polpermissive;
4014 for (
i = 0;
i < numTables;
i++)
4023 if (tbinfo->
relkind != RELKIND_RELATION &&
4024 tbinfo->
relkind != RELKIND_PARTITIONED_TABLE)
4028 if (tbloids->
len > 1)
4049 polinfo->
dobj.namespace = tbinfo->
dobj.namespace;
4068 pg_log_info(
"reading row-level security policies");
4071 "SELECT pol.oid, pol.tableoid, pol.polrelid, pol.polname, pol.polcmd, ");
4077 "CASE WHEN pol.polroles = '{0}' THEN NULL ELSE "
4078 " 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, "
4079 "pg_catalog.pg_get_expr(pol.polqual, pol.polrelid) AS polqual, "
4080 "pg_catalog.pg_get_expr(pol.polwithcheck, pol.polrelid) AS polwithcheck "
4081 "FROM unnest('%s'::pg_catalog.oid[]) AS src(tbloid)\n"
4082 "JOIN pg_catalog.pg_policy pol ON (src.tbloid = pol.polrelid)",
4102 for (
j = 0;
j < ntups;
j++)
4114 polinfo[
j].
dobj.namespace = tbinfo->
dobj.namespace;
4123 polinfo[
j].polroles = NULL;
4186 .namespace = polinfo->
dobj.namespace->dobj.
name,
4188 .description =
"ROW SECURITY",
4190 .createStmt = query->
data,
4198 if (polinfo->
polcmd ==
'*')
4200 else if (polinfo->
polcmd ==
'r')
4201 cmd =
" FOR SELECT";
4202 else if (polinfo->
polcmd ==
'a')
4203 cmd =
" FOR INSERT";
4204 else if (polinfo->
polcmd ==
'w')
4205 cmd =
" FOR UPDATE";
4206 else if (polinfo->
polcmd ==
'd')
4207 cmd =
" FOR DELETE";
4209 pg_fatal(
"unexpected policy command type: %c",
4245 .
namespace = polinfo->
dobj.namespace->dobj.
name,
4247 .description =
"POLICY",
4249 .createStmt = query->
data,
4250 .dropStmt = delqry->
data));
4296 "SELECT p.tableoid, p.oid, p.pubname, "
4298 "p.puballtables, p.pubinsert, p.pubupdate, p.pubdelete, p.pubtruncate, p.pubviaroot "
4299 "FROM pg_publication p");
4302 "SELECT p.tableoid, p.oid, p.pubname, "
4304 "p.puballtables, p.pubinsert, p.pubupdate, p.pubdelete, p.pubtruncate, false AS pubviaroot "
4305 "FROM pg_publication p");
4308 "SELECT p.tableoid, p.oid, p.pubname, "
4310 "p.puballtables, p.pubinsert, p.pubupdate, p.pubdelete, false AS pubtruncate, false AS pubviaroot "
4311 "FROM pg_publication p");
4333 for (
i = 0;
i < ntups;
i++)
4441 .description =
"PUBLICATION",
4443 .createStmt = query->
data,
4444 .dropStmt = delq->
data));
4487 "SELECT tableoid, oid, pnpubid, pnnspid "
4488 "FROM pg_catalog.pg_publication_namespace");
4502 for (
i = 0;
i < ntups;
i++)
4514 if (pubinfo == NULL)
4517 if (nspinfo == NULL)
4533 pubsinfo[
j].
dobj.namespace = nspinfo->
dobj.namespace;
4577 "SELECT tableoid, oid, prpubid, prrelid, "
4578 "pg_catalog.pg_get_expr(prqual, prrelid) AS prrelqual, "
4580 " WHEN pr.prattrs IS NOT NULL THEN\n"
4581 " (SELECT array_agg(attname)\n"
4583 " pg_catalog.generate_series(0, pg_catalog.array_upper(pr.prattrs::pg_catalog.int2[], 1)) s,\n"
4584 " pg_catalog.pg_attribute\n"
4585 " WHERE attrelid = pr.prrelid AND attnum = prattrs[s])\n"
4586 " ELSE NULL END) prattrs "
4587 "FROM pg_catalog.pg_publication_rel pr");
4590 "SELECT tableoid, oid, prpubid, prrelid, "
4591 "NULL AS prrelqual, NULL AS prattrs "
4592 "FROM pg_catalog.pg_publication_rel");
4608 for (
i = 0;
i < ntups;
i++)
4620 if (pubinfo == NULL)
4635 pubrinfo[
j].dobj.catId.tableoid =
4639 pubrinfo[
j].dobj.namespace = tbinfo->
dobj.namespace;
4640 pubrinfo[
j].dobj.name = tbinfo->
dobj.
name;
4641 pubrinfo[
j].publication = pubinfo;
4642 pubrinfo[
j].pubtable = tbinfo;
4644 pubrinfo[
j].pubrelqual = NULL;
4655 &attnames, &nattnames))
4656 pg_fatal(
"could not parse %s array",
"prattrs");
4658 for (
int k = 0; k < nattnames; k++)
4665 pubrinfo[
j].pubrattrs = attribs->
data;
4668 pubrinfo[
j].pubrattrs = NULL;
4711 .
namespace = schemainfo->
dobj.
name,
4713 .description =
"PUBLICATION TABLES IN SCHEMA",
4715 .createStmt = query->
data));
4749 if (pubrinfo->pubrattrs)
4752 if (pubrinfo->pubrelqual)
4771 ArchiveEntry(fout, pubrinfo->dobj.catId, pubrinfo->dobj.dumpId,
4773 .
namespace = tbinfo->
dobj.namespace->dobj.
name,
4775 .description =
"PUBLICATION TABLE",
4777 .createStmt = query->
data));
4796 if (
val && strcmp(
val,
"on") == 0)
4814 "SELECT set_config(name, '%s', false) "
4816 "WHERE name = 'restrict_nonsystem_relation_kind'",
4841 int i_subtwophasestate;
4842 int i_subdisableonerr;
4843 int i_subpasswordrequired;
4844 int i_subrunasowner;
4847 int i_subsynccommit;
4848 int i_subpublications;
4850 int i_suboriginremotelsn;
4864 "SELECT count(*) FROM pg_subscription "
4865 "WHERE subdbid = (SELECT oid FROM pg_database"
4866 " WHERE datname = current_database())",
4870 pg_log_warning(
"subscriptions not dumped because current user is not a superuser");
4879 "SELECT s.tableoid, s.oid, s.subname,\n"
4881 " s.subconninfo, s.subslotname, s.subsynccommit,\n"
4882 " s.subpublications,\n");
4896 " s.subtwophasestate,\n"
4897 " s.subdisableonerr,\n");
4900 " '%c' AS subtwophasestate,\n"
4901 " false AS subdisableonerr,\n",
4906 " s.subpasswordrequired,\n"
4907 " s.subrunasowner,\n"
4911 " 't' AS subpasswordrequired,\n"
4912 " 't' AS subrunasowner,\n"
4913 " '%s' AS suborigin,\n",
4918 " s.subenabled,\n");
4921 " false AS subenabled,\n");
4925 " s.subfailover\n");
4928 " false AS subfailover\n");
4931 "FROM pg_subscription s\n");
4935 "LEFT JOIN pg_catalog.pg_replication_origin_status o \n"
4936 " ON o.external_id = 'pg_' || s.oid::text \n");
4939 "WHERE s.subdbid = (SELECT oid FROM pg_database\n"
4940 " WHERE datname = current_database())");
4956 i_subtwophasestate =
PQfnumber(
res,
"subtwophasestate");
4958 i_subpasswordrequired =
PQfnumber(
res,
"subpasswordrequired");
4965 i_suboriginremotelsn =
PQfnumber(
res,
"suboriginremotelsn");
4971 for (
i = 0;
i < ntups;
i++)