Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kPpu1-0002ZD-Ox for pgsql-bugs@arkaria.postgresql.org; Tue, 06 Oct 2020 16:33:25 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1kPpu0-0006Ys-K7 for pgsql-bugs@arkaria.postgresql.org; Tue, 06 Oct 2020 16:33:24 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kPpu0-0006Yk-Dw for pgsql-bugs@lists.postgresql.org; Tue, 06 Oct 2020 16:33:24 +0000 Received: from tamriel.snowman.net ([2001:470:e38f::11]) by magus.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1kPpty-0001PC-2l for pgsql-bugs@lists.postgresql.org; Tue, 06 Oct 2020 16:33:23 +0000 Received: by tamriel.snowman.net (Postfix, from userid 1000) id 15C5D5F799; Tue, 6 Oct 2020 12:33:19 -0400 (EDT) Date: Tue, 6 Oct 2020 12:33:18 -0400 From: Stephen Frost To: Tom Lane Cc: cam.daniel@gmail.com, pgsql-bugs@lists.postgresql.org Subject: Re: BUG #16655: pg_dump segfault when excluding postgis table Message-ID: <20201006163318.GX3063@tamriel.snowman.net> References: <16655-5c92d6b3a9438137@postgresql.org> <1819571.1601937068@sss.pgh.pa.us> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="R9dSeJxMIUBTi9Do" Content-Disposition: inline In-Reply-To: <1819571.1601937068@sss.pgh.pa.us> User-Agent: Mutt/1.5.24 (2015-08-30) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk --R9dSeJxMIUBTi9Do Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Greetings, * Tom Lane (tgl@sss.pgh.pa.us) wrote: > PG Bug reporting form writes: > > I'm getting a segfault when trying to pg_dump a database containing the > > postgis extension, but only when excluding the spatial_ref_sys table. >=20 > Yeah, I can reproduce this here. You don't really need postgis. > What I did was >=20 > 1. Install the src/test/modules/test_pg_dump module into an > empty database. >=20 > 2. alter table regress_table_dumpable add check(col1 > 0); While we certainly shouldn't just segfault, I don't think this is actually something that's intended or should be supported- the extension defines the table structure and users are really only expected to change permissions (and related bits) on the table (and, to some extent, even then only if they're familiar enough with the extension to know that the extension understands that a user may change the privileges post-install). all-in-all, it's not really a great situation but it's at least better than it had been (when we didn't try to deal with users changing privileges on extension objects and people complained about that). > 3. pg_dump -T regress_table_dumpable d1 >=20 > While I haven't traced through it in complete detail, what seems to > be happening is >=20 > A. checkExtensionMembership sees that the table belongs to an extension, > hence marks it >=20 > dobj->dump =3D ext->dobj.dump_contains & (DUMP_COMPONENT_ACL | > DUMP_COMPONENT_SECLAB= EL | > DUMP_COMPONENT_POLICY= ); >=20 > (This ends up setting only the SECLABEL and POLICY bits, I didn't > check why.) >=20 > B. processExtensionTables sees that the table is excluded by an exclusion > switch, so it sets configtbl->interesting =3D false. >=20 > (I've not verified whether B happens before or after A. But we definitely > end up with a TableInfo having dobj.dump =3D 40, interesting =3D false.) >=20 > C. getTableAttrs sees that the table is marked interesting =3D false, > so it doesn't bother loading any subsidiary data; particularly not > the checkexprs[] array. But ncheck is positive because getTables filled > it. >=20 > D. Since dobj.dump is non-zero, we eventually wind up at dumpTableSchema, > which crashes because checkexprs is NULL. It's a bit surprising that > it doesn't crash sooner, but whatever. We should absolutely not be in > that code at all for a table we didn't load all the subsidiary data for. >=20 > So I think the basic problem here is that checkExtensionMembership and > processExtensionTables are not on the same page. We can't have > interesting =3D false for a table that any of the dobj.dump bits are set > for. >=20 > Arguably, we should get rid of the "interesting" flag entirely now that > we have dobj.dump. I can't see that it's anything but a foot-gun. >=20 > Stephen, I think you touched this code last; any thoughts? I had contemplated trying to get rid of the 'interesting' flag but, my recollection anyway, is that it needed to be set sometimes even though dobj.dump wasn't. Has been a number of years though and either my memory or my review at the time might be faulty. I do agree with the general idea of trying to get rid of it though, and instead using dobj.dump to decide when we need to load additional info. In the end though, with this case at least, either way, we don't currently track what constraints are installed by the extension and what are installed by users after, and so we can't possibly recreate the object in the same way that the user has- if we include all CHECK constraints then we'll end up with duplicates for any that the extension created originally, and if we don't include any then the restored table will be missing any the user added. Ultimately, if getting rid of 'interesting' and replacing it with checking dobj.dump works, great, but that isn't going to actually make this case 'work' for the user, it'll just make pg_dump not crash (which is certainly good) but the added CHECK constraint will get lost. Thinking about it a bit more, I'd be inclined to argue that what we should really do here is mark tables created by extensions in a similar manner that system tables are- basically, if you try to ALTER them, you get an error unless you've set some extra bit that says you know what you're doing and that you understand your change will get lost if you dump/reload or pg_upgrade. Thanks, Stephen --R9dSeJxMIUBTi9Do Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v1 iQIcBAEBCgAGBQJffJxOAAoJEO1sijiDR2RVeywQAIFCR4a1ELc+sm/7zHQOpbIZ ShIhVvD8/rWlrSEK0s6UU8dPllOlfdro002ejBgskJpkHY2wJOsKwGAaDjxIxOMl c/PEbbShRLKor7EQfuNgmoYbv6+pg+MjdWwSUbRVatnR82+/8RzkHxYjFHA5IcR0 8s/Pvx/I7z/wqn/OjGr4pHSxPKgECxc96GK87krnlrms9cPgTUhKGc8wFH2gvRnM uNUEWrTADG4QqcaAbvPJeFlHA5wa9qI41ZcteokTivJ6T/jLQgX3LTtJaPCAlx63 +PRwVin0a6aTTxhNMn9gSdTLRNKtN+cuoiOsxSxravKeaJyqlrTGPTl5h5RPb4Ne vwKnrKSib1Q1bW+hp5ff9vt19AxUtCz5mCl9iLa1iOGb/bkcFhXgedwSC/SFroPA KH9uCjjG/gwLPK/LqLw0Yr3ODo9oRuMVl0bFmGjsRrHqrMzkeuTCWFCAWqvOOvSa a6ST6PqwBpZ0rr+i+wThgokFkXr5tAh06Bb/DDeU0YKU7x+nGQ9gHFumHddXcR0u oCOfuVFIpUJVZkAMxCC3A4hXpOZHMExZ8E9xYFCxY1CWLwFeBpL7T5A53/U9zH/Y gX3Z4mwi20E/v5ySX3EfX/T2kUw3d3lWzDV9r5sR/s1T68Y9gFiW1ZCocOuJ1olW EyGRDiaLcx8fhH8G/3rD =qUsB -----END PGP SIGNATURE----- --R9dSeJxMIUBTi9Do--