[Bucardo-general] Foreign key consistency

Hans van der Riet hans at electude.nl
Thu Sep 19 16:21:47 UTC 2013


Hi,

I'm new to Bucardo and like it so far. I have however a question about 
the consistency of foreign keys. Consider these two simple tables with 
master/master replication (Bucardo 5 / Psql 9.1):

create table parent (
         id      serial,
         name    text,
         primary key (id)
);
create table child (
         id      serial,
         name    text,
         parent  int,
         foreign key (parent) references parent(id) on delete cascade,
         primary key (id)
);

After adding a row to each table the database looks like this:

foo=> select * from parent;
  id | name
----+------
   1 | p
(1 row)

foo=> select * from child;
  id | name | parent
----+------+--------
   1 | c    |      1
(1 row)

Now in one database ('foo') I delete the parent row, and then 
immediately (before replication kicks in) update the child in the other 
database ('bar'):

foo=> delete from parent where id = 1;
DELETE 1
foo=> \c bar
You are now connected to database "bar" as user "dba".
bar=> update child set name = 'newc' where id = 1;
UPDATE 1

After Bucardo finishes replication the child row still exists, because 
the conflict strategy is set to 'latest'. This is the result (in both 
databases):

bar=> select * from parent;
  id | name
----+------
(0 rows)

bar=> select * from child;
  id | name | parent
----+------+--------
   1 | newc |      1
(1 row)


The database is no longer consistent, the foreign key constraint is 
violated since the parent has been deleted.

Is there any way to avoid / resolve this type of inconsistency?

Kind regards,
-- 
Hans van der Riet



More information about the Bucardo-general mailing list