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

Commit5698f6b

Browse files
committed
Remove the -d and -D options of pg_dump and pg_dumpall. The functionality
is still available, but you must now write the long equivalent --insertsor --column-inserts. This change is made to eliminate confusion with theuse of -d to specify a database name in most other Postgres client programs.Original patch by Greg Mullane, modified per subsequent discussion.
1 parent0fd85d7 commit5698f6b

File tree

4 files changed

+124
-127
lines changed

4 files changed

+124
-127
lines changed

‎doc/src/sgml/ref/pg_dump.sgml

Lines changed: 55 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<!--
2-
$PostgreSQL: pgsql/doc/src/sgml/ref/pg_dump.sgml,v 1.112 2009/03/04 11:57:00 petere Exp $
2+
$PostgreSQL: pgsql/doc/src/sgml/ref/pg_dump.sgml,v 1.113 2009/03/22 16:44:26 tgl Exp $
33
PostgreSQL documentation
44
-->
55

@@ -175,46 +175,6 @@ PostgreSQL documentation
175175
</listitem>
176176
</varlistentry>
177177

178-
<varlistentry>
179-
<term><option>-d</option></term>
180-
<term><option>--inserts</option></term>
181-
<listitem>
182-
<para>
183-
Dump data as <command>INSERT</command> commands (rather
184-
than <command>COPY</command>). This will make restoration very slow;
185-
it is mainly useful for making dumps that can be loaded into
186-
non-<productname>PostgreSQL</productname> databases.
187-
Also, since this option generates a separate command for each row,
188-
an error in reloading a row causes only that row to be lost rather
189-
than the entire table contents.
190-
Note that
191-
the restore might fail altogether if you have rearranged column order.
192-
The <option>-D</option> option is safe against column order changes,
193-
though even slower.
194-
</para>
195-
</listitem>
196-
</varlistentry>
197-
198-
<varlistentry>
199-
<term><option>-D</option></term>
200-
<term><option>--column-inserts</option></term>
201-
<term><option>--attribute-inserts</option></term>
202-
<listitem>
203-
<para>
204-
Dump data as <command>INSERT</command> commands with explicit
205-
column names (<literal>INSERT INTO
206-
<replaceable>table</replaceable>
207-
(<replaceable>column</replaceable>, ...) VALUES
208-
...</literal>). This will make restoration very slow; it is mainly
209-
useful for making dumps that can be loaded into
210-
non-<productname>PostgreSQL</productname> databases.
211-
Also, since this option generates a separate command for each row,
212-
an error in reloading a row causes only that row to be lost rather
213-
than the entire table contents.
214-
</para>
215-
</listitem>
216-
</varlistentry>
217-
218178
<varlistentry>
219179
<term><option>-E <replaceable class="parameter">encoding</replaceable></option></term>
220180
<term><option>--encoding=<replaceable class="parameter">encoding</replaceable></option></term>
@@ -562,6 +522,44 @@ PostgreSQL documentation
562522
</listitem>
563523
</varlistentry>
564524

525+
<varlistentry>
526+
<term><option>--inserts</option></term>
527+
<listitem>
528+
<para>
529+
Dump data as <command>INSERT</command> commands (rather
530+
than <command>COPY</command>). This will make restoration very slow;
531+
it is mainly useful for making dumps that can be loaded into
532+
non-<productname>PostgreSQL</productname> databases.
533+
Also, since this option generates a separate command for each row,
534+
an error in reloading a row causes only that row to be lost rather
535+
than the entire table contents.
536+
Note that
537+
the restore might fail altogether if you have rearranged column order.
538+
The <option>--column-inserts</option> option is safe against column
539+
order changes, though even slower.
540+
</para>
541+
</listitem>
542+
</varlistentry>
543+
544+
<varlistentry>
545+
<term><option>--column-inserts</option></term>
546+
<term><option>--attribute-inserts</option></term>
547+
<listitem>
548+
<para>
549+
Dump data as <command>INSERT</command> commands with explicit
550+
column names (<literal>INSERT INTO
551+
<replaceable>table</replaceable>
552+
(<replaceable>column</replaceable>, ...) VALUES
553+
...</literal>). This will make restoration very slow; it is mainly
554+
useful for making dumps that can be loaded into
555+
non-<productname>PostgreSQL</productname> databases.
556+
Also, since this option generates a separate command for each row,
557+
an error in reloading a row causes only that row to be lost rather
558+
than the entire table contents.
559+
</para>
560+
</listitem>
561+
</varlistentry>
562+
565563
<varlistentry>
566564
<term><option>--disable-dollar-quoting</></term>
567565
<listitem>
@@ -814,11 +812,10 @@ CREATE DATABASE foo WITH TEMPLATE template0;
814812
</para>
815813

816814
<para>
817-
<application>pg_dump</application> has a limitation; when a
818-
data-only dump is chosen and the option <option>--disable-triggers</>
815+
When a data-only dump is chosen and the option <option>--disable-triggers</>
819816
is used, <application>pg_dump</application> emits commands
820-
to disable triggers on user tables before inserting the data
821-
and commands to re-enable them after the data has been
817+
to disable triggers on user tables before inserting the data,
818+
andthencommands to re-enable them after the data has been
822819
inserted. If the restore is stopped in the middle, the system
823820
catalogs might be left in the wrong state.
824821
</para>
@@ -846,12 +843,19 @@ CREATE DATABASE foo WITH TEMPLATE template0;
846843
<para>
847844
Because <application>pg_dump</application> is used to transfer data
848845
to newer versions of <productname>PostgreSQL</>, the output of
849-
<application>pg_dump</application> can be loaded into
850-
newer <productname>PostgreSQL</> databases. It also can read older
851-
<productname>PostgreSQL</> databases. However, it usually cannot
852-
read newer <productname>PostgreSQL</> databases or produce dump output
853-
that can be loaded into older database versions. To do this, manual
854-
editing of the dump file might be required.
846+
<application>pg_dump</application> can be expected to load into
847+
<productname>PostgreSQL</> server versions newer than
848+
<application>pg_dump</>'s version. <application>pg_dump</> can also
849+
dump from <productname>PostgreSQL</> servers older than its own version.
850+
(Currently, servers back to version 7.0 are supported.)
851+
However, <application>pg_dump</> cannot dump from
852+
<productname>PostgreSQL</> servers newer than its own major version;
853+
it will refuse to even try, rather than risk making an invalid dump.
854+
Also, it is not guaranteed that <application>pg_dump</>'s output can
855+
be loaded into a server of an older major version &mdash; not even if the
856+
dump was taken from a server of that version. Loading a dump file
857+
into an older server may require manual editing of the dump file
858+
to remove syntax not understood by the older server.
855859
</para>
856860
</refsect1>
857861

‎doc/src/sgml/ref/pg_dumpall.sgml

Lines changed: 33 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<!--
2-
$PostgreSQL: pgsql/doc/src/sgml/ref/pg_dumpall.sgml,v 1.78 2009/03/04 11:57:00 petere Exp $
2+
$PostgreSQL: pgsql/doc/src/sgml/ref/pg_dumpall.sgml,v 1.79 2009/03/22 16:44:26 tgl Exp $
33
PostgreSQL documentation
44
-->
55

@@ -98,38 +98,6 @@ PostgreSQL documentation
9898
</listitem>
9999
</varlistentry>
100100

101-
<varlistentry>
102-
<term><option>-d</option></term>
103-
<term><option>--inserts</option></term>
104-
<listitem>
105-
<para>
106-
Dump data as <command>INSERT</command> commands (rather
107-
than <command>COPY</command>). This will make restoration very slow;
108-
it is mainly useful for making dumps that can be loaded into
109-
non-<productname>PostgreSQL</productname> databases. Note that
110-
the restore might fail altogether if you have rearranged column order.
111-
The <option>-D</option> option is safer, though even slower.
112-
</para>
113-
</listitem>
114-
</varlistentry>
115-
116-
<varlistentry>
117-
<term><option>-D</option></term>
118-
<term><option>--column-inserts</option></term>
119-
<term><option>--attribute-inserts</option></term>
120-
<listitem>
121-
<para>
122-
Dump data as <command>INSERT</command> commands with explicit
123-
column names (<literal>INSERT INTO
124-
<replaceable>table</replaceable>
125-
(<replaceable>column</replaceable>, ...) VALUES
126-
...</literal>). This will make restoration very slow; it is mainly
127-
useful for making dumps that can be loaded into
128-
non-<productname>PostgreSQL</productname> databases.
129-
</para>
130-
</listitem>
131-
</varlistentry>
132-
133101
<varlistentry>
134102
<term><option>-f <replaceable class="parameter">filename</replaceable></option></term>
135103
<term><option>--file=<replaceable class="parameter">filename</replaceable></option></term>
@@ -302,6 +270,37 @@ PostgreSQL documentation
302270
</listitem>
303271
</varlistentry>
304272

273+
<varlistentry>
274+
<term><option>--inserts</option></term>
275+
<listitem>
276+
<para>
277+
Dump data as <command>INSERT</command> commands (rather
278+
than <command>COPY</command>). This will make restoration very slow;
279+
it is mainly useful for making dumps that can be loaded into
280+
non-<productname>PostgreSQL</productname> databases. Note that
281+
the restore might fail altogether if you have rearranged column order.
282+
The <option>--column-inserts</option> option is safer, though even
283+
slower.
284+
</para>
285+
</listitem>
286+
</varlistentry>
287+
288+
<varlistentry>
289+
<term><option>--column-inserts</option></term>
290+
<term><option>--attribute-inserts</option></term>
291+
<listitem>
292+
<para>
293+
Dump data as <command>INSERT</command> commands with explicit
294+
column names (<literal>INSERT INTO
295+
<replaceable>table</replaceable>
296+
(<replaceable>column</replaceable>, ...) VALUES
297+
...</literal>). This will make restoration very slow; it is mainly
298+
useful for making dumps that can be loaded into
299+
non-<productname>PostgreSQL</productname> databases.
300+
</para>
301+
</listitem>
302+
</varlistentry>
303+
305304
<varlistentry>
306305
<term><option>--disable-dollar-quoting</></term>
307306
<listitem>
@@ -511,7 +510,7 @@ PostgreSQL documentation
511510

512511
<para>
513512
<application>pg_dumpall</application> requires all needed
514-
tablespace directories to exist before the restore or
513+
tablespace directories to exist before the restore, else
515514
database creation will fail for databases in non-default
516515
locations.
517516
</para>

‎src/bin/pg_dump/pg_dump.c

Lines changed: 21 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
*by PostgreSQL
1313
*
1414
* IDENTIFICATION
15-
* $PostgreSQL: pgsql/src/bin/pg_dump/pg_dump.c,v 1.529 2009/03/17 10:10:13 petere Exp $
15+
* $PostgreSQL: pgsql/src/bin/pg_dump/pg_dump.c,v 1.530 2009/03/22 16:44:26 tgl Exp $
1616
*
1717
*-------------------------------------------------------------------------
1818
*/
@@ -67,8 +67,6 @@ Archive *g_fout;/* the script file */
6767
PGconn*g_conn;/* the database connection */
6868

6969
/* various user-settable parameters */
70-
booldumpInserts;/* dump data using proper insert strings */
71-
boolattrNames;/* put attr names into insert strings */
7270
boolschemaOnly;
7371
booldataOnly;
7472
boolaclsSkip;
@@ -99,8 +97,6 @@ static SimpleOidList table_exclude_oids = {NULL, NULL};
9997
/* default, if no "inclusion" switches appear, is to dump everything */
10098
staticboolinclude_everything= true;
10199

102-
staticintbinary_upgrade=0;
103-
104100
charg_opaque_type[10];/* name for the opaque type */
105101

106102
/* placeholders for the delimiters for comments */
@@ -113,8 +109,11 @@ static const CatalogId nilCatalogId = {0, 0};
113109
staticNamespaceInfo*g_namespaces;
114110
staticintg_numNamespaces;
115111

116-
/* flag to turn on/off dollar quoting */
112+
/* flags for various command-line long options */
113+
staticintbinary_upgrade=0;
117114
staticintdisable_dollar_quoting=0;
115+
staticintdump_inserts=0;
116+
staticintcolumn_inserts=0;
118117

119118

120119
staticvoidhelp(constchar*progname);
@@ -239,16 +238,12 @@ main(int argc, char **argv)
239238
staticintuse_setsessauth=0;
240239

241240
structoptionlong_options[]= {
242-
{"binary-upgrade",no_argument,&binary_upgrade,1},/* not documented */
243241
{"data-only",no_argument,NULL,'a'},
244242
{"blobs",no_argument,NULL,'b'},
245243
{"clean",no_argument,NULL,'c'},
246244
{"create",no_argument,NULL,'C'},
247245
{"file",required_argument,NULL,'f'},
248246
{"format",required_argument,NULL,'F'},
249-
{"inserts",no_argument,NULL,'d'},
250-
{"attribute-inserts",no_argument,NULL,'D'},
251-
{"column-inserts",no_argument,NULL,'D'},
252247
{"host",required_argument,NULL,'h'},
253248
{"ignore-version",no_argument,NULL,'i'},
254249
{"no-reconnect",no_argument,NULL,'R'},
@@ -275,8 +270,12 @@ main(int argc, char **argv)
275270
/*
276271
* the following options don't have an equivalent short option letter
277272
*/
273+
{"attribute-inserts",no_argument,&column_inserts,1},
274+
{"binary-upgrade",no_argument,&binary_upgrade,1},
275+
{"column-inserts",no_argument,&column_inserts,1},
278276
{"disable-dollar-quoting",no_argument,&disable_dollar_quoting,1},
279277
{"disable-triggers",no_argument,&disable_triggers,1},
278+
{"inserts",no_argument,&dump_inserts,1},
280279
{"lock-wait-timeout",required_argument,NULL,2},
281280
{"no-tablespaces",no_argument,&outputNoTablespaces,1},
282281
{"role",required_argument,NULL,3},
@@ -293,7 +292,7 @@ main(int argc, char **argv)
293292
g_comment_end[0]='\0';
294293
strcpy(g_opaque_type,"opaque");
295294

296-
dataOnly=schemaOnly=dumpInserts=attrNames=false;
295+
dataOnly=schemaOnly= false;
297296
lockWaitTimeout=NULL;
298297

299298
progname=get_progname(argv[0]);
@@ -316,7 +315,7 @@ main(int argc, char **argv)
316315
}
317316
}
318317

