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

Commit4317e02

Browse files
committed
Rewrite --section option to decouple it from --schema-only/--data-only.
The initial implementation of pg_dump's --section option supposed that theexisting --schema-only and --data-only options could be made equivalent to--section settings. This is wrong, though, due to dubious but long sinceset-in-stone decisions about where to dump SEQUENCE SET items, as seen inbug report from Martin Pitt. (And I'm not totally convinced there weren'tother bugs, either.) Undo that coupling and instead drive --sectionfiltering off current-section state tracked as we scan through the TOClist to call _tocEntryRequired().To make sure those decisions don't shift around and hopefully save a fewcycles, run _tocEntryRequired() only once per TOC entry and save the resultin a new TOC field. This required minor rejiggering of ACL handling butalso allows a far cleaner implementation of inhibit_data_for_failed_table.Also, to ensure that pg_dump and pg_restore have the same behavior withrespect to the --section switches, add _tocEntryRequired() filtering toWriteToc() and WriteDataChunks(), rather than trying to implement sectionfiltering in an entirely orthogonal way in dumpDumpableObject(). Thisrequired adjusting the handling of the special ENCODING and STDSTRINGSitems, but they were pretty weird before anyway.Minor other code review for the patch, too.
1 parent4bc6fb5 commit4317e02

File tree

10 files changed

+238
-238
lines changed

10 files changed

+238
-238
lines changed

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

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -113,10 +113,12 @@ PostgreSQL documentation
113113
<listitem>
114114
<para>
115115
Dump only the data, not the schema (data definitions).
116+
Table data, large objects, and sequence values are dumped.
116117
</para>
117118

118119
<para>
119-
This option is equivalent to specifying <option>--section=data</>.
120+
This option is similar to, but for historical reasons not identical
121+
to, specifying <option>--section=data</>.
120122
</para>
121123
</listitem>
122124
</varlistentry>
@@ -403,12 +405,18 @@ PostgreSQL documentation
403405
Dump only the object definitions (schema), not data.
404406
</para>
405407
<para>
406-
To exclude table data for only a subset of tables in the database,
407-
see <option>--exclude-table-data</>.
408+
This option is the inverse of <option>--data-only</>.
409+
It is similar to, but for historical reasons not identical to,
410+
specifying
411+
<option>--section=pre-data --section=post-data</>.
408412
</para>
409413
<para>
410-
This option is equivalent to specifying
411-
<option>--section=pre-data --section=post-data</>.
414+
(Do not confuse this with the <option>--schema</> option, which
415+
uses the word <quote>schema</> in a different meaning.)
416+
</para>
417+
<para>
418+
To exclude table data for only a subset of tables in the database,
419+
see <option>--exclude-table-data</>.
412420
</para>
413421
</listitem>
414422
</varlistentry>
@@ -722,14 +730,17 @@ PostgreSQL documentation
722730
<term><option>--section=<replaceable class="parameter">sectionname</replaceable></option></term>
723731
<listitem>
724732
<para>
725-
Only dump the named section. The name can be one of <option>pre-data</>, <option>data</>
726-
and <option>post-data</>.
727-
This option can be specified more than once. The default is to dump all sections.
733+
Only dump the named section. The section name can be
734+
<option>pre-data</>, <option>data</>, or <option>post-data</>.
735+
This option can be specified more than once to select multiple
736+
sections. The default is to dump all sections.
728737
</para>
729738
<para>
730-
Post-data items consist of definitions of indexes, triggers, rules
731-
and constraints other than validated check constraints.
732-
Pre-data items consist of all other data definition items.
739+
The data section contains actual table data as well as large-object
740+
definitions.
741+
Post-data items consist of definitions of indexes, triggers, rules
742+
and constraints other than validated check constraints.
743+
Pre-data items consist of all other data definition items.
733744
</para>
734745
</listitem>
735746
</varlistentry>

‎doc/src/sgml/ref/pg_restore.sgml

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -92,9 +92,13 @@
9292
<listitem>
9393
<para>
9494
Restore only the data, not the schema (data definitions).
95+
Table data, large objects, and sequence values are restored,
96+
if present in the archive.
9597
</para>
98+
9699
<para>
97-
This option is equivalent to specifying <option>--section=data</>.
100+
This option is similar to, but for historical reasons not identical
101+
to, specifying <option>--section=data</>.
98102
</para>
99103
</listitem>
100104
</varlistentry>
@@ -357,15 +361,19 @@
357361
<term><option>--schema-only</option></term>
358362
<listitem>
359363
<para>
360-
Restore only the schema (data definitions), not the data (table
361-
contents). Current sequence values will not be restored, either.
362-
(Do not confuse this with the <option>--schema</> option, which
363-
uses the word <quote>schema</> in a different meaning.)
364+
Restore only the schema (data definitions), not data,
365+
to the extent that schema entries are present in the archive.
364366
</para>
365367
<para>
366-
This option is equivalent to specifying
368+
This option is the inverse of <option>--data-only</>.
369+
It is similar to, but for historical reasons not identical to,
370+
specifying
367371
<option>--section=pre-data --section=post-data</>.
368372
</para>
373+
<para>
374+
(Do not confuse this with the <option>--schema</> option, which
375+
uses the word <quote>schema</> in a different meaning.)
376+
</para>
369377
</listitem>
370378
</varlistentry>
371379

@@ -515,14 +523,17 @@
515523
<term><option>--section=<replaceable class="parameter">sectionname</replaceable></option></term>
516524
<listitem>
517525
<para>
518-
Only restore the named section. The name can be one of <option>pre-data</>, <option>data</>
519-
and <option>post-data</>.
520-
This option can be specified more than once. The default is to restore all sections.
526+
Only restore the named section. The section name can be
527+
<option>pre-data</>, <option>data</>, or <option>post-data</>.
528+
This option can be specified more than once to select multiple
529+
sections. The default is to restore all sections.
521530
</para>
522531
<para>
523-
Post-data items consist of definitions of indexes, triggers, rules
524-
and constraints other than validated check constraints.
525-
Pre-data items consist of all other data definition items.
532+
The data section contains actual table data as well as large-object
533+
definitions.
534+
Post-data items consist of definitions of indexes, triggers, rules
535+
and constraints other than validated check constraints.
536+
Pre-data items consist of all other data definition items.
526537
</para>
527538
</listitem>
528539
</varlistentry>

‎src/bin/pg_dump/dumputils.c

Lines changed: 31 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
#include<ctype.h>
1818

1919
#include"dumputils.h"
20-
#include"pg_backup.h"
2120

2221
#include"parser/keywords.h"
2322

@@ -1230,6 +1229,37 @@ emitShSecLabels(PGconn *conn, PGresult *res, PQExpBuffer buffer,
12301229
}
12311230

12321231

1232+
/*
1233+
* Parse a --section=foo command line argument.
1234+
*
1235+
* Set or update the bitmask in *dumpSections according to arg.
1236+
* dumpSections is initialised as DUMP_UNSECTIONED by pg_dump and
1237+
* pg_restore so they can know if this has even been called.
1238+
*/
1239+
void
1240+
set_dump_section(constchar*arg,int*dumpSections)
1241+
{
1242+
/* if this is the first call, clear all the bits */
1243+
if (*dumpSections==DUMP_UNSECTIONED)
1244+
*dumpSections=0;
1245+
1246+
if (strcmp(arg,"pre-data")==0)
1247+
*dumpSections |=DUMP_PRE_DATA;
1248+
elseif (strcmp(arg,"data")==0)
1249+
*dumpSections |=DUMP_DATA;
1250+
elseif (strcmp(arg,"post-data")==0)
1251+
*dumpSections |=DUMP_POST_DATA;
1252+
else
1253+
{
1254+
fprintf(stderr,_("%s: unknown section name \"%s\")\n"),
1255+
progname,arg);
1256+
fprintf(stderr,_("Try \"%s --help\" for more information.\n"),
1257+
progname);
1258+
exit_nicely(1);
1259+
}
1260+
}
1261+
1262+
12331263
/*
12341264
* Write a printf-style message to stderr.
12351265
*
@@ -1279,35 +1309,6 @@ exit_horribly(const char *modulename, const char *fmt,...)
12791309
exit_nicely(1);
12801310
}
12811311

1282-
/*
1283-
* Set the bitmask in dumpSections according to the first argument.
1284-
* dumpSections is initialised as DUMP_UNSECTIONED by pg_dump and
1285-
* pg_restore so they can know if this has even been called.
1286-
*/
1287-
1288-
void
1289-
set_section (constchar*arg,int*dumpSections)
1290-
{
1291-
/* if this is the first, clear all the bits */
1292-
if (*dumpSections==DUMP_UNSECTIONED)
1293-
*dumpSections=0;
1294-
1295-
if (strcmp(arg,"pre-data")==0)
1296-
*dumpSections |=DUMP_PRE_DATA;
1297-
elseif (strcmp(arg,"data")==0)
1298-
*dumpSections |=DUMP_DATA;
1299-
elseif (strcmp(arg,"post-data")==0)
1300-
*dumpSections |=DUMP_POST_DATA;
1301-
else
1302-
{
1303-
fprintf(stderr,_("%s: unknown section name \"%s\")\n"),
1304-
progname,arg);
1305-
fprintf(stderr,_("Try \"%s --help\" for more information.\n"),
1306-
progname);
1307-
exit_nicely(1);
1308-
}
1309-
}
1310-
13111312
/* Register a callback to be run when exit_nicely is invoked. */
13121313
void
13131314
on_exit_nicely(on_exit_nicely_callbackfunction,void*arg)

