Skip to content

Commit 05227e0

Browse files
committed
pg_dump: Only dump publications when dumping everything
Don't dump publications with pg_dump -t or similar cases that select specific groups of objects. Author: Petr Jelinek <petr.jelinek@2ndquadrant.com>
1 parent 9212810 commit 05227e0

File tree

2 files changed

+48
-29
lines changed

2 files changed

+48
-29
lines changed

src/bin/pg_dump/pg_dump.c

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1621,6 +1621,23 @@ selectDumpableExtension(ExtensionInfo *extinfo, DumpOptions *dopt)
16211621
DUMP_COMPONENT_NONE;
16221622
}
16231623

1624+
/*
1625+
* selectDumpablePublicationTable: policy-setting subroutine
1626+
* Mark a publication table as to be dumped or not
1627+
*
1628+
* Publication tables have schemas, but those are ignored in decision making,
1629+
* because publications are only dumped when we are dumping everything.
1630+
*/
1631+
static void
1632+
selectDumpablePublicationTable(DumpableObject *dobj, Archive *fout)
1633+
{
1634+
if (checkExtensionMembership(dobj, fout))
1635+
return; /* extension membership overrides all else */
1636+
1637+
dobj->dump = fout->dopt->include_everything ?
1638+
DUMP_COMPONENT_ALL : DUMP_COMPONENT_NONE;
1639+
}
1640+
16241641
/*
16251642
* selectDumpableObject: policy-setting subroutine
16261643
* Mark a generic dumpable object as to be dumped or not
@@ -3414,6 +3431,9 @@ getPublications(Archive *fout)
34143431
if (strlen(pubinfo[i].rolname) == 0)
34153432
write_msg(NULL, "WARNING: owner of publication \"%s\" appears to be invalid\n",
34163433
pubinfo[i].dobj.name);
3434+
3435+
/* Decide whether we want to dump it */
3436+
selectDumpableObject(&(pubinfo[i].dobj), fout);
34173437
}
34183438
PQclear(res);
34193439

@@ -3427,11 +3447,10 @@ getPublications(Archive *fout)
34273447
static void
34283448
dumpPublication(Archive *fout, PublicationInfo *pubinfo)
34293449
{
3430-
DumpOptions *dopt = fout->dopt;
34313450
PQExpBuffer delq;
34323451
PQExpBuffer query;
34333452

3434-
if (dopt->dataOnly)
3453+
if (!(pubinfo->dobj.dump & DUMP_COMPONENT_DEFINITION))
34353454
return;
34363455

34373456
delq = createPQExpBuffer();
@@ -3560,6 +3579,9 @@ getPublicationTables(Archive *fout, TableInfo tblinfo[], int numTables)
35603579
pubrinfo[j].dobj.name = tbinfo->dobj.name;
35613580
pubrinfo[j].pubname = pg_strdup(PQgetvalue(res, j, i_pubname));
35623581
pubrinfo[j].pubtable = tbinfo;
3582+
3583+
/* Decide whether we want to dump it */
3584+
selectDumpablePublicationTable(&(pubrinfo[j].dobj), fout);
35633585
}
35643586
PQclear(res);
35653587
}
@@ -3573,12 +3595,11 @@ getPublicationTables(Archive *fout, TableInfo tblinfo[], int numTables)
35733595
static void
35743596
dumpPublicationTable(Archive *fout, PublicationRelInfo *pubrinfo)
35753597
{
3576-
DumpOptions *dopt = fout->dopt;
35773598
TableInfo *tbinfo = pubrinfo->pubtable;
35783599
PQExpBuffer query;
35793600
char *tag;
35803601

3581-
if (dopt->dataOnly)
3602+
if (!(pubrinfo->dobj.dump & DUMP_COMPONENT_DEFINITION))
35823603
return;
35833604

35843605
tag = psprintf("%s %s", pubrinfo->pubname, tbinfo->dobj.name);

src/bin/pg_dump/t/002_pg_dump.pl

Lines changed: 23 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -653,22 +653,22 @@
653653
exclude_test_table_data => 1,
654654
no_privs => 1,
655655
no_blobs => 1,
656-
only_dump_test_schema => 1, # XXX Should be unlike
657-
only_dump_test_table => 1, # XXX Should be unlike
658656
pg_dumpall_dbprivs => 1,
659-
role => 1, # XXX Should be unlike
660657
schema_only => 1,
661658
section_post_data => 1,
662-
test_schema_plus_blobs => 1, # XXX Should be unlike
663659
with_oids => 1, },
664660
unlike => {
665661
column_inserts => 1,
666662
data_only => 1,
667663
no_owner => 1,
664+
only_dump_test_schema => 1,
665+
only_dump_test_table => 1,
668666
pg_dumpall_globals => 1,
669667
pg_dumpall_globals_clean => 1,
668+
role => 1,
670669
section_pre_data => 1,
671-
section_data => 1, }, },
670+
section_data => 1,
671+
test_schema_plus_blobs => 1, }, },
672672

