Hi

I met a problem in synchronous logical replication. The client hangs when 
TRUNCATE TABLE at publisher.

Example of the procedure:
------publisher------
create table test (a int primary key);
create publication pub for table test;

------subscriber------
create table test (a int primary key);
create subscription sub connection 'dbname=postgres' publication pub;

Then, set synchronous_standby_names = 'sub’  on publisher, and reload publisher.

------publisher------
truncate test;

Then the client of publisher will wait for a long time. A moment later, the 
publisher and subscriber will report following errors.
Subscriber log
2021-04-07 12:13:07.700 CST [3542235] logical replication worker ERROR:  
terminating logical replication worker due to timeout
2021-04-07 12:13:07.722 CST [3542217] postmaster LOG:  background worker 
"logical replication worker" (PID 3542235) exited with exit code 1
2021-04-07 12:13:07.723 CST [3542357] logical replication worker LOG:  logical 
replication apply worker for subscription "sub" has started
2021-04-07 12:13:07.745 CST [3542357] logical replication worker ERROR:  could 
not start WAL streaming: ERROR:  replication slot "sub" is active for PID 
3542236
Publisher log
2021-04-07 12:13:07.745 CST [3542358] walsender ERROR:  replication slot "sub" 
is active for PID 3542236
2021-04-07 12:13:07.745 CST [3542358] walsender STATEMENT:  START_REPLICATION 
SLOT "sub" LOGICAL 0/169ECE8 (proto_version '2', publication_names '"pub"')

I checked the PG-DOC, found it says that “Replication of TRUNCATE commands is 
supported”[1], so maybe TRUNCATE is not supported in synchronous logical 
replication? 

If my understanding is right, maybe PG-DOC can be modified like this. Any 
thought?
Replication of TRUNCATE commands is supported
->
Replication of TRUNCATE commands is supported in asynchronous mode

[1]https://www.postgresql.org/docs/devel/logical-replication-restrictions.html

Regards,
Tang


Reply via email to