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 ?
Question posted in PostgreSQL
The official documentation can be found here.
The official documentation can be found here.
2
Answers
https://www.postgresql.org/docs/current/logical-replication-architecture.html#LOGICAL-REPLICATION-SNAPSHOT
It takes a snapshot of the existing data at the beginning for you.
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"?