Skip to content

Instantly share code, notes, and snippets.

@champierre
Created January 29, 2009 15:00
Show Gist options
  • Save champierre/54568 to your computer and use it in GitHub Desktop.
Save champierre/54568 to your computer and use it in GitHub Desktop.
#!/usr/bin/ruby
print "Specify dbname: "
dbname = gets.chomp
pids = `psql -U postgres -c "select procpid from pg_stat_activity where datname = '#{dbname}'"`.scan(/^\s+(\d+)$/)
pids.flatten.each do |pid|
print "Kill #{pid}?[yN] "
system "sudo kill -9 #{pid}" if gets.chomp.downcase == "y"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment