@@ -91,6 +91,7 @@ PGconn *g_conn; /* the database connection */
91
91
/* various user-settable parameters */
92
92
bool schemaOnly ;
93
93
bool dataOnly ;
94
+ int dumpSections ; /* bitmask of chosen sections */
94
95
bool aclsSkip ;
95
96
const char * lockWaitTimeout ;
96
97
@@ -247,7 +248,7 @@ static const char *fmtCopyColumnList(const TableInfo *ti);
247
248
static void do_sql_command (PGconn * conn , const char * query );
248
249
static void check_sql_result (PGresult * res , PGconn * conn , const char * query ,
249
250
ExecStatusType expected );
250
-
251
+ static void set_section ( const char * arg );
251
252
252
253
int
253
254
main (int argc , char * * argv )
@@ -330,6 +331,7 @@ main(int argc, char **argv)
330
331
{"quote-all-identifiers" , no_argument , & quote_all_identifiers , 1 },
331
332
{"role" , required_argument , NULL , 3 },
332
333
{"serializable-deferrable" , no_argument , & serializable_deferrable , 1 },
334
+ {"section" , required_argument , NULL , 5 },
333
335
{"use-set-session-authorization" , no_argument , & use_setsessauth , 1 },
334
336
{"no-security-labels" , no_argument , & no_security_labels , 1 },
335
337
{"no-unlogged-table-data" , no_argument , & no_unlogged_table_data , 1 },
@@ -346,6 +348,7 @@ main(int argc, char **argv)
346
348
strcpy (g_opaque_type , "opaque" );
347
349
348
350
dataOnly = schemaOnly = false;
351
+ dumpSections = DUMP_UNSECTIONED ;
349
352
lockWaitTimeout = NULL ;
350
353
351
354
progname = get_progname (argv [0 ]);
@@ -487,6 +490,10 @@ main(int argc, char **argv)
487
490
use_role = optarg ;
488
491
break ;
489
492
493
+ case 5 : /* section */
494
+ set_section (optarg );
495
+ break ;
496
+
490
497
default :
491
498
fprintf (stderr , _ ("Try \"%s --help\" for more information.\n" ), progname );
492
499
exit (1 );
@@ -517,6 +524,22 @@ main(int argc, char **argv)
517
524
exit (1 );
518
525
}
519
526
527
+ if ((dataOnly || schemaOnly ) && dumpSections != DUMP_UNSECTIONED )
528
+ {
529
+ write_msg (NULL , "options -s/--schema-only and -a/--data-only cannot be used with --section\n" );
530
+ exit (1 );
531
+ }
532
+
533
+ if (dataOnly )
534
+ dumpSections = DUMP_DATA ;
535
+ else if (schemaOnly )
536
+ dumpSections = DUMP_PRE_DATA | DUMP_POST_DATA ;
537
+ else if ( dumpSections != DUMP_UNSECTIONED )
538
+ {
539
+ dataOnly = dumpSections == DUMP_DATA ;
540
+ schemaOnly = !(dumpSections & DUMP_DATA );
541
+ }
542
+
520
543
if (dataOnly && outputClean )
521
544
{
522
545
write_msg (NULL , "options -c/--clean and -a/--data-only cannot be used together\n" );
@@ -859,6 +882,7 @@ help(const char *progname)
859
882
printf (_ (" --no-tablespaces do not dump tablespace assignments\n" ));
860
883
printf (_ (" --no-unlogged-table-data do not dump unlogged table data\n" ));
861
884
printf (_ (" --quote-all-identifiers quote all identifiers, even if not key words\n" ));
885
+ printf (_ (" --section=SECTION dump named section (pre-data, data or post-data\n" ));
862
886
printf (_ (" --serializable-deferrable wait until the dump can run without anomalies\n" ));
863
887
printf (_ (" --use-set-session-authorization\n"
864
888
" use SET SESSION AUTHORIZATION commands instead of\n"
@@ -7038,6 +7062,28 @@ collectComments(Archive *fout, CommentItem **items)
7038
7062
static void
7039
7063
dumpDumpableObject (Archive * fout , DumpableObject * dobj )
7040
7064
{
7065
+
7066
+ int skip = 0 ;
7067
+
7068
+ switch (dobj -> objType )
7069
+ {
7070
+ case DO_INDEX :
7071
+ case DO_TRIGGER :
7072
+ case DO_CONSTRAINT :
7073
+ case DO_FK_CONSTRAINT :
7074
+ case DO_RULE :
7075
+ skip = !(dumpSections & DUMP_POST_DATA );
7076
+ break ;
7077
+ case DO_TABLE_DATA :
7078
+ skip = !(dumpSections & DUMP_DATA );
7079
+ break ;
7080
+ default :
7081
+ skip = !(dumpSections & DUMP_PRE_DATA );
7082
+ }
7083
+
7084
+ if (skip )
7085
+ return ;
7086
+
7041
7087
switch (dobj -> objType )
7042
7088
{
7043
7089
case DO_NAMESPACE :
@@ -14402,3 +14448,25 @@ check_sql_result(PGresult *res, PGconn *conn, const char *query,
14402
14448
write_msg (NULL , "The command was: %s\n" , query );
14403
14449
exit_nicely ();
14404
14450
}
14451
+
14452
+ static void set_section (const char * arg )
14453
+ {
14454
+ /* if this is the first, clear all the bits */
14455
+ if (dumpSections == DUMP_UNSECTIONED )
14456
+ dumpSections = 0 ;
14457
+
14458
+ if (strcmp (arg ,"pre-data" ) == 0 )
14459
+ dumpSections |= DUMP_PRE_DATA ;
14460
+ else if (strcmp (arg ,"data" ) == 0 )
14461
+ dumpSections |= DUMP_DATA ;
14462
+ else if (strcmp (arg ,"post-data" ) == 0 )
14463
+ dumpSections |= DUMP_POST_DATA ;
14464
+ else
14465
+ {
14466
+ fprintf (stderr , _ ("%s: unknown section name \"%s\")\n" ),
14467
+ progname , arg );
14468
+ fprintf (stderr , _ ("Try \"%s --help\" for more information.\n" ),
14469
+ progname );
14470
+ exit (1 );
14471
+ }
14472
+ }
0 commit comments