From: | ilya(dot)v(dot)gladyshev(at)gmail(dot)com |
---|---|
To: | pgsql-hackers(at)lists(dot)postgresql(dot)org |
Subject: | Segfault on logical replication to partitioned table with foreign children |
Date: | 2022-10-28 19:31:09 |
Message-ID: | 6b93e3748ba43298694f376ca8797279d7945e29.camel@gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | 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 | Content-Type | Size |
---|---|---|
0001-check-relkind-of-subscription-target-recursively.patch | text/x-patch | 5.2 KB |
From | Date | Subject | |
---|---|---|---|
Next Message | David Zhang | 2022-10-28 21:21:18 | Re: Error for WITH options on partitioned tables |
Previous Message | Julien Tachoires | 2022-10-28 17:24:47 | Re: SUBTRANS: Minimizing calls to SubTransSetParent() |