-
-
Save masonjm/5883b4eaa9a100d88103 to your computer and use it in GitHub Desktop.
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 | |
end | |
# | |
# This patch ensures db:drop works for postgres db, by killing the postgres connections | |
# | |
task 'db:drop' => 'db:kill_postgres_connections' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment