Busca en todas las páginas de la documentación
Migration deploy jobs must fail fast on lock contention and never block application traffic unbounded. Encode timeouts and phased DDL in team rules.
-- First lines of every production migration file
SET lock_timeout = '5s';
SET statement_timeout = '0'; -- allow long CONCURRENTLY
SET idle_in_transaction_session_timeout = '60s';# Deploy job wrapper
flyway migrate || { echo "migration failed - app NOT rolled forward"; exit 1; }When to reach for this: CI template for SQL migrations, incident retro after lock pile-up, Flyway/Liquibase standardization.
SET lock_timeout = '3s';
BEGIN;
CREATE TABLE app.new_feature (
id bigint GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
name text NOT NULL
);
COMMIT;-- Separate file: executeInTransaction=false (Flyway)
SET lock_timeout = '10s';
SET statement_timeout = '0';
CREATE INDEX CONCURRENTLY IF NOT EXISTS idx_new_feature_name
ON app.new_feature (name);Deploy pipeline rules:
lock timeout in migration logsSELECT indexrelid::regclass
FROM pg_index
WHERE NOT indisvalid;| Setting | Migration default | Purpose |
|---|---|---|
lock_timeout | 3s-10s | Abort if cannot acquire lock |
statement_timeout | 0 for CONCURRENTLY; 30s for trial DDL | Kill runaway statements |
idle_in_transaction_session_timeout | 60s | Prevent hung migrator sessions |
ADD COLUMN nullable (fast)CREATE INDEX CONCURRENTLYADD CONSTRAINT NOT VALIDVALIDATE CONSTRAINT off-peakDROP COLUMN only after app contract phaselock_timeout.| Alternative | Use When | Don't Use When |
|---|---|---|
| Online schema change tool (gh-ost class) | MySQL habits | Postgres native CONCURRENTLY suffices |
| Maintenance window | Tiny table startup | SLA-bound service |
| Manual DBA runbook | Regulated one-off | Continuous deploy shop |
Yes with exponential backoff in deploy job - after confirming no partial non-transactional step left INVALID objects.
Apps use shorter timeouts for queries; migrations use separate role and job - do not copy values blindly.
DBA publishes template; dev copies into every migration file via linter or snippet.
Stack versions: This page was written for PostgreSQL 18.4 (stable 18, maintenance 17), pgvector 0.8+, PgBouncer 1.x, Patroni 3.x, and PostGIS 3.5+.