This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
namespace :db do | |
desc 'kills connections to postgres db' | |
task :kill_postgres_connections => :environment do | |
puts "WARN: killing connections to #{ActiveRecord::Base.connection_config[:database]}." | |
ActiveRecord::Base.connection.execute("SELECT pid, pg_terminate_backend(pid) as terminated FROM pg_stat_activity WHERE pid <> pg_backend_pid()") | |
end | |
desc 'Alias for :kill_postgres_connections' | |
task :kill => :kill_postgres_connections |