673673
'ALTER LARGE OBJECT ... OWNER TO' => {
674674
all_runs => 1,
@@ -4168,19 +4168,18 @@
41684168
no_blobs => 1,
41694169
no_privs => 1,
41704170
no_owner => 1,
4171-
only_dump_test_schema => 1, # XXX Should be unlike
4172-
only_dump_test_table => 1, # XXX Should be unlike
41734171
pg_dumpall_dbprivs => 1,
4174-
role => 1, # XXX Should be unlike
41754172
schema_only => 1,
41764173
section_post_data => 1,
4177-
test_schema_plus_blobs => 1, # XXX Should be unlike
41784174
with_oids => 1, },
41794175
unlike => {
4180-
section_pre_data => 1,
4176+
only_dump_test_schema => 1,
4177+
only_dump_test_table => 1,
41814178
pg_dumpall_globals => 1,
41824179
pg_dumpall_globals_clean => 1,
4183-
section_pre_data => 1, }, },
4180+
role => 1,
4181+
section_pre_data => 1,
4182+
test_schema_plus_blobs => 1, }, },
41844183
41854184
'CREATE PUBLICATION pub2' => {
41864185
all_runs => 1,
@@ -4206,19 +4205,18 @@
42064205
no_blobs => 1,
42074206
no_privs => 1,
42084207
no_owner => 1,
4209-
only_dump_test_schema => 1, # XXX Should be unlike
4210-
only_dump_test_table => 1, # XXX Should be unlike
42114208
pg_dumpall_dbprivs => 1,
4212-
role => 1, # XXX Should be unlike
42134209
schema_only => 1,
42144210
section_post_data => 1,
4215-
test_schema_plus_blobs => 1, # XXX Should be unlike
42164211
with_oids => 1, },
42174212
unlike => {
4218-
section_pre_data => 1,
4213+
only_dump_test_schema => 1,
4214+
only_dump_test_table => 1,
42194215
pg_dumpall_globals => 1,
42204216
pg_dumpall_globals_clean => 1,
4221-
section_pre_data => 1, }, },
4217+
role => 1,
4218+
section_pre_data => 1,
4219+
test_schema_plus_blobs => 1, }, },
42224220
42234221
'CREATE SUBSCRIPTION sub1' => {
42244222
all_runs => 1,
@@ -4274,12 +4272,9 @@
42744272
no_blobs => 1,
42754273
no_privs => 1,
42764274
no_owner => 1,
4277-
only_dump_test_schema => 1,
4278-
only_dump_test_table => 1,
42794275
pg_dumpall_dbprivs => 1,
42804276
schema_only => 1,
42814277
section_post_data => 1,
4282-
test_schema_plus_blobs => 1,
42834278
with_oids => 1, },
42844279
unlike => {
42854280
column_inserts => 1,
@@ -4289,8 +4284,11 @@
42894284
section_pre_data => 1,
42904285
exclude_dump_test_schema => 1,
42914286
exclude_test_table => 1,
4287+
only_dump_test_schema => 1,
4288+
only_dump_test_table => 1,
42924289
pg_dumpall_globals => 1,
4293-
pg_dumpall_globals_clean => 1, }, },
4290+
pg_dumpall_globals_clean => 1,
4291+
test_schema_plus_blobs => 1, }, },
42944292
'ALTER PUBLICATION pub1 ADD TABLE test_second_table' => {
42954293
create_order => 52,
42964294
create_sql =>
@@ -4308,17 +4306,17 @@
43084306
exclude_test_table_data => 1,
43094307
no_privs => 1,
43104308
no_owner => 1,
4311-
only_dump_test_schema => 1,
43124309
pg_dumpall_dbprivs => 1,
43134310
schema_only => 1,
4314-
section_post_data => 1,
4315-
test_schema_plus_blobs => 1, },
4311+
section_post_data => 1, },
43164312
unlike => {
43174313
section_pre_data => 1,
43184314
exclude_dump_test_schema => 1,
4315+
only_dump_test_schema => 1,
43194316
only_dump_test_table => 1,
43204317
pg_dumpall_globals => 1,
4321-
pg_dumpall_globals_clean => 1, }, },
4318+
pg_dumpall_globals_clean => 1,
4319+
test_schema_plus_blobs => 1, }, },
43224320
43234321
'CREATE SCHEMA dump_test' => {
43244322
all_runs => 1,

0 commit comments

Comments
 (0)