Skip to content

Instantly share code, notes, and snippets.

@sungmin-park
Last active March 11, 2020 13:45
Show Gist options
  • Save sungmin-park/8cc82013a68a2def2a7e to your computer and use it in GitHub Desktop.
Save sungmin-park/8cc82013a68a2def2a7e to your computer and use it in GitHub Desktop.
Disconnect all connection on target database for postgresql.
#!/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