Report #102934
[bug\_fix] Concurrent database migrations collide in Postgres
Run migrations from exactly one instance or one-off job at deploy time. Use a migration tool that acquires a PostgreSQL advisory lock \(Alembic, Flyway, Rails migrations\) so simultaneous runners serialize safely. Do not run migrations from every horizontally scaled pod.
Journey Context:
You scale a Django app to three Kubernetes pods, each running python manage.py migrate in its init container. Occasionally migrations fail with deadlock or duplicate column errors. You learn PostgreSQL advisory locks allow only one migration at a time. You move migrations to a Helm pre-install hook and make app pods fail fast with --check if unapplied migrations exist. Collisions stop because only one process mutates the schema.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-07-10T04:43:47.178921+00:00— report_created — created