Skip to content

Commit 27324c2

Browse files
committed
fix: disable client connections during upgrade
1 parent 7630b53 commit 27324c2

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

ansible/files/admin_api_scripts/pg_upgrade_scripts/common.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,10 @@ CI_start_postgres() {
8888

8989
swap_postgres_and_supabase_admin() {
9090
run_sql <<'EOSQL'
91+
alter database postgres connection limit 0;
92+
select pg_terminate_backend(pid) from pg_stat_activity where backend_type = 'client backend' and pid != pg_backend_pid();
93+
EOSQL
94+
run_sql <<'EOSQL'
9195
set statement_timeout = '300s';
9296
begin;
9397
create role supabase_tmp superuser;
@@ -509,6 +513,8 @@ begin
509513
end
510514
$$;
511515
516+
alter database postgres connection limit -1;
517+
512518
set session authorization supabase_admin;
513519
drop role supabase_tmp;
514520
commit;

ansible/files/admin_api_scripts/pg_upgrade_scripts/initiate.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,9 @@ cleanup() {
125125
echo "Removing SUPERUSER grant from postgres"
126126
run_sql -c "ALTER USER postgres WITH NOSUPERUSER;"
127127

128+
echo "Resetting postgres database connection limit"
129+
run_sql -c "ALTER DATABASE postgres CONNECTION LIMIT -1;"
130+
128131
if [ -z "$IS_CI" ] && [ -z "$IS_LOCAL_UPGRADE" ]; then
129132
echo "Unmounting data disk from ${MOUNT_POINT}"
130133
umount $MOUNT_POINT

0 commit comments

Comments
 (0)