require xpgdbcmd
pgdb_disallow_connects ()
{
local old=${1:?}
PGDATABASE=postgres \
PGUSER=postgres \
pgdbcmd "
UPDATE pg_database
SET datallowconn=false
WHERE datname='$old'
;"
}
__no_no_disabled_dontuse_pgdb_disallow_connects ()
{
local old=${1:?}
local -a roles
roles=($(xpgdbcmd "
SELECT role_name
FROM information_schema.enabled_roles
WHERE role_name != 'postgres'
;")) || return 1
for role in ${roles[@]}
do
PGUSER=postgres xpgdbcmd "
REVOKE CONNECT
ON DATABASE \"$old\"
FROM \"$role\"
;" || return 2
done
}