Home›Practice›Practice 5: fix a real cluster
Practice · Chapter 5

Hands-on labs: fix a broken cluster

A real PostgreSQL primary and replica run on your laptop. The lab breaks them the way production breaks. You get the alert, a terminal and three hints, and a check that grades your fix against the live database. No answers in the box: the task and the grading come from this site, for your session only.

How it works

Four steps, one broken cluster

1. Install the kit

One command with your personal key. It writes a small Docker Compose file and a lab script, marked with your name. The kit is an empty cluster: no tasks, no answers.

2. Start a lab

./lab start replica-lag asks this site for a new session. The site picks one of several causes, breaks your cluster to match, and starts a steady write load. Every session can be different.

3. Investigate and fix

Use ./lab psql primary and ./lab psql replica like on call. Stuck? ./lab hint 1, 2, 3, from a nudge to the place to look.

4. Check

./lab check reads a few numbers from your cluster and sends them here. The site decides pass or fail and tells you what is still wrong, without giving the answer away.

Labs

Available now

LabThe alertWhat you practice
replica-lagReplica lag on orders-db has been rising for 10 minutes. Reads from the replica show stale data.Reading pg_stat_replication, telling receive lag from replay lag, and finding what stops replay on the replica. Read Replication first if the terms are new.
patroni-failoverWrites to orders-db fail on a three-node Patroni cluster.Reading patronictl list and the Patroni logs, and finding why the leader stopped taking writes and why no other member was promoted. Read PostgreSQL high availability with Patroni first.
connection-stormThe orders app is timing out behind PgBouncer. Nothing was deployed today.Telling apart a database out of connection slots, connections stuck waiting on a lock, and a pooler that will not hand them out, with pg_stat_activity, pg_blocking_pids and PgBouncer's SHOW POOLS. Read the connection limit section of the AI agents guide for PgBouncer basics.
What you need

Before you start

  • Docker with Compose (Docker Desktop on Mac or Windows, or Docker Engine on Linux), about 2 GB of disk and 2 GB of free memory. The first Patroni lab builds a small image, which takes a few minutes once.
  • curl and python3 (already on macOS and most Linux).
  • A lab key. Labs are invite only for now. Request one with the form below; a key is personal and lasts 30 days.
# install the kit (replace KEY with yours)
curl -fsS -H "Authorization: Bearer KEY" https://howdatabaseswork.com/api/lab/kit | bash
cd howdbswork-lab
./lab login KEY
./lab start replica-lag
./lab psql replica          # investigate
./lab hint 1                # if you are stuck
./lab check                 # graded on the site
./lab reset                 # remove the cluster and its data
What leaves your laptop

Only a few numbers, only when you ask

./lab check sends: how many replicas the primary sees, the replay gap in bytes, whether replay is paused, two replica settings (recovery_min_apply_delay, max_standby_streaming_delay), and how many transactions on the replica are older than 10 seconds. No data from your tables, no host names. The site logs your key id, the lab, and pass or fail. The cluster runs only on your machine and holds only lab data.

Get a hands-on lab keyLabs are invite only while they are new. Leave your email and you get a personal key when a spot opens.