Skip to content

Obtaining the cluster LEADER node

It may be useful to know the PostgreSQL cluster LEADER node without having to consult the logs. To do this, the following command run as root meets this need:

1
patronictl -c /etc/patroni/config.yml topology

Example

The result obtained should have the following form:

1
2
3
4
5
6
7
+ Cluster: 15-cleanroomvault5 ------+---------+---------+----+-----------+
| Member           | Host           | Role    | State   | TL | Lag in MB |
+------------------+----------------+---------+---------+----+-----------+
| PSQL_3           | psql_3         | Leader  | running | 2  |           |
| + PSQL_1         | psql_1         | Replica | running | 2  | 0         |
| + PSQL_2         | psql_2         | Replica | stopped | 2  | 0         |
+------------------+----------------+---------+---------+----+-----------+

In addition to giving the LEADER, the command also shows in the last column the number of MB of delay compared to the LEADER.
If a node has just stopped, the stopped status will be indicated. Note that in the event of a cluster node failure, this information will only be displayed temporarily before the node is removed from the list.