pgcopydb icon indicating copy to clipboard operation
pgcopydb copied to clipboard

Add logical replication as an alternative follow mode

Open marcocitus opened this issue 2 years ago • 3 comments

For migration scenarios where the source is at PostgreSQL 10 or newer, it would be useful if pgcopydb follow mode could use logical replication (CREATE PUBLICATION & CREATE SUBSCRIPTION).

A benefit of using logical replication is that tables can be added over time, even after the initial snapshot. A new snapshot & replication slot are used for each table, after initial data copy the changes for that table are consumed separately, and then the table is handed off to the main apply worker. Another benefit is that the apply side is relatively efficient.

marcocitus avatar Jul 12 '23 13:07 marcocitus

If we chose SUBSCRIPTION on target side then we would lose the benefit of prefetch. Sort of a tradeoff between simplicity of Logical Replication and benefits of prefetch. Which might be fine for smaller databases where offline copy doesn't take much time. I haven't much used Logical Replication, but IIUC we won't be able to set endpos for follow mode in pgcopydb. So it might be completely different follow mode.

shubhamdhama avatar Dec 12 '23 12:12 shubhamdhama

If we chose SUBSCRIPTION on target side then we would lose the benefit of prefetch. Sort of a tradeoff between simplicity of Logical Replication and benefits of prefetch. Which might be fine for smaller databases where offline copy doesn't take much time.

See https://www.postgresql.org/docs/current/sql-createsubscription.html#SQL-CREATESUBSCRIPTION-WITH : we can also use the option copy_data and include the initial COPY of the data within the logical replication framework, and let Postgres handle the prefetch trade-offs.

dimitri avatar Dec 12 '23 13:12 dimitri

I can start with the simplest approach of create publication/subscription using FOR ALL TABLES, then we can iterate on this for non-super user. For the latter I'm trying out combinations of multiple publication-subscription and investigating it's performance vs for-all-tables.

shubhamdhama avatar Dec 28 '23 10:12 shubhamdhama