postgres.git / summary / log / commit / refs

commit    bec96c82f8ff4fcf7ef0f070f6f7447edf106de3
Author:   Stephen Frost <sfrost@snowman.net>
Date:     Thu Jan 19 17:06:21 2017 +0000

    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.


src/bin/pg_dump/pg_dump.c | 2 +- src/test/modules/test_pg_dump/t/001_base.pl | 19 +++++++++++++++++++ src/test/modules/test_pg_dump/test_pg_dump--1.0.sql | 3 +++ 3 files changed, 23 insertions(+), 1 deletion(-) diff --git a/src/bin/pg_dump/pg_dump.c b/src/bin/pg_dump/pg_dump.c index 1f3f019506c..883fde1e5aa 100644 --- a/src/bin/pg_dump/pg_dump.c +++ b/src/bin/pg_dump/pg_dump.c @@ -15671,7 +15671,7 @@ dumpSequenceData(Archive *fout, TableDataInfo *tdinfo) appendPQExpBuffer(query, ", %s, %s);\n", last, (called ? "true" : "false")); - if (tbinfo->dobj.dump & DUMP_COMPONENT_DATA) + if (tdinfo->dobj.dump & DUMP_COMPONENT_DATA) ArchiveEntry(fout, nilCatalogId, createDumpId(), tbinfo->dobj.name, tbinfo->dobj.namespace->dobj.name, diff --git a/src/test/modules/test_pg_dump/t/001_base.pl b/src/test/modules/test_pg_dump/t/001_base.pl index dc90a4aa12f..70719a36a7e 100644 --- a/src/test/modules/test_pg_dump/t/001_base.pl +++ b/src/test/modules/test_pg_dump/t/001_base.pl @@ -265,6 +265,25 @@ my %tests = ( schema_only => 1, section_pre_data => 1, section_post_data => 1, }, }, + 'SETVAL SEQUENCE regress_seq_dumpable' => { + create_order => 6, + create_sql => qq{SELECT nextval('regress_seq_dumpable');}, + regexp => qr/^ + \QSELECT pg_catalog.setval('regress_seq_dumpable', 1, true);\E + \n/xm, + like => { + clean => 1, + clean_if_exists => 1, + createdb => 1, + data_only => 1, + defaults => 1, + no_owner => 1, + no_privs => 1, }, + unlike => { + pg_dumpall_globals => 1, + schema_only => 1, + section_pre_data => 1, + section_post_data => 1, }, }, 'CREATE TABLE regress_pg_dump_table' => { regexp => qr/^ \QCREATE TABLE regress_pg_dump_table (\E diff --git a/src/test/modules/test_pg_dump/test_pg_dump--1.0.sql b/src/test/modules/test_pg_dump/test_pg_dump--1.0.sql index ca9fb18e540..3ed007a7b1b 100644 --- a/src/test/modules/test_pg_dump/test_pg_dump--1.0.sql +++ b/src/test/modules/test_pg_dump/test_pg_dump--1.0.sql @@ -10,6 +10,9 @@ CREATE TABLE regress_pg_dump_table ( CREATE SEQUENCE regress_pg_dump_seq; +CREATE SEQUENCE regress_seq_dumpable; +SELECT pg_catalog.pg_extension_config_dump('regress_seq_dumpable', ''); + CREATE SCHEMA regress_pg_dump_schema; GRANT USAGE ON regress_pg_dump_seq TO regress_dump_test_role; [parent: 30bcebbdcf23]