Skip to content

Commit

Permalink
feat(azure-db): prevent foot in the door user reconnection (#582)
Browse files Browse the repository at this point in the history
  • Loading branch information
douglasduteil authored Mar 26, 2021
1 parent cd11152 commit c5d7386
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion azure-db/bin/drop-db-user
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,14 @@ DROP_USER_BASE=${DROP_USER%%@*} || $DROP_USER
echo
echo "disconnect activities on database ${DROP_DATABASE} on ${PGHOST}"
psql -abe "$PG_URL_ADMIN" -c "
SELECT pg_terminate_backend (pg_stat_activity.pid) FROM pg_stat_activity WHERE pg_stat_activity.datname = '${DROP_DATABASE}';
-- Inspired by https://stackoverflow.com/questions/3185266/postgresql-temporarily-disable-connections
-- Temporarily disable connections
UPDATE pg_database SET datallowconn = false WHERE datname = '${DROP_DATABASE}';
-- Disconnect users from database
SELECT pg_terminate_backend (pg_stat_activity.pid)
FROM pg_stat_activity
WHERE pg_stat_activity.datname = '${DROP_DATABASE}';
"

echo
Expand Down

0 comments on commit c5d7386

Please sign in to comment.