lordav
lordav

Reputation: 187

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 ?

Upvotes: 3

Views: 1971

Answers (2)

jjanes
jjanes

Reputation: 44343

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"?

Upvotes: 0

Richard Huxton
Richard Huxton

Reputation: 22952

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.

Upvotes: 0

Related Questions