pglogical icon indicating copy to clipboard operation
pglogical copied to clipboard

TRUNCATE not replicated when executed with session_replication_role='replica'

Open gargii opened this issue 5 years ago • 5 comments

pglogical 2.1.1, postgresql 10.5

We have setup replication on table trunc_test between two databases. It works well except for TRUNCATE.

It does not replicate to target database when executed in 'replica' role:

set session_replication_role = 'replica';
truncate trunc_test;
set session_replication_role = 'origin';

This is replicates just fine

truncate trunc_test;

INSERTs, UPDATEs and DELETEs are replicated both in 'replica' and 'origin' roles.

So far we have worked around this by creating a trigger in the source datbase which executes DELETE from trunc_test before the TRUNCATE trunc_test is executed.

But in a long term we need pglogical to be consistent in handling TRUNCATE.

gargii avatar Apr 03 '19 13:04 gargii

That's expected in PG10, we use trigger for replication of truncates. Long term it's solved in PG11.

PJMODOS avatar May 08 '19 15:05 PJMODOS

How do you know this is expected? Can't find any information about this...

gargii avatar May 09 '19 07:05 gargii

Triggers are not executed with session_replication_role = 'replica' that's documented in postgres manual. We have to use trigger on PG10 and older for supporting TRUNCATE replication, because logical decoding of TRUNCATE was added in PG11 (well, pglogical 2 uses trigger even on PG11 currently, which is why I am keeping this open).

PJMODOS avatar May 09 '19 12:05 PJMODOS

OK, so to fix the issue we must migrate to PG11 and use pglogical 3, which is not freely available now. Am I right? Will you open source pglogical 3 any time soon?

gargii avatar May 23 '19 11:05 gargii

@PJMODOS Do you have any update here? Pglogical 3 still not released. Any chance you backport it to the 2.x branch?

gargii avatar Apr 19 '21 19:04 gargii