Created
February 1, 2012 19:16
-
-
Save jeremyhaile/1718726 to your computer and use it in GitHub Desktop.
Kill Postgres connections prior to rake db:drop
This file contains hidden or 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
task :kill_postgres_connections => :environment do | |
db_name = ActiveRecord::Base.configurations[Rails.env.to_s]['database'] | |
raise "No database name found in #{Rails.env} configuration." if db_name.nil? | |
sh = <<EOF | |
ps xa \ | |
| grep postgres: \ | |
| grep #{db_name} \ | |
| grep -v grep \ | |
| awk '{print $1}' \ | |
| xargs kill | |
EOF | |
puts `#{sh}` | |
end | |
task "db:drop" => :kill_postgres_connections |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment