patroni / patroni

A template for PostgreSQL High Availability with Etcd, Consul, ZooKeeper, or Kubernetes
MIT License
6.77k stars 843 forks source link

Patroni with Two DataCenters and sync/async replication #2157

Closed OriRub closed 2 years ago

OriRub commented 2 years ago

Hi,

I am implementing a Patroni PostgreSQL cluster between two data centers. I would like to have the Leader and one sync Standby on DC1 and remote async replica on DC2 with a sync replica for it in order to have HA for the second DC.

I am using the Patroni synchronous_mode: true, however it seems that there is no distinguish between the datacenters and mode of replication.

How can I achieve such a desired mode of replication between Data Center and inside each Data Center ? Is it something that Patroni can managed with the synchronous_mode, or requires the PostgreSQL replication parameters ?

Thanks,

Ori

CyberDem0n commented 2 years ago

https://patroni.readthedocs.io/en/latest/SETTINGS.html#tags

tags.nosync allows to exclude replica from being synchronous

OriRub commented 2 years ago

https://patroni.readthedocs.io/en/latest/SETTINGS.html#tags

tags.nosync allows to exclude replica from being synchronous

OriRub commented 2 years ago

Hi,

Thanks!!!! that can assist for sure.

Few additional questions:

1. The config I would like to achieve is: DC1: Master ans Sync Replica

DC2: ASync Replica for Master on DC1 cascade Sync Replica to first Replica in DC2

Is it possible to achieve that with Patroni ? Or, should I have two ASync Replicas in DC2 from Master on DC1 ?

2. When we have Sync and ASync Replicas, in case of failover, which one will Patroni favor ? Will it always favor the Sync over ASync ? What if DC1 is completely down and all that left is DC2 with two ASync replication, will the Failover be automatically ? (*) considering that there is always a quruom for etcd.

Thanks,

Ori

CyberDem0n commented 2 years ago

The documentation https://patroni.readthedocs.io has all the answers. Also, I would really recommend you:

  1. Go through Patroni tutorial slides: https://github.com/patroni-training/2019
  2. Deploy a test setup and play with it.

It will give your more understanding and confidence than just blindly asking questions.

ronbarak commented 1 year ago

Did you manage to do what you wanted, OriRub?

Because, reading through the patroni (HA multi-datacentre) documentation, I gather that to implement failover between multiple datacentres (IOW, to have a multi datacentre (DC) cluster that can automatically tolerate a zone drop) using Synchronous Replication, then a minimum of three data centres is required.

CongSon commented 11 months ago

hi @OriRub , did you implement successfully? Can you share your solution?