‎src/bin/pg_dump/dumputils.h

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,16 @@
1919
#include"libpq-fe.h"
2020
#include"pqexpbuffer.h"
2121

22+
typedefenum/* bits returned by set_dump_section */
23+
{
24+
DUMP_PRE_DATA=0x01,
25+
DUMP_DATA=0x02,
26+
DUMP_POST_DATA=0x04,
27+
DUMP_UNSECTIONED=0xff
28+
}DumpSections;
29+
30+
typedefvoid (*on_exit_nicely_callback) (intcode,void*arg);
31+
2232
externintquote_all_identifiers;
2333
externconstchar*progname;
2434

@@ -52,15 +62,13 @@ extern void buildShSecLabelQuery(PGconn *conn, const char *catalog_name,
5262
uint32objectId,PQExpBuffersql);
5363
externvoidemitShSecLabels(PGconn*conn,PGresult*res,
5464
PQExpBufferbuffer,constchar*target,constchar*objname);
65+
externvoidset_dump_section(constchar*arg,int*dumpSections);
5566
externvoidwrite_msg(constchar*modulename,constchar*fmt,...)
5667
__attribute__((format(PG_PRINTF_ATTRIBUTE,2,3)));
5768
externvoidvwrite_msg(constchar*modulename,constchar*fmt,va_listap)
5869
__attribute__((format(PG_PRINTF_ATTRIBUTE,2,0)));
5970
externvoidexit_horribly(constchar*modulename,constchar*fmt,...)
6071
__attribute__((format(PG_PRINTF_ATTRIBUTE,2,3),noreturn));
61-
externvoidset_section (constchar*arg,int*dumpSections);
62-
63-
typedefvoid (*on_exit_nicely_callback) (intcode,void*arg);
6472
externvoidon_exit_nicely(on_exit_nicely_callbackfunction,void*arg);
6573
externvoidexit_nicely(intcode) __attribute__((noreturn));
6674

‎src/bin/pg_dump/pg_backup.h

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -68,14 +68,6 @@ typedef enum _teSection
6868
SECTION_POST_DATA/* stuff to be processed after data */
6969
}teSection;
7070

71-
typedefenum
72-
{
73-
DUMP_PRE_DATA=0x01,
74-
DUMP_DATA=0x02,
75-
DUMP_POST_DATA=0x04,
76-
DUMP_UNSECTIONED=0xff
77-
}DumpSections;
78-
7971
/*
8072
*We may want to have some more user-readable data, but in the mean
8173
*time this gives us some abstraction and type checking.
@@ -114,9 +106,9 @@ typedef struct _restoreOptions
114106
intno_security_labels;/* Skip security label entries */
115107
char*superuser;/* Username to use as superuser */
116108
char*use_role;/* Issue SET ROLE to this */
117-
intdataOnly;
118109
intdropSchema;
119110
constchar*filename;
111+
intdataOnly;
120112
intschemaOnly;
121113
intdumpSections;
122114
intverbose;
@@ -187,7 +179,9 @@ extern intEndBlob(Archive *AH, Oid oid);
187179

188180
externvoidCloseArchive(Archive*AH);
189181

190-
externvoidRestoreArchive(Archive*AH,RestoreOptions*ropt);
182+
externvoidSetArchiveRestoreOptions(Archive*AH,RestoreOptions*ropt);
183+
184+
externvoidRestoreArchive(Archive*AH);
191185

192186
/* Open an existing archive */
193187
externArchive*OpenArchive(constchar*FileSpec,constArchiveFormatfmt);
@@ -203,7 +197,6 @@ extern RestoreOptions *NewRestoreOptions(void);
203197

204198
/* Rearrange and filter TOC entries */
205199
externvoidSortTocFromFile(Archive*AHX,RestoreOptions*ropt);
206-
externvoidInitDummyWantedList(Archive*AHX,RestoreOptions*ropt);
207200

208201
/* Convenience functions used only when writing DATA */
209202
externintarchputs(constchar*s,Archive*AH);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp