Hi one my customer has to specify dumped tables name by name. After years and increasing database size and table numbers he has problem with too short command line. He need to read the list of tables from file (or from stdin).
I wrote simple PoC patch Comments, notes, ideas? Regards Pavel
diff --git a/src/bin/pg_dump/pg_dump.c b/src/bin/pg_dump/pg_dump.c index bd14d38740..d8330ec32a 100644 --- a/src/bin/pg_dump/pg_dump.c +++ b/src/bin/pg_dump/pg_dump.c @@ -362,6 +362,7 @@ main(int argc, char **argv) {"serializable-deferrable", no_argument, &dopt.serializable_deferrable, 1}, {"snapshot", required_argument, NULL, 6}, {"strict-names", no_argument, &strict_names, 1}, + {"table-names-from-file", required_argument, NULL, 8}, {"use-set-session-authorization", no_argument, &dopt.use_setsessauth, 1}, {"no-publications", no_argument, &dopt.no_publications, 1}, {"no-security-labels", no_argument, &dopt.no_security_labels, 1}, @@ -553,6 +554,59 @@ main(int argc, char **argv) dosync = false; break; + case 8: /* read table names from file */ + { + FILE *f; + char *line; + size_t line_size = 1024; + ssize_t chars; + bool use_stdin = false; + + if (strcmp(optarg, "-") != 0) + { + f = fopen(optarg, "r"); + if (!f) + { + fprintf(stderr, _("%s: could not open the input file \"%s\": %s\n"), + progname, optarg, strerror(errno)); + exit_nicely(1); + } + } + else + { + f = stdin; + use_stdin = true; + } + + line = malloc(line_size); + + while ((chars = getline(&line, &line_size, f)) != -1) + { + if (line[chars - 1] == '\n') + line[chars - 1] = '\0'; + + /* ignore empty rows */ + if (*line != '\0') + { + simple_string_list_append(&table_include_patterns, line); + dopt.include_everything = false; + } + } + + if (ferror(f)) + { + fprintf(stderr, _("%s: could not read from file \"%s\": %s\n"), + progname, use_stdin ? "stdin" : optarg, strerror(errno)); + exit_nicely(1); + } + + if (!use_stdin) + fclose(f); + + free(line); + } + break; + default: fprintf(stderr, _("Try \"%s --help\" for more information.\n"), progname); exit_nicely(1); @@ -977,6 +1031,8 @@ help(const char *progname) printf(_(" --snapshot=SNAPSHOT use given snapshot for the dump\n")); printf(_(" --strict-names require table and/or schema include patterns to\n" " match at least one entity each\n")); + printf(_(" --table-names-from-file=FILENAME\n" + " read table's names from file (one table name per line)\n")); printf(_(" --use-set-session-authorization\n" " use SET SESSION AUTHORIZATION commands instead of\n" " ALTER OWNER commands to set ownership\n"));