Sobes.tech
Middle+

How to configure master node selection in Patroni if one node is weaker and should not become primary?

sobes.tech AI

Answer from AI

In Patroni, you can configure the primary (master) selection priority using the tags parameter in each node's configuration. To prevent a node with fewer resources from becoming primary, you can assign it a tag with a low priority, for example:

 tags:
  nofailover: true
  noloadbalance: true
  clonefrom: false
  # or explicitly specify a low priority
  primary_priority: 0

The main parameter is primary_priority (an integer value, default is 100). Nodes with a higher value have a greater priority for selection as primary. Set primary_priority: 0 or another low value on a weak node so Patroni does not select it as the master during failover.

Example configuration for a weak node:

scope: my_cluster
name: weak_node
restapi:
  listen: 0.0.0.0:8008
  connect_address: 10.0.0.3:8008
etcd:
  host: 10.0.0.1:2379
postgresql:
  listen: 0.0.0.0:5432
  connect_address: 10.0.0.3:5432
  data_dir: /var/lib/postgresql/data
tags:
  primary_priority: 0

Thus, when choosing the primary, Patroni will prefer nodes with a higher primary_priority, excluding the weak node from candidate masters.