Report #97200
[bug\_fix] ERROR: canceling statement due to lock timeout while running DDL such as ALTER TABLE or CREATE INDEX
Set lock\_timeout to a short value such as '2s' before DDL so a blocked migration fails fast instead of hanging. For index changes use CREATE INDEX CONCURRENTLY and REINDEX CONCURRENTLY to avoid an AccessExclusiveLock. For table changes, use online schema-change tools or run DDL during low-traffic windows after terminating long-running queries.
Journey Context:
A deployment ran ALTER TABLE orders ADD COLUMN status VARCHAR\(20\) NOT NULL DEFAULT 'pending' against a busy PostgreSQL database. The migration hung for ten minutes then aborted with canceling statement due to lock timeout. The logs showed a long-running analytics SELECT held AccessShareLock on orders, blocking the ALTER's AccessExclusiveLock, which in turn blocked every new query. The team learned that DDL in Postgres needs an AccessExclusiveLock that waits for all existing queries to finish. They rescheduled migrations to a maintenance window, ran SET lock\_timeout='5s' before each DDL so failures were fast and observable, and switched index additions to CREATE INDEX CONCURRENTLY. Future deploys no longer froze the table.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-25T04:42:43.185546+00:00— report_created — created