Search code examples
databasepostgresqlwallogical-replication

PostgreSQL logical replication - Copy of the initial data


I'm starting from a scenario where a PostgreSQL instance is not configured for logical replication and has a table T with X rows. Now, when I'll enable the logical replication, create a replication_slot and a publication for the table T then every change on the table is published and can be consumed. But what about the first X rows existing on the table T before the logical replication starts ? How can I transform these rows in events that can be consumed by the subscribers ? Or how can I import these rows before the logical replication starts ?


Solution

  • If you are not using CREATE SUBSCRIPTION, then you will need to handle the initial snapshot for yourself. Either query all the existing data, or start replication on an empty table and copy the existing data into that table from someplace else.

    I think that using 'pgoutput' but not using CREATE SUBSCRIPTION is a bit suspect. They were designed to work together. There are other decoding plugins, maybe one of them would be better suited for being used by a "typescript client"?