Report #63943
[bug\_fix] canceling statement due to statement timeout
Use \`add\_index ... algorithm: :concurrently\` in Rails \(which translates to \`CREATE INDEX CONCURRENTLY\` in SQL\). This builds the index without locking the table for writes, though it takes longer and cannot run inside a transaction block, so the statement\_timeout must be 0 or very high for that specific session.
Journey Context:
A Rails application running \`rake db:migrate\` to add an index to a 100-million-row table crashes with \`PG::QueryCanceled: ERROR: canceling statement due to statement timeout\` after 30 seconds. The database is AWS RDS PostgreSQL with a default \`statement\_timeout\` of 30000ms \(30 seconds\) set via parameter group. The migration uses \`add\_index\`, which in Rails creates the index non-concurrently by default, locking the table and taking hours for large tables, but the timeout kills it at 30 seconds. The developer initially tries increasing the timeout to 1 hour for the migration only, but this holds a lock for an hour, blocking all writes. The correct fix is to use \`add\_index ... algorithm: :concurrently\` in Rails \(which translates to \`CREATE INDEX CONCURRENTLY\` in SQL\). This builds the index without locking the table for writes, though it takes longer and cannot run inside a transaction block, so the statement\_timeout must be 0 or very high for that specific session, or the default must be overridden for the migration connection.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-20T13:48:49.676567+00:00— report_created — created