Patroni and etcd - AWS Prescriptive Guidance

Patroni and etcd

We recommend Patroni as a solution for providing HA with automatic failover management. Patroni is an open-source automatic failover manager for PostgreSQL databases. You can use Patroni as a template to create your own customized HA solution by using Python and a distributed configuration store, such as etcd, for maximum accessibility.

Patroni also provides APIs to check the status of the PostgreSQL service and the roles of each DB instance or node. You must install Patroni on each DB instance for it to work with etcd (distributed configuration store).

By default, Patroni configures PostgreSQL for asynchronous replication. Choosing your replication method is dependent on your business considerations. Patroni is one of the best tools for setting up HA because it's highly configurable. Here are some of the advantages of using Patroni:

  1. It's easy to switch between different modes of replication (synchronous and asynchronous).

  2. Patroni has a rich REST API. Patroni uses this API for itself to perform failovers during the leader race by using HAProxy or another load balancer to perform HTTP health checks.

  3. Patroni must temporarily step down from managing the cluster, while still retaining the cluster state in the Distributed Configuration Store (DCS). For example, you don’t want a failover to happen during a manual maintenance window. Patroni offers pause and resume commands so that you can avoid unwanted downtime.

  4. To avoid the split-brain problem, Patroni must ensure that PostgreSQL won’t accept any transaction commits after the leader key expires in the DCS. Patroni also supports devices like Watchdog to avoid the split-brain problem. For more information on the split-brain problem and Watchdog, see Watchdog support in the Patroni documentation.

Architecture

The following diagram shows the architecture for setting up HADR for your on-premises PostgreSQL database on Amazon EC2 by using Patroni and etcd.

Patroni architecture

The diagram shows the following workflow:

  1. Create EC2 instances.

  2. Install a PostgreSQL database.

  3. Install and configure Patroni on EC2 instances.

  4. Create and configure a Network Load Balancer.

  5. Configure each PostgreSQL database in etcd (for Patroni) to get HA.

Considerations

We recommend that you consider the following before starting your migration by using Patroni:

  • Users must have PostgreSQL administration and DCS expertise to use Patroni.

  • Patroni has a steep learning curve and many configuration options to choose from.

  • You must have extra ports dedicated to Patroni.