Patroni — Complete Guide
Patroni — Complete Guide: free step-by-step lesson with examples, common mistakes, and interview tips — part of PostgreSQL Tutorial on Toolliyo Academy.
On this page
PostgreSQL Tutorial · Lesson 66 of 100
Patroni
SQL ✓ → Advanced
Advanced · 2 — Production · ~10 min · PostgreSQL — Replication & High Availability
What is this?
Patroni is HA template using DCS (etcd, Consul, Kubernetes) to manage PostgreSQL leader, replicas, failover, and configuration — replaces manual promote scripts.
Why should you care?
PostgresVerse K8s cluster runs Patroni so pod death auto-elects new primary without pager at 3 AM.
See it live — copy this example
Run in pgAdmin or psql.
# patronictl cluster overview (CLI output concept)
patronictl -c /etc/patroni.yml list
# SQL on any member
SELECT pg_is_in_recovery();
Run Example »
This lesson uses terminal or setup steps. Run commands on your computer — the live editor appears on coding lessons.
What happened?
- patronictl list shows Leader, Replica, Lag, State.
- Only leader accepts writes.
- DCS holds lock; Patroni agents restart postgres with correct role.
Practice next
- Deploy Patroni lab (Spilo or chart).
- Run patronictl list and note Leader.
- Kill leader pod; watch new leader elected.
- Trigger switchover: patronictl switchover --leader old --candidate new.
- Inspect patroni REST API /health on each node.
Remember
Patroni automates replication + failover. Needs reliable DCS cluster. patronictl for ops; HAProxy/K8s service for apps.
PostgresVerse K8s HA
Node drain during patch; Patroni switchover before maintenance window ends.
Outcome: Zero unplanned downtime; planned switchover under 30s.
Interview prep for this lesson
Practice these questions aloud after reading—each links to a full structured answer.
Sign in to ask a question or upvote helpful answers.
No questions yet — be the first to ask!