Re: Cannot dump foreign key constraints on partitioned table
Michael Paquier <michael@paquier.xyz>
From: Michael Paquier <michael@paquier.xyz>
To: amul sul <sulamul@gmail.com>
Cc: PostgreSQL-development <pgsql-hackers@postgresql.org>
Date: 2018-07-12T03:48:14Z
Lists: pgsql-hackers
Attachments
- dump-partition-fk.patch (text/x-diff) patch
On Wed, Jul 11, 2018 at 03:49:59PM +0530, amul sul wrote: > On the master head, getConstraints() function skips FK constraints for > a partitioned table because of tbinfo->hastriggers is false. > > While creating FK constraints on the partitioned table, the FK triggers are only > created on leaf partitions and skipped for the partitioned tables. Oops. Good catch. > To fix this, either bypass the aforementioned condition of getConstraints() or > set pg_class.relhastriggers to true for the partitioned table which doesn't seem > to be the right solution, IMO. Thoughts? Changing pg_class.relhastriggers is out of scope because as far as I know partitioned tables have no triggers, so the current value is correct, and that would be a catalog change at this stage which would cause any existing deployments of v11 to complain about the inconsistency. I think that this should be fixed client-side as the attached does. I have just stolen this SQL set from Alvaro to check the consistency of the dumps created: create table prim (a int primary key); create table partfk (a int references prim) partition by range (a); create table partfk1 partition of partfk for values from (0) to (100); create table partfk2 partition of partfk for values from (100) to (200); Thoughts? -- Michael
Commits
-
Dump foreign keys on partitioned tables
- 2af39c39df94 11.0 landed
- 93ad00c968ae 12.0 landed