You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Note: this library only supports PostgreSQL 9.3+. If you're interested in adding support for other databases, we're open to pull requests!
Postgres holds ACCESS EXCLUSIVE locks for almost all DDL
operations. ACCESS EXCLUSIVE locks conflict with all other table-level locks,
which can cause issues in several situations. For instance:
If the lock is held for a long time, all other access to the table will be
blocked, which can result in downtime.
Even if the lock is only held breifly, it will block all other access to the
table while it is in the lock queue, as it conflicts with all other locks.
The lock can't be acquired until all other queries ahead of it have finished,
so having to wait on long-running queries can also result in downtime.
See here for more details.
Both these issues can be avoided by setting timeouts on the migration connection -
statement_timeout and lock_timeout respectively.
Once this gem is loaded, all migrations will automatically have a
lock_timeout and a statement_timeout set. The initial lock_timeout
default is 750ms, and the initial statement_timeout default is 1500ms. Both
defaults can be easily changed (e.g. in a Rails initializer).
To disable timeouts for a migration, use the disable_lock_timeout! and
disable_statement_timeout! class methods. Note that this is extremely
dangerous if you're doing any schema alterations in your migration.
classLockTest < ActiveRecord::Migration# Only do this if you really know what you're doing!disable_lock_timeout!disable_statement_timeout!defchangecreate_table:lock_testendend
Use with PgBouncer
This gem sets session-level settings on Postgres connections. If you're using
PgBouncer in transaction pooling mode, using session-level settings is
dangerous, as you can't guarantee which connection will receive the setting.
For this reason, this gem is incompatible with transaction-pooling and should
only be used if migrations are run on connections that support session-level
features.