1
0
mirror of https://github.com/postgres/postgres.git synced 2025-10-15 05:46:52 +03:00

pg_dump: Add dumpSchema and dumpData derivative flags.

Various parts of pg_dump consult the --schema-only and --data-only
options to determine whether to run a section of code.  While this
is simple enough for two mutually-exclusive options, it will become
progressively more complicated as more options are added.  In
anticipation of that, this commit introduces new internal flags
called dumpSchema and dumpData, which are derivatives of
--schema-only and --data-only.  This commit also removes the
schemaOnly and dataOnly members from the dump/restore options
structs to prevent their use elsewhere.

Note that this change neither adds new user-facing command-line
options nor changes the existing --schema-only and --data-only
options.

Author: Corey Huinker
Reviewed-by: Jeff Davis
Discussion: https://postgr.es/m/CADkLM%3DcQgghMJOS8EcAVBwRO4s1dUVtxGZv5gLPfZkQ1nL1gzA%40mail.gmail.com
This commit is contained in:
Nathan Bossart
2024-11-25 16:36:37 -06:00
parent 648333a99f
commit 96a81c1be9
4 changed files with 144 additions and 124 deletions

View File

@@ -147,6 +147,8 @@ InitDumpOptions(DumpOptions *opts)
opts->include_everything = true;
opts->cparams.promptPassword = TRI_DEFAULT;
opts->dumpSections = DUMP_UNSECTIONED;
opts->dumpSchema = true;
opts->dumpData = true;
}
/*
@@ -165,8 +167,8 @@ dumpOptionsFromRestoreOptions(RestoreOptions *ropt)
dopt->cparams.username = ropt->cparams.username ? pg_strdup(ropt->cparams.username) : NULL;
dopt->cparams.promptPassword = ropt->cparams.promptPassword;
dopt->outputClean = ropt->dropSchema;
dopt->dataOnly = ropt->dataOnly;
dopt->schemaOnly = ropt->schemaOnly;
dopt->dumpData = ropt->dumpData;
dopt->dumpSchema = ropt->dumpSchema;
dopt->if_exists = ropt->if_exists;
dopt->column_inserts = ropt->column_inserts;
dopt->dumpSections = ropt->dumpSections;
@@ -419,12 +421,12 @@ RestoreArchive(Archive *AHX)
* Work out if we have an implied data-only restore. This can happen if
* the dump was data only or if the user has used a toc list to exclude
* all of the schema data. All we do is look for schema entries - if none
* are found then we set the dataOnly flag.
* are found then we unset the dumpSchema flag.
*
* We could scan for wanted TABLE entries, but that is not the same as
* dataOnly. At this stage, it seems unnecessary (6-Mar-2001).
* data-only. At this stage, it seems unnecessary (6-Mar-2001).
*/
if (!ropt->dataOnly)
if (ropt->dumpSchema)
{
int impliedDataOnly = 1;
@@ -438,7 +440,7 @@ RestoreArchive(Archive *AHX)
}
if (impliedDataOnly)
{
ropt->dataOnly = impliedDataOnly;
ropt->dumpSchema = false;
pg_log_info("implied data-only restore");
}
}
@@ -824,7 +826,7 @@ restore_toc_entry(ArchiveHandle *AH, TocEntry *te, bool is_parallel)
/* Dump any relevant dump warnings to stderr */
if (!ropt->suppressDumpWarnings && strcmp(te->desc, "WARNING") == 0)
{
if (!ropt->dataOnly && te->defn != NULL && strlen(te->defn) != 0)
if (ropt->dumpSchema && te->defn != NULL && strlen(te->defn) != 0)
pg_log_warning("warning from original dump file: %s", te->defn);
else if (te->copyStmt != NULL && strlen(te->copyStmt) != 0)
pg_log_warning("warning from original dump file: %s", te->copyStmt);
@@ -1080,6 +1082,8 @@ NewRestoreOptions(void)
opts->dumpSections = DUMP_UNSECTIONED;
opts->compression_spec.algorithm = PG_COMPRESSION_NONE;
opts->compression_spec.level = 0;
opts->dumpSchema = true;
opts->dumpData = true;
return opts;
}
@@ -1090,7 +1094,7 @@ _disableTriggersIfNecessary(ArchiveHandle *AH, TocEntry *te)
RestoreOptions *ropt = AH->public.ropt;
/* This hack is only needed in a data-only restore */
if (!ropt->dataOnly || !ropt->disable_triggers)
if (ropt->dumpSchema || !ropt->disable_triggers)
return;
pg_log_info("disabling triggers for %s", te->tag);
@@ -1116,7 +1120,7 @@ _enableTriggersIfNecessary(ArchiveHandle *AH, TocEntry *te)
RestoreOptions *ropt = AH->public.ropt;
/* This hack is only needed in a data-only restore */
if (!ropt->dataOnly || !ropt->disable_triggers)
if (ropt->dumpSchema || !ropt->disable_triggers)
return;
pg_log_info("enabling triggers for %s", te->tag);
@@ -3147,13 +3151,13 @@ _tocEntryRequired(TocEntry *te, teSection curSection, ArchiveHandle *AH)
if ((strcmp(te->desc, "<Init>") == 0) && (strcmp(te->tag, "Max OID") == 0))
return 0;
/* Mask it if we only want schema */
if (ropt->schemaOnly)
/* Mask it if we don't want data */
if (!ropt->dumpData)
{
/*
* The sequence_data option overrides schemaOnly for SEQUENCE SET.
* The sequence_data option overrides dumpData for SEQUENCE SET.
*
* In binary-upgrade mode, even with schemaOnly set, we do not mask
* In binary-upgrade mode, even with dumpData unset, we do not mask
* out large objects. (Only large object definitions, comments and
* other metadata should be generated in binary-upgrade mode, not the
* actual data, but that need not concern us here.)
@@ -3171,8 +3175,8 @@ _tocEntryRequired(TocEntry *te, teSection curSection, ArchiveHandle *AH)
res = res & REQ_SCHEMA;
}
/* Mask it if we only want data */
if (ropt->dataOnly)
/* Mask it if we don't want schema */
if (!ropt->dumpSchema)
res = res & REQ_DATA;
return res;