Remove superuser access from Studio
Learn how to switch from the supabase_admin to postgres role in self-hosted Supabase.
A guide from Supabase
Apps on Plentiful run on Supabase's open-source database, sign-in, file storage and live updates, so most of this guide applies. The differences: your app reaches its database through its own server — not Supabase's data API (supabase.from(…)) — there are no Edge Functions (your app's server does that work), and scheduled work uses Jobs. Where it says "Supabase dashboard", use your app's Dashboard. Ask the builder when in doubt.
Overview#
In late 2022, Supabase introduced a security change in hosted projects that removed superuser access from the dashboard SQL editor and shifted ownership of user-created database objects away from supabase_admin toward the postgres role.
You can read more about it in the official announcement.
However, this migration was never automatically applied to self-hosted Supabase instances.
As a result:
- Objects created via the dashboard may still be owned by
supabase_admin - Behavior differs from the Supabase platform
- Some migrations may fail when run as
postgres
This guide explains how to align your self-hosted Supabase instance with the security enhancements and ownership model used on the Supabase platform.
Changing the configuration#
Step 1: Update database object ownership#
Use the provided script to reassign ownership of database objects in the public schema from supabase_admin to postgres. From the project directory containing docker-compose.yml, run:
1sh utils/reassign-owner.shThis script only updates ownership for database objects in the public schema. Supabase-managed and custom schemas are not affected.
Step 2: Update environment variables in docker-compose.yml#
-
In your
docker-compose.ymlconfiguration, uncomment the following line for thestudioservice to use thepostgresrole for read/write operations:docker-compose.yml
1studio:2environment:3POSTGRES_USER_READ_WRITE: postgres -
Locate the
metaservice environment variables and change thePG_META_DB_USERenvironment variable fromsupabase_admintopostgres:docker-compose.yml
1meta:2environment:3PG_META_DB_USER: postgres
Studio uses its own credentials to access Postgres via postgres-meta, so this change is only needed for backward compatibility and consistency.
Step 3: Restart Supabase#
1docker compose down && docker compose up -dVerify roles#
After restarting your services, verify that Supabase Studio is now using the postgres role. Run the following query in the Supabase Studio SQL Editor:
1select current_user;2-- expected result: postgres