Ruby Postgresql 并行加索引避免锁表

在 Rails 4 之後可以直接加入 algorithm: :concurrently 在你的 migration 檔案內

例如:

class AddIndexToUsers < ActiveRecord::Migration
  disable_ddl_transaction!

  def change
    add_index :users, :alive, algorithm: :concurrently
  end
end

不過這邊要注意的是, disable_ddl_transaction! 與 algorithm: :concurrently 是一組的,必須一起使用。

原文:
https://blog.niclin.tw/2018/06/15/rails-如何快速的對大資料量建立索引避免-downtime/

你可能感兴趣的:(Ruby Postgresql 并行加索引避免锁表)