Stop and Resume pglogical Replication -PostgreSQL 12 - postgresql

I wanted to check if there is a way to stop and resume PostgreSQL replication using pglogical? For some reason, if either the publisher or subscriber needs to restart and go offline for sometime (or connectivity issues because of some n/w issues), is there a way to stop the replication and resume it again? I know it is not a relevant example but AWS DMS (which used Postgres native logical replication) gives you an option to stop/resume the replication. Wanted to check if there is a similar option available in pglogical.
Thanks

Sure there is. I presume You have pglogical extension installed and there is standard logical replication:
select pglogical.alter_subscription_disable('subscription_name');
You can use a WHERE clause to aim it specifically:
select pglogical.alter_subscription_disable(subscription_name) from pglogical.subscriptions where writer = 'name_of_writer';

Related

replication slot lag when using test_decoding plugin

I am using test_decoding plugin (have issues with pglogical plugin unable to detect the replication slot) on RDS Postgres 11. Replication slot lag seems to increase drastically (~33gb) even when there is no user activity.
As soon as I send DML operations from the application, I can see the data is replicated to the cutover and replication slot lag have come down to 224 bytes and restart_lsn/confirmed_flush_lsn value have changed.
Can you please advise why the slot piles up when there is no user activity?
Anyway to read what is the data in the slot? Also did anyone used this plugin in production.
I am using the following config:
max_wal_size=2GB
max_worker_process=21
max_wal_senders=15
max_parallel_workers=8
autovauum_max_workers=3

Is there a way during replication to turn off the automatic start of the backup server when the live server fails?

I have a Live - Backup pair with the replication HA policy. I would like to manage the replica startup myself when the live server fails, leaving only data replication between them. Is it possible to somehow achieve this behavior?
One of the main goals of the live/backup pair is failover (i.e. automatically starting the backup when the live fails). There is no way to disable this functionality and still use a live/backup pair.
However, you could potentially use a broker-connection with the "mirror" configuration to get the results you want.

Check postgresql replication

I have created a replicated Postgresql database (Master - Slave). I did this with an already existing Ansible Playbook (Role) , which I don't fully understand yet. The cluster currently consists of only 2 databases on different VMs.
So I want to test this replication now.
Unfortunately I have little experience with Postgresql.
How can I control whether they connect stable?
If the slave really takes over the task if the master should fail?
Many thanks for any information, tips & tricks.
Postgresql v. 9.6
Official PostgreSQL does not yet support automatic failover (Although there are multiple third-party projects which support this feature). Therefore if the deployment you have mentioned is only official PostgreSQL, after master failure, none of replicas take over the write task. But they can answer read queries if they are configured as hot_standby.
If you want to check the state of replication, in master you can check out pg_stat_replication in master.
Also these official docs would help you understand Postgres streaming replication & failover better:
https://www.postgresql.org/docs/9.6/warm-standby.html#STREAMING-REPLICATION
https://www.postgresql.org/docs/9.6/warm-standby-failover.html

PostgreSQL Slony replication - scheduled sync

I am migrating Oracle database into Postgres and I need to implement replication of the master database to multiple slave dbs. The replication should be executed once a day at specified time (to take the load off the dbs) and only replicate the data that was changed.
I am trying to achieve that using Slony - it seems to do what I need except it syncs the data in short intervals. I haven't been able to find any information on how to configure Slony for scheduled sync, is it even possible?
Or do I have to launch slon daemons at desired time and then kill them using some script/scheduler?
Yes, you can specify lag_interval to set sync within specified interval, here is the documentation . You can specify this option for Slony daemon with -l option.

Which PostgreSQL replication solution to use for my specific scenario

I need to replicate a PostgreSQL database server as follows:
Two servers are adjacent to each-other - one is the master and the other standby. If the master fails, the standby takes over. Replication from master to slave needs to be failsafe, hence, synchronous. The standby will not be used for any querying unless it has become a master. So, no high-availability/load-balancing is required.
There is another backup server at a remote location. Data from the master server mentioned above will be replicated to this remote server asynchronously and in batches. Time is not a factor at all in this replication - a couple of hours is just fine. This server would be used just for backup.
I've studied the currently available replication solutions from the PostgreSQL docs as well as from Google, but can't decide which combination of synchronous-asynchronous solutions would I need.
The closest I came up with is using pgpool-II for scenario 1 and Mammoth for scenario 2. However, as pgpool is statement-based, what would happen to queries containing rand() and now()?
Please note that I'd rather use free and open-source replication tools.
Also, just a side question - according to scenario 1 above, when the master fails, the standby will take over. Would the master-slave role be reversed after that, or would after the recovery of the master server the slave would go back to its standby state?
Any suggestion would be highly appreciated. Thanks.
I suggest using DRBD for scenario 1 and either 9.0 built-in replication or Slony for scenario 2.
Before PostgreSQL 9.1 (not yet released), there is no other synchronous replication solution available, and DRBD is widely established for this purpose. Together with Pacemaker or Heartbeat, which come with all the scripts needed for PostgreSQL monitoring and switchover, you have a very robust and fairly easy to manage solution. (In fact, I'd consider continuing to use DRBD even after 9.1 comes out; it's just a lot easier and has a longer track record.)
For the cross-site asynchronous, you could try the built-in replication of PostgreSQL 9.0, perhaps in conjunction with repmgr for monitoring and management. Alternatively, you could try the (now a bit) old-school Slony, but I'd guess it will more complicated for your needs.
You didn't mention if the server in question was on a specific version or if this was a new project with the freedom to choose the version. The answers vary based on that information.
If you are starting with a clean slate, I would recommend designing based on the PostgreSQL 9.1 beta. The final version will be released long before you would be ready to go into a production environment and it has binary synchronous replication built-in.
I've been using the built-in asynchronous replication in PostgreSQL for years in almost the exact same scenario you describe and it has always been rock-solid for me. It's become even better with 9.0 with Hot standby and it's become much easier to configure and maintain. 9.1 provides the only missing piece you require.
However, if you are trying to replicate an existing server, built-in asynchronous replication with aggressive settings for "checkpoint_timeout" a very frequent backup of unarchived WAL files could be sufficient until you can upgrade to 9.1.
The bottom line here is that you can get exactly what you want is with stock PostgreSQL 9.1--no third-party products required.
As for failover, it is not an automatic process, you'll need to handle that yourself. I would recommend that after a failover, switching the roles of the two machines until either the next failover event or until a controlled manual failover during a scheduled outage during a slow period of use. Again, this is not automatic and much be managed by the administrator (via shell scripts, presumably).