2016-01-12 13:08:43 +01:00
|
|
|
#!/usr/bin/env bash
|
2015-09-28 19:45:35 +02:00
|
|
|
set -e
|
|
|
|
|
2019-04-13 01:30:49 +02:00
|
|
|
POSTGRES_USER="postgres"
|
2016-01-12 13:08:43 +01:00
|
|
|
if [ "$(uname)" = "OpenBSD" ]; then
|
2019-04-13 01:30:49 +02:00
|
|
|
POSTGRES_USER="_postgresql"
|
2016-01-12 13:08:43 +01:00
|
|
|
fi
|
|
|
|
|
2015-09-28 19:45:35 +02:00
|
|
|
cd /
|
|
|
|
|
|
|
|
username=$1
|
2015-11-10 07:16:41 +01:00
|
|
|
|
2015-09-28 19:45:35 +02:00
|
|
|
shift
|
2019-01-16 04:32:27 +01:00
|
|
|
tables="$(printf "'%s'," "${@//\'/\'\'}")"
|
|
|
|
tables="${tables%,}"
|
2015-09-28 19:45:35 +02:00
|
|
|
|
2019-04-04 23:29:21 +02:00
|
|
|
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
|
|
|
|
|
2019-04-23 00:49:48 +02:00
|
|
|
"${psql[@]}" <<EOF
|
2018-08-10 00:24:22 +02:00
|
|
|
SELECT pg_terminate_backend(pid) FROM pg_stat_activity WHERE datname IN ($tables);
|
2015-09-28 19:45:35 +02:00
|
|
|
EOF
|