I am experiencing an issue where the triggers on my logical replication instance are not working.
Context:
I have 2 AWS RDS Postgres(v14.5) instances: A (the writer) and B (which has a table “Journals” which is being logically replicated from A to B).
My ultimate goal is to populate an audit log table on B for “Journals” whenever a change occurs. My idea is that when a change occurs on A, logical replication will propagate that change to B, and then a trigger (defined on B) will fire and fill in an audit log table entry on B with details of the change.
I tested out the logical replication by making a change in A.”Journals”, and I know it works because I see those changes get replicated on the B.”Journals” table.
I also defined my trigger on B, and I know that’s working in some sense because I made a manual change in B.”Journals” and a row was created in the audit log table by the trigger.
Problem:
However, when a change to B.”Journals” is made due to logical replication (after a change in A.”Journals” occurs), an entry in the audit log is not created. Which suggests the trigger is not firing.
To fix this, I tried enabling the trigger with ALTER TABLE Journals ENABLE ALWAYS TRIGGER journals_trigger;
as suggested in this post. However, this stopped the logical replication from working at all (after running this command, when I make a change in A.”Journals” it no longer gets updated in B.”Journals”; I have to drop the trigger to get the logical replication working again).
Does anyone know why enabling the trigger with Alter Table
is breaking the logical replication?
Thank you for any help.
“A” Config:
“B” Config: