[BUG] Logical replica crash if there was an error in a function.

From: "Anton A(dot) Melnikov" <aamelnikov(at)inbox(dot)ru>
To: PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Cc: Maxim Orlov <orlovmg(at)gmail(dot)com>
Subject: [BUG] Logical replica crash if there was an error in a function.
Date: 2022-08-21 14:33:57
Message-ID: b570c367-ba38-95f3-f62d-5f59b9808226@inbox.ru
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hello!

Here is a fix for the bug first described in:
https://www.postgresql.org/message-id/flat/adf0452f-8c6b-7def-d35e-ab516c80088e%40inbox.ru

Reproduction:
1) On master with 'wal_level = logical' execute mascmd.sql attached.

2) On replica substitute the correct port in repcmd.sql and execute it.

3) On master execute command:
INSERT INTO rul_rule_set VALUES ('1', 'name','1','age','true');

Replica will crash with:
FailedAssertion("ActivePortal && ActivePortal->status == PORTAL_ACTIVE", File: "pg_proc.c", Line: 1038, PID: 42894)
in infinite loop.

After applying this patch replica will give the correct error message instead of assertion:

2022-08-21 17:08:39.935 MSK [143171] ERROR: relation "rul_rule_set" does not exist at character 172
2022-08-21 17:08:39.935 MSK [143171] QUERY:
-- Last modified: 2022-08-21 17:08:39.930842+03
with parameters as (
<<--- skipped by me --- >>>
)
2022-08-21 17:08:39.935 MSK [143171] CONTEXT: SQL statement "create or replace function public.rule_set_selector(
<<--- skipped by me --- >>>
SQL statement "call public.rebuild_rule_set_selector()"
PL/pgSQL function public.rul_rule_set_trg() line 4 at CALL
processing remote data for replication origin "pg_16401" during "INSERT"
for replication target relation "public.rul_rule_set" in transaction 741 finished at 0/17BE180

With best regards,
--
Anton A. Melnikov
Postgres Professional: http://www.postgrespro.com
The Russian Postgres Company

Attachment Content-Type Size
mascmd.sql application/sql 277 bytes
repcmd.sql application/sql 2.6 KB
v1-0001-Fix-logical-replica-assert-on-func-error.patch text/x-patch 1.1 KB

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Anton A. Melnikov 2022-08-21 15:32:36 Re: [BUG] Logical replica crash if there was an error in a function.
Previous Message Zhihong Yu 2022-08-21 14:05:52 Re: including pid's for `There are XX other sessions using the database`