Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 96a81c1

Browse files
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
1 parent 648333a commit 96a81c1

File tree

4 files changed

+144
-124
lines changed

4 files changed

+144
-124
lines changed

src/bin/pg_dump/pg_backup.h

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -116,8 +116,6 @@ typedef struct _restoreOptions
116116
int strict_names;
117117

118118
const char *filename;
119-
int dataOnly;
120-
int schemaOnly;
121119
int dumpSections;
122120
int verbose;
123121
int aclsSkip;
@@ -158,6 +156,10 @@ typedef struct _restoreOptions
158156
int enable_row_security;
159157
int sequence_data; /* dump sequence data even in schema-only mode */
160158
int binary_upgrade;
159+
160+
/* flags derived from the user-settable flags */
161+
bool dumpSchema;
162+
bool dumpData;
161163
} RestoreOptions;
162164

163165
typedef struct _dumpOptions
@@ -167,8 +169,6 @@ typedef struct _dumpOptions
167169
int binary_upgrade;
168170

169171
/* various user-settable parameters */
170-
bool schemaOnly;
171-
bool dataOnly;
172172
int dumpSections; /* bitmask of chosen sections */
173173
bool aclsSkip;
174174
const char *lockWaitTimeout;
@@ -204,6 +204,10 @@ typedef struct _dumpOptions
204204

205205
int sequence_data; /* dump sequence data even in schema-only mode */
206206
int do_nothing;
207+
208+
/* flags derived from the user-settable flags */
209+
bool dumpSchema;
210+
bool dumpData;
207211
} DumpOptions;
208212

209213
/*

src/bin/pg_dump/pg_backup_archiver.c

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,8 @@ InitDumpOptions(DumpOptions *opts)
147147
opts->include_everything = true;
148148
opts->cparams.promptPassword = TRI_DEFAULT;
149149
opts->dumpSections = DUMP_UNSECTIONED;
150+
opts->dumpSchema = true;
151+
opts->dumpData = true;
150152
}
151153

152154
/*
@@ -165,8 +167,8 @@ dumpOptionsFromRestoreOptions(RestoreOptions *ropt)
165167
dopt->cparams.username = ropt->cparams.username ? pg_strdup(ropt->cparams.username) : NULL;
166168
dopt->cparams.promptPassword = ropt->cparams.promptPassword;
167169
dopt->outputClean = ropt->dropSchema;
168-
dopt->dataOnly = ropt->dataOnly;
169-
dopt->schemaOnly = ropt->schemaOnly;
170+
dopt->dumpData = ropt->dumpData;
171+
dopt->dumpSchema = ropt->dumpSchema;
170172
dopt->if_exists = ropt->if_exists;
171173
dopt->column_inserts = ropt->column_inserts;
172174
dopt->dumpSections = ropt->dumpSections;
@@ -419,12 +421,12 @@ RestoreArchive(Archive *AHX)
419421
* Work out if we have an implied data-only restore. This can happen if
420422
* the dump was data only or if the user has used a toc list to exclude
421423
* all of the schema data. All we do is look for schema entries - if none
422-
* are found then we set the dataOnly flag.
424+
* are found then we unset the dumpSchema flag.
423425
*
424426
* We could scan for wanted TABLE entries, but that is not the same as
425-
* dataOnly. At this stage, it seems unnecessary (6-Mar-2001).
427+
* data-only. At this stage, it seems unnecessary (6-Mar-2001).
426428
*/
427-
if (!ropt->dataOnly)
429+
if (ropt->dumpSchema)
428430
{
429431
int impliedDataOnly = 1;
430432

@@ -438,7 +440,7 @@ RestoreArchive(Archive *AHX)
438440
}
439441
if (impliedDataOnly)
440442
{
441-
ropt->dataOnly = impliedDataOnly;
443+
ropt->dumpSchema = false;
442444
pg_log_info("implied data-only restore");
443445
}
444446
}
@@ -824,7 +826,7 @@ restore_toc_entry(ArchiveHandle *AH, TocEntry *te, bool is_parallel)
824826
/* Dump any relevant dump warnings to stderr */
825827
if (!ropt->suppressDumpWarnings && strcmp(te->desc, "WARNING") == 0)
826828
{
827-
if (!ropt->dataOnly && te->defn != NULL && strlen(te->defn) != 0)
829+
if (ropt->dumpSchema && te->defn != NULL && strlen(te->defn) != 0)
828830
pg_log_warning("warning from original dump file: %s", te->defn);
829831
else if (te->copyStmt != NULL && strlen(te->copyStmt) != 0)
830832
pg_log_warning("warning from original dump file: %s", te->copyStmt);
@@ -1080,6 +1082,8 @@ NewRestoreOptions(void)
10801082
opts->dumpSections = DUMP_UNSECTIONED;
10811083
opts->compression_spec.algorithm = PG_COMPRESSION_NONE;
10821084
opts->compression_spec.level = 0;
1085+
opts->dumpSchema = true;
1086+
opts->dumpData = true;
10831087

10841088
return opts;
10851089
}
@@ -1090,7 +1094,7 @@ _disableTriggersIfNecessary(ArchiveHandle *AH, TocEntry *te)
10901094
RestoreOptions *ropt = AH->public.ropt;
10911095

10921096
/* This hack is only needed in a data-only restore */
1093-
if (!ropt->dataOnly || !ropt->disable_triggers)
1097+
if (ropt->dumpSchema || !ropt->disable_triggers)
10941098
return;
10951099

10961100
pg_log_info("disabling triggers for %s", te->tag);
@@ -1116,7 +1120,7 @@ _enableTriggersIfNecessary(ArchiveHandle *AH, TocEntry *te)
11161120
RestoreOptions *ropt = AH->public.ropt;
11171121

11181122
/* This hack is only needed in a data-only restore */
1119-
if (!ropt->dataOnly || !ropt->disable_triggers)
1123+
if (ropt->dumpSchema || !ropt->disable_triggers)
11201124
return;
11211125

11221126
pg_log_info("enabling triggers for %s", te->tag);
@@ -3147,13 +3151,13 @@ _tocEntryRequired(TocEntry *te, teSection curSection, ArchiveHandle *AH)
31473151
if ((strcmp(te->desc, "<Init>") == 0) && (strcmp(te->tag, "Max OID") == 0))
31483152
return 0;
31493153

3150-
/* Mask it if we only want schema */
3151-
if (ropt->schemaOnly)
3154+
/* Mask it if we don't want data */
3155+
if (!ropt->dumpData)
31523156
{
31533157
/*
3154-
* The sequence_data option overrides schemaOnly for SEQUENCE SET.
3158+
* The sequence_data option overrides dumpData for SEQUENCE SET.
31553159
*
3156-
* In binary-upgrade mode, even with schemaOnly set, we do not mask
3160+
* In binary-upgrade mode, even with dumpData unset, we do not mask
31573161
* out large objects. (Only large object definitions, comments and
31583162
* other metadata should be generated in binary-upgrade mode, not the
31593163
* actual data, but that need not concern us here.)
@@ -3171,8 +3175,8 @@ _tocEntryRequired(TocEntry *te, teSection curSection, ArchiveHandle *AH)
31713175
res = res & REQ_SCHEMA;
31723176
}
31733177

3174-
/* Mask it if we only want data */
3175-
if (ropt->dataOnly)
3178+
/* Mask it if we don't want schema */
3179+
if (!ropt->dumpSchema)
31763180
res = res & REQ_DATA;
31773181

31783182
return res;

0 commit comments

Comments
 (0)