Optimization of vacuum for logical replication - Mailing list pgsql-hackers

From Konstantin Knizhnik
Subject Optimization of vacuum for logical replication
Date
Msg-id 3a833bdb-2696-2294-9ee2-f7a8deaae707@postgrespro.ru
Whole thread Raw
Responses Re: Optimization of vacuum for logical replication  (Bernd Helmle <mailings@oopsware.de>)
List pgsql-hackers
Hi, hackers.

Right now if replication level is rgeater or equal than "replica", 
vacuum  of relation copies all its data to WAL:


     /*
      * We need to log the copied data in WAL iff WAL archiving/streaming is
      * enabled AND it's a WAL-logged rel.
      */
     use_wal = XLogIsNeeded() && RelationNeedsWAL(NewHeap);

Obviously we have to do it for physical replication and WAL archiving.
But why do we need to do so expensive operation (actually copy all table 
data three times) if we use logical replication?
Logically vacuum doesn't change relation so there is no need to write 
any data to the log and process it by WAL sender.

I wonder if we can check that

1. wal_revel is "logical"
2. There are no physical replication slots
3. WAL archiving is disables

and in this cases do not write cloned relation to the WAL?
Small patch implementing such behavior is attached to this mail.
It allows to significantly reduce WAL size when performing vacuum at 
multimaster, which uses logical replication between cluster nodes.

What can be wrong with such optimization?

-- 

Konstantin Knizhnik
Postgres Professional: http://www.postgrespro.com
The Russian Postgres Company


Attachment

pgsql-hackers by date:

Previous
From: Konstantin Knizhnik
Date:
Subject: Re: Global temporary tables
Next
From: Bernd Helmle
Date:
Subject: Re: Optimization of vacuum for logical replication