[BUG] Logical replica crash if there was an error in a function. - Mailing list pgsql-hackers

From Anton A. Melnikov
Subject [BUG] Logical replica crash if there was an error in a function.
Date
Msg-id b570c367-ba38-95f3-f62d-5f59b9808226@inbox.ru
Whole thread Raw
Responses Re: [BUG] Logical replica crash if there was an error in a function.
List 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

pgsql-hackers by date:

Previous
From: Zhihong Yu
Date:
Subject: Re: including pid's for `There are XX other sessions using the database`
Next
From: "Anton A. Melnikov"
Date:
Subject: Re: [BUG] Logical replica crash if there was an error in a function.