Last active
March 11, 2020 13:45
-
-
Save sungmin-park/8cc82013a68a2def2a7e to your computer and use it in GitHub Desktop.
Disconnect all connection on target database for postgresql.
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
#!/usr/bin/env bash | |
if [ -z "$1" ]; then | |
echo "usage> $0 database" | |
exit 1 | |
fi | |
cat <<-EOF | psql -d $1 | |
SELECT pg_terminate_backend(pg_stat_activity.pid) | |
FROM pg_stat_activity | |
WHERE pg_stat_activity.datname = '$1' | |
AND pid <> pg_backend_pid(); | |
EOF |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment