aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/bin/pg_dump/pg_backup.h12
-rw-r--r--src/bin/pg_dump/pg_backup_archiver.c34
-rw-r--r--src/bin/pg_dump/pg_dump.c208
-rw-r--r--src/bin/pg_dump/pg_restore.c14
4 files changed, 144 insertions, 124 deletions
diff --git a/src/bin/pg_dump/pg_backup.h b/src/bin/pg_dump/pg_backup.h
index 68ae2970ade..f0f19bb0b29 100644
--- a/src/bin/pg_dump/pg_backup.h
+++ b/src/bin/pg_dump/pg_backup.h
@@ -116,8 +116,6 @@ typedef struct _restoreOptions
int strict_names;
const char *filename;
- int dataOnly;
- int schemaOnly;
int dumpSections;
int verbose;
int aclsSkip;
@@ -158,6 +156,10 @@ typedef struct _restoreOptions
int enable_row_security;
int sequence_data; /* dump sequence data even in schema-only mode */
int binary_upgrade;
+
+ /* flags derived from the user-settable flags */
+ bool dumpSchema;
+ bool dumpData;
} RestoreOptions;
typedef struct _dumpOptions
@@ -167,8 +169,6 @@ typedef struct _dumpOptions
int binary_upgrade;
/* various user-settable parameters */
- bool schemaOnly;
- bool dataOnly;
int dumpSections; /* bitmask of chosen sections */
bool aclsSkip;
const char *lockWaitTimeout;
@@ -204,6 +204,10 @@ typedef struct _dumpOptions
int sequence_data; /* dump sequence data even in schema-only mode */
int do_nothing;
+
+ /* flags derived from the user-settable flags */
+ bool dumpSchema;
+ bool dumpData;
} DumpOptions;
/*
diff --git a/src/bin/pg_dump/pg_backup_archiver.c b/src/bin/pg_dump/pg_backup_archiver.c
index 8c20c263c4b..33182d5b445 100644
--- a/src/bin/pg_dump/pg_backup_archiver.c
+++ b/src/bin/pg_dump/pg_backup_archiver.c
@@ -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;
diff --git a/src/bin/pg_dump/pg_dump.c b/src/bin/pg_dump/pg_dump.c
index c30aafbe70d..add7f16c902 100644
--- a/src/bin/pg_dump/pg_dump.c
+++ b/src/bin/pg_dump/pg_dump.c
@@ -428,6 +428,8 @@ main(int argc, char **argv)
char *error_detail = NULL;
bool user_compression_defined = false;
DataDirSyncMethod sync_method = DATA_DIR_SYNC_METHOD_FSYNC;
+ bool data_only = false;
+ bool schema_only = false;
static DumpOptions dopt;
@@ -543,7 +545,7 @@ main(int argc, char **argv)
switch (c)
{
case 'a': /* Dump data only */
- dopt.dataOnly = true;
+ data_only = true;
break;
case 'b': /* Dump LOs */
@@ -616,7 +618,7 @@ main(int argc, char **argv)
break;
case 's': /* dump schema only */
- dopt.schemaOnly = true;
+ schema_only = true;
break;
case 'S': /* Username for superuser in plain text output */
@@ -780,21 +782,25 @@ main(int argc, char **argv)
if (dopt.binary_upgrade)
dopt.sequence_data = 1;
- if (dopt.dataOnly && dopt.schemaOnly)
+ if (data_only && schema_only)
pg_fatal("options -s/--schema-only and -a/--data-only cannot be used together");
- if (dopt.schemaOnly && foreign_servers_include_patterns.head != NULL)
+ if (schema_only && foreign_servers_include_patterns.head != NULL)
pg_fatal("options -s/--schema-only and --include-foreign-data cannot be used together");
if (numWorkers > 1 && foreign_servers_include_patterns.head != NULL)
pg_fatal("option --include-foreign-data is not supported with parallel backup");
- if (dopt.dataOnly && dopt.outputClean)
+ if (data_only && dopt.outputClean)
pg_fatal("options -c/--clean and -a/--data-only cannot be used together");
if (dopt.if_exists && !dopt.outputClean)
pg_fatal("option --if-exists requires option -c/--clean");
+ /* set derivative flags */
+ dopt.dumpSchema = (!data_only);
+ dopt.dumpData = (!schema_only);
+
/*
* --inserts are already implied above if --column-inserts or
* --rows-per-insert were specified.
@@ -977,7 +983,7 @@ main(int argc, char **argv)
* -s means "schema only" and LOs are data, not schema, so we never
* include LOs when -s is used.
*/
- if (dopt.include_everything && !dopt.schemaOnly && !dopt.dontOutputLOs)
+ if (dopt.include_everything && dopt.dumpData && !dopt.dontOutputLOs)
dopt.outputLOs = true;
/*
@@ -991,15 +997,15 @@ main(int argc, char **argv)
*/
tblinfo = getSchemaData(fout, &numTables);
- if (!dopt.schemaOnly)
+ if (dopt.dumpData)
{
getTableData(&dopt, tblinfo, numTables, 0);
buildMatViewRefreshDependencies(fout);
- if (dopt.dataOnly)
+ if (!dopt.dumpSchema)
getTableDataFKConstraints();
}
- if (dopt.schemaOnly && dopt.sequence_data)
+ if (!dopt.dumpData && dopt.sequence_data)
getTableData(&dopt, tblinfo, numTables, RELKIND_SEQUENCE);
/*
@@ -1091,8 +1097,8 @@ main(int argc, char **argv)
ropt->cparams.username = dopt.cparams.username ? pg_strdup(dopt.cparams.username) : NULL;
ropt->cparams.promptPassword = dopt.cparams.promptPassword;
ropt->dropSchema = dopt.outputClean;
- ropt->dataOnly = dopt.dataOnly;
- ropt->schemaOnly = dopt.schemaOnly;
+ ropt->dumpData = dopt.dumpData;
+ ropt->dumpSchema = dopt.dumpSchema;
ropt->if_exists = dopt.if_exists;
ropt->column_inserts = dopt.column_inserts;
ropt->dumpSections = dopt.dumpSections;
@@ -1987,7 +1993,7 @@ selectDumpableType(TypeInfo *tyinfo, Archive *fout)
* Mark a default ACL as to be dumped or not
*
* For per-schema default ACLs, dump if the schema is to be dumped.
- * Otherwise dump if we are dumping "everything". Note that dataOnly
+ * Otherwise dump if we are dumping "everything". Note that dumpSchema
* and aclsSkip are checked separately.
*/
static void
@@ -4161,8 +4167,8 @@ dumpPolicy(Archive *fout, const PolicyInfo *polinfo)
const char *cmd;
char *tag;
- /* Do nothing in data-only dump */
- if (dopt->dataOnly)
+ /* Do nothing if not dumping schema */
+ if (!dopt->dumpSchema)
return;
/*
@@ -4383,8 +4389,8 @@ dumpPublication(Archive *fout, const PublicationInfo *pubinfo)
char *qpubname;
bool first = true;
- /* Do nothing in data-only dump */
- if (dopt->dataOnly)
+ /* Do nothing if not dumping schema */
+ if (!dopt->dumpSchema)
return;
delq = createPQExpBuffer();
@@ -4701,8 +4707,8 @@ dumpPublicationNamespace(Archive *fout, const PublicationSchemaInfo *pubsinfo)
PQExpBuffer query;
char *tag;
- /* Do nothing in data-only dump */
- if (dopt->dataOnly)
+ /* Do nothing if not dumping schema */
+ if (!dopt->dumpSchema)
return;
tag = psprintf("%s %s", pubinfo->dobj.name, schemainfo->dobj.name);
@@ -4744,8 +4750,8 @@ dumpPublicationTable(Archive *fout, const PublicationRelInfo *pubrinfo)
PQExpBuffer query;
char *tag;
- /* Do nothing in data-only dump */
- if (dopt->dataOnly)
+ /* Do nothing if not dumping schema */
+ if (!dopt->dumpSchema)
return;
tag = psprintf("%s %s", pubinfo->dobj.name, tbinfo->dobj.name);
@@ -5130,8 +5136,8 @@ dumpSubscriptionTable(Archive *fout, const SubRelInfo *subrinfo)
PQExpBuffer query;
char *tag;
- /* Do nothing in data-only dump */
- if (dopt->dataOnly)
+ /* Do nothing if not dumping schema */
+ if (!dopt->dumpSchema)
return;
Assert(fout->dopt->binary_upgrade && fout->remoteVersion >= 170000);
@@ -5204,8 +5210,8 @@ dumpSubscription(Archive *fout, const SubscriptionInfo *subinfo)
int i;
char two_phase_disabled[] = {LOGICALREP_TWOPHASE_STATE_DISABLED, '\0'};
- /* Do nothing in data-only dump */
- if (dopt->dataOnly)
+ /* Do nothing if not dumping schema */
+ if (!dopt->dumpSchema)
return;
delq = createPQExpBuffer();
@@ -7356,8 +7362,8 @@ getPartitioningInfo(Archive *fout)
/* hash partitioning didn't exist before v11 */
if (fout->remoteVersion < 110000)
return;
- /* needn't bother if schema-only dump */
- if (fout->dopt->schemaOnly)
+ /* needn't bother if not dumping data */
+ if (!fout->dopt->dumpData)
return;
query = createPQExpBuffer();
@@ -9055,7 +9061,7 @@ getTableAttrs(Archive *fout, TableInfo *tblinfo, int numTables)
* Now get info about column defaults. This is skipped for a data-only
* dump, as it is only needed for table schemas.
*/
- if (!dopt->dataOnly && tbloids->len > 1)
+ if (dopt->dumpSchema && tbloids->len > 1)
{
AttrDefInfo *attrdefs;
int numDefaults;
@@ -9185,7 +9191,7 @@ getTableAttrs(Archive *fout, TableInfo *tblinfo, int numTables)
* Get info about table CHECK constraints. This is skipped for a
* data-only dump, as it is only needed for table schemas.
*/
- if (!dopt->dataOnly && checkoids->len > 2)
+ if (dopt->dumpSchema && checkoids->len > 2)
{
ConstraintInfo *constrs;
int numConstrs;
@@ -10199,13 +10205,13 @@ dumpCommentExtended(Archive *fout, const char *type,
/* Comments are schema not data ... except LO comments are data */
if (strcmp(type, "LARGE OBJECT") != 0)
{
- if (dopt->dataOnly)
+ if (!dopt->dumpSchema)
return;
}
else
{
/* We do dump LO comments in binary-upgrade mode */
- if (dopt->schemaOnly && !dopt->binary_upgrade)
+ if (!dopt->dumpData && !dopt->binary_upgrade)
return;
}
@@ -10312,7 +10318,7 @@ dumpTableComment(Archive *fout, const TableInfo *tbinfo,
return;
/* Comments are SCHEMA not data */
- if (dopt->dataOnly)
+ if (!dopt->dumpSchema)
return;
/* Search for comments associated with relation, using table */
@@ -10758,8 +10764,8 @@ dumpNamespace(Archive *fout, const NamespaceInfo *nspinfo)
PQExpBuffer delq;
char *qnspname;
- /* Do nothing in data-only dump */
- if (dopt->dataOnly)
+ /* Do nothing if not dumping schema */
+ if (!dopt->dumpSchema)
return;
q = createPQExpBuffer();
@@ -10835,8 +10841,8 @@ dumpExtension(Archive *fout, const ExtensionInfo *extinfo)
PQExpBuffer delq;
char *qextname;
- /* Do nothing in data-only dump */
- if (dopt->dataOnly)
+ /* Do nothing if not dumping schema */
+ if (!dopt->dumpSchema)
return;
q = createPQExpBuffer();
@@ -10960,8 +10966,8 @@ dumpType(Archive *fout, const TypeInfo *tyinfo)
{
DumpOptions *dopt = fout->dopt;
- /* Do nothing in data-only dump */
- if (dopt->dataOnly)
+ /* Do nothing if not dumping schema */
+ if (!dopt->dumpSchema)
return;
/* Dump out in proper style */
@@ -12071,8 +12077,8 @@ dumpShellType(Archive *fout, const ShellTypeInfo *stinfo)
DumpOptions *dopt = fout->dopt;
PQExpBuffer q;
- /* Do nothing in data-only dump */
- if (dopt->dataOnly)
+ /* Do nothing if not dumping schema */
+ if (!dopt->dumpSchema)
return;
q = createPQExpBuffer();
@@ -12123,8 +12129,8 @@ dumpProcLang(Archive *fout, const ProcLangInfo *plang)
FuncInfo *inlineInfo = NULL;
FuncInfo *validatorInfo = NULL;
- /* Do nothing in data-only dump */
- if (dopt->dataOnly)
+ /* Do nothing if not dumping schema */
+ if (!dopt->dumpSchema)
return;
/*
@@ -12331,8 +12337,8 @@ dumpFunc(Archive *fout, const FuncInfo *finfo)
int nconfigitems = 0;
const char *keyword;
- /* Do nothing in data-only dump */
- if (dopt->dataOnly)
+ /* Do nothing if not dumping schema */
+ if (!dopt->dumpSchema)
return;
query = createPQExpBuffer();
@@ -12723,8 +12729,8 @@ dumpCast(Archive *fout, const CastInfo *cast)
const char *sourceType;
const char *targetType;
- /* Do nothing in data-only dump */
- if (dopt->dataOnly)
+ /* Do nothing if not dumping schema */
+ if (!dopt->dumpSchema)
return;
/* Cannot dump if we don't have the cast function's info */
@@ -12829,8 +12835,8 @@ dumpTransform(Archive *fout, const TransformInfo *transform)
char *lanname;
const char *transformType;
- /* Do nothing in data-only dump */
- if (dopt->dataOnly)
+ /* Do nothing if not dumping schema */
+ if (!dopt->dumpSchema)
return;
/* Cannot dump if we don't have the transform functions' info */
@@ -12978,8 +12984,8 @@ dumpOpr(Archive *fout, const OprInfo *oprinfo)
char *oprregproc;
char *oprref;
- /* Do nothing in data-only dump */
- if (dopt->dataOnly)
+ /* Do nothing if not dumping schema */
+ if (!dopt->dumpSchema)
return;
/*
@@ -13265,8 +13271,8 @@ dumpAccessMethod(Archive *fout, const AccessMethodInfo *aminfo)
PQExpBuffer delq;
char *qamname;
- /* Do nothing in data-only dump */
- if (dopt->dataOnly)
+ /* Do nothing if not dumping schema */
+ if (!dopt->dumpSchema)
return;
q = createPQExpBuffer();
@@ -13368,8 +13374,8 @@ dumpOpclass(Archive *fout, const OpclassInfo *opcinfo)
bool needComma;
int i;
- /* Do nothing in data-only dump */
- if (dopt->dataOnly)
+ /* Do nothing if not dumping schema */
+ if (!dopt->dumpSchema)
return;
query = createPQExpBuffer();
@@ -13639,8 +13645,8 @@ dumpOpfamily(Archive *fout, const OpfamilyInfo *opfinfo)
bool needComma;
int i;
- /* Do nothing in data-only dump */
- if (dopt->dataOnly)
+ /* Do nothing if not dumping schema */
+ if (!dopt->dumpSchema)
return;
query = createPQExpBuffer();
@@ -13846,8 +13852,8 @@ dumpCollation(Archive *fout, const CollInfo *collinfo)
const char *colllocale;
const char *collicurules;
- /* Do nothing in data-only dump */
- if (dopt->dataOnly)
+ /* Do nothing if not dumping schema */
+ if (!dopt->dumpSchema)
return;
query = createPQExpBuffer();
@@ -14100,8 +14106,8 @@ dumpConversion(Archive *fout, const ConvInfo *convinfo)
const char *conproc;
bool condefault;
- /* Do nothing in data-only dump */
- if (dopt->dataOnly)
+ /* Do nothing if not dumping schema */
+ if (!dopt->dumpSchema)
return;
query = createPQExpBuffer();
@@ -14248,8 +14254,8 @@ dumpAgg(Archive *fout, const AggInfo *agginfo)
const char *proparallel;
char defaultfinalmodify;
- /* Do nothing in data-only dump */
- if (dopt->dataOnly)
+ /* Do nothing if not dumping schema */
+ if (!dopt->dumpSchema)
return;
query = createPQExpBuffer();
@@ -14578,8 +14584,8 @@ dumpTSParser(Archive *fout, const TSParserInfo *prsinfo)
PQExpBuffer delq;
char *qprsname;
- /* Do nothing in data-only dump */
- if (dopt->dataOnly)
+ /* Do nothing if not dumping schema */
+ if (!dopt->dumpSchema)
return;
q = createPQExpBuffer();
@@ -14646,8 +14652,8 @@ dumpTSDictionary(Archive *fout, const TSDictInfo *dictinfo)
char *nspname;
char *tmplname;
- /* Do nothing in data-only dump */
- if (dopt->dataOnly)
+ /* Do nothing if not dumping schema */
+ if (!dopt->dumpSchema)
return;
q = createPQExpBuffer();
@@ -14722,8 +14728,8 @@ dumpTSTemplate(Archive *fout, const TSTemplateInfo *tmplinfo)
PQExpBuffer delq;
char *qtmplname;
- /* Do nothing in data-only dump */
- if (dopt->dataOnly)
+ /* Do nothing if not dumping schema */
+ if (!dopt->dumpSchema)
return;
q = createPQExpBuffer();
@@ -14788,8 +14794,8 @@ dumpTSConfig(Archive *fout, const TSConfigInfo *cfginfo)
int i_tokenname;
int i_dictname;
- /* Do nothing in data-only dump */
- if (dopt->dataOnly)
+ /* Do nothing if not dumping schema */
+ if (!dopt->dumpSchema)
return;
q = createPQExpBuffer();
@@ -14900,8 +14906,8 @@ dumpForeignDataWrapper(Archive *fout, const FdwInfo *fdwinfo)
PQExpBuffer delq;
char *qfdwname;
- /* Do nothing in data-only dump */
- if (dopt->dataOnly)
+ /* Do nothing if not dumping schema */
+ if (!dopt->dumpSchema)
return;
q = createPQExpBuffer();
@@ -14973,8 +14979,8 @@ dumpForeignServer(Archive *fout, const ForeignServerInfo *srvinfo)
char *qsrvname;
char *fdwname;
- /* Do nothing in data-only dump */
- if (dopt->dataOnly)
+ /* Do nothing if not dumping schema */
+ if (!dopt->dumpSchema)
return;
q = createPQExpBuffer();
@@ -15164,8 +15170,8 @@ dumpDefaultACL(Archive *fout, const DefaultACLInfo *daclinfo)
PQExpBuffer tag;
const char *type;
- /* Do nothing in data-only dump, or if we're skipping ACLs */
- if (dopt->dataOnly || dopt->aclsSkip)
+ /* Do nothing if not dumping schema, or if we're skipping ACLs */
+ if (!dopt->dumpSchema || dopt->aclsSkip)
return;
q = createPQExpBuffer();
@@ -15265,7 +15271,7 @@ dumpACL(Archive *fout, DumpId objDumpId, DumpId altDumpId,
return InvalidDumpId;
/* --data-only skips ACLs *except* large object ACLs */
- if (dopt->dataOnly && strcmp(type, "LARGE OBJECT") != 0)
+ if (!dopt->dumpSchema && strcmp(type, "LARGE OBJECT") != 0)
return InvalidDumpId;
sql = createPQExpBuffer();
@@ -15394,13 +15400,13 @@ dumpSecLabel(Archive *fout, const char *type, const char *name,
*/
if (strcmp(type, "LARGE OBJECT") != 0)
{
- if (dopt->dataOnly)
+ if (!dopt->dumpSchema)
return;
}
else
{
/* We do dump large object security labels in binary-upgrade mode */
- if (dopt->schemaOnly && !dopt->binary_upgrade)
+ if (!dopt->dumpData && !dopt->binary_upgrade)
return;
}
@@ -15468,7 +15474,7 @@ dumpTableSecLabel(Archive *fout, const TableInfo *tbinfo, const char *reltypenam
return;
/* SecLabel are SCHEMA not data */
- if (dopt->dataOnly)
+ if (!dopt->dumpSchema)
return;
/* Search for comments associated with relation, using table */
@@ -15707,8 +15713,8 @@ dumpTable(Archive *fout, const TableInfo *tbinfo)
DumpId tableAclDumpId = InvalidDumpId;
char *namecopy;
- /* Do nothing in data-only dump */
- if (dopt->dataOnly)
+ /* Do nothing if not dumping schema */
+ if (!dopt->dumpSchema)
return;
if (tbinfo->dobj.dump & DUMP_COMPONENT_DEFINITION)
@@ -16895,8 +16901,8 @@ dumpTableAttach(Archive *fout, const TableAttachInfo *attachinfo)
PGresult *res;
char *partbound;
- /* Do nothing in data-only dump */
- if (dopt->dataOnly)
+ /* Do nothing if not dumping schema */
+ if (!dopt->dumpSchema)
return;
q = createPQExpBuffer();
@@ -16967,8 +16973,8 @@ dumpAttrDef(Archive *fout, const AttrDefInfo *adinfo)
char *tag;
char *foreign;
- /* Do nothing in data-only dump */
- if (dopt->dataOnly)
+ /* Do nothing if not dumping schema */
+ if (!dopt->dumpSchema)
return;
/* Skip if not "separate"; it was dumped in the table's definition */
@@ -17056,8 +17062,8 @@ dumpIndex(Archive *fout, const IndxInfo *indxinfo)
char *qindxname;
char *qqindxname;
- /* Do nothing in data-only dump */
- if (dopt->dataOnly)
+ /* Do nothing if not dumping schema */
+ if (!dopt->dumpSchema)
return;
q = createPQExpBuffer();
@@ -17189,8 +17195,8 @@ dumpIndex(Archive *fout, const IndxInfo *indxinfo)
static void
dumpIndexAttach(Archive *fout, const IndexAttachInfo *attachinfo)
{
- /* Do nothing in data-only dump */
- if (fout->dopt->dataOnly)
+ /* Do nothing if not dumping schema */
+ if (!fout->dopt->dumpSchema)
return;
if (attachinfo->partitionIdx->dobj.dump & DUMP_COMPONENT_DEFINITION)
@@ -17236,8 +17242,8 @@ dumpStatisticsExt(Archive *fout, const StatsExtInfo *statsextinfo)
PGresult *res;
char *stxdef;
- /* Do nothing in data-only dump */
- if (dopt->dataOnly)
+ /* Do nothing if not dumping schema */
+ if (!dopt->dumpSchema)
return;
q = createPQExpBuffer();
@@ -17312,8 +17318,8 @@ dumpConstraint(Archive *fout, const ConstraintInfo *coninfo)
char *tag = NULL;
char *foreign;
- /* Do nothing in data-only dump */
- if (dopt->dataOnly)
+ /* Do nothing if not dumping schema */
+ if (!dopt->dumpSchema)
return;
q = createPQExpBuffer();
@@ -17662,7 +17668,7 @@ collectSequences(Archive *fout)
if (fout->remoteVersion < 100000)
return;
else if (fout->remoteVersion < 180000 ||
- (fout->dopt->schemaOnly && !fout->dopt->sequence_data))
+ (!fout->dopt->dumpData && !fout->dopt->sequence_data))
query = "SELECT seqrelid, format_type(seqtypid, NULL), "
"seqstart, seqincrement, "
"seqmax, seqmin, "
@@ -18049,8 +18055,8 @@ dumpTrigger(Archive *fout, const TriggerInfo *tginfo)
char *qtabname;
char *tag;
- /* Do nothing in data-only dump */
- if (dopt->dataOnly)
+ /* Do nothing if not dumping schema */
+ if (!dopt->dumpSchema)
return;
query = createPQExpBuffer();
@@ -18171,8 +18177,8 @@ dumpEventTrigger(Archive *fout, const EventTriggerInfo *evtinfo)
PQExpBuffer delqry;
char *qevtname;
- /* Do nothing in data-only dump */
- if (dopt->dataOnly)
+ /* Do nothing if not dumping schema */
+ if (!dopt->dumpSchema)
return;
query = createPQExpBuffer();
@@ -18262,8 +18268,8 @@ dumpRule(Archive *fout, const RuleInfo *rinfo)
PGresult *res;
char *tag;
- /* Do nothing in data-only dump */
- if (dopt->dataOnly)
+ /* Do nothing if not dumping schema */
+ if (!dopt->dumpSchema)
return;
/*
@@ -18529,7 +18535,7 @@ processExtensionTables(Archive *fout, ExtensionInfo extinfo[],
* objects for them, ensuring their data will be dumped even though the
* tables themselves won't be.
*
- * Note that we create TableDataInfo objects even in schemaOnly mode, ie,
+ * Note that we create TableDataInfo objects even in schema-only mode, ie,
* user data in a configuration table is treated like schema data. This
* seems appropriate since system data in a config table would get
* reloaded by CREATE EXTENSION. If the extension is not listed in the
diff --git a/src/bin/pg_dump/pg_restore.c b/src/bin/pg_dump/pg_restore.c
index 10da7d27da8..88ae39d938a 100644
--- a/src/bin/pg_dump/pg_restore.c
+++ b/src/bin/pg_dump/pg_restore.c
@@ -75,6 +75,8 @@ main(int argc, char **argv)
static int no_security_labels = 0;
static int no_subscriptions = 0;
static int strict_names = 0;
+ bool data_only = false;
+ bool schema_only = false;
struct option cmdopts[] = {
{"clean", 0, NULL, 'c'},
@@ -160,7 +162,7 @@ main(int argc, char **argv)
switch (c)
{
case 'a': /* Dump data only */
- opts->dataOnly = 1;
+ data_only = true;
break;
case 'c': /* clean (i.e., drop) schema prior to create */
opts->dropSchema = 1;
@@ -236,7 +238,7 @@ main(int argc, char **argv)
simple_string_list_append(&opts->triggerNames, optarg);
break;
case 's': /* dump schema only */
- opts->schemaOnly = 1;
+ schema_only = true;
break;
case 'S': /* Superuser username */
if (strlen(optarg) != 0)
@@ -339,10 +341,10 @@ main(int argc, char **argv)
opts->useDB = 1;
}
- if (opts->dataOnly && opts->schemaOnly)
+ if (data_only && schema_only)
pg_fatal("options -s/--schema-only and -a/--data-only cannot be used together");
- if (opts->dataOnly && opts->dropSchema)
+ if (data_only && opts->dropSchema)
pg_fatal("options -c/--clean and -a/--data-only cannot be used together");
if (opts->single_txn && opts->txn_size > 0)
@@ -359,6 +361,10 @@ main(int argc, char **argv)
if (opts->single_txn && numWorkers > 1)
pg_fatal("cannot specify both --single-transaction and multiple jobs");
+ /* set derivative flags */
+ opts->dumpSchema = (!data_only);
+ opts->dumpData = (!schema_only);
+
opts->disable_triggers = disable_triggers;
opts->enable_row_security = enable_row_security;
opts->noDataForFailedTables = no_data_for_failed_tables;