v35-0004-Add-no-schema-option-to-pg_dump-etc.patch
text/x-patch
Filename: v35-0004-Add-no-schema-option-to-pg_dump-etc.patch
Type: text/x-patch
Part: 0
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 v35-0004
Subject: Add --no-schema option to pg_dump, etc.
| File | + | − |
|---|---|---|
| doc/src/sgml/ref/pg_dump.sgml | 9 | 0 |
| doc/src/sgml/ref/pg_restore.sgml | 10 | 0 |
| src/bin/pg_dump/pg_backup_archiver.c | 1 | 0 |
| src/bin/pg_dump/pg_backup.h | 2 | 0 |
| src/bin/pg_dump/pg_dump.c | 4 | 2 |
| src/bin/pg_dump/pg_restore.c | 5 | 1 |
From 27674ebea83387e0d714239effac486a30d8d70d Mon Sep 17 00:00:00 2001
From: Corey Huinker <corey.huinker@gmail.com>
Date: Thu, 12 Dec 2024 16:58:21 -0500
Subject: [PATCH v35 04/12] Add --no-schema option to pg_dump, etc.
Previously, users could use --data-only when they wanted to suppress
schema from a dump. However, that no longer makes sense now that the
data/schema binary has become the data/schema/statistics trinary.
---
src/bin/pg_dump/pg_backup.h | 2 ++
src/bin/pg_dump/pg_backup_archiver.c | 1 +
src/bin/pg_dump/pg_dump.c | 6 ++++--
src/bin/pg_dump/pg_restore.c | 6 +++++-
doc/src/sgml/ref/pg_dump.sgml | 9 +++++++++
doc/src/sgml/ref/pg_restore.sgml | 10 ++++++++++
6 files changed, 31 insertions(+), 3 deletions(-)
diff --git a/src/bin/pg_dump/pg_backup.h b/src/bin/pg_dump/pg_backup.h
index 241855d017..24295110cf 100644
--- a/src/bin/pg_dump/pg_backup.h
+++ b/src/bin/pg_dump/pg_backup.h
@@ -112,6 +112,7 @@ typedef struct _restoreOptions
int no_comments; /* Skip comments */
int no_data; /* Skip data */
int no_publications; /* Skip publication entries */
+ int no_schema; /* Skip schema generation */
int no_security_labels; /* Skip security label entries */
int no_subscriptions; /* Skip subscription entries */
int no_statistics; /* Skip statistics import */
@@ -187,6 +188,7 @@ typedef struct _dumpOptions
int no_subscriptions;
int no_statistics;
int no_data;
+ int no_schema;
int no_toast_compression;
int no_unlogged_table_data;
int serializable_deferrable;
diff --git a/src/bin/pg_dump/pg_backup_archiver.c b/src/bin/pg_dump/pg_backup_archiver.c
index 41001e64ac..d62f419560 100644
--- a/src/bin/pg_dump/pg_backup_archiver.c
+++ b/src/bin/pg_dump/pg_backup_archiver.c
@@ -187,6 +187,7 @@ dumpOptionsFromRestoreOptions(RestoreOptions *ropt)
dopt->no_security_labels = ropt->no_security_labels;
dopt->no_subscriptions = ropt->no_subscriptions;
dopt->no_data = ropt->no_data;
+ dopt->no_schema = ropt->no_schema;
dopt->no_statistics = ropt->no_statistics;
dopt->lockWaitTimeout = ropt->lockWaitTimeout;
dopt->include_everything = ropt->include_everything;
diff --git a/src/bin/pg_dump/pg_dump.c b/src/bin/pg_dump/pg_dump.c
index e626243f3a..61f90d7f78 100644
--- a/src/bin/pg_dump/pg_dump.c
+++ b/src/bin/pg_dump/pg_dump.c
@@ -497,6 +497,7 @@ main(int argc, char **argv)
{"no-data", no_argument, &dopt.no_data, 1},
{"no-publications", no_argument, &dopt.no_publications, 1},
{"no-security-labels", no_argument, &dopt.no_security_labels, 1},
+ {"no-schema", no_argument, &dopt.no_schema, 1},
{"no-statistics", no_argument, &dopt.no_statistics, 1},
{"no-subscriptions", no_argument, &dopt.no_subscriptions, 1},
{"no-toast-compression", no_argument, &dopt.no_toast_compression, 1},
@@ -799,7 +800,8 @@ main(int argc, char **argv)
if (data_only && dopt.no_data)
pg_fatal("options -a/--data-only and --no-data cannot be used together");
-
+ if (schema_only && dopt.no_schema)
+ pg_fatal("options -s/--schema-only and --no-schema cannot be used together");
if (statistics_only && dopt.no_statistics)
pg_fatal("options -X/--statistics-only and --no-statistics cannot be used together");
@@ -817,7 +819,7 @@ main(int argc, char **argv)
/* set derivative flags */
dopt.dumpData = data_only || (!schema_only && !statistics_only && !dopt.no_data);
- dopt.dumpSchema = schema_only || (!data_only && !statistics_only);
+ dopt.dumpSchema = schema_only || (!data_only && !statistics_only && !dopt.no_schema);
dopt.dumpStatistics = statistics_only || (!data_only && !schema_only && !dopt.no_statistics);
/*
diff --git a/src/bin/pg_dump/pg_restore.c b/src/bin/pg_dump/pg_restore.c
index 31c3cd32de..90db03f0d4 100644
--- a/src/bin/pg_dump/pg_restore.c
+++ b/src/bin/pg_dump/pg_restore.c
@@ -72,6 +72,7 @@ main(int argc, char **argv)
static int outputNoTablespaces = 0;
static int use_setsessauth = 0;
static int no_data = 0;
+ static int no_schema = 0;
static int no_comments = 0;
static int no_publications = 0;
static int no_security_labels = 0;
@@ -134,6 +135,7 @@ main(int argc, char **argv)
{"filter", required_argument, NULL, 4},
{"no-statistics", no_argument, &no_statistics, 1},
{"no-data", no_argument, &no_data, 1},
+ {"no-schema", no_argument, &no_schema, 1},
{NULL, 0, NULL, 0}
};
@@ -376,7 +378,7 @@ main(int argc, char **argv)
pg_fatal("cannot specify both --single-transaction and multiple jobs");
/* set derivative flags */
- opts->dumpSchema = (!data_only && !statistics_only);
+ opts->dumpSchema = (!no_schema && !data_only && !statistics_only);
opts->dumpData = (!no_data && !schema_only && !statistics_only);
opts->dumpStatistics = (!no_statistics && !data_only && !schema_only);
@@ -511,7 +513,9 @@ usage(const char *progname)
printf(_(" --no-data-for-failed-tables do not restore data of tables that could not be\n"
" created\n"));
printf(_(" --no-publications do not restore publications\n"));
+ printf(_(" --no-schema do not restore schema\n"));
printf(_(" --no-security-labels do not restore security labels\n"));
+ printf(_(" --no-statistics do not restore statistics\n"));
printf(_(" --no-subscriptions do not restore subscriptions\n"));
printf(_(" --no-table-access-method do not restore table access methods\n"));
printf(_(" --no-tablespaces do not restore tablespace assignments\n"));
diff --git a/doc/src/sgml/ref/pg_dump.sgml b/doc/src/sgml/ref/pg_dump.sgml
index aa4785c612..889b8d4e18 100644
--- a/doc/src/sgml/ref/pg_dump.sgml
+++ b/doc/src/sgml/ref/pg_dump.sgml
@@ -1113,6 +1113,15 @@ PostgreSQL documentation
</listitem>
</varlistentry>
+ <varlistentry>
+ <term><option>--no-schema</option></term>
+ <listitem>
+ <para>
+ Do not dump schema.
+ </para>
+ </listitem>
+ </varlistentry>
+
<varlistentry>
<term><option>--no-statistics</option></term>
<listitem>
diff --git a/doc/src/sgml/ref/pg_restore.sgml b/doc/src/sgml/ref/pg_restore.sgml
index ff1441a243..cc9dbb4808 100644
--- a/doc/src/sgml/ref/pg_restore.sgml
+++ b/doc/src/sgml/ref/pg_restore.sgml
@@ -738,6 +738,16 @@ PostgreSQL documentation
</listitem>
</varlistentry>
+ <varlistentry>
+ <term><option>--no-schema</option></term>
+ <listitem>
+ <para>
+ Do not output commands to restore schema, even if the archive
+ contains them.
+ </para>
+ </listitem>
+ </varlistentry>
+
<varlistentry>
<term><option>--no-statistics</option></term>
<listitem>
--
2.47.1