0

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

  1. disable the subscriber on SOR DB
  2. rename the (receiving) table on SOR DB
  3. rename the table on main DB, also add the tables to the publication
  4. re-enable subscriber on SOR DB
  5. 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:

  1. we use PG 14 on AWS RDS
  2. The reason for this change is we are migrating a parent-child table into a partitioned table
  3. 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.
asked May 9, 2024 at 16:34

1 Answer 1

0

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.

answered May 10, 2024 at 7:10
2
  • 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 ? Commented 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. Commented May 12, 2024 at 18:21

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.