Skip to content

Instantly share code, notes, and snippets.

View BorisBresciani's full-sized avatar
👨‍💻
Coding

Boris BorisBresciani

👨‍💻
Coding
View GitHub Profile
@BorisBresciani
BorisBresciani / optimization.rake
Created June 26, 2019 12:11 — forked from merqlove/optimization.rake
PostgreSQL optimization tasks for ActiveRecord
namespace :optimization do
desc "Provide DB vacuum for production environment"
task :vacuum => :environment do
begin
tables = ActiveRecord::Base.connection.tables
tables.each do |table|
ActiveRecord::Base.connection.execute("VACUUM FULL ANALYZE #{table};")
end
rescue Exception => exc
Rails.logger.error("Database VACUUM error: #{exc.message}")