Aditia Mahdar


kodelasut

Web Developer. Railsnoob. Freelancer

Jun 24, 2017

CodeNote: Concurrently Add Index to a Table Without Downtime

You can use this migration code below if you forget to add index to your table and the data is big already.
This method will make you able to add index without lock any transaction in your table, but it also need more time and more CPU and I/O process.

class AddIndexToBuildMetricIdOnBuilds < ActiveRecord::Migration
  disable_ddl_transaction!
  def change
    add_index :table, :the_field, :algorithm => :concurrently
  end
end

Happy Code!

No comments:

Post a Comment