Skip to content

Commit

Permalink
chore: cleanup pgbouncer.get_auth ownership accordingly
Browse files Browse the repository at this point in the history
  • Loading branch information
dragarcia authored and darora committed Nov 11, 2024
1 parent 9e285dd commit a627e17
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions ansible/files/admin_api_scripts/pg_upgrade_scripts/initiate.sh
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ MOUNT_POINT="/data_migration"
LOG_FILE="/var/log/pg-upgrade-initiate.log"

POST_UPGRADE_EXTENSION_SCRIPT="/tmp/pg_upgrade/pg_upgrade_extensions.sql"
POST_UPGRADE_PGBOUNCER_CLEANUP_SCRIPT="/tmp/pg_upgrade/pg_upgrade_pgbouncer_cleanup.sql"
OLD_PGVERSION=$(run_sql -A -t -c "SHOW server_version;")

SERVER_LC_COLLATE=$(run_sql -A -t -c "SHOW lc_collate;")
Expand Down Expand Up @@ -132,6 +133,22 @@ cleanup() {
echo "Resetting postgres database connection limit"
retry 5 run_sql -c "ALTER DATABASE postgres CONNECTION LIMIT -1;"

echo "Making sure postgres still has access to pg_shadow"
cat << EOF >> $POST_UPGRADE_PGBOUNCER_CLEANUP_SCRIPT
DO \$\$
BEGIN
IF EXISTS (SELECT 1 FROM pg_views WHERE viewname = 'pg_shadow' AND viewowner = 'supabase_admin') THEN
ALTER function pgbouncer.get_auth owner to supabase_admin;
GRANT EXECUTE ON FUNCTION pgbouncer.get_auth(p_usename TEXT) TO postgres;
END IF;
END;
\$\$;
EOF

if [ -f $POST_UPGRADE_PGBOUNCER_CLEANUP_SCRIPT ]; then
retry 5 run_sql -f $POST_UPGRADE_PGBOUNCER_CLEANUP_SCRIPT
fi

if [ -z "$IS_CI" ] && [ -z "$IS_LOCAL_UPGRADE" ]; then
echo "Unmounting data disk from ${MOUNT_POINT}"
retry 3 umount $MOUNT_POINT
Expand Down

0 comments on commit a627e17

Please sign in to comment.