@@ -119,11 +119,15 @@ static SimpleStringList schema_exclude_patterns = {NULL, NULL};
119
119
static SimpleOidList schema_exclude_oids = {NULL, NULL};
120
120
121
121
static SimpleStringList table_include_patterns = {NULL, NULL};
122
+ static SimpleStringList table_include_patterns_and_children = {NULL, NULL};
122
123
static SimpleOidList table_include_oids = {NULL, NULL};
123
124
static SimpleStringList table_exclude_patterns = {NULL, NULL};
125
+ static SimpleStringList table_exclude_patterns_and_children = {NULL, NULL};
124
126
static SimpleOidList table_exclude_oids = {NULL, NULL};
125
127
static SimpleStringList tabledata_exclude_patterns = {NULL, NULL};
128
+ static SimpleStringList tabledata_exclude_patterns_and_children = {NULL, NULL};
126
129
static SimpleOidList tabledata_exclude_oids = {NULL, NULL};
130
+
127
131
static SimpleStringList foreign_servers_include_patterns = {NULL, NULL};
128
132
static SimpleOidList foreign_servers_include_oids = {NULL, NULL};
129
133
@@ -180,7 +184,8 @@ static void expand_foreign_server_name_patterns(Archive *fout,
180
184
static void expand_table_name_patterns(Archive *fout,
181
185
SimpleStringList *patterns,
182
186
SimpleOidList *oids,
183
- bool strict_names);
187
+ bool strict_names,
188
+ bool with_child_tables);
184
189
static void prohibit_crossdb_refs(PGconn *conn, const char *dbname,
185
190
const char *pattern);
186
191
@@ -421,6 +426,9 @@ main(int argc, char **argv)
421
426
{"on-conflict-do-nothing", no_argument, &dopt.do_nothing, 1},
422
427
{"rows-per-insert", required_argument, NULL, 10},
423
428
{"include-foreign-data", required_argument, NULL, 11},
429
+ {"table-and-children", required_argument, NULL, 12},
430
+ {"exclude-table-and-children", required_argument, NULL, 13},
431
+ {"exclude-table-data-and-children", required_argument, NULL, 14},
424
432
425
433
{NULL, 0, NULL, 0}
426
434
};
@@ -631,6 +639,22 @@ main(int argc, char **argv)
631
639
optarg);
632
640
break;
633
641
642
+ case 12: /* include table(s) and their children */
643
+ simple_string_list_append(&table_include_patterns_and_children,
644
+ optarg);
645
+ dopt.include_everything = false;
646
+ break;
647
+
648
+ case 13: /* exclude table(s) and their children */
649
+ simple_string_list_append(&table_exclude_patterns_and_children,
650
+ optarg);
651
+ break;
652
+
653
+ case 14: /* exclude data of table(s) and children */
654
+ simple_string_list_append(&tabledata_exclude_patterns_and_children,
655
+ optarg);
656
+ break;
657
+
634
658
default:
635
659
/* getopt_long already emitted a complaint */
636
660
pg_log_error_hint("Try \"%s --help\" for more information.", progname);
@@ -810,21 +834,30 @@ main(int argc, char **argv)
810
834
/* non-matching exclusion patterns aren't an error */
811
835
812
836
/* Expand table selection patterns into OID lists */
813
- if (table_include_patterns.head != NULL)
814
- {
815
- expand_table_name_patterns(fout, &table_include_patterns,
816
- &table_include_oids,
817
- strict_names);
818
- if (table_include_oids.head == NULL)
819
- pg_fatal("no matching tables were found");
820
- }
837
+ expand_table_name_patterns(fout, &table_include_patterns,
838
+ &table_include_oids,
839
+ strict_names, false);
840
+ expand_table_name_patterns(fout, &table_include_patterns_and_children,
841
+ &table_include_oids,
842
+ strict_names, true);
843
+ if ((table_include_patterns.head != NULL ||
844
+ table_include_patterns_and_children.head != NULL) &&
845
+ table_include_oids.head == NULL)
846
+ pg_fatal("no matching tables were found");
847
+
821
848
expand_table_name_patterns(fout, &table_exclude_patterns,
822
849
&table_exclude_oids,
823
- false);
850
+ false, false);
851
+ expand_table_name_patterns(fout, &table_exclude_patterns_and_children,
852
+ &table_exclude_oids,
853
+ false, true);
824
854
825
855
expand_table_name_patterns(fout, &tabledata_exclude_patterns,
826
856
&tabledata_exclude_oids,
827
- false);
857
+ false, false);
858
+ expand_table_name_patterns(fout, &tabledata_exclude_patterns_and_children,
859
+ &tabledata_exclude_oids,
860
+ false, true);
828
861
829
862
expand_foreign_server_name_patterns(fout, &foreign_servers_include_patterns,
830
863
&foreign_servers_include_oids);
@@ -1051,7 +1084,7 @@ help(const char *progname)
1051
1084
" plain-text format\n"));
1052
1085
printf(_(" -s, --schema-only dump only the schema, no data\n"));
1053
1086
printf(_(" -S, --superuser=NAME superuser user name to use in plain-text format\n"));
1054
- printf(_(" -t, --table=PATTERN dump the specified table(s) only \n"));
1087
+ printf(_(" -t, --table=PATTERN dump only the specified table(s)\n"));
1055
1088
printf(_(" -T, --exclude-table=PATTERN do NOT dump the specified table(s)\n"));
1056
1089
printf(_(" -x, --no-privileges do not dump privileges (grant/revoke)\n"));
1057
1090
printf(_(" --binary-upgrade for use by upgrade utilities only\n"));
@@ -1060,7 +1093,13 @@ help(const char *progname)
1060
1093
printf(_(" --disable-triggers disable triggers during data-only restore\n"));
1061
1094
printf(_(" --enable-row-security enable row security (dump only content user has\n"
1062
1095
" access to)\n"));
1096
+ printf(_(" --exclude-table-and-children=PATTERN\n"
1097
+ " do NOT dump the specified table(s),\n"
1098
+ " including child and partition tables\n"));
1063
1099
printf(_(" --exclude-table-data=PATTERN do NOT dump data for the specified table(s)\n"));
1100
+ printf(_(" --exclude-table-data-and-children=PATTERN\n"
1101
+ " do NOT dump data for the specified table(s),\n"
1102
+ " including child and partition tables\n"));
1064
1103
printf(_(" --extra-float-digits=NUM override default setting for extra_float_digits\n"));
1065
1104
printf(_(" --if-exists use IF EXISTS when dropping objects\n"));
1066
1105
printf(_(" --include-foreign-data=PATTERN\n"
@@ -1084,6 +1123,8 @@ help(const char *progname)
1084
1123
printf(_(" --snapshot=SNAPSHOT use given snapshot for the dump\n"));
1085
1124
printf(_(" --strict-names require table and/or schema include patterns to\n"
1086
1125
" match at least one entity each\n"));
1126
+ printf(_(" --table-and-children=PATTERN dump only the specified table(s),\n"
1127
+ " including child and partition tables\n"));
1087
1128
printf(_(" --use-set-session-authorization\n"
1088
1129
" use SET SESSION AUTHORIZATION commands instead of\n"
1089
1130
" ALTER OWNER commands to set ownership\n"));
@@ -1497,7 +1538,7 @@ expand_foreign_server_name_patterns(Archive *fout,
1497
1538
static void
1498
1539
expand_table_name_patterns(Archive *fout,
1499
1540
SimpleStringList *patterns, SimpleOidList *oids,
1500
- bool strict_names)
1541
+ bool strict_names, bool with_child_tables )
1501
1542
{
1502
1543
PQExpBuffer query;
1503
1544
PGresult *res;
@@ -1523,7 +1564,15 @@ expand_table_name_patterns(Archive *fout,
1523
1564
* Query must remain ABSOLUTELY devoid of unqualified names. This
1524
1565
* would be unnecessary given a pg_table_is_visible() variant taking a
1525
1566
* search_path argument.
1567
+ *
1568
+ * For with_child_tables, we start with the basic query's results and
1569
+ * recursively search the inheritance tree to add child tables.
1526
1570
*/
1571
+ if (with_child_tables)
1572
+ {
1573
+ appendPQExpBuffer(query, "WITH RECURSIVE partition_tree (relid) AS (\n");
1574
+ }
1575
+
1527
1576
appendPQExpBuffer(query,
1528
1577
"SELECT c.oid"
1529
1578
"\nFROM pg_catalog.pg_class c"
@@ -1546,6 +1595,17 @@ expand_table_name_patterns(Archive *fout,
1546
1595
prohibit_crossdb_refs(GetConnection(fout), dbbuf.data, cell->val);
1547
1596
termPQExpBuffer(&dbbuf);
1548
1597
1598
+ if (with_child_tables)
1599
+ {
1600
+ appendPQExpBuffer(query, "UNION"
1601
+ "\nSELECT i.inhrelid"
1602
+ "\nFROM partition_tree p"
1603
+ "\n JOIN pg_catalog.pg_inherits i"
1604
+ "\n ON p.relid OPERATOR(pg_catalog.=) i.inhparent"
1605
+ "\n)"
1606
+ "\nSELECT relid FROM partition_tree");
1607
+ }
1608
+
1549
1609
ExecuteSqlStatement(fout, "RESET search_path");
1550
1610
res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
1551
1611
PQclear(ExecuteSqlQueryForSingleRow(fout,
0 commit comments