
How we stopped ORM migrations from taking down our Postgres database
If you've ever run a database migration that applied a seemingly minor change, like ALTER TABLE users ADD COLUMN is_verified BOOLEAN DEFAULT false , only to watch your API response times spike and connection pools exhaust, you've met the Postgres ACCESS EXCLUSIVE lock. Modern ORMs like TypeORM, Sequelize, Prisma, and Drizzle hide the underlying Postgres locking mechanics. When developers can't see the DDL statements their ORMs are running, they can't optimize them. The Lock Queue Death Spiral Postgres requires strict locks for schema changes. When a migration runs an ALTER TABLE command, it normally requires an ACCESS EXCLUSIVE lock. If there's currently a 30-second reporting query running on that table, the migration has to wait in line. While the migration is waiting, every other incoming production query behind it is also forced to wait. Suddenly, your app is down. Introducing pgfence To solve this, I built pgfence , a source-available TypeScript CLI designed specifically for the No
Continue reading on Dev.to DevOps
Opens in a new tab




