pgbreaker 30-Second Chaos Demo
Demonstrates a runaway slow query saturating a fixed PostgreSQL connection pool (max_connections = 14, superuser_reserved_connections = 4, leaving 10 app slots), followed by live recovery via SELECT pgbreaker.trip(query_id) with zero restart.
Run
Requires Docker with Compose v2 (docker compose >= 2.20 for top-level name: and up --wait). No local psql installation or host port binding is needed—PostgreSQL binds strictly to loopback (127.0.0.1) inside the pg service of the per-UID Compose project pgbreaker-demo-$(id -u), and all probes run via docker compose exec. Note that rerunning ./run_demo.sh clears any pre-existing pgbreaker rules in the demo service before starting Phase 1.
cd demo
./run_demo.sh
Tear down when finished:
docker compose -p "pgbreaker-demo-$(id -u)" down -v
What Happens
- Healthy baseline: core OLTP lookups (
SELECT amount FROM orders WHERE id = 1) run asapp_userand assert20/20exact1.25results. - Poison query storm (unprotected): 12 concurrent slow queries (
pg_sleep(1.5)) saturate all 10 non-superuser connection slots, asserting confirmed slot-admission starvation (remaining connection slots are reserved/too many clients) with zero unexpected errors. - Live circuit breaker:
postgresconnects via a reserved superuser slot, pollspg_stat_activityfor the poisonquery_id, and callsSELECT pgbreaker.trip(query_id). While the storm continues hammering the server, core OLTP recovers to20/20exact1.25results andrejects_totalincreases during recovery; after joining the storm workers, a standalone poison query is independently verified to fail non-zero withSQLSTATE 53P01. - Live rejection telemetry: prints
pgbreaker.rulesconfirmingrejects_totalincreased across both the storm and standalone probe, then disarms the demo rule viapgbreaker.remove_rule(rule_id).