On Fri, Nov 29, 2019 at 11:06 AM Florian Philippon <florian.philippon@xxxxxxxxxxxx> wrote:
We tried another solution: we loaded a minimal schema (without indexes and constraints) on the subscriber and created the subscription. The initial copy phase was way faster (a few hours). Then we created indexes and constraints. Is this a suitable solution for production?
This is probably not suitable for production. Once the COPY is finished, it still has to replicate row-by-row changes to the table rows which occurred since the starting COPY snapshot. UPDATEs and DELETEs will probably fail due to the lack of indexes on the “replica identity” columns. This failure will make the entire transaction, including the COPY, roll back to beginning. So you there will be no point at which you can build the missing indexes without first losing all the work that was done. If the master was quiescent (at least in regards to UPDATEs and DELETEs) then it there will be no row-by-row changes to apply between the start of the COPY and the start of transactional replication. In that case, the COPY will have committed before the system discovers the problem with the “replica identity”, giving you an opportunity to go build the index without losing all of the work.
Will the logical replication flow be buffered by the replication slots during index creation and get in sync afterwards or will it conflict due to locking issues?
It can't buffer in the middle of the transaction which includes the initial COPY.
Cheers,
Jeff