Idea to skip initial copy of logical replication by using a backup taken by continuous archiving. The original idea is from this post.
Steps
Note: This is just an idea and not tested yet.
- create a publication and a replication slot
- create a backup by continuous archiving (pg_basebackup + WAL archiving)
- restore the DB by Point-In-Time Recovery
- check the latest LSN
SELECT pg_current_wal_lsn();
- create a subscription without a replication slot
- With options
copy_data = false, create_slot = false, enabled = false
- With options
- advance the replication slot to sync with the subscriber
pg_replication_origin_advance
- enable the subscription and drain WALs