diff --git a/app/helpers/pg_hero/home_helper.rb b/app/helpers/pg_hero/home_helper.rb
index 6caa2d4c4..afb40aedd 100644
--- a/app/helpers/pg_hero/home_helper.rb
+++ b/app/helpers/pg_hero/home_helper.rb
@@ -16,6 +16,15 @@ def pghero_js_value(value)
json_escape(value.to_json(root: false)).html_safe
end
+ def pghero_drop_idx_concurrently_explanation
+ if @database.drop_idx_concurrently_supported?
+ ret = "
Tip: Use CONCURRENTLY for DROP INDEX
"
+ ret << "- Add
disable_ddl_transaction!
to your migration "
+ ret << "- Add
algorithm: :concurrently
to each remove_index
"
+ ret.html_safe
+ end
+ end
+
def pghero_remove_index(query)
if query[:columns]
columns = query[:columns].map(&:to_sym)
@@ -24,6 +33,7 @@ def pghero_remove_index(query)
ret = String.new("remove_index #{query[:table].to_sym.inspect}")
ret << ", name: #{(query[:name] || query[:index]).to_s.inspect}"
ret << ", column: #{columns.inspect}" if columns
+ ret << ", algorithm: concurrently" if @database.drop_idx_concurrently_supported?
ret
end
diff --git a/app/views/pg_hero/home/index.html.erb b/app/views/pg_hero/home/index.html.erb
index dfb80ef11..7e7001aec 100644
--- a/app/views/pg_hero/home/index.html.erb
+++ b/app/views/pg_hero/home/index.html.erb
@@ -391,6 +391,10 @@
rails generate migration remove_unneeded_indexes
And paste
+ <% if @database.drop_idx_concurrently_supported? %>
+
<%= pghero_drop_idx_concurrently_explanation %>
+ <% end %>
+
And paste
<% @duplicate_indexes.each do |query| %>
<%= pghero_remove_index(query[:unneeded_index]) %><% end %>
diff --git a/app/views/pg_hero/home/space.html.erb b/app/views/pg_hero/home/space.html.erb
index 0376b291b..c74fbe9ab 100644
--- a/app/views/pg_hero/home/space.html.erb
+++ b/app/views/pg_hero/home/space.html.erb
@@ -31,6 +31,9 @@
rails generate migration remove_unused_indexes
+ <% if @database.drop_idx_concurrently_supported? %>
+
<%= pghero_drop_idx_concurrently_explanation %>
+ <% end %>
And paste
<% @unused_indexes.sort_by { |q| [-q[:size_bytes], q[:index]] }.each do |query| %>
<%= pghero_remove_index(query) %><% end %>
diff --git a/lib/pghero/methods/basic.rb b/lib/pghero/methods/basic.rb
index a17bca635..302a5f456 100644
--- a/lib/pghero/methods/basic.rb
+++ b/lib/pghero/methods/basic.rb
@@ -34,6 +34,10 @@ def quote_ident(value)
connection.quote_column_name(value)
end
+ def drop_idx_concurrently_supported?
+ server_version_num >= 140000
+ end
+
private
def select_all(sql, conn: nil, query_columns: [])