Can logical replication be stopped anytime I want?

317 views Asked by At

I have two databases in different servers and data streaming from one server (X database) to another server (Y database) with the help of logical replication.

My question is the following: is there any way to stop logical replication any time I want (for example for 20 minutes) and then enable it again? Or maybe switch between logical replication and foreign data wrapper. I want to do this over the website I have built.

1

There are 1 answers

0
Laurenz Albe On

You can pause logical replication with

ALTER SUBSCRIPTION name DISABLE;

and resume it with

ALTER SUBSCRIPTION name ENABLE;

While replication is disabled, the replication slot on the publisher makes the publisher retain all the WAL that is necessary for the subscriber to catch up, and the subscriber will do so automatically when you enable the subscription again. The danger is not that the subscriber can lose data, but that the publisher's disk can run full if the subscription is disabled for too long.