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_cast_d.h" 48 #include "catalog/pg_class_d.h" 49 #include "catalog/pg_collation_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" 54 #include "catalog/pg_trigger_d.h" 55 #include "catalog/pg_type_d.h" 136 #define DUMP_DEFAULT_ROWS_PER_INSERT 1 141 #define fmtQualifiedDumpable(obj) \ 142 fmtQualifiedId((obj)->dobj.namespace->dobj.name, \ 147 const char *dumpencoding,
const char *dumpsnapshot,
166 const char *
namespace,
const char *owner,
172 const char *
namespace,
const char *owner,
221 const char *servername,
const char *
namespace,
227 const char *nspname,
const char *owner,
228 const char *acls,
const char *racls,
229 const char *initacls,
const char *initracls);
234 DumpId **dependencies,
int *nDeps,
int *allocDeps);
249 const FuncInfo *finfo,
int nallargs,
254 const FuncInfo *finfo,
bool honor_quotes);
276 bool force_array_type,
277 bool include_multirange_type);
282 Oid pg_class_oid,
bool is_index);
287 const char *objnamespace);
292 int enc,
bool coll_unknown,
295 const char *prefix,
Archive *fout);
317 bool g_verbose =
false;
318 const char *dumpencoding = NULL;
319 const char *dumpsnapshot = NULL;
320 char *use_role = NULL;
323 int compressLevel = -1;
330 static struct option long_options[] = {
340 {
"jobs", 1, NULL,
'j'},
413 if (strcmp(argv[1],
"--help") == 0 || strcmp(argv[1],
"-?") == 0)
418 if (strcmp(argv[1],
"--version") == 0 || strcmp(argv[1],
"-V") == 0)
420 puts(
"pg_dump (PostgreSQL) " PG_VERSION);
427 while ((c =
getopt_long(argc, argv,
"abBcCd:E:f:F:h:j:n:N:Op:RsS:t:T:U:vwWxZ:",
428 long_options, &optindex)) != -1)
473 numWorkers = atoi(
optarg);
536 compressLevel = atoi(
optarg);
537 if (compressLevel < 0 || compressLevel > 9)
539 pg_log_error(
"compression level must be in range 0..9");
575 if (extra_float_digits < -15 || extra_float_digits > 3)
577 pg_log_error(
"extra_float_digits must be in range -15..3");
594 rowsPerInsert = strtol(
optarg, &endptr, 10);
596 if (endptr ==
optarg || *endptr !=
'\0' ||
597 rowsPerInsert <= 0 || rowsPerInsert > INT_MAX ||
628 pg_log_error(
"too many command-line arguments (first is \"%s\")",
630 fprintf(stderr,
_(
"Try \"%s --help\" for more information.\n"),
649 pg_log_error(
"options -s/--schema-only and -a/--data-only cannot be used together");
653 if (dopt.
schemaOnly && foreign_servers_include_patterns.
head != NULL)
654 fatal(
"options -s/--schema-only and --include-foreign-data cannot be used together");
656 if (numWorkers > 1 && foreign_servers_include_patterns.
head != NULL)
657 fatal(
"option --include-foreign-data is not supported with parallel backup");
661 pg_log_error(
"options -c/--clean and -a/--data-only cannot be used together");
666 fatal(
"option --if-exists requires option -c/--clean");
673 fatal(
"option --on-conflict-do-nothing requires option --inserts, --rows-per-insert, or --column-inserts");
683 if (compressLevel == -1)
694 if (compressLevel != 0)
695 pg_log_warning(
"requested compression not available in this installation -- archive will be uncompressed");
713 || numWorkers > MAXIMUM_WAIT_OBJECTS
716 fatal(
"invalid number of parallel jobs");
720 fatal(
"parallel backup only supported by the directory format");
724 fatal(
"option --index-collation-versions-unknown only works in binary upgrade mode");
779 fatal(
"Synchronized snapshots are not supported by this server version.\n" 780 "Run with --no-synchronized-snapshots instead if you do not need\n" 781 "synchronized snapshots.");
785 fatal(
"Exported snapshots are not supported by this server version.");
800 if (schema_include_patterns.
head != NULL)
803 &schema_include_oids,
805 if (schema_include_oids.
head == NULL)
806 fatal(
"no matching schemas were found");
809 &schema_exclude_oids,
814 if (table_include_patterns.
head != NULL)
819 if (table_include_oids.
head == NULL)
820 fatal(
"no matching tables were found");
827 &tabledata_exclude_oids,
831 &foreign_servers_include_oids);
865 getTableData(&dopt, tblinfo, numTables, RELKIND_SEQUENCE);
904 boundaryObjs[0].dumpId, boundaryObjs[1].dumpId);
921 for (i = 0; i < numObjs; i++)
961 if (compressLevel == -1)
1000 printf(
_(
"%s dumps a database as a text file or to other formats.\n\n"), progname);
1002 printf(
_(
" %s [OPTION]... [DBNAME]\n"), progname);
1004 printf(
_(
"\nGeneral options:\n"));
1005 printf(
_(
" -f, --file=FILENAME output file or directory name\n"));
1006 printf(
_(
" -F, --format=c|d|t|p output file format (custom, directory, tar,\n" 1007 " plain text (default))\n"));
1008 printf(
_(
" -j, --jobs=NUM use this many parallel jobs to dump\n"));
1009 printf(
_(
" -v, --verbose verbose mode\n"));
1010 printf(
_(
" -V, --version output version information, then exit\n"));
1011 printf(
_(
" -Z, --compress=0-9 compression level for compressed formats\n"));
1012 printf(
_(
" --lock-wait-timeout=TIMEOUT fail after waiting TIMEOUT for a table lock\n"));
1013 printf(
_(
" --no-sync do not wait for changes to be written safely to disk\n"));
1014 printf(
_(
" -?, --help show this help, then exit\n"));
1016 printf(
_(
"\nOptions controlling the output content:\n"));
1017 printf(
_(
" -a, --data-only dump only the data, not the schema\n"));
1018 printf(
_(
" -b, --blobs include large objects in dump\n"));
1019 printf(
_(
" -B, --no-blobs exclude large objects in dump\n"));
1020 printf(
_(
" -c, --clean clean (drop) database objects before recreating\n"));
1021 printf(
_(
" -C, --create include commands to create database in dump\n"));
1022 printf(
_(
" -E, --encoding=ENCODING dump the data in encoding ENCODING\n"));
1023 printf(
_(
" -n, --schema=PATTERN dump the specified schema(s) only\n"));
1024 printf(
_(
" -N, --exclude-schema=PATTERN do NOT dump the specified schema(s)\n"));
1025 printf(
_(
" -O, --no-owner skip restoration of object ownership in\n" 1026 " plain-text format\n"));
1027 printf(
_(
" -s, --schema-only dump only the schema, no data\n"));
1028 printf(
_(
" -S, --superuser=NAME superuser user name to use in plain-text format\n"));
1029 printf(
_(
" -t, --table=PATTERN dump the specified table(s) only\n"));
1030 printf(
_(
" -T, --exclude-table=PATTERN do NOT dump the specified table(s)\n"));
1031 printf(
_(
" -x, --no-privileges do not dump privileges (grant/revoke)\n"));
1032 printf(
_(
" --binary-upgrade for use by upgrade utilities only\n"));
1033 printf(
_(
" --column-inserts dump data as INSERT commands with column names\n"));
1034 printf(
_(
" --disable-dollar-quoting disable dollar quoting, use SQL standard quoting\n"));
1035 printf(
_(
" --disable-triggers disable triggers during data-only restore\n"));
1036 printf(
_(
" --enable-row-security enable row security (dump only content user has\n" 1038 printf(
_(
" --exclude-table-data=PATTERN do NOT dump data for the specified table(s)\n"));
1039 printf(
_(
" --extra-float-digits=NUM override default setting for extra_float_digits\n"));
1040 printf(
_(
" --if-exists use IF EXISTS when dropping objects\n"));
1041 printf(
_(
" --include-foreign-data=PATTERN\n" 1042 " include data of foreign tables on foreign\n" 1043 " servers matching PATTERN\n"));
1044 printf(
_(
" --inserts dump data as INSERT commands, rather than COPY\n"));
1045 printf(
_(
" --load-via-partition-root load partitions via the root table\n"));
1046 printf(
_(
" --no-comments do not dump comments\n"));
1047 printf(
_(
" --no-publications do not dump publications\n"));
1048 printf(
_(
" --no-security-labels do not dump security label assignments\n"));
1049 printf(
_(
" --no-subscriptions do not dump subscriptions\n"));
1050 printf(
_(
" --no-synchronized-snapshots do not use synchronized snapshots in parallel jobs\n"));
1051 printf(
_(
" --no-tablespaces do not dump tablespace assignments\n"));
1052 printf(
_(
" --no-unlogged-table-data do not dump unlogged table data\n"));
1053 printf(
_(
" --on-conflict-do-nothing add ON CONFLICT DO NOTHING to INSERT commands\n"));
1054 printf(
_(
" --quote-all-identifiers quote all identifiers, even if not key words\n"));
1055 printf(
_(
" --rows-per-insert=NROWS number of rows per INSERT; implies --inserts\n"));
1056 printf(
_(
" --section=SECTION dump named section (pre-data, data, or post-data)\n"));
1057 printf(
_(
" --serializable-deferrable wait until the dump can run without anomalies\n"));
1058 printf(
_(
" --snapshot=SNAPSHOT use given snapshot for the dump\n"));
1059 printf(
_(
" --strict-names require table and/or schema include patterns to\n" 1060 " match at least one entity each\n"));
1061 printf(
_(
" --use-set-session-authorization\n" 1062 " use SET SESSION AUTHORIZATION commands instead of\n" 1063 " ALTER OWNER commands to set ownership\n"));
1065 printf(
_(
"\nConnection options:\n"));
1066 printf(
_(
" -d, --dbname=DBNAME database to dump\n"));
1067 printf(
_(
" -h, --host=HOSTNAME database server host or socket directory\n"));
1068 printf(
_(
" -p, --port=PORT database server port number\n"));
1069 printf(
_(
" -U, --username=NAME connect as specified database user\n"));
1070 printf(
_(
" -w, --no-password never prompt for password\n"));
1071 printf(
_(
" -W, --password force password prompt (should happen automatically)\n"));
1072 printf(
_(
" --role=ROLENAME do SET ROLE before dump\n"));
1074 printf(
_(
"\nIf no database name is supplied, then the PGDATABASE environment\n" 1075 "variable value is used.\n\n"));
1076 printf(
_(
"Report bugs to <%s>.\n"), PACKAGE_BUGREPORT);
1077 printf(
_(
"%s home page: <%s>\n"), PACKAGE_NAME, PACKAGE_URL);
1082 const char *dumpsnapshot,
char *use_role)
1086 const char *std_strings;
1096 fatal(
"invalid client encoding \"%s\" specified",
1107 AH->
std_strings = (std_strings && strcmp(std_strings,
"on") == 0);
1206 "SET TRANSACTION ISOLATION LEVEL " 1207 "SERIALIZABLE, READ ONLY, DEFERRABLE");
1210 "SET TRANSACTION ISOLATION LEVEL " 1211 "REPEATABLE READ, READ ONLY");
1216 "SET TRANSACTION ISOLATION LEVEL " 1217 "SERIALIZABLE, READ ONLY");
1242 fatal(
"Synchronized snapshots on standby servers are not supported by this server version.\n" 1243 "Run with --no-synchronized-snapshots instead if you do not need\n" 1244 "synchronized snapshots.");
1270 char *query =
"SELECT pg_catalog.pg_export_snapshot()";
1311 fatal(
"invalid output format \"%s\" specified", format);
1312 return archiveFormat;
1330 if (patterns->
head == NULL)
1340 for (cell = patterns->
head; cell; cell = cell->
next)
1343 "SELECT oid FROM pg_catalog.pg_namespace n\n");
1345 false, NULL,
"n.nspname", NULL, NULL);
1348 if (strict_names &&
PQntuples(res) == 0)
1349 fatal(
"no matching schemas were found for pattern \"%s\"", cell->
val);
1377 if (patterns->
head == NULL)
1387 for (cell = patterns->
head; cell; cell = cell->
next)
1390 "SELECT oid FROM pg_catalog.pg_foreign_server s\n");
1392 false, NULL,
"s.srvname", NULL, NULL);
1396 fatal(
"no matching foreign servers were found for pattern \"%s\"", cell->
val);
1423 if (patterns->
head == NULL)
1433 for (cell = patterns->
head; cell; cell = cell->
next)
1442 "\nFROM pg_catalog.pg_class c" 1443 "\n LEFT JOIN pg_catalog.pg_namespace n" 1444 "\n ON n.oid OPERATOR(pg_catalog.=) c.relnamespace" 1445 "\nWHERE c.relkind OPERATOR(pg_catalog.=) ANY" 1446 "\n (array['%c', '%c', '%c', '%c', '%c', '%c'])\n",
1447 RELKIND_RELATION, RELKIND_SEQUENCE, RELKIND_VIEW,
1448 RELKIND_MATVIEW, RELKIND_FOREIGN_TABLE,
1449 RELKIND_PARTITIONED_TABLE);
1451 false,
"n.nspname",
"c.relname", NULL,
1452 "pg_catalog.pg_table_is_visible(c.oid)");
1458 if (strict_names &&
PQntuples(res) == 0)
1459 fatal(
"no matching tables were found for pattern \"%s\"", cell->
val);
1540 if (table_include_oids.
head != NULL)
1542 else if (schema_include_oids.
head != NULL)
1548 strcmp(nsinfo->
dobj.
name,
"pg_catalog") == 0)
1557 else if (strncmp(nsinfo->
dobj.
name,
"pg_", 3) == 0 ||
1558 strcmp(nsinfo->
dobj.
name,
"information_schema") == 0)
1563 else if (strcmp(nsinfo->
dobj.
name,
"public") == 0)
1611 if (table_include_oids.
head != NULL)
1645 tyinfo->
typrelkind != RELKIND_COMPOSITE_TYPE)
1650 if (tytable != NULL)
1690 if (dinfo->
dobj.namespace)
1841 if (dobj->namespace)
1858 const char *classname = tbinfo->
dobj.
name;
1870 const char *column_list;
1872 pg_log_info(
"dumping contents of table \"%s.%s\"",
1873 tbinfo->
dobj.namespace->dobj.
name, classname);
1893 if (strlen(column_list) > 2)
1979 pg_log_error(
"Dumping the contents of table \"%s\" failed: PQgetCopyData() failed.", classname);
1989 pg_log_error(
"Dumping the contents of table \"%s\" failed: PQgetResult() failed.", classname);
1998 pg_log_warning(
"unexpected extra results during COPY of table \"%s\"",
2024 int rows_this_statement = 0;
2027 "SELECT * FROM ONLY %s",
2047 if (insertStmt == NULL)
2077 for (
int field = 0; field < nfields; field++)
2094 for (
int tuple = 0; tuple <
PQntuples(res); tuple++)
2097 if (rows_this_statement == 0)
2113 if (rows_per_statement == 1)
2115 else if (rows_this_statement > 0)
2120 for (
int field = 0; field < nfields; field++)
2157 const char *s =
PQgetvalue(res, tuple, field);
2159 if (strspn(s,
"0123456789 +-eE.") == strlen(s))
2173 if (strcmp(
PQgetvalue(res, tuple, field),
"t") == 0)
2194 if (++rows_this_statement >= rows_per_statement)
2197 archputs(
" ON CONFLICT DO NOTHING;\n", fout);
2201 rows_this_statement = 0;
2214 if (rows_this_statement > 0)
2217 archputs(
" ON CONFLICT DO NOTHING;\n", fout);
2227 if (insertStmt != NULL)
2245 parentTbinfo = tbinfo->
parents[0];
2249 parentTbinfo = parentTbinfo->
parents[0];
2252 return parentTbinfo;
2270 const char *copyFrom;
2300 copyStmt = copyBuf->
data;
2320 .namespace = tbinfo->
dobj.namespace->dobj.
name,
2322 .description =
"TABLE DATA",
2324 .copyStmt = copyStmt,
2328 .dumpArg = tdinfo));
2373 .namespace = tbinfo->
dobj.namespace->dobj.
name,
2375 .description =
"MATERIALIZED VIEW DATA",
2377 .createStmt = q->
data,
2396 (!relkind || tblinfo[i].
relkind == relkind))
2420 if (tbinfo->
relkind == RELKIND_VIEW)
2423 if (tbinfo->
relkind == RELKIND_FOREIGN_TABLE &&
2424 (foreign_servers_include_oids.
head == NULL ||
2429 if (tbinfo->
relkind == RELKIND_PARTITIONED_TABLE)
2445 if (tbinfo->
relkind == RELKIND_MATVIEW)
2447 else if (tbinfo->
relkind == RELKIND_SEQUENCE)
2460 tdinfo->
dobj.namespace = tbinfo->
dobj.namespace;
2497 "SELECT d1.objid, d2.refobjid, c2.relkind AS refrelkind " 2498 "FROM pg_depend d1 " 2499 "JOIN pg_class c1 ON c1.oid = d1.objid " 2501 " JOIN pg_rewrite r1 ON r1.ev_class = d1.objid " 2502 "JOIN pg_depend d2 ON d2.classid = 'pg_rewrite'::regclass " 2503 "AND d2.objid = r1.oid " 2504 "AND d2.refobjid <> d1.objid " 2505 "JOIN pg_class c2 ON c2.oid = d2.refobjid " 2506 "AND c2.relkind IN (" CppAsString2(RELKIND_MATVIEW)
"," 2508 "WHERE d1.classid = 'pg_class'::regclass " 2510 "SELECT w.objid, d3.refobjid, c3.relkind " 2512 "JOIN pg_rewrite r3 ON r3.ev_class = w.refobjid " 2513 "JOIN pg_depend d3 ON d3.classid = 'pg_rewrite'::regclass " 2514 "AND d3.objid = r3.oid " 2515 "AND d3.refobjid <> w.refobjid " 2516 "JOIN pg_class c3 ON c3.oid = d3.refobjid " 2517 "AND c3.relkind IN (" CppAsString2(RELKIND_MATVIEW)
"," 2520 "SELECT 'pg_class'::regclass::oid AS classid, objid, refobjid " 2530 i_refobjid =
PQfnumber(res,
"refobjid");
2532 for (i = 0; i < ntups; i++)
2559 if (refdobj == NULL)
2566 if (refdobj == NULL)
2602 for (i = 0; i < numObjs; i++)
2614 if (ftable == NULL ||
2661 if (tbinfo->
relkind == RELKIND_SEQUENCE ||
2662 tbinfo->
relkind == RELKIND_VIEW)
2672 if (numParents == 0)
2676 for (j = 0; j < tbinfo->
ncheck; j++)
2682 for (k = 0; k < numParents; k++)
2686 parent = parents[k];
2687 for (l = 0; l < parent->
ncheck; l++)
2764 "(%s datdba) AS dba, " 2765 "pg_encoding_to_char(encoding) AS encoding, " 2766 "datcollate, datctype, datfrozenxid, datminmxid, " 2767 "(SELECT array_agg(acl ORDER BY row_n) FROM " 2768 " (SELECT acl, row_n FROM " 2769 " unnest(coalesce(datacl,acldefault('d',datdba))) " 2770 " WITH ORDINALITY AS perm(acl,row_n) " 2771 " WHERE NOT EXISTS ( " 2773 " FROM unnest(acldefault('d',datdba)) " 2774 " AS init(init_acl) " 2775 " WHERE acl = init_acl)) AS datacls) " 2777 "(SELECT array_agg(acl ORDER BY row_n) FROM " 2778 " (SELECT acl, row_n FROM " 2779 " unnest(acldefault('d',datdba)) " 2780 " WITH ORDINALITY AS initp(acl,row_n) " 2781 " WHERE NOT EXISTS ( " 2783 " FROM unnest(coalesce(datacl,acldefault('d',datdba))) " 2784 " AS permp(orig_acl) " 2785 " WHERE acl = orig_acl)) AS rdatacls) " 2787 "datistemplate, datconnlimit, " 2788 "(SELECT spcname FROM pg_tablespace t WHERE t.oid = dattablespace) AS tablespace, " 2789 "shobj_description(oid, 'pg_database') AS description " 2792 "WHERE datname = current_database()",
2798 "(%s datdba) AS dba, " 2799 "pg_encoding_to_char(encoding) AS encoding, " 2800 "datcollate, datctype, datfrozenxid, datminmxid, " 2801 "datacl, '' as rdatacl, datistemplate, datconnlimit, " 2802 "(SELECT spcname FROM pg_tablespace t WHERE t.oid = dattablespace) AS tablespace, " 2803 "shobj_description(oid, 'pg_database') AS description " 2806 "WHERE datname = current_database()",
2812 "(%s datdba) AS dba, " 2813 "pg_encoding_to_char(encoding) AS encoding, " 2814 "datcollate, datctype, datfrozenxid, 0 AS datminmxid, " 2815 "datacl, '' as rdatacl, datistemplate, datconnlimit, " 2816 "(SELECT spcname FROM pg_tablespace t WHERE t.oid = dattablespace) AS tablespace, " 2817 "shobj_description(oid, 'pg_database') AS description " 2820 "WHERE datname = current_database()",
2826 "(%s datdba) AS dba, " 2827 "pg_encoding_to_char(encoding) AS encoding, " 2828 "NULL AS datcollate, NULL AS datctype, datfrozenxid, 0 AS datminmxid, " 2829 "datacl, '' as rdatacl, datistemplate, datconnlimit, " 2830 "(SELECT spcname FROM pg_tablespace t WHERE t.oid = dattablespace) AS tablespace, " 2831 "shobj_description(oid, 'pg_database') AS description " 2834 "WHERE datname = current_database()",
2840 "(%s datdba) AS dba, " 2841 "pg_encoding_to_char(encoding) AS encoding, " 2842 "NULL AS datcollate, NULL AS datctype, datfrozenxid, 0 AS datminmxid, " 2843 "datacl, '' as rdatacl, datistemplate, " 2844 "-1 as datconnlimit, " 2845 "(SELECT spcname FROM pg_tablespace t WHERE t.oid = dattablespace) AS tablespace " 2847 "WHERE datname = current_database()",
2853 i_tableoid =
PQfnumber(res,
"tableoid");
2857 i_encoding =
PQfnumber(res,
"encoding");
2858 i_collate =
PQfnumber(res,
"datcollate");
2860 i_frozenxid =
PQfnumber(res,
"datfrozenxid");
2861 i_minmxid =
PQfnumber(res,
"datminmxid");
2864 i_datistemplate =
PQfnumber(res,
"datistemplate");
2865 i_datconnlimit =
PQfnumber(res,
"datconnlimit");
2866 i_tablespace =
PQfnumber(res,
"tablespace");
2879 datistemplate =
PQgetvalue(res, 0, i_datistemplate);
2880 datconnlimit =
PQgetvalue(res, 0, i_datconnlimit);
2881 tablespace =
PQgetvalue(res, 0, i_tablespace);
2893 if (strlen(encoding) > 0)
2898 if (strlen(collate) > 0 && strcmp(collate, ctype) == 0)
2905 if (strlen(collate) > 0)
2910 if (strlen(ctype) > 0)
2925 if (strlen(tablespace) > 0 && strcmp(tablespace,
"pg_default") != 0 &&
2941 .description =
"DATABASE",
2943 .createStmt = creaQry->
data,
2944 .dropStmt = delQry->
data));
2974 .description =
"COMMENT",
2976 .createStmt = dbQry->
data,
2983 dumpComment(fout,
"DATABASE", qdatname, NULL, dba,
2984 dbCatId, 0, dbDumpId);
2999 if (seclabelQry->
len > 0)
3003 .description =
"SECURITY LABEL",
3005 .createStmt = seclabelQry->
data,
3017 qdatname, NULL, NULL,
3018 dba, datacl, rdatacl,
"",
"");
3031 if (strlen(datconnlimit) > 0 && strcmp(datconnlimit,
"-1") != 0)
3033 qdatname, datconnlimit);
3035 if (strcmp(datistemplate,
"t") == 0)
3048 "SET datistemplate = false WHERE datname = ");
3064 "SET datfrozenxid = '%u', datminmxid = '%u'\n" 3066 frozenxid, minmxid);
3071 if (creaQry->
len > 0)
3075 .description =
"DATABASE PROPERTIES",
3077 .createStmt = creaQry->
data,
3078 .dropStmt = delQry->
data,
3079 .deps = &dbDumpId));
3098 "FROM pg_catalog.pg_class\n" 3099 "WHERE oid = %u;\n",
3100 LargeObjectRelationId);
3103 "FROM pg_catalog.pg_class\n" 3104 "WHERE oid = %u;\n",
3105 LargeObjectRelationId);
3109 i_relfrozenxid =
PQfnumber(lo_res,
"relfrozenxid");
3110 i_relminmxid =
PQfnumber(lo_res,
"relminmxid");
3112 appendPQExpBufferStr(loOutQry,
"\n-- For binary upgrade, set pg_largeobject relfrozenxid and relminmxid\n");
3114 "SET relfrozenxid = '%u', relminmxid = '%u'\n" 3115 "WHERE oid = %u;\n",
3118 LargeObjectRelationId);
3121 .description =
"pg_largeobject",
3123 .createStmt = loOutQry->
data));
3161 "WHERE setrole = 0 AND setdatabase = '%u'::oid",
3164 printfPQExpBuffer(buf,
"SELECT datconfig[%d] FROM pg_database WHERE oid = '%u'::oid", count, dboid);
3172 "DATABASE", dbname, NULL, NULL,
3189 "FROM pg_db_role_setting s, pg_roles r " 3190 "WHERE setrole = r.oid AND setdatabase = '%u'::oid",
3229 .description =
"ENCODING",
3231 .createStmt = qry->
data));
3243 const char *stdstrings = AH->
std_strings ?
"on" :
"off";
3246 pg_log_info(
"saving standard_conforming_strings = %s",
3254 .description =
"STDSTRINGS",
3256 .createStmt = qry->
data));
3270 char **schemanames = NULL;
3271 int nschemanames = 0;
3282 "SELECT pg_catalog.current_schemas(false)");
3285 fatal(
"could not parse result of current_schemas()");
3293 for (i = 0; i < nschemanames; i++)
3308 .description =
"SEARCHPATH",
3310 .createStmt = qry->
data));
3355 init_racl_subquery,
"l.lomacl",
"l.lomowner",
"'L'",
3359 "SELECT l.oid, (%s l.lomowner) AS rolname, " 3362 "%s AS initlomacl, " 3363 "%s AS initrlomacl " 3364 "FROM pg_largeobject_metadata l " 3365 "LEFT JOIN pg_init_privs pip ON " 3366 "(l.oid = pip.objoid " 3367 "AND pip.classoid = 'pg_largeobject'::regclass " 3368 "AND pip.objsubid = 0) ",
3371 racl_subquery->
data,
3372 init_acl_subquery->
data,
3373 init_racl_subquery->
data);
3382 "SELECT oid, (%s lomowner) AS rolname, lomacl, " 3383 "NULL AS rlomacl, NULL AS initlomacl, " 3384 "NULL AS initrlomacl " 3385 " FROM pg_largeobject_metadata",
3389 "SELECT DISTINCT loid AS oid, " 3390 "NULL::name AS rolname, NULL::oid AS lomacl, " 3391 "NULL::oid AS rlomacl, NULL::oid AS initlomacl, " 3392 "NULL::oid AS initrlomacl " 3393 " FROM pg_largeobject");
3401 i_initlomacl =
PQfnumber(res,
"initlomacl");
3402 i_initrlomacl =
PQfnumber(res,
"initrlomacl");
3411 for (i = 0; i < ntups; i++)
3471 "SELECT pg_catalog.lo_create('%s');\n",
3475 "SELECT pg_catalog.lo_unlink('%s');\n",
3482 .description =
"BLOB",
3484 .createStmt = cquery->
data,
3485 .dropStmt = dquery->
data));
3517 const char *blobQry;
3518 const char *blobFetchQry;
3534 "DECLARE bloboid CURSOR FOR " 3535 "SELECT oid FROM pg_largeobject_metadata ORDER BY 1";
3538 "DECLARE bloboid CURSOR FOR " 3539 "SELECT DISTINCT loid FROM pg_largeobject ORDER BY 1";
3544 blobFetchQry =
"FETCH 1000 IN bloboid";
3553 for (i = 0; i < ntups; i++)
3562 fatal(
"could not open large object %u: %s",
3572 fatal(
"error reading large object %u: %s",
3584 }
while (ntups > 0);
3603 int i_polpermissive;
3624 pg_log_info(
"reading row security enabled for table \"%s.%s\"",
3644 polinfo->
dobj.namespace = tbinfo->
dobj.namespace;
3655 pg_log_info(
"reading policies for table \"%s.%s\"",
3664 "SELECT oid, tableoid, pol.polname, pol.polcmd, pol.polpermissive, " 3665 "CASE WHEN pol.polroles = '{0}' THEN NULL ELSE " 3666 " 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, " 3667 "pg_catalog.pg_get_expr(pol.polqual, pol.polrelid) AS polqual, " 3668 "pg_catalog.pg_get_expr(pol.polwithcheck, pol.polrelid) AS polwithcheck " 3669 "FROM pg_catalog.pg_policy pol " 3670 "WHERE polrelid = '%u'",
3674 "SELECT oid, tableoid, pol.polname, pol.polcmd, 't' as polpermissive, " 3675 "CASE WHEN pol.polroles = '{0}' THEN NULL ELSE " 3676 " 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, " 3677 "pg_catalog.pg_get_expr(pol.polqual, pol.polrelid) AS polqual, " 3678 "pg_catalog.pg_get_expr(pol.polwithcheck, pol.polrelid) AS polwithcheck " 3679 "FROM pg_catalog.pg_policy pol " 3680 "WHERE polrelid = '%u'",
3698 i_tableoid =
PQfnumber(res,
"tableoid");
3701 i_polpermissive =
PQfnumber(res,
"polpermissive");
3702 i_polroles =
PQfnumber(res,
"polroles");
3704 i_polwithcheck =
PQfnumber(res,
"polwithcheck");
3708 for (j = 0; j < ntups; j++)
3715 polinfo[j].
dobj.namespace = tbinfo->
dobj.namespace;
3724 polinfo[j].polroles = NULL;
3783 .namespace = polinfo->
dobj.namespace->dobj.
name,
3785 .description =
"ROW SECURITY",
3787 .createStmt = query->
data,
3795 if (polinfo->
polcmd ==
'*')
3797 else if (polinfo->
polcmd ==
'r')
3798 cmd =
" FOR SELECT";
3799 else if (polinfo->
polcmd ==
'a')
3800 cmd =
" FOR INSERT";
3801 else if (polinfo->
polcmd ==
'w')
3802 cmd =
" FOR UPDATE";
3803 else if (polinfo->
polcmd ==
'd')
3804 cmd =
" FOR DELETE";
3845 .
namespace = polinfo->
dobj.namespace->dobj.
name,
3847 .description =
"POLICY",
3849 .createStmt = query->
data,
3850 .dropStmt = delqry->
data));
3890 *numPublications = 0;
3901 "SELECT p.tableoid, p.oid, p.pubname, " 3902 "(%s p.pubowner) AS rolname, " 3903 "p.puballtables, p.pubinsert, p.pubupdate, p.pubdelete, p.pubtruncate, p.pubviaroot " 3904 "FROM pg_publication p",
3908 "SELECT p.tableoid, p.oid, p.pubname, " 3909 "(%s p.pubowner) AS rolname, " 3910 "p.puballtables, p.pubinsert, p.pubupdate, p.pubdelete, p.pubtruncate, false AS pubviaroot " 3911 "FROM pg_publication p",
3915 "SELECT p.tableoid, p.oid, p.pubname, " 3916 "(%s p.pubowner) AS rolname, " 3917 "p.puballtables, p.pubinsert, p.pubupdate, p.pubdelete, false AS pubtruncate, false AS pubviaroot " 3918 "FROM pg_publication p",
3925 i_tableoid =
PQfnumber(res,
"tableoid");
3929 i_puballtables =
PQfnumber(res,
"puballtables");
3930 i_pubinsert =
PQfnumber(res,
"pubinsert");
3931 i_pubupdate =
PQfnumber(res,
"pubupdate");
3932 i_pubdelete =
PQfnumber(res,
"pubdelete");
3933 i_pubtruncate =
PQfnumber(res,
"pubtruncate");
3934 i_pubviaroot =
PQfnumber(res,
"pubviaroot");
3938 for (i = 0; i < ntups; i++)
3948 (strcmp(
PQgetvalue(res, i, i_puballtables),
"t") == 0);
3950 (strcmp(
PQgetvalue(res, i, i_pubinsert),
"t") == 0);
3952 (strcmp(
PQgetvalue(res, i, i_pubupdate),
"t") == 0);
3954 (strcmp(
PQgetvalue(res, i, i_pubdelete),
"t") == 0);
3956 (strcmp(
PQgetvalue(res, i, i_pubtruncate),
"t") == 0);
3958 (strcmp(
PQgetvalue(res, i, i_pubviaroot),
"t") == 0);
3960 if (strlen(pubinfo[i].
rolname) == 0)
3961 pg_log_warning(
"owner of publication \"%s\" appears to be invalid",
3962 pubinfo[i].dobj.name);
3971 *numPublications = ntups;
4048 .description =
"PUBLICATION",
4050 .createStmt = query->
data,
4051 .dropStmt = delq->
data));
4094 "SELECT tableoid, oid, prpubid, prrelid " 4095 "FROM pg_catalog.pg_publication_rel");
4100 i_tableoid =
PQfnumber(res,
"tableoid");
4109 for (i = 0; i < ntups; i++)
4121 if (pubinfo == NULL)
4140 pubrinfo[j].
dobj.namespace = tbinfo->
dobj.namespace;
4188 .
namespace = tbinfo->
dobj.namespace->dobj.
name,
4190 .description =
"PUBLICATION TABLE",
4192 .createStmt = query->
data));
4209 if (val && strcmp(val,
"on") == 0)
4233 int i_subsynccommit;
4234 int i_subpublications;
4247 "SELECT count(*) FROM pg_subscription " 4248 "WHERE subdbid = (SELECT oid FROM pg_database" 4249 " WHERE datname = current_database())",
4253 pg_log_warning(
"subscriptions not dumped because current user is not a superuser");
4262 "SELECT s.tableoid, s.oid, s.subname,\n" 4263 " (%s s.subowner) AS rolname,\n" 4264 " s.subconninfo, s.subslotname, s.subsynccommit,\n" 4265 " s.subpublications,\n",
4279 "FROM pg_subscription s\n" 4280 "WHERE s.subdbid = (SELECT oid FROM pg_database\n" 4281 " WHERE datname = current_database())");
4287 i_tableoid =
PQfnumber(res,
"tableoid");
4291 i_subconninfo =
PQfnumber(res,
"subconninfo");
4292 i_subslotname =
PQfnumber(res,
"subslotname");
4293 i_subsynccommit =
PQfnumber(res,
"subsynccommit");
4294 i_subpublications =
PQfnumber(res,
"subpublications");
4295 i_subbinary =
PQfnumber(res,
"subbinary");
4296 i_substream =
PQfnumber(res,
"substream");
4300 for (i = 0; i < ntups; i++)
4323 if (strlen(subinfo[i].
rolname) == 0)
4324 pg_log_warning(
"owner of subscription \"%s\" appears to be invalid",
4325 subinfo[i].dobj.name);
4346 char **pubnames = NULL;
4367 fatal(
"could not parse subpublications array");
4370 for (i = 0; i < npubnames; i++)
4378 appendPQExpBuffer(query,
" PUBLICATION %s WITH (connect = false, slot_name = ", publications->
data);
4384 if (strcmp(subinfo->
subbinary,
"t") == 0)
4387 if (strcmp(subinfo->
substream,
"f") != 0)
4398 .description =
"SUBSCRIPTION",
4400 .createStmt = query->
data,
4401 .dropStmt = delq->
data));
4430 const char *catalog,
4431 const char *keyword,
4432 const char *objname)
4449 "FROM pg_catalog.pg_depend d, pg_catalog.pg_extension e " 4450 "WHERE d.refobjid = e.oid AND classid = '%s'::pg_catalog.regclass " 4451 "AND objid = '%u'::pg_catalog.oid AND deptype = 'x' " 4452 "AND refclassid = 'pg_catalog.pg_extension'::pg_catalog.regclass",
4458 for (i = 0; i < ntups; i++)
4488 ++next_possible_free_oid;
4490 "SELECT EXISTS(SELECT 1 " 4491 "FROM pg_catalog.pg_type " 4492 "WHERE oid = '%u'::pg_catalog.oid);",
4493 next_possible_free_oid);
4499 return next_possible_free_oid;
4506 bool force_array_type,
4507 bool include_multirange_type)
4511 Oid pg_type_array_oid;
4512 Oid pg_type_multirange_oid;
4513 Oid pg_type_multirange_array_oid;
4517 "SELECT pg_catalog.binary_upgrade_set_next_pg_type_oid('%u'::pg_catalog.oid);\n\n",
4523 "FROM pg_catalog.pg_type " 4524 "WHERE oid = '%u'::pg_catalog.oid;",
4533 if (!
OidIsValid(pg_type_array_oid) && force_array_type)
4539 "\n-- For binary upgrade, must preserve pg_type array oid\n");
4541 "SELECT pg_catalog.binary_upgrade_set_next_array_pg_type_oid('%u'::pg_catalog.oid);\n\n",
4548 if (include_multirange_type)
4553 "SELECT t.oid, t.typarray " 4554 "FROM pg_catalog.pg_type t " 4555 "JOIN pg_catalog.pg_range r " 4556 "ON t.oid = r.rngmultitypid " 4557 "WHERE r.rngtypid = '%u'::pg_catalog.oid;",
4574 "\n-- For binary upgrade, must preserve multirange pg_type oid\n");
4576 "SELECT pg_catalog.binary_upgrade_set_next_multirange_pg_type_oid('%u'::pg_catalog.oid);\n\n",
4577 pg_type_multirange_oid);
4579 "\n-- For binary upgrade, must preserve multirange pg_type array oid\n");
4581 "SELECT pg_catalog.binary_upgrade_set_next_multirange_array_pg_type_oid('%u'::pg_catalog.oid);\n\n",
4582 pg_type_multirange_array_oid);
4598 "SELECT c.reltype AS crel " 4599 "FROM pg_catalog.pg_class c " 4600 "WHERE c.oid = '%u'::pg_catalog.oid;",
4609 pg_type_oid,
false,
false);
4621 "\n-- For binary upgrade, must preserve pg_class oids\n");
4627 Oid pg_class_reltoastrelid;
4628 char pg_class_relkind;
4629 Oid pg_index_indexrelid;
4632 "SELECT pg_catalog.binary_upgrade_set_next_heap_pg_class_oid('%u'::pg_catalog.oid);\n",
4648 "SELECT c.reltoastrelid, c.relkind, i.indexrelid " 4649 "FROM pg_catalog.pg_class c LEFT JOIN " 4650 "pg_catalog.pg_index i ON (c.reltoastrelid = i.indrelid AND i.indisvalid) " 4651 "WHERE c.oid = '%u'::pg_catalog.oid;",
4657 PQfnumber(upgrade_res,
"reltoastrelid")));
4658 pg_class_relkind = *
PQgetvalue(upgrade_res, 0,
4668 pg_class_relkind != RELKIND_PARTITIONED_TABLE)
4671 "SELECT pg_catalog.binary_upgrade_set_next_toast_pg_class_oid('%u'::pg_catalog.oid);\n",
4672 pg_class_reltoastrelid);
4676 "SELECT pg_catalog.binary_upgrade_set_next_index_pg_class_oid('%u'::pg_catalog.oid);\n",
4677 pg_index_indexrelid);
4685 "SELECT pg_catalog.binary_upgrade_set_next_index_pg_class_oid('%u'::pg_catalog.oid);\n",
4701 const char *objtype,
4702 const char *objname,
4703 const char *objnamespace)
4717 for (i = 0; i < dobj->
nDeps; i++)
4725 fatal(
"could not find parent extension for %s %s",
4729 "\n-- For binary upgrade, handle extension membership the hard way\n");
4733 if (objnamespace && *objnamespace)
4777 init_racl_subquery,
"n.nspacl",
"n.nspowner",
"'n'",
4781 "(%s nspowner) AS rolname, " 4784 "%s as initnspacl, " 4785 "%s as initrnspacl " 4786 "FROM pg_namespace n " 4787 "LEFT JOIN pg_init_privs pip " 4788 "ON (n.oid = pip.objoid " 4789 "AND pip.classoid = 'pg_namespace'::regclass " 4790 "AND pip.objsubid = 0",
4793 racl_subquery->
data,
4794 init_acl_subquery->
data,
4795 init_racl_subquery->
data);
4806 "(%s nspowner) AS rolname, " 4807 "nspacl, NULL as rnspacl, " 4808 "NULL AS initnspacl, NULL as initrnspacl " 4809 "FROM pg_namespace",
4818 i_tableoid =
PQfnumber(res,
"tableoid");
4824 i_initnspacl =
PQfnumber(res,
"initnspacl");
4825 i_initrnspacl =
PQfnumber(res,
"initrnspacl");
4827 for (i = 0; i < ntups; i++)
4856 if (strlen(nsinfo[i].
rolname) == 0)
4858 nsinfo[i].dobj.name);
4864 *numNamespaces = ntups;
4880 fatal(
"schema with OID %u does not exist", nsoid);
4904 int i_extrelocatable;
4921 "x.extname, n.nspname, x.extrelocatable, x.extversion, x.extconfig, x.extcondition " 4922 "FROM pg_extension x " 4923 "JOIN pg_namespace n ON n.oid = x.extnamespace");
4931 i_tableoid =
PQfnumber(res,
"tableoid");
4935 i_extrelocatable =
PQfnumber(res,
"extrelocatable");
4936 i_extversion =
PQfnumber(res,
"extversion");
4937 i_extconfig =
PQfnumber(res,
"extconfig");
4938 i_extcondition =
PQfnumber(res,
"extcondition");
4940 for (i = 0; i < ntups; i++)
4960 *numExtensions = ntups;
5025 initracl_subquery,
"t.typacl",
"t.typowner",
"'T'",
5032 "%s AS inittypacl, " 5033 "%s AS initrtypacl, " 5034 "(%s t.typowner) AS rolname, " 5035 "t.typelem, t.typrelid, " 5036 "CASE WHEN t.typrelid = 0 THEN ' '::\"char\" " 5037 "ELSE (SELECT relkind FROM pg_class WHERE oid = t.typrelid) END AS typrelkind, " 5038 "t.typtype, t.typisdefined, " 5039 "t.typname[0] = '_' AND t.typelem != 0 AND " 5040 "(SELECT typarray FROM pg_type te WHERE oid = t.typelem) = t.oid AS isarray " 5042 "LEFT JOIN pg_init_privs pip ON " 5043 "(t.oid = pip.objoid " 5044 "AND pip.classoid = 'pg_type'::regclass " 5045 "AND pip.objsubid = 0) ",
5047 racl_subquery->
data,
5048 initacl_subquery->
data,
5049 initracl_subquery->
data,
5060 "typnamespace, typacl, NULL as rtypacl, " 5061 "NULL AS inittypacl, NULL AS initrtypacl, " 5062 "(%s typowner) AS rolname, " 5063 "typelem, typrelid, " 5064 "CASE WHEN typrelid = 0 THEN ' '::\"char\" " 5065 "ELSE (SELECT relkind FROM pg_class WHERE oid = typrelid) END AS typrelkind, " 5066 "typtype, typisdefined, " 5067 "typname[0] = '_' AND typelem != 0 AND " 5068 "(SELECT typarray FROM pg_type te WHERE oid = pg_type.typelem) = oid AS isarray " 5075 "typnamespace, NULL AS typacl, NULL as rtypacl, " 5076 "NULL AS inittypacl, NULL AS initrtypacl, " 5077 "(%s typowner) AS rolname, " 5078 "typelem, typrelid, " 5079 "CASE WHEN typrelid = 0 THEN ' '::\"char\" " 5080 "ELSE (SELECT relkind FROM pg_class WHERE oid = typrelid) END AS typrelkind, " 5081 "typtype, typisdefined, " 5082 "typname[0] = '_' AND typelem != 0 AND " 5083 "(SELECT typarray FROM pg_type te WHERE oid = pg_type.typelem) = oid AS isarray " 5090 "typnamespace, NULL AS typacl, NULL as rtypacl, " 5091 "NULL AS inittypacl, NULL AS initrtypacl, " 5092 "(%s typowner) AS rolname, " 5093 "typelem, typrelid, " 5094 "CASE WHEN typrelid = 0 THEN ' '::\"char\" " 5095 "ELSE (SELECT relkind FROM pg_class WHERE oid = typrelid) END AS typrelkind, " 5096 "typtype, typisdefined, " 5097 "typname[0] = '_' AND typelem != 0 AS isarray " 5108 i_tableoid =
PQfnumber(res,
"tableoid");
5111 i_typnamespace =
PQfnumber(res,
"typnamespace");
5114 i_inittypacl =
PQfnumber(res,
"inittypacl");
5115 i_initrtypacl =
PQfnumber(res,
"initrtypacl");
5118 i_typrelid =
PQfnumber(res,
"typrelid");
5119 i_typrelkind =
PQfnumber(res,
"typrelkind");
5121 i_typisdefined =
PQfnumber(res,
"typisdefined");
5124 for (i = 0; i < ntups; i++)
5131 tyinfo[
i].
dobj.namespace =
5144 if (strcmp(
PQgetvalue(res, i, i_typisdefined),
"t") == 0)
5149 if (strcmp(
PQgetvalue(res, i, i_isarray),
"t") == 0)
5154 if (tyinfo[i].typtype ==
'm')
5174 tyinfo[i].
typtype == TYPTYPE_DOMAIN)
5187 if ((tyinfo[i].dobj.dump & DUMP_COMPONENT_DEFINITION) &&
5188 (tyinfo[i].
typtype == TYPTYPE_BASE ||
5189 tyinfo[i].
typtype == TYPTYPE_RANGE))
5196 stinfo->
dobj.namespace = tyinfo[
i].
dobj.namespace;
5208 if (strlen(tyinfo[i].
rolname) == 0)
5209 pg_log_warning(
"owner of data type \"%s\" appears to be invalid",
5210 tyinfo[i].dobj.name);
5252 "(%s oprowner) AS rolname, " 5254 "oprcode::oid AS oprcode " 5265 i_tableoid =
PQfnumber(res,
"tableoid");
5268 i_oprnamespace =
PQfnumber(res,
"oprnamespace");
5273 for (i = 0; i < ntups; i++)