Segfault on logical replication to partitioned table with foreign children - Mailing list pgsql-hackers

From ilya.v.gladyshev@gmail.com
Subject Segfault on logical replication to partitioned table with foreign children
Date
Msg-id 6b93e3748ba43298694f376ca8797279d7945e29.camel@gmail.com
Whole thread Raw
Responses Re: Segfault on logical replication to partitioned table with foreign children
Re: Segfault on logical replication to partitioned table with foreign children
List pgsql-hackers
Hi,

Right now it is possible to add a partitioned table with foreign tables
as its children as a target of a subscription. It can lead to an assert
(or a segfault, if compiled without asserts) on a logical replication
worker when the worker attempts to insert the data received via
replication into the foreign table. Reproduce with caution, the worker
is going to crash and restart indefinitely. The setup:

Publisher on 5432 port:

CREATE TABLE parent (id int, num int);
CREATE PUBLICATION parent_pub FOR TABLE parent;

Subscriber on 5433 port:

CREATE EXTENSION postgres_fdw;
CREATE SERVER loopback foreign data wrapper postgres_fdw options (host
'127.0.0.1', port '5433', dbname 'postgres');
CREATE USER MAPPING FOR CURRENT_USER SERVER loopback;
CREATE TABLE parent (id int, num int) partition by range (id);
CREATE FOREIGN TABLE p1 PARTITION OF parent DEFAULT SERVER loopback;
CREATE TABLE p1_loc(id int, num int);
CREATE SUBSCRIPTION parent_sub CONNECTION 'host=127.0.0.1 port=5432
dbname=postgres' PUBLICATION parent_pub;

Then run an insert on the publisher: INSERT INTO parent VALUES (1, 1);

This will cause a segfault or raise an assert, because inserting into
foreign tables via logical replication is not possible. The solution I
propose is to add recursive checks of relkind for children of a target,
if the target is a partitioned table. I have attached a patch for this
and managed to reproduce this on REL_14_STABLE as well, not sure if a
patch for that version is also needed.

Kind Regards,
Ilya Gladyshev


Attachment

pgsql-hackers by date:

Previous
From: Julien Tachoires
Date:
Subject: Re: SUBTRANS: Minimizing calls to SubTransSetParent()
Next
From: David Zhang
Date:
Subject: Re: Error for WITH options on partitioned tables