Collect attribute data on extension owned tables being dumped
authorAndrew Dunstan <andrew@dunslane.net>
Fri, 4 Sep 2020 17:53:09 +0000 (13:53 -0400)
committerAndrew Dunstan <andrew@dunslane.net>
Fri, 4 Sep 2020 17:54:54 +0000 (13:54 -0400)
If this data is not collected, pg_dump segfaults if asked for column
inserts.

Fix by Fabrízio de Royes Mello

Backpatch to release 12 where the bug was introduced.

src/bin/pg_dump/pg_dump.c
src/test/modules/test_pg_dump/t/001_base.pl
src/test/modules/test_pg_dump/test_pg_dump--1.0.sql

index d3ca54e4dc6a490ad315acb9ce0e662520f00438..784bceaec39489c1c02733d78939870335921dc0 100644 (file)
@@ -2095,6 +2095,8 @@ dumpTableData_insert(Archive *fout, void *dcontext)
                        if (nfields == 0)
                                continue;
 
+                       Assert(tbinfo->attgenerated);
+
                        /* Emit a row heading */
                        if (rows_per_statement == 1)
                                archputs(" (", fout);
@@ -17913,6 +17915,8 @@ processExtensionTables(Archive *fout, ExtensionInfo extinfo[],
                                                        configtbl->dataObj->filtercond = pg_strdup(extconditionarray[j]);
                                        }
                                }
+
+                               configtbl->interesting = dumpobj;
                        }
                }
                if (extconfigarray)
index ae120a5ee366f0bed31c9621ad48ba9937699abe..78aa07ce511a4fc1dc217260a6711dba6b48b283 100644 (file)
@@ -135,6 +135,12 @@ my %pgdump_runs = (
                        "$tempdir/defaults_tar_format.tar",
                ],
        },
+       extension_schema => {
+               dump_cmd => [
+                       'pg_dump', '--schema=public', '--inserts',
+                       "--file=$tempdir/extension_schema.sql", 'postgres',
+               ],
+       },
        pg_dumpall_globals => {
                dump_cmd => [
                        'pg_dumpall',                             '--no-sync',
@@ -301,8 +307,9 @@ my %tests = (
                        \n/xm,
                like => {
                        %full_runs,
-                       data_only    => 1,
-                       section_data => 1,
+                       data_only        => 1,
+                       section_data     => 1,
+                       extension_schema => 1,
                },
        },
 
@@ -536,6 +543,7 @@ my %tests = (
                like   => {%pgdump_runs},
                unlike => {
                        data_only          => 1,
+                       extension_schema   => 1,
                        pg_dumpall_globals => 1,
                        section_data       => 1,
                        section_pre_data   => 1,
@@ -549,6 +557,7 @@ my %tests = (
                like   => {%pgdump_runs},
                unlike => {
                        data_only          => 1,
+                       extension_schema   => 1,
                        pg_dumpall_globals => 1,
                        section_data       => 1,
                        section_pre_data   => 1,
@@ -569,6 +578,17 @@ my %tests = (
                        schema_only      => 1,
                        section_pre_data => 1,
                },
+       },
+
+       # Dumpable object inside specific schema
+       'INSERT INTO public.regress_table_dumpable VALUES (1);' => {
+               create_sql   => 'INSERT INTO public.regress_table_dumpable VALUES (1);',
+               regexp       => qr/^
+                       \QINSERT INTO public.regress_table_dumpable VALUES (1);\E
+                       \n/xm,
+               like => {
+                       extension_schema => 1,
+               },
        },);
 
 #########################################
index 3ed007a7b1b4190f269d34dc4a59af9f7ada39bf..90e461ed3573b1733ab511ac0c3fa2dae5bc3fb3 100644 (file)
@@ -13,6 +13,11 @@ CREATE SEQUENCE regress_pg_dump_seq;
 CREATE SEQUENCE regress_seq_dumpable;
 SELECT pg_catalog.pg_extension_config_dump('regress_seq_dumpable', '');
 
+CREATE TABLE regress_table_dumpable (
+       col1 int
+);
+SELECT pg_catalog.pg_extension_config_dump('regress_table_dumpable', '');
+
 CREATE SCHEMA regress_pg_dump_schema;
 
 GRANT USAGE ON regress_pg_dump_seq TO regress_dump_test_role;