Skip to content

Commit bec96c8

Browse files
committed
Dump sequence data based on the TableDataInfo flag
When considering a sequence's Data entry in dumpSequenceData, we were actually looking at the sequence definition's dump flag to decide if we should dump the data or not. That's generally fine, except for when the sequence data entry was created by processExtensionTables() because it's a config sequence. In that case, the sequence itself won't be marked as dumping data because it's part of an extension, leading to the need for processExtensionTables() to create the sequence data entry. This leads to extension config sequence data not being included in the dump when it should be. Fix this by looking at the sequence data's dump flag instead, just as dumpTableData() was doing for tables (which is why config tables were correctly being handled), and add a regression test to make sure we don't break it moving forward. All of this is a bit round-about since we can now represent which components of a given dump item should be dumped out through the dump flag. A future improvement might be to change checkExtensionMembership() to check for config sequences/tables and set the dump flag based on that directly, possibly removing the need for processExtensionTables(). Bug found by Daniele Varrazzo. Discussion: https://postgr.es/m/CA+mi_8ZmxQM7+nZ7pJ8uyfxc9V3o=UAG14dVqvftdmvw8OJ3gQ@mail.gmail.com Patch by Michael Paquier, with some tweaking of the regression tests by me. Back-patch to 9.6 where the bug was introduced.
1 parent 30bcebb commit bec96c8

File tree

3 files changed

+23
-1
lines changed

3 files changed

+23
-1
lines changed

src/bin/pg_dump/pg_dump.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -15671,7 +15671,7 @@ dumpSequenceData(Archive *fout, TableDataInfo *tdinfo)
1567115671
appendPQExpBuffer(query, ", %s, %s);\n",
1567215672
last, (called ? "true" : "false"));
1567315673

15674-
if (tbinfo->dobj.dump & DUMP_COMPONENT_DATA)
15674+
if (tdinfo->dobj.dump & DUMP_COMPONENT_DATA)
1567515675
ArchiveEntry(fout, nilCatalogId, createDumpId(),
1567615676
tbinfo->dobj.name,
1567715677
tbinfo->dobj.namespace->dobj.name,

src/test/modules/test_pg_dump/t/001_base.pl

+19
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,25 @@
265265
schema_only => 1,
266266
section_pre_data => 1,
267267
section_post_data => 1, }, },
268+
'SETVAL SEQUENCE regress_seq_dumpable' => {
269+
create_order => 6,
270+
create_sql => qq{SELECT nextval('regress_seq_dumpable');},
271+
regexp => qr/^
272+
\QSELECT pg_catalog.setval('regress_seq_dumpable', 1, true);\E
273+
\n/xm,
274+
like => {
275+
clean => 1,
276+
clean_if_exists => 1,
277+
createdb => 1,
278+
data_only => 1,
279+
defaults => 1,
280+
no_owner => 1,
281+
no_privs => 1, },
282+
unlike => {
283+
pg_dumpall_globals => 1,
284+
schema_only => 1,
285+
section_pre_data => 1,
286+
section_post_data => 1, }, },
268287
'CREATE TABLE regress_pg_dump_table' => {
269288
regexp => qr/^
270289
\QCREATE TABLE regress_pg_dump_table (\E

src/test/modules/test_pg_dump/test_pg_dump--1.0.sql

+3
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ CREATE TABLE regress_pg_dump_table (
1010

1111
CREATE SEQUENCE regress_pg_dump_seq;
1212

13+
CREATE SEQUENCE regress_seq_dumpable;
14+
SELECT pg_catalog.pg_extension_config_dump('regress_seq_dumpable', '');
15+
1316
CREATE SCHEMA regress_pg_dump_schema;
1417

1518
GRANT USAGE ON regress_pg_dump_seq TO regress_dump_test_role;

0 commit comments

Comments
 (0)