Patroni has a REST API that allows HAProxy and other kinds of load balancers to perform HTTP health checks. This blog post explains how HAProxy uses Health check endpoints with Patroni and how to debug the status issue.

HAProxy and Patroni setup:

Sample configuration:

 

 

  • OPTIONS /primary: This is the primary health check endpoint. The Patroni REST API returns HTTP status code 200 only when the Patroni node is running as the primary with leader lock.
  • OPTIONS /replica: Replica health check endpoint. Patroni REST API returns HTTP status code 200 only when the Patroni node is in the state running, the role is a replica, and noloadbalance tag is not set.

Here is the complete list of health check endpoints.

HAProxy and Patroni [WARNING] Server is DOWN, code: 503, info: “Service Unavailable”

In some cases, you might see the HAProxy startup giving the following warning.

Root cause

As the HAProxy Patroni REST API endpoints to get the node status with the node’s current role, adding all nodes like the below configuration will cause this Warning.

PG nodes role:

Haproxy http-check config:

When we add all PostgreSQL nodes under httpchk primary and replica, for a few node/s  Patroni REST API returns different status codes, for example, 503, as the node is running with a different role (Primary/Replica).
You can see these status code details in Patroni logs, as shown in the below example,

Enable DEBUG login for Patroni (patroni conf file) to see API response status messages.

Patroni debug log:

HAProxy Warnings:

All nodes, except the current primary/leader node, will show “DOWN” status for the /primary endpoint, and the current primary/leader node will show as “DOWN” for the /replica endpoint.

These [WARNING] messages are harmless & expected; connection via the haproxy port should work fine for the respective endpoint servers.

Further reading: https://patroni.readthedocs.io/en/latest/rest_api.html#health-check-endpoints

PostgreSQL Performance Tuning

Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments