Logical replication failing when foreign key present

From: Thom Brown <thom(at)linux(dot)com>
To: PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Logical replication failing when foreign key present
Date: 2017-01-22 17:50:28
Message-ID: CAA-aLv5WRQbfxdR_ha=tR_ghuS00pezr1ymia6WNMeO7hUDeLQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi,

There's an issue which I haven't seen documented as expected
behaviour, where replicating data to a table which has a foreign key
results in a replication failure. This produces the following log
entries:

LOG: starting logical replication worker for subscription "contacts_sub"
LOG: logical replication apply for subscription "contacts_sub" has started
ERROR: AfterTriggerSaveEvent() called outside of query
LOG: worker process: logical replication worker for subscription
16408 (PID 19201) exited with exit code 1

Reproducible test case:

On both instances:

CREATE TABLE b (bid int PRIMARY KEY);
CREATE TABLE a (id int PRIMARY KEY, bid int REFERENCES b (bid));
INSERT INTO b (bid) VALUES (1);

First instance:
CREATE PUBLICATION a_pub FOR TABLE a;

Second instance:
CREATE SUBSCRIPTION a_sub CONNECTION 'host=127.0.0.1 port=5530
user=thom dbname=postgres' PUBLICATION a_pub;

First instance:
INSERT INTO a (id, bid) VALUES (1,1);

Regards

Thom

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Tom Lane 2017-01-22 18:58:32 Re: PATCH: recursive json_populate_record()
Previous Message Stephen Frost 2017-01-22 15:45:49 Re: new autovacuum criterion for visible pages