Skip to content

Commit 6a46089

Browse files
committed
Simplify options in pg_dump and pg_restore.
Remove redundant options --with-data and --with-schema, and rename --with-statistics to just --statistics. Reviewed-by: Nathan Bossart <nathandbossart@gmail.com> Reviewed-by: Fujii Masao <masao.fujii@gmail.com> Discussion: https://postgr.es/m/f379d0aeefe8effe13302a436bc28f549f09e924.camel@j-davis.com Backpatch-through: 18
1 parent 2106fe2 commit 6a46089

File tree

8 files changed

+118
-218
lines changed

8 files changed

+118
-218
lines changed

doc/src/sgml/ref/pg_dump.sgml

Lines changed: 10 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1354,6 +1354,15 @@ PostgreSQL documentation
13541354
</listitem>
13551355
</varlistentry>
13561356

1357+
<varlistentry>
1358+
<term><option>--statistics</option></term>
1359+
<listitem>
1360+
<para>
1361+
Dump statistics.
1362+
</para>
1363+
</listitem>
1364+
</varlistentry>
1365+
13571366
<varlistentry>
13581367
<term><option>--statistics-only</option></term>
13591368
<listitem>
@@ -1440,33 +1449,6 @@ PostgreSQL documentation
14401449
</listitem>
14411450
</varlistentry>
14421451

1443-
<varlistentry>
1444-
<term><option>--with-data</option></term>
1445-
<listitem>
1446-
<para>
1447-
Dump data. This is the default.
1448-
</para>
1449-
</listitem>
1450-
</varlistentry>
1451-
1452-
<varlistentry>
1453-
<term><option>--with-schema</option></term>
1454-
<listitem>
1455-
<para>
1456-
Dump schema (data definitions). This is the default.
1457-
</para>
1458-
</listitem>
1459-
</varlistentry>
1460-
1461-
<varlistentry>
1462-
<term><option>--with-statistics</option></term>
1463-
<listitem>
1464-
<para>
1465-
Dump statistics.
1466-
</para>
1467-
</listitem>
1468-
</varlistentry>
1469-
14701452
<varlistentry>
14711453
<term><option>-?</option></term>
14721454
<term><option>--help</option></term>
@@ -1682,7 +1664,7 @@ CREATE DATABASE foo WITH TEMPLATE template0;
16821664
</para>
16831665

16841666
<para>
1685-
If <option>--with-statistics</option> is specified,
1667+
If <option>--statistics</option> is specified,
16861668
<command>pg_dump</command> will include most optimizer statistics in the
16871669
resulting dump file. However, some statistics may not be included, such as
16881670
those created explicitly with <xref linkend="sql-createstatistics"/> or

doc/src/sgml/ref/pg_dumpall.sgml

Lines changed: 10 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -605,6 +605,15 @@ exclude database <replaceable class="parameter">PATTERN</replaceable>
605605
</listitem>
606606
</varlistentry>
607607

608+
<varlistentry>
609+
<term><option>--statistics</option></term>
610+
<listitem>
611+
<para>
612+
Dump statistics.
613+
</para>
614+
</listitem>
615+
</varlistentry>
616+
608617
<varlistentry>
609618
<term><option>--statistics-only</option></term>
610619
<listitem>
@@ -640,33 +649,6 @@ exclude database <replaceable class="parameter">PATTERN</replaceable>
640649
</listitem>
641650
</varlistentry>
642651

643-
<varlistentry>
644-
<term><option>--with-data</option></term>
645-
<listitem>
646-
<para>
647-
Dump data. This is the default.
648-
</para>
649-
</listitem>
650-
</varlistentry>
651-
652-
<varlistentry>
653-
<term><option>--with-schema</option></term>
654-
<listitem>
655-
<para>
656-
Dump schema (data definitions). This is the default.
657-
</para>
658-
</listitem>
659-
</varlistentry>
660-
661-
<varlistentry>
662-
<term><option>--with-statistics</option></term>
663-
<listitem>
664-
<para>
665-
Dump statistics.
666-
</para>
667-
</listitem>
668-
</varlistentry>
669-
670652
<varlistentry>
671653
<term><option>-?</option></term>
672654
<term><option>--help</option></term>
@@ -878,7 +860,7 @@ exclude database <replaceable class="parameter">PATTERN</replaceable>
878860
</para>
879861

880862
<para>
881-
If <option>--with-statistics</option> is specified,
863+
If <option>--statistics</option> is specified,
882864
<command>pg_dumpall</command> will include most optimizer statistics in the
883865
resulting dump file. However, some statistics may not be included, such as
884866
those created explicitly with <xref linkend="sql-createstatistics"/> or

doc/src/sgml/ref/pg_restore.sgml

Lines changed: 10 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -815,6 +815,16 @@ PostgreSQL documentation
815815
</listitem>
816816
</varlistentry>
817817

818+
<varlistentry>
819+
<term><option>--statistics</option></term>
820+
<listitem>
821+
<para>
822+
Output commands to restore statistics, if the archive contains them.
823+
This is the default.
824+
</para>
825+
</listitem>
826+
</varlistentry>
827+
818828
<varlistentry>
819829
<term><option>--statistics-only</option></term>
820830
<listitem>
@@ -873,36 +883,6 @@ PostgreSQL documentation
873883
</listitem>
874884
</varlistentry>
875885

876-
<varlistentry>
877-
<term><option>--with-data</option></term>
878-
<listitem>
879-
<para>
880-
Output commands to restore data, if the archive contains them.
881-
This is the default.
882-
</para>
883-
</listitem>
884-
</varlistentry>
885-
886-
<varlistentry>
887-
<term><option>--with-schema</option></term>
888-
<listitem>
889-
<para>
890-
Output commands to restore schema (data definitions), if the archive
891-
contains them. This is the default.
892-
</para>
893-
</listitem>
894-
</varlistentry>
895-
896-
<varlistentry>
897-
<term><option>--with-statistics</option></term>
898-
<listitem>
899-
<para>
900-
Output commands to restore statistics, if the archive contains them.
901-
This is the default.
902-
</para>
903-
</listitem>
904-
</varlistentry>
905-
906886
<varlistentry>
907887
<term><option>-?</option></term>
908888
<term><option>--help</option></term>

src/bin/pg_dump/pg_dump.c

Lines changed: 11 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -449,8 +449,6 @@ main(int argc, char **argv)
449449
bool data_only = false;
450450
bool schema_only = false;
451451
bool statistics_only = false;
452-
bool with_data = false;
453-
bool with_schema = false;
454452
bool with_statistics = false;
455453
bool no_data = false;
456454
bool no_schema = false;
@@ -514,6 +512,7 @@ main(int argc, char **argv)
514512
{"section", required_argument, NULL, 5},
515513
{"serializable-deferrable", no_argument, &dopt.serializable_deferrable, 1},
516514
{"snapshot", required_argument, NULL, 6},
515+
{"statistics", no_argument, NULL, 22},
517516
{"statistics-only", no_argument, NULL, 18},
518517
{"strict-names", no_argument, &strict_names, 1},
519518
{"use-set-session-authorization", no_argument, &dopt.use_setsessauth, 1},
@@ -528,9 +527,6 @@ main(int argc, char **argv)
528527
{"no-toast-compression", no_argument, &dopt.no_toast_compression, 1},
529528
{"no-unlogged-table-data", no_argument, &dopt.no_unlogged_table_data, 1},
530529
{"no-sync", no_argument, NULL, 7},
531-
{"with-data", no_argument, NULL, 22},
532-
{"with-schema", no_argument, NULL, 23},
533-
{"with-statistics", no_argument, NULL, 24},
534530
{"on-conflict-do-nothing", no_argument, &dopt.do_nothing, 1},
535531
{"rows-per-insert", required_argument, NULL, 10},
536532
{"include-foreign-data", required_argument, NULL, 11},
@@ -798,14 +794,6 @@ main(int argc, char **argv)
798794
break;
799795

800796
case 22:
801-
with_data = true;
802-
break;
803-
804-
case 23:
805-
with_schema = true;
806-
break;
807-
808-
case 24:
809797
with_statistics = true;
810798
break;
811799

@@ -852,24 +840,17 @@ main(int argc, char **argv)
852840
if (statistics_only && no_statistics)
853841
pg_fatal("options --statistics-only and --no-statistics cannot be used together");
854842

855-
/* reject conflicting "with-" and "no-" options */
856-
if (with_data && no_data)
857-
pg_fatal("options --with-data and --no-data cannot be used together");
858-
if (with_schema && no_schema)
859-
pg_fatal("options --with-schema and --no-schema cannot be used together");
843+
/* reject conflicting "no-" options */
860844
if (with_statistics && no_statistics)
861-
pg_fatal("options --with-statistics and --no-statistics cannot be used together");
845+
pg_fatal("options --statistics and --no-statistics cannot be used together");
862846

863-
/* reject conflicting "-only" and "with-" options */
864-
if (data_only && (with_schema || with_statistics))
865-
pg_fatal("options %s and %s cannot be used together",
866-
"-a/--data-only", with_schema ? "--with-schema" : "--with-statistics");
867-
if (schema_only && (with_data || with_statistics))
847+
/* reject conflicting "-only" options */
848+
if (data_only && with_statistics)
868849
pg_fatal("options %s and %s cannot be used together",
869-
"-s/--schema-only", with_data ? "--with-data" : "--with-statistics");
870-
if (statistics_only && (with_data || with_schema))
850+
"-a/--data-only", "--statistics");
851+
if (schema_only && with_statistics)
871852
pg_fatal("options %s and %s cannot be used together",
872-
"--statistics-only", with_data ? "--with-data" : "--with-schema");
853+
"-s/--schema-only", "--statistics");
873854

874855
if (schema_only && foreign_servers_include_patterns.head != NULL)
875856
pg_fatal("options -s/--schema-only and --include-foreign-data cannot be used together");
@@ -889,9 +870,9 @@ main(int argc, char **argv)
889870
* of the checks above.
890871
*/
891872
dopt.dumpData = ((dopt.dumpData && !schema_only && !statistics_only) ||
892-
(data_only || with_data)) && !no_data;
873+
data_only) && !no_data;
893874
dopt.dumpSchema = ((dopt.dumpSchema && !data_only && !statistics_only) ||
894-
(schema_only || with_schema)) && !no_schema;
875+
schema_only) && !no_schema;
895876
dopt.dumpStatistics = ((dopt.dumpStatistics && !schema_only && !data_only) ||
896877
(statistics_only || with_statistics)) && !no_statistics;
897878

@@ -1364,6 +1345,7 @@ help(const char *progname)
13641345
printf(_(" --sequence-data include sequence data in dump\n"));
13651346
printf(_(" --serializable-deferrable wait until the dump can run without anomalies\n"));
13661347
printf(_(" --snapshot=SNAPSHOT use given snapshot for the dump\n"));
1348+
printf(_(" --statistics dump the statistics\n"));
13671349
printf(_(" --statistics-only dump only the statistics, not schema or data\n"));
13681350
printf(_(" --strict-names require table and/or schema include patterns to\n"
13691351
" match at least one entity each\n"));
@@ -1372,9 +1354,6 @@ help(const char *progname)
13721354
printf(_(" --use-set-session-authorization\n"
13731355
" use SET SESSION AUTHORIZATION commands instead of\n"
13741356
" ALTER OWNER commands to set ownership\n"));
1375-
printf(_(" --with-data dump the data\n"));
1376-
printf(_(" --with-schema dump the schema\n"));
1377-
printf(_(" --with-statistics dump the statistics\n"));
13781357

13791358
printf(_("\nConnection options:\n"));
13801359
printf(_(" -d, --dbname=DBNAME database to dump\n"));

src/bin/pg_dump/pg_dumpall.c

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,6 @@ static int no_subscriptions = 0;
105105
static int no_toast_compression = 0;
106106
static int no_unlogged_table_data = 0;
107107
static int no_role_passwords = 0;
108-
static int with_data = 0;
109-
static int with_schema = 0;
110108
static int with_statistics = 0;
111109
static int server_version;
112110
static int load_via_partition_root = 0;
@@ -180,11 +178,9 @@ main(int argc, char *argv[])
180178
{"no-sync", no_argument, NULL, 4},
181179
{"no-toast-compression", no_argument, &no_toast_compression, 1},
182180
{"no-unlogged-table-data", no_argument, &no_unlogged_table_data, 1},
183-
{"with-data", no_argument, &with_data, 1},
184-
{"with-schema", no_argument, &with_schema, 1},
185-
{"with-statistics", no_argument, &with_statistics, 1},
186181
{"on-conflict-do-nothing", no_argument, &on_conflict_do_nothing, 1},
187182
{"rows-per-insert", required_argument, NULL, 7},
183+
{"statistics", no_argument, &with_statistics, 1},
188184
{"statistics-only", no_argument, &statistics_only, 1},
189185
{"filter", required_argument, NULL, 8},
190186
{"sequence-data", no_argument, &sequence_data, 1},
@@ -475,12 +471,8 @@ main(int argc, char *argv[])
475471
appendPQExpBufferStr(pgdumpopts, " --no-toast-compression");
476472
if (no_unlogged_table_data)
477473
appendPQExpBufferStr(pgdumpopts, " --no-unlogged-table-data");
478-
if (with_data)
479-
appendPQExpBufferStr(pgdumpopts, " --with-data");
480-
if (with_schema)
481-
appendPQExpBufferStr(pgdumpopts, " --with-schema");
482474
if (with_statistics)
483-
appendPQExpBufferStr(pgdumpopts, " --with-statistics");
475+
appendPQExpBufferStr(pgdumpopts, " --statistics");
484476
if (on_conflict_do_nothing)
485477
appendPQExpBufferStr(pgdumpopts, " --on-conflict-do-nothing");
486478
if (statistics_only)
@@ -712,13 +704,11 @@ help(void)
712704
printf(_(" --quote-all-identifiers quote all identifiers, even if not key words\n"));
713705
printf(_(" --rows-per-insert=NROWS number of rows per INSERT; implies --inserts\n"));
714706
printf(_(" --sequence-data include sequence data in dump\n"));
707+
printf(_(" --statistics dump the statistics\n"));
715708
printf(_(" --statistics-only dump only the statistics, not schema or data\n"));
716709
printf(_(" --use-set-session-authorization\n"
717710
" use SET SESSION AUTHORIZATION commands instead of\n"
718711
" ALTER OWNER commands to set ownership\n"));
719-
printf(_(" --with-data dump the data\n"));
720-
printf(_(" --with-schema dump the schema\n"));
721-
printf(_(" --with-statistics dump the statistics\n"));
722712

723713
printf(_("\nConnection options:\n"));
724714
printf(_(" -d, --dbname=CONNSTR connect using connection string\n"));

0 commit comments

Comments
 (0)