30 Jul '13, 12am

How to Create Postgres Indexes Concurrently in ActiveRecord Migrations

July 29, 2013 dancroak postgres activerecord How to Create Postgres Indexes Concurrently in ActiveRecord Migrations By default, Postgres locks writes (but not reads) to a table while creating an index on it. That can result in unacceptable downtime during a production deploy. On a large table, indexing can take hours. However, Postgres has a CONCURRENTLY option for CREATE INDEX that creates the index without preventing concurrent INSERT s, UPDATE s, or DELETE s on the table. To make this option easier to use in migrations, ActiveRecord 4 introduced an algorithm: :concurrently option for add_index . Here’s an example: class AddIndexToAsksActive < ActiveRecord::Migration disable_ddl_transaction! def change add_index :asks, :active, algorithm: :concurrently end end The caveat is that concurrent indexes must be created outside a transaction . By default, ActiveRecord migration...

Full article: http://robots.thoughtbot.com/post/56828751507/how-to-crea...

Tweets

How to Create Postgres Indexes Concurrently in ...

rubyflow.com 30 Jul '13, 12am

How to Create Postgres Indexes Concurrently in ActiveRecord Migrations Posted by croaky on July 30, 2013 — 0 comments By d...

Just launched - our new DB9 configurator, creat...

astonmartin.com 29 Jul '13, 4pm

Aston Martin Lagonda Limited would like to be able to contact you about invitations, news, and information about its produ...