Segfault when a replica trigger tries to refresh subscription

From: Jeremy Finzel <finzelj(at)gmail(dot)com>
To: pgsql-bugs(at)postgresql(dot)org
Subject: Segfault when a replica trigger tries to refresh subscription
Date: 2020-11-11 18:23:06
Message-ID: CAMa1XUh7ZVnBzORqjJKYOv4_pDSDUCvELRbkF0VtW7pvDW9rZw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

Greetings!

I have found that executing ALTER SUBSCRIPTION foo REFRESH PUBLICATION from
a replica trigger running under the same subscription foo causes a
segfault. I have only attempted to reproduce this on pg 11.9.

To reproduce:
Publisher:
CREATE PUBLICATION foo;
CREATE TABLE bar (id serial primary key);
GRANT SELECT ON TABLE bar TO replication_role;
ALTER PUBLICATION foo ADD TABLE bar;

Subscriber:
CREATE TABLE bar (id serial primary key);
CREATE SUBSCRIPTION foo CONNECTION 'host=localhost dbname=foo port=5432
user=replication_role password=foo' PUBLICATION foo;
CREATE FUNCTION refresh_sub() RETURNS TRIGGER AS $BODY$
BEGIN
ALTER SUBSCRIPTION foo REFRESH PUBLICATION;
RETURN NEW;
END;
$BODY$
LANGUAGE plpgsql;
CREATE TRIGGER refresh_sub
BEFORE INSERT ON bar
FOR EACH ROW EXECUTE PROCEDURE refresh_sub();
ALTER TABLE bar ENABLE REPLICA TRIGGER refresh_sub;

Now on provider, this will create a segfault on subscriber:
INSERT INTO bar (id) VALUES (1);

Logs:
2020-11-11 18:14:09.535 GMT,,,21636,,5fa58af6.5484,8583,,2020-11-06
17:42:14 GMT,,0,LOG,00000,"background worker ""logical replication worker""
(PID 24492) wa
s terminated by signal 11: Segmentation fault",,,,,,,,,""
2020-11-11 18:14:09.535 GMT,,,21636,,5fa58af6.5484,8584,,2020-11-06
17:42:14 GMT,,0,LOG,00000,"terminating any other active server
processes",,,,,,,,,""
2020-11-11 18:14:09.535 GMT,,,22766,,5fac286d.58ee,1,,2020-11-11 18:07:41
GMT,1/0,0,WARNING,57P02,"terminating connection because of crash of another
server p
rocess","The postmaster has commanded this server process to roll back the
current transaction and exit, because another server process exited
abnormally and
possibly corrupted shared memory.","In a moment you should be able to
reconnect to the database and repeat your command.",,,,,,,""
2020-11-11 18:14:09.537 GMT,,,21636,,5fa58af6.5484,8585,,2020-11-06
17:42:14 GMT,,0,LOG,00000,"all server processes terminated;
reinitializing",,,,,,,,,""

I have been working on adding support for native logical replication to
pgl_ddl_deploy, and this is the reason for the above command which executes
from a ddl queue table. The purpose is to automatically add new tables to
replication which is not possible to do only from the provider with native
logical replication as it is with pglogical.

Thanks,
Jeremy

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message Bruce Momjian 2020-11-11 19:54:30 Re: BUG #16708: Please add some more restrictions to the default systemd unit files
Previous Message Tom Lane 2020-11-11 16:47:13 Re: BUG #16710: Deprecated timezone