Skip to content

Commit b602211

Browse files
committed
working
1 parent 95d2af1 commit b602211

File tree

2 files changed

+77
-1
lines changed

2 files changed

+77
-1
lines changed

src/bin/pg_dump/pg_backup.h

+8
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,14 @@ typedef enum _teSection
6969
SECTION_POST_DATA /* stuff to be processed after data */
7070
} teSection;
7171

72+
typedef enum
73+
{
74+
DUMP_PRE_DATA = 0x01,
75+
DUMP_DATA = 0x02,
76+
DUMP_POST_DATA = 0x04,
77+
DUMP_UNSECTIONED = 0xff
78+
} DumpSections;
79+
7280
/*
7381
* We may want to have some more user-readable data, but in the mean
7482
* time this gives us some abstraction and type checking.

src/bin/pg_dump/pg_dump.c

+69-1
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ PGconn *g_conn; /* the database connection */
9191
/* various user-settable parameters */
9292
bool schemaOnly;
9393
bool dataOnly;
94+
int dumpSections; /* bitmask of chosen sections */
9495
bool aclsSkip;
9596
const char *lockWaitTimeout;
9697

@@ -247,7 +248,7 @@ static const char *fmtCopyColumnList(const TableInfo *ti);
247248
static void do_sql_command(PGconn *conn, const char *query);
248249
static void check_sql_result(PGresult *res, PGconn *conn, const char *query,
249250
ExecStatusType expected);
250-
251+
static void set_section(const char *arg);
251252

252253
int
253254
main(int argc, char **argv)
@@ -330,6 +331,7 @@ main(int argc, char **argv)
330331
{"quote-all-identifiers", no_argument, &quote_all_identifiers, 1},
331332
{"role", required_argument, NULL, 3},
332333
{"serializable-deferrable", no_argument, &serializable_deferrable, 1},
334+
{"section", required_argument, NULL, 5},
333335
{"use-set-session-authorization", no_argument, &use_setsessauth, 1},
334336
{"no-security-labels", no_argument, &no_security_labels, 1},
335337
{"no-unlogged-table-data", no_argument, &no_unlogged_table_data, 1},
@@ -346,6 +348,7 @@ main(int argc, char **argv)
346348
strcpy(g_opaque_type, "opaque");
347349

348350
dataOnly = schemaOnly = false;
351+
dumpSections = DUMP_UNSECTIONED;
349352
lockWaitTimeout = NULL;
350353

351354
progname = get_progname(argv[0]);
@@ -487,6 +490,10 @@ main(int argc, char **argv)
487490
use_role = optarg;
488491
break;
489492

493+
case 5: /* section */
494+
set_section(optarg);
495+
break;
496+
490497
default:
491498
fprintf(stderr, _("Try \"%s --help\" for more information.\n"), progname);
492499
exit(1);
@@ -517,6 +524,22 @@ main(int argc, char **argv)
517524
exit(1);
518525
}
519526

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+
520543
if (dataOnly && outputClean)
521544
{
522545
write_msg(NULL, "options -c/--clean and -a/--data-only cannot be used together\n");
@@ -859,6 +882,7 @@ help(const char *progname)
859882
printf(_(" --no-tablespaces do not dump tablespace assignments\n"));
860883
printf(_(" --no-unlogged-table-data do not dump unlogged table data\n"));
861884
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"));
862886
printf(_(" --serializable-deferrable wait until the dump can run without anomalies\n"));
863887
printf(_(" --use-set-session-authorization\n"
864888
" use SET SESSION AUTHORIZATION commands instead of\n"
@@ -7038,6 +7062,28 @@ collectComments(Archive *fout, CommentItem **items)
70387062
static void
70397063
dumpDumpableObject(Archive *fout, DumpableObject *dobj)
70407064
{
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+
70417087
switch (dobj->objType)
70427088
{
70437089
case DO_NAMESPACE:
@@ -14402,3 +14448,25 @@ check_sql_result(PGresult *res, PGconn *conn, const char *query,
1440214448
write_msg(NULL, "The command was: %s\n", query);
1440314449
exit_nicely();
1440414450
}
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

Comments
 (0)