We have a table in main DB that is getting logically replicated to another DB called SOR. We need to rename this table, and add a bunch of tables to the publication on the main DB. I tried this procedure
- disable the subscriber on SOR DB
- rename the (receiving) table on SOR DB
- rename the table on main DB, also add the tables to the publication
- re-enable subscriber on SOR DB
- refresh the subscription
ALTER SUBSCRIPTION my_subscription REFRESH PUBLICATION WITH (copy_data=false);
I waited for the replication slot on main DB to clear up, and then checked record count, SOR DB lost some data in this time window. Is there a seamless way to rename a table in logical replication without losing data on the subscriber side ? Would (copy_data=true)
help ?
Thank you !
some more details:
- we use PG 14 on AWS RDS
- The reason for this change is we are migrating a parent-child table into a partitioned table
- The said table (to be renamed) is close to 6 TB, and the DB is our live production database, so we would like to avoid copying this table over from scratch.
1 Answer 1
You should rename the table on the publisher first, then add the renamed table to the publication. Then run ALTER SUBSCRIPTION ... REFRESH PUBLICATION WITH (copy_data = off)
on the subscriber and wait until you get a replication conflict because the renamed table does not exist on the subscriber. Then rename the table on the subscriber, and logical replication should be able to catch up.
-
thank you Laurenz, appreciate your help ! a few follow up questions: (1) I suppose there is no need to disable and re-enable the logical replication on the subscriber side ? (2) Just to confirm, your suggestion will not cause data loss on the subscriber side, right ?hxcb– hxcb2024年05月10日 20:11:11 +00:00Commented May 10, 2024 at 20:11
-
I don't think you have to disable and re-enable the subscription. This should work without data loss, but please test, there is always the possibility that I missed something.Laurenz Albe– Laurenz Albe2024年05月12日 18:21:45 +00:00Commented May 12, 2024 at 18:21
Explore related questions
See similar questions with these tags.