diff options
| author | Dean Rasheed | 2024-03-20 08:05:44 +0000 |
|---|---|---|
| committer | Dean Rasheed | 2024-03-20 08:05:44 +0000 |
| commit | 522ed12f7c600243870b13d9ff59f8fd5af10978 (patch) | |
| tree | 27dd4d18d02ee32efc4c515715561a78efb837ee /src/bin | |
| parent | d63d486d6c393817810d0477569fc657c388bfb2 (diff) | |
Add "--exclude-extension" to pg_dump's options.
This option (or equivalently specifying "exclude extension pattern" in
a filter file) allows extensions matching the specified pattern to be
excluded from the dump.
Ayush Vatsa, reviewed by Junwang Zhao, Dean Rasheed, and Daniel
Gustafsson.
Discussion: https://postgr.es/m/CACX+KaP=VgVy9h-EUh598DTu+-fNr1jyEmpghC8rRp9s=w33Kg@mail.gmail.com
Diffstat (limited to 'src/bin')
| -rw-r--r-- | src/bin/pg_dump/pg_dump.c | 33 |
1 files changed, 32 insertions, 1 deletions
diff --git a/src/bin/pg_dump/pg_dump.c b/src/bin/pg_dump/pg_dump.c index a5149ca823c..3ab7c6676a2 100644 --- a/src/bin/pg_dump/pg_dump.c +++ b/src/bin/pg_dump/pg_dump.c @@ -136,6 +136,9 @@ static SimpleOidList foreign_servers_include_oids = {NULL, NULL}; static SimpleStringList extension_include_patterns = {NULL, NULL}; static SimpleOidList extension_include_oids = {NULL, NULL}; +static SimpleStringList extension_exclude_patterns = {NULL, NULL}; +static SimpleOidList extension_exclude_oids = {NULL, NULL}; + static const CatalogId nilCatalogId = {0, 0}; /* override for standard extra_float_digits setting */ @@ -437,6 +440,7 @@ main(int argc, char **argv) {"exclude-table-data-and-children", required_argument, NULL, 14}, {"sync-method", required_argument, NULL, 15}, {"filter", required_argument, NULL, 16}, + {"exclude-extension", required_argument, NULL, 17}, {NULL, 0, NULL, 0} }; @@ -672,6 +676,11 @@ main(int argc, char **argv) read_dump_filters(optarg, &dopt); break; + case 17: /* exclude extension(s) */ + simple_string_list_append(&extension_exclude_patterns, + optarg); + break; + default: /* getopt_long already emitted a complaint */ pg_log_error_hint("Try \"%s --help\" for more information.", progname); @@ -890,6 +899,10 @@ main(int argc, char **argv) if (extension_include_oids.head == NULL) pg_fatal("no matching extensions were found"); } + expand_extension_name_patterns(fout, &extension_exclude_patterns, + &extension_exclude_oids, + false); + /* non-matching exclusion patterns aren't an error */ /* * Dumping LOs is the default for dumps where an inclusion switch is not @@ -1095,6 +1108,7 @@ help(const char *progname) printf(_(" -c, --clean clean (drop) database objects before recreating\n")); printf(_(" -C, --create include commands to create database in dump\n")); printf(_(" -e, --extension=PATTERN dump the specified extension(s) only\n")); + printf(_(" --exclude-extension=PATTERN do NOT dump the specified extension(s)\n")); printf(_(" -E, --encoding=ENCODING dump the data in encoding ENCODING\n")); printf(_(" -n, --schema=PATTERN dump the specified schema(s) only\n")); printf(_(" -N, --exclude-schema=PATTERN do NOT dump the specified schema(s)\n")); @@ -2028,6 +2042,12 @@ selectDumpableExtension(ExtensionInfo *extinfo, DumpOptions *dopt) extinfo->dobj.dump = extinfo->dobj.dump_contains = dopt->include_everything ? DUMP_COMPONENT_ALL : DUMP_COMPONENT_NONE; + + /* check that the extension is not explicitly excluded */ + if (extinfo->dobj.dump && + simple_oid_list_member(&extension_exclude_oids, + extinfo->dobj.catId.oid)) + extinfo->dobj.dump = extinfo->dobj.dump_contains = DUMP_COMPONENT_NONE; } } @@ -18265,6 +18285,15 @@ processExtensionTables(Archive *fout, ExtensionInfo extinfo[], curext->dobj.catId.oid)) continue; + /* + * Check if this extension is listed as to exclude in the dump. If + * yes, any table data associated with it is discarded. + */ + if (extension_exclude_oids.head != NULL && + simple_oid_list_member(&extension_exclude_oids, + curext->dobj.catId.oid)) + continue; + if (strlen(extconfig) != 0 || strlen(extcondition) != 0) { int j; @@ -18965,7 +18994,6 @@ read_dump_filters(const char *filename, DumpOptions *dopt) case FILTER_OBJECT_TYPE_FUNCTION: case FILTER_OBJECT_TYPE_INDEX: case FILTER_OBJECT_TYPE_TRIGGER: - case FILTER_OBJECT_TYPE_EXTENSION: case FILTER_OBJECT_TYPE_FOREIGN_DATA: pg_log_filter_error(&fstate, _("%s filter for \"%s\" is not allowed"), "exclude", @@ -18973,6 +19001,9 @@ read_dump_filters(const char *filename, DumpOptions *dopt) exit_nicely(1); break; + case FILTER_OBJECT_TYPE_EXTENSION: + simple_string_list_append(&extension_exclude_patterns, objname); + break; case FILTER_OBJECT_TYPE_TABLE_DATA: simple_string_list_append(&tabledata_exclude_patterns, objname); |
