Search code examples
postgresqltriggersreplicationterminatepglogical

pglogical: REPLICA TRIGGER before delete causes database corruption


I'm experimenting with a 2-node bidirectional replication using pglogical-9.6. I'm able to consistently cause a seg fault when I set pglogical.conflict_resolution = 'last_update_wins'.

I'm create a BEFORE DELETE TRIGGER to prevent insertion some values into replicated table.

CREATE  TRIGGER TR_REP BEFORE DELETE
ON table_for_repl
FOR EACH ROW
EXECUTE PROCEDURE check_value();

CREATE OR REPLACE FUNCTION public.check_value()
  RETURNS trigger AS
$BODY$
BEGIN
 IF OLD."origin"::text =  'test' then
   RETURN OLD;
 ELSE
   RETURN Null;
 END IF;  
END;
$BODY$
  LANGUAGE plpgsq;

This trigger works fine for a normal delete operation. When I turn it on for replication (ALTER TABLE table_for_repl ENABLE REPLICA TRIGGER TR_REP;) and I reproduce the situation when the trigger should prevent insertion (i.e. the function will return Null).. I get:

background worker "pglogical apply 16384:1892658794" (PID 4250) was terminated by signal 11: Segmentation fault.
terminating any other active server processes
recovered replication state of node 1 to 0/1764C38
database system was not properly shut down; automatic recovery in progress

Error is repeated on pglogical-11


Solution

  • A segmentation fault is always a bug unless it is caused by hardware problems or data corruption.

    You should file a bug with 2ndQuadrant; it is their software.

    Make sure to include the reproducer with the bug report.