Hello
Ilian Kostadinov,
Here’s how you can achieve this without needing to sync all data from the beginning:
Make sure logical replication is enabled on Server B. In your postgresql.conf, set the following parameters on Server B:
wal_level = logical
max_replication_slots = <desired number>
max_wal_senders = <desired number>
Restart PostgreSQL on Server B for these changes to take effect.
On Server B, create a publication for the tables you want to replicate:
CREATE PUBLICATION my_publication FOR ALL TABLES;
If you need specific tables, adjust the query accordingly.
Create a logical replication slot on Server B. This slot will be used by Server C to stream changes:
SELECT * FROM pg_create_logical_replication_slot('my_slot', 'pgoutput');
On Server C, create a subscription to the publication on Server B:
On Server C, create a subscription to the publication on Server B:
CREATE SUBSCRIPTION my_subscription
CONNECTION 'host=<Server B IP> dbname=<dbname> user=<replication_user> password=<password>'
PUBLICATION my_publication
WITH (copy_data = false);
The WITH (copy_data = false) clause is crucial because it prevents Server C from copying all the data from scratch, which would be inefficient given your 50TB database size. Instead, it will start replicating changes from the point when the subscription is created.
Since you're skipping the initial data copy, you need to ensure that the data on Server C is in sync with Server B. If Server C was already a streaming replica of Server B, this should already be the case.
However, if any discrepancies exist, you may need to manually sync specific tables or sequences.
Best Regards,
Asad Ali