Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit96a81c1

Browse files
pg_dump: Add dumpSchema and dumpData derivative flags.
Various parts of pg_dump consult the --schema-only and --data-onlyoptions to determine whether to run a section of code. While thisis simple enough for two mutually-exclusive options, it will becomeprogressively more complicated as more options are added. Inanticipation of that, this commit introduces new internal flagscalled dumpSchema and dumpData, which are derivatives of--schema-only and --data-only. This commit also removes theschemaOnly and dataOnly members from the dump/restore optionsstructs to prevent their use elsewhere.Note that this change neither adds new user-facing command-lineoptions nor changes the existing --schema-only and --data-onlyoptions.Author: Corey HuinkerReviewed-by: Jeff DavisDiscussion:https://postgr.es/m/CADkLM%3DcQgghMJOS8EcAVBwRO4s1dUVtxGZv5gLPfZkQ1nL1gzA%40mail.gmail.com
1 parent648333a commit96a81c1

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
intstrict_names;
117117

118118
constchar*filename;
119-
intdataOnly;
120-
intschemaOnly;
121119
intdumpSections;
122120
intverbose;
123121
intaclsSkip;
@@ -158,6 +156,10 @@ typedef struct _restoreOptions
158156
intenable_row_security;
159157
intsequence_data;/* dump sequence data even in schema-only mode */
160158
intbinary_upgrade;
159+
160+
/* flags derived from the user-settable flags */
161+
booldumpSchema;
162+
booldumpData;
161163
}RestoreOptions;
162164

163165
typedefstruct_dumpOptions
@@ -167,8 +169,6 @@ typedef struct _dumpOptions
167169
intbinary_upgrade;
168170

169171
/* various user-settable parameters */
170-
boolschemaOnly;
171-
booldataOnly;
172172
intdumpSections;/* bitmask of chosen sections */
173173
boolaclsSkip;
174174
constchar*lockWaitTimeout;
@@ -204,6 +204,10 @@ typedef struct _dumpOptions
204204

205205
intsequence_data;/* dump sequence data even in schema-only mode */
206206
intdo_nothing;
207+
208+
/* flags derived from the user-settable flags */
209+
booldumpSchema;
210+
booldumpData;
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 weset thedataOnly flag.
424+
* are found then weunset thedumpSchema 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
intimpliedDataOnly=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
elseif (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
returnopts;
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
return0;
31493153

3150-
/* Mask it if weonly wantschema */
3151-
if (ropt->schemaOnly)
3154+
/* Mask it if wedon't wantdata */
3155+
if (!ropt->dumpData)
31523156
{
31533157
/*
3154-
* The sequence_data option overridesschemaOnly for SEQUENCE SET.
3158+
* The sequence_data option overridesdumpData for SEQUENCE SET.
31553159
*
3156-
* In binary-upgrade mode, even withschemaOnly set, we do not mask
3160+
* In binary-upgrade mode, even withdumpData 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 weonly wantdata */
3175-
if (ropt->dataOnly)
3178+
/* Mask it if wedon't wantschema */
3179+
if (!ropt->dumpSchema)
31763180
res=res&REQ_DATA;
31773181

31783182
returnres;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp