terminate-psql-sessions: Rely on the caller to set PGHOST, PGUSER.

Signed-off-by: Anders Kaseorg <anders@zulip.com>
This commit is contained in:
Anders Kaseorg
2020-06-15 16:36:02 -07:00
committed by Tim Abbott
parent f2ce856b8f
commit fa2496c229
7 changed files with 13 additions and 28 deletions

View File

@@ -1,32 +1,12 @@
#!/usr/bin/env bash
set -e
POSTGRES_USER="postgres"
if [ "$(uname)" = "OpenBSD" ]; then
POSTGRES_USER="_postgresql"
fi
cd /
username=$1
shift
tables="$(printf "'%s'," "${@//\'/\'\'}")"
tables="${tables%,}"
case "$(id -un)" in
root)
psql=(su -s /usr/bin/env - -- "$POSTGRES_USER" psql postgres "$POSTGRES_USER")
;;
"$POSTGRES_USER")
psql=(psql postgres "$POSTGRES_USER")
;;
*)
psql=(psql -h localhost postgres "$username")
;;
esac
"${psql[@]}" -v ON_ERROR_STOP=1 <<EOF
psql postgres -v ON_ERROR_STOP=1 <<EOF
SELECT pg_terminate_backend(s.pid)
FROM pg_stat_activity s, pg_roles r
WHERE