@@ -91,6 +91,7 @@ PGconn *g_conn;/* the database connection */
9191/* various user-settable parameters */
9292bool schemaOnly ;
9393bool dataOnly ;
94+ int dumpSections ;/* bitmask of chosen sections */
9495bool aclsSkip ;
9596const char * lockWaitTimeout ;
9697
@@ -250,7 +251,6 @@ static void do_sql_command(PGconn *conn, const char *query);
250251static void check_sql_result (PGresult * res ,PGconn * conn ,const char * query ,
251252ExecStatusType expected );
252253
253-
254254int
255255main (int argc ,char * * argv )
256256{
@@ -332,6 +332,7 @@ main(int argc, char **argv)
332332{"no-tablespaces" ,no_argument ,& outputNoTablespaces ,1 },
333333{"quote-all-identifiers" ,no_argument ,& quote_all_identifiers ,1 },
334334{"role" ,required_argument ,NULL ,3 },
335+ {"section" ,required_argument ,NULL ,5 },
335336{"serializable-deferrable" ,no_argument ,& serializable_deferrable ,1 },
336337{"use-set-session-authorization" ,no_argument ,& use_setsessauth ,1 },
337338{"no-security-labels" ,no_argument ,& no_security_labels ,1 },
@@ -349,6 +350,7 @@ main(int argc, char **argv)
349350strcpy (g_opaque_type ,"opaque" );
350351
351352dataOnly = schemaOnly = false;
353+ dumpSections = DUMP_UNSECTIONED ;
352354lockWaitTimeout = NULL ;
353355
354356progname = get_progname (argv [0 ]);
@@ -494,6 +496,10 @@ main(int argc, char **argv)
494496simple_string_list_append (& tabledata_exclude_patterns ,optarg );
495497break ;
496498
499+ case 5 :/* section */
500+ set_section (optarg ,& dumpSections );
501+ break ;
502+
497503default :
498504fprintf (stderr ,_ ("Try \"%s --help\" for more information.\n" ),progname );
499505exit (1 );
@@ -524,6 +530,22 @@ main(int argc, char **argv)
524530exit (1 );
525531}
526532
533+ if ((dataOnly || schemaOnly )&& dumpSections != DUMP_UNSECTIONED )
534+ {
535+ write_msg (NULL ,"options -s/--schema-only and -a/--data-only cannot be used with --section\n" );
536+ exit (1 );
537+ }
538+
539+ if (dataOnly )
540+ dumpSections = DUMP_DATA ;
541+ else if (schemaOnly )
542+ dumpSections = DUMP_PRE_DATA |DUMP_POST_DATA ;
543+ else if (dumpSections != DUMP_UNSECTIONED )
544+ {
545+ dataOnly = dumpSections == DUMP_DATA ;
546+ schemaOnly = !(dumpSections & DUMP_DATA );
547+ }
548+
527549if (dataOnly && outputClean )
528550{
529551write_msg (NULL ,"options -c/--clean and -a/--data-only cannot be used together\n" );
@@ -871,6 +893,7 @@ help(const char *progname)
871893printf (_ (" --no-tablespaces do not dump tablespace assignments\n" ));
872894printf (_ (" --no-unlogged-table-data do not dump unlogged table data\n" ));
873895printf (_ (" --quote-all-identifiers quote all identifiers, even if not key words\n" ));
896+ printf (_ (" --section=SECTION dump named section (pre-data, data or post-data)\n" ));
874897printf (_ (" --serializable-deferrable wait until the dump can run without anomalies\n" ));
875898printf (_ (" --use-set-session-authorization\n"
876899" use SET SESSION AUTHORIZATION commands instead of\n"
@@ -1107,7 +1130,7 @@ selectDumpableTable(TableInfo *tbinfo)
11071130tbinfo -> dobj .dumpdata = true;
11081131else
11091132tbinfo -> dobj .dumpdata = false;
1110-
1133+
11111134}
11121135
11131136/*
@@ -7093,6 +7116,28 @@ collectComments(Archive *fout, CommentItem **items)
70937116static void
70947117dumpDumpableObject (Archive * fout ,DumpableObject * dobj )
70957118{
7119+
7120+ bool skip = false;
7121+
7122+ switch (dobj -> objType )
7123+ {
7124+ case DO_INDEX :
7125+ case DO_TRIGGER :
7126+ case DO_CONSTRAINT :
7127+ case DO_FK_CONSTRAINT :
7128+ case DO_RULE :
7129+ skip = !(dumpSections & DUMP_POST_DATA );
7130+ break ;
7131+ case DO_TABLE_DATA :
7132+ skip = !(dumpSections & DUMP_DATA );
7133+ break ;
7134+ default :
7135+ skip = !(dumpSections & DUMP_PRE_DATA );
7136+ }
7137+
7138+ if (skip )
7139+ return ;
7140+
70967141switch (dobj -> objType )
70977142{
70987143case DO_NAMESPACE :