PlanTwin
Catch PostgreSQL query-plan regressions in pull requests, with no production rows.
$ ./bin/plantwin demo## PlanTwin: HEAD~1 → HEADResult: failing. 1 error(s), 0 warning(s), 1 info.### customer_lookupERROR lost_index (estimated)Index use lost on orders: the table is now readby a sequential scan (about 500K rows).Fix: recreate the index, or run `plantwin accept`.The problem
A migration can pass every test and still turn an index scan into a sequential scan in production, because CI databases are empty and the planner chooses differently there.
PlanTwin loads production planner statistics into an empty PostgreSQL 18 database in CI, compares the plans before and after a migration or query change, and reports what shifted.
What it does
- Exports the statistics the planner uses from a read replica with a role that cannot read table rows, into a redacted, ed25519-signed bundle.
- Builds base and head “twins” from your migrations plus the imported stats, then diffs canonical plan shapes.
- Detects the migration tool: plain SQL, Flyway, Django, Rails, Prisma, Alembic or Atlas.
- Reports as a Markdown PR comment, JSON with a schema version, or SARIF 2.1.0 for code scanning.
- plantwin accept records intentional changes; plantwin doctor checks Docker, the bundle, its signature and its age.
How it works
- 1
Export runs in a read-only session with server-side timeouts and writes a signed statistics bundle.
- 2
Each twin is a throwaway PostgreSQL 18 container; a small extension loaded only in CI makes the planner use the imported table sizes.
- 3
Every query in a catalog is explained on both twins, reduced to its shape (operators, relations, indexes, join order) and diffed against documented thresholds.
Decisions worth noting
A compatibility promise
From 1.0.0, CLI flags, exit codes, config keys and the JSON report's schema_version 1 stay compatible within 1.x.
Typos are errors
Unknown keys in plantwin.yaml fail with the line number, so a misspelled option can't be silently ignored.