319-
while ((c=getopt_long(argc,argv,"abcCdDE:f:F:h:in:N:oOp:RsS:t:T:U:vwWxX:Z:",
318+
while ((c=getopt_long(argc,argv,"abcCE:f:F:h:in:N:oOp:RsS:t:T:U:vwWxX:Z:",
320319
long_options,&optindex))!=-1)
321320
{
322321
switch (c)
@@ -337,16 +336,6 @@ main(int argc, char **argv)
337336
outputCreate=1;
338337
break;
339338

340-
case'd':/* dump data as proper insert strings */
341-
dumpInserts= true;
342-
break;
343-
344-
case'D':/* dump data as proper insert strings with
345-
* attr names */
346-
dumpInserts= true;
347-
attrNames= true;
348-
break;
349-
350339
case'E':/* Dump encoding */
351340
dumpencoding=optarg;
352341
break;
@@ -484,6 +473,10 @@ main(int argc, char **argv)
484473
if (optind<argc)
485474
dbname=argv[optind];
486475

476+
/* --column-inserts implies --inserts */
477+
if (column_inserts)
478+
dump_inserts=1;
479+
487480
if (dataOnly&&schemaOnly)
488481
{
489482
write_msg(NULL,"options -s/--schema-only and -a/--data-only cannot be used together\n");
@@ -496,9 +489,9 @@ main(int argc, char **argv)
496489
exit(1);
497490
}
498491

499-
if (dumpInserts== true&&oids== true)
492+
if (dump_inserts&&oids)
500493
{
501-
write_msg(NULL,"options -d/-D/--inserts/--column-inserts and -o/--oids cannot be used together\n");
494+
write_msg(NULL,"options --inserts/--column-inserts and -o/--oids cannot be used together\n");
502495
write_msg(NULL,"(The INSERT command cannot set OIDs.)\n");
503496
exit(1);
504497
}
@@ -815,8 +808,6 @@ help(const char *progname)
815808
printf(_(" -b, --blobs include large objects in dump\n"));
816809
printf(_(" -c, --clean clean (drop) database objects before recreating\n"));
817810
printf(_(" -C, --create include commands to create database in dump\n"));
818-
printf(_(" -d, --inserts dump data as INSERT commands, rather than COPY\n"));
819-
printf(_(" -D, --column-inserts dump data as INSERT commands with column names\n"));
820811
printf(_(" -E, --encoding=ENCODING dump the data in encoding ENCODING\n"));
821812
printf(_(" -n, --schema=SCHEMA dump the named schema(s) only\n"));
822813
printf(_(" -N, --exclude-schema=SCHEMA do NOT dump the named schema(s)\n"));
@@ -829,6 +820,8 @@ help(const char *progname)
829820
printf(_(" -T, --exclude-table=TABLE do NOT dump the named table(s)\n"));
830821
printf(_(" -x, --no-privileges do not dump privileges (grant/revoke)\n"));
831822
printf(_(" --binary-upgrade for use by upgrade utilities only\n"));
823+
printf(_(" --inserts dump data as INSERT commands, rather than COPY\n"));
824+
printf(_(" --column-inserts dump data as INSERT commands with column names\n"));
832825
printf(_(" --disable-dollar-quoting disable dollar quoting, use SQL standard quoting\n"));
833826
printf(_(" --disable-triggers disable triggers during data-only restore\n"));
834827
printf(_(" --no-tablespaces do not dump tablespace assignments\n"));
@@ -1269,7 +1262,7 @@ dumpTableData_insert(Archive *fout, void *dcontext)
12691262
archprintf(fout,"DEFAULT VALUES;\n");
12701263
continue;
12711264
}
1272-
if (attrNames== true)
1265+
if (column_inserts)
12731266
{
12741267
resetPQExpBuffer(q);
12751268
appendPQExpBuffer(q,"(");
@@ -1376,7 +1369,7 @@ dumpTableData(Archive *fout, TableDataInfo *tdinfo)
13761369
DataDumperPtrdumpFn;
13771370
char*copyStmt;
13781371

1379-
if (!dumpInserts)
1372+
if (!dump_inserts)
13801373
{
13811374
/* Dump/restore using COPY */
13821375
dumpFn=dumpTableData_copy;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp