v30-0002-Remove-schemaOnly-dataOnly-from-dump-restore-opt.patch
application/x-patch
Filename: v30-0002-Remove-schemaOnly-dataOnly-from-dump-restore-opt.patch
Type: application/x-patch
Part: 2
Message:
Re: Statistics Import and Export
Patch
Same data as JSON:
GET /api/v1/attachments/:id/patch
the parsed metadata as JSON — format, series position, per-file stats; never the diff bytes.
API reference →
Format: format-patch
Series: patch v30-0002
Subject: Remove schemaOnly, dataOnly from dump/restore options structures.
| File | + | − |
|---|---|---|
| src/bin/pg_dump/pg_backup_archiver.c | 13 | 13 |
| src/bin/pg_dump/pg_backup.h | 0 | 4 |
| src/bin/pg_dump/pg_dump.c | 14 | 12 |
| src/bin/pg_dump/pg_restore.c | 9 | 6 |
From beca392b00f53b33438f0d019286239e45631cea Mon Sep 17 00:00:00 2001
From: Corey Huinker <corey.huinker@gmail.com>
Date: Fri, 1 Nov 2024 11:56:34 -0400
Subject: [PATCH v30 2/4] Remove schemaOnly, dataOnly from dump/restore options
structures.
The user-facing flags still exist, but the results of those flags are
already resolved into dumpSchema and dumpData.
All logic about which objects to dump which previously used schemaOnly
and dataOnly in the negative (ex. we should dump large objects because
schemaOnly is NOT set), which would have gotten unweildly when a third
option (statisticsOnly) was added.
---
src/bin/pg_dump/pg_backup.h | 4 ----
src/bin/pg_dump/pg_backup_archiver.c | 26 +++++++++++++-------------
src/bin/pg_dump/pg_dump.c | 26 ++++++++++++++------------
src/bin/pg_dump/pg_restore.c | 15 +++++++++------
4 files changed, 36 insertions(+), 35 deletions(-)
diff --git a/src/bin/pg_dump/pg_backup.h b/src/bin/pg_dump/pg_backup.h
index 9bd3266a63..f74e848714 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;
@@ -171,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;
diff --git a/src/bin/pg_dump/pg_backup_archiver.c b/src/bin/pg_dump/pg_backup_archiver.c
index 8c20c263c4..32c8e588f5 100644
--- a/src/bin/pg_dump/pg_backup_archiver.c
+++ b/src/bin/pg_dump/pg_backup_archiver.c
@@ -165,8 +165,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 +419,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 set the data-only 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 +438,7 @@ RestoreArchive(Archive *AHX)
}
if (impliedDataOnly)
{
- ropt->dataOnly = impliedDataOnly;
+ ropt->dumpSchema = false;
pg_log_info("implied data-only restore");
}
}
@@ -824,7 +824,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);
@@ -1090,7 +1090,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 +1116,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);
@@ -3148,12 +3148,12 @@ _tocEntryRequired(TocEntry *te, teSection curSection, ArchiveHandle *AH)
return 0;
/* Mask it if we only want schema */
- if (ropt->schemaOnly)
+ if (!ropt->dumpData)
{
/*
- * The sequence_data option overrides schemaOnly for SEQUENCE SET.
+ * The sequence_data option overrides schema-only for SEQUENCE SET.
*
- * In binary-upgrade mode, even with schemaOnly set, we do not mask
+ * In binary-upgrade mode, even with schema-only set, 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.)
@@ -3172,7 +3172,7 @@ _tocEntryRequired(TocEntry *te, teSection curSection, ArchiveHandle *AH)
}
/* Mask it if we only want data */
- if (ropt->dataOnly)
+ 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 3eb8523fd7..d5d2e51be2 100644
--- a/src/bin/pg_dump/pg_dump.c
+++ b/src/bin/pg_dump/pg_dump.c
@@ -425,6 +425,8 @@ main(int argc, char **argv)
char *compression_algorithm_str = "none";
char *error_detail = NULL;
bool user_compression_defined = false;
+ bool data_only = false;
+ bool schema_only = false;
DataDirSyncMethod sync_method = DATA_DIR_SYNC_METHOD_FSYNC;
static DumpOptions dopt;
@@ -541,7 +543,7 @@ main(int argc, char **argv)
switch (c)
{
case 'a': /* Dump data only */
- dopt.dataOnly = true;
+ data_only = true;
break;
case 'b': /* Dump LOs */
@@ -614,7 +616,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 */
@@ -778,24 +780,24 @@ 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 = (!dopt.dataOnly);
- dopt.dumpData = (!dopt.schemaOnly);
+ dopt.dumpSchema = (!data_only);
+ dopt.dumpData = (!schema_only);
/*
* --inserts are already implied above if --column-inserts or
@@ -1093,8 +1095,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;
@@ -1989,7 +1991,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 data-only
* and aclsSkip are checked separately.
*/
static void
@@ -17414,7 +17416,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, "
@@ -18281,7 +18283,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 3475168a64..f6e04e3a3b 100644
--- a/src/bin/pg_dump/pg_restore.c
+++ b/src/bin/pg_dump/pg_restore.c
@@ -77,6 +77,9 @@ main(int argc, char **argv)
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'},
{"create", 0, NULL, 'C'},
@@ -161,7 +164,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;
@@ -237,7 +240,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)
@@ -340,10 +343,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)
@@ -361,8 +364,8 @@ main(int argc, char **argv)
pg_fatal("cannot specify both --single-transaction and multiple jobs");
/* set derivative flags */
- opts->dumpSchema = (opts->dataOnly != 1);
- opts->dumpData = (opts->schemaOnly != 1);
+ opts->dumpSchema = (!data_only);
+ opts->dumpData = (!schema_only);
opts->disable_triggers = disable_triggers;
opts->enable_row_security = enable_row_security;
--
2.47.0