# 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. ```bash cd demo ./run_demo.sh ``` Tear down when finished: ```bash docker compose -p "pgbreaker-demo-$(id -u)" down -v ``` ## What Happens 1. **Healthy baseline**: core OLTP lookups (`SELECT amount FROM orders WHERE id = 1`) run as `app_user` and assert `20/20` exact `1.25` results. 2. **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. 3. **Live circuit breaker**: `postgres` connects via a reserved superuser slot, polls `pg_stat_activity` for the poison `query_id`, and calls `SELECT pgbreaker.trip(query_id)`. While the storm continues hammering the server, core OLTP recovers to `20/20` exact `1.25` results and `rejects_total` increases during recovery; after joining the storm workers, a standalone poison query is independently verified to fail non-zero with `SQLSTATE 53P01`. 4. **Live rejection telemetry**: prints `pgbreaker.rules` confirming `rejects_total` increased across both the storm and standalone probe, then disarms the demo rule via `pgbreaker.remove_rule(rule_id)`.