4 ms·
A "Postgres lock diagnostics" tool for migrations. We've been bitten a few times, by seemingly innocent migrations that ended up acquiring locks we did not expe
by pasxizeis 1y ago
A "Postgres lock diagnostics" tool for migrations. We've been bitten a few times, by seemingly innocent migrations that ended up acquiring locks we did not expect (yes, RTFM).
So I thought: what if, when you opened the PR, you had a tool that actually executed your migrations, saw what locks they acquired (in runtime) and then reported it as a comment to your PR? This would provide you with yet another data point you could use to reason about whether your migration is safe to deploy or not. For example:
ALTER TABLE users ADD COLUMN email TEXT:
acquired AccessExclusiveLock on relation `users`
It does this by opening a transaction, executing the statement, and observing the `pg_locks` view from _a different_ connection before the initial transaction is rolled bac (or committed, depending in the flags you passed). The idea is to be able to use it as a CLI, as a library or with a ready-made GitHub Action (which will take care of commenting in your PR).
It's in early-stage and very much a PoC yet, but I think there's merit in the idea.
https://github.com/agis/pglockanalyze https://github.com/agis/pglockanalyze
P.S. Also, an excuse to learn Rust - so any feedback from Rust ppl more than welcome
- andrelaszlo 1y agoThis sounds super useful. I imagine a pipeline where each migration has to explicitly mentioned which locks it will acquire (and the build failing if there's a mismatch).
- wutwutwat 1y agoA thing I always go back to, regardless of what language I'm working in, is the checks performed by strong migrations https://github.com/ankane/strong_migrations?tab=readme-ov-file#checks https://github.com/ankane/strong_migrations?tab=readme-ov-fi... It's pretty popular, and has even been ported to other languages https://github.com/Artur-Sulej/excellent_migrations https://github.com/Artur-Sulej/excellent_migrations