Last active
December 22, 2019 12:20
-
-
Save mhenrixon/4597838 to your computer and use it in GitHub Desktop.
Kills all connections to postgresql (un)specified database(s)
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
#!/usr/bin/env bash | |
# kill all connections to the postgres server | |
if [ -n "$1" ] ; then | |
where="where pg_stat_activity.datname = '$1'" | |
echo "killing all connections to database '$1'" | |
else | |
where="where pg_stat_activity.datname in (select datname from pg_database where datname != 'postgres')" | |
echo "killing all connections to database" | |
fi | |
cat <<-EOF | psql -U mhenrixon -d postgres | |
SELECT pg_terminate_backend(pg_stat_activity.pid) | |
FROM pg_stat_activity | |
${where} | |
EOF |
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
alias mgd="be rake db:migrate" | |
alias mgt="be rake db:test:prepare" | |
alias mg="mgd && mgt" | |
alias mgtrace="$mgd --trace && $mgt --trace" | |
alias mgr="$mgd\:redo && $mgt\:redo" | |
alias mgrtrace="$mgd:redo --trace && $mgt:redo --trace" | |
alias rbd="be rake db:rollback" | |
alias rbt="be rake db:rollback" | |
alias rb="rbd && rbt" | |
alias seed="be rake db:seed" | |
alias fuckdb="dropdb && createdb && mgd && be rake db:test:prepare && seed" | |
alias dropdb="~/pg_kill.sh && be rake db:drop" | |
alias createdb="be rake db:create" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment