Skip to content

pg_dump: Add --schema-no-create option [PG16] #657

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: REL_16_STABLE_neon
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion src/bin/pg_dump/pg_dump.c
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,8 @@ static SimpleOidList schema_include_oids = {NULL, NULL};
static SimpleStringList schema_exclude_patterns = {NULL, NULL};
static SimpleOidList schema_exclude_oids = {NULL, NULL};

static SimpleStringList schema_include_no_create_patterns = {NULL, NULL};

static SimpleStringList table_include_patterns = {NULL, NULL};
static SimpleStringList table_include_patterns_and_children = {NULL, NULL};
static SimpleOidList table_include_oids = {NULL, NULL};
Expand Down Expand Up @@ -433,7 +435,7 @@ main(int argc, char **argv)
{"table-and-children", required_argument, NULL, 12},
{"exclude-table-and-children", required_argument, NULL, 13},
{"exclude-table-data-and-children", required_argument, NULL, 14},

{"schema-no-create", required_argument, NULL, 15},
{NULL, 0, NULL, 0}
};

Expand Down Expand Up @@ -659,6 +661,16 @@ main(int argc, char **argv)
optarg);
break;

case 15: /* schema-no-create */
simple_string_list_append(&schema_include_no_create_patterns,
optarg);
/*
* Also include the schema in the regular include list,
* because we need to dump the data.
*/
simple_string_list_append(&schema_include_patterns, optarg);
break;

default:
/* getopt_long already emitted a complaint */
pg_log_error_hint("Try \"%s --help\" for more information.", progname);
Expand Down Expand Up @@ -1124,6 +1136,7 @@ help(const char *progname)
printf(_(" --on-conflict-do-nothing add ON CONFLICT DO NOTHING to INSERT commands\n"));
printf(_(" --quote-all-identifiers quote all identifiers, even if not key words\n"));
printf(_(" --rows-per-insert=NROWS number of rows per INSERT; implies --inserts\n"));
printf(_(" --schema-no-create=SCHEMA do not create the specified schema(s)\n"));
printf(_(" --section=SECTION dump named section (pre-data, data, or post-data)\n"));
printf(_(" --serializable-deferrable wait until the dump can run without anomalies\n"));
printf(_(" --snapshot=SNAPSHOT use given snapshot for the dump\n"));
Expand Down Expand Up @@ -1729,6 +1742,8 @@ selectDumpableNamespace(NamespaceInfo *nsinfo, Archive *fout)
* DUMP_COMPONENT_DEFINITION, this value is irrelevant.)
*/
nsinfo->create = true;
if (simple_string_list_member(&schema_include_no_create_patterns, nsinfo->dobj.name))
nsinfo->create = false;

/*
* If specific tables are being dumped, do not dump any complete
Expand Down