PostgreSQL High Availability and Point-in-Time Recovery with Patroni

Build a three-member Patroni cluster that keeps every acknowledged payment through a failover, then recover an accidental delete to a chosen moment without rewinding production.

PostgreSQL DBA. Advanced.

What you will build and explain

  • Explain what a commit guarantees under synchronous, strict and quorum replication, and prove a failover lost no acknowledged write.
  • Operate Patroni on etcd: leader leases, switchover, failover, pg_rewind rejoin and safe configuration changes.
  • Archive WAL and back up to a separate TLS repository host, restore to a point in time in isolation and repair production selectively.
  • Alert on leadership, replication, archiving and quorum failures with rules that have their own unit tests.

Before you begin

  • SQL with keys, constraints and transactions; PostgreSQL roles, grants and settings on one server; basic Docker and Compose; reading short Bash and Python.
  • A workstation with Docker 26+ and Compose 2.24+, about 4 CPU cores, 6 GB of memory for Docker and 8 GB of free disk. Replication, Patroni, etcd, HAProxy, pgBackRest and Prometheus are taught.

Who this is for

For database and platform engineers who run SQL and manage a single PostgreSQL server, and want to build, break and recover a highly available cluster with Patroni, etcd and pgBackRest.

Curriculum

Learning topics (11)
  1. Follow a payment through the cluster, a failover and a recovery

    The diagram shows everything that runs when the lab is up. Clients on the left reach PostgreSQL only through HAProxy. Three Patroni-managed PostgreSQL members sit in the middle, coordinated by a three-member etcd cluster above them. The repository host on the left receives WAL and backups, and the isolated restore server below it exists only during a recovery drill. Prometheus and the exporter on the right observe all of it. pg1 is drawn as the leader, but that is a snapshot:

  2. Prepare the workstation and the ideas you will need

    This project assumes you can already run SQL, manage roles on one PostgreSQL server and start containers. It does not assume you have ever replicated a database. This page lists exactly what you should be able to do before you start, what the project will teach you, and how to check your workstation.

  3. Explain what a commit guarantees on one server and on two

    Goal: explain how PostgreSQL makes a commit durable on one server, how the same mechanism copies it to replicas, and exactly what this lab's synchronous replication promises when a client hears "COMMIT".

  4. Keep exactly one leader through a lease in etcd

    Goal: understand how three Patroni agents agree on one primary through etcd, why the agreement needs three etcd members, and how the timing settings turn into failover behaviour.

  5. Give clients one address that follows the primary

    Goal: explain how applications reach the current primary, and a healthy replica for reads, without knowing which member that is, and what clients experience while the role moves.

  6. Move the primary, rejoin the old one and measure the cost

    Goal: perform a planned switchover and survive an unplanned primary loss, then bring the former primary back as a replica, and measure what each event cost in unavailability and data.

  7. Keep the database's history on a separate repository host

    Goal: configure continuous WAL archiving and full, differential and incremental backups to a separate repository host, explain how the hosts authenticate each other, and know how to tell that the archive is healthy.

  8. Undo a mistake without rewinding production

    Goal: rebuild the database as it was just before a mistake, in isolation, verify it, and repair production selectively, while understanding exactly which commits the restored copy contains.

  9. Alert when the cluster's guarantees stop holding

    Goal: collect the metrics that show whether the cluster's guarantees still hold, write alert rules that name a condition and an action, and test those rules without waiting for an incident.

  10. Separate authority at every boundary

    Goal: explain who can do what in this cluster and why, trace how each credential is created and delivered, and recognize the limits a production deployment would have to close.

  11. Change a running cluster without causing an outage

    Goal: change configuration, restart members, pause automation for maintenance and update software without turning routine work into an outage.

Practical build steps (9)
  1. Prepare the workstation

    Starting point: a copy of the project source and a workstation you are allowed to administer. Finishing point: Docker, Compose and enough memory, disk and free ports confirmed, before anything is created.

  2. Create the lab inputs

    Starting point: the workstation checks passed. Finishing point: your own settings file in .runtime/lab.settings, exported for this terminal, and a validated Compose configuration. Still nothing is running.

  3. Build the node image

    Starting point: a validated Compose configuration. Finishing point: the <prefix>-node:lab image, containing PostgreSQL 18.6, Patroni 4.1.5, pgBackRest 2.59.3, the lab's configuration files, SQL and tools.

  4. Start the cluster

    Starting point: the node image exists and no lab containers are running. Finishing point: three etcd members, one leader and two streaming replicas (one synchronous), the ledger database with generated data, and HAProxy routing writes and reads by role.

  5. Check metrics and alerts

    Starting point: a running cluster. Finishing point: every scrape target up in Prometheus, and the alerts page understood, including the one alert that should be firing at this point.

  6. Create the stanza and first backups

    Starting point: a running, observed cluster with archiving failing. Finishing point: the ledger stanza in the repository, archiving working end to end, a full, a differential and an incremental backup, and an archive outage you caused and recovered.

  7. Run a switchover and a failover

    Starting point: a healthy cluster with backups. Finishing point: a planned switchover and an abrupt failover performed under write load, each verified to have lost no acknowledged payment, and the former primary rewound and streaming again.

  8. Recover an accidental delete

    Starting point: a healthy cluster with at least one backup. Finishing point: customer 7's deleted payments restored into production exactly once, from an isolated point-in-time copy, with production never rewound.

  9. Remove the lab

    Starting point: any state, including a partial start or a failed step. Finishing point: no container, network or volume carrying your project's label remains, and you know which images are left.

Access

Learning Access: INR 199 plus 18% GST. Source Pack: INR 299 plus 18% GST. 90 days of online access. No auto-renewal.

Cloud costs and boundaries

Runs entirely on your own workstation with Docker: no cloud account or paid service is used. The container images use about 1.3 GB of disk. Workstation, network and Docker licensing terms remain your responsibility.

Licence and completion

Vectametric Project Source Licence (2026-09-27): personal learning, modification/deployment and attributed portfolio/interview demonstrations are permitted. Lawfully obtained copies remain usable after online access expires. Do not redistribute original source or the Source Pack; commercial/client production use requires separate permission. Third-party terms remain separate. See included LICENSE.txt and the Project Source Licence section of the site Terms.

Questions about projects

Do I need a cloud account?

You can read the project material without deploying it. Running a cloud build requires the accounts, permissions and tools listed in that project's prerequisites. Deployment runs in your environment, not in a hosted Vectametric lab.

Can I read the code with Learning Access?

Yes. Learning Access includes the online source-file browser and explanations. The Source Pack adds the downloadable reference repository where available. The project's licence governs use of the source.

Are cloud charges included?

No. Cloud and CI usage are separate. Read the project's cost notice, set a budget and stop deadline, and follow its destruction and leftover-resource checks.

Does the project include troubleshooting and interview preparation?

The project curriculum lists the available scenarios and interview topics. These focus on understanding the architecture and explaining decisions; they are not a promise of particular interview questions or a job.

How long can I use the project?

The project page and checkout show the online access period for your selected plan. Access does not auto-renew. Downloaded source remains subject to its licence; future releases are not automatically included.

Review the Terms and No-Refund Policy before confirming access. All sales are final; Vectametric does not offer refunds.

This website is operated by VECTAMETRIC EDTECH (OPC) PRIVATE LIMITED, operating as Vectametric.

Corporate Identity Number (CIN): U85499KA2026OPC229822. GSTIN: 29AAMCV8281D1ZS. Registered office: RS NO/38/2A/1 BASTAND, ROAD MAHANTESH NAGAR, Ramdurg, Ramdurg, Belgaum- 591123, Karnataka.

Queries and grievances: Prajval Honnungar, Grievance Officer and Data Protection Contact.

Telephone: +91 94800 09310. Support: support@vectametric.com. Grievances: support@vectametric.com.

Copyright 2026 VECTAMETRIC EDTECH (OPC) PRIVATE LIMITED. All rights reserved.

Vectametric home · Roadmaps · Vecta IT Exams · Vecta Government Exams · Vecta Banking & Finance Exams · Vecta Entrance Exams · About us · Contact · Privacy Policy · Terms and Conditions · No-Refund Policy