© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
SupabaseS
Supabase•5mo ago•
1 reply
chrisb2244

Self-hosted roles: supabase_admin and postgres (and local dev supabase cli...), non-public schema

I'm hitting issues with permissions on my deployed, self-hosted database when using a non-public schema.

I created the schema with migrations like the following (referencing https://supabase.com/docs/guides/api/using-custom-schemas):

CREATE SCHEMA IF NOT EXISTS myschema;

-- Allow API access
GRANT USAGE ON SCHEMA myschema TO anon, authenticated, service_role;
GRANT ALL ON ALL TABLES IN SCHEMA myschema TO anon, authenticated, service_role;
GRANT ALL ON ALL ROUTINES IN SCHEMA myschema TO anon, authenticated, service_role;
GRANT ALL ON ALL SEQUENCES IN SCHEMA myschema TO anon, authenticated, service_role;
ALTER DEFAULT PRIVILEGES FOR ROLE postgres IN SCHEMA myschema GRANT ALL ON TABLES TO anon, authenticated, service_role;
ALTER DEFAULT PRIVILEGES FOR ROLE postgres IN SCHEMA myschema GRANT ALL ON ROUTINES TO anon, authenticated, service_role;
ALTER DEFAULT PRIVILEGES FOR ROLE postgres IN SCHEMA myschema GRANT ALL ON SEQUENCES TO anon, authenticated, service_role;
CREATE SCHEMA IF NOT EXISTS myschema;

-- Allow API access
GRANT USAGE ON SCHEMA myschema TO anon, authenticated, service_role;
GRANT ALL ON ALL TABLES IN SCHEMA myschema TO anon, authenticated, service_role;
GRANT ALL ON ALL ROUTINES IN SCHEMA myschema TO anon, authenticated, service_role;
GRANT ALL ON ALL SEQUENCES IN SCHEMA myschema TO anon, authenticated, service_role;
ALTER DEFAULT PRIVILEGES FOR ROLE postgres IN SCHEMA myschema GRANT ALL ON TABLES TO anon, authenticated, service_role;
ALTER DEFAULT PRIVILEGES FOR ROLE postgres IN SCHEMA myschema GRANT ALL ON ROUTINES TO anon, authenticated, service_role;
ALTER DEFAULT PRIVILEGES FOR ROLE postgres IN SCHEMA myschema GRANT ALL ON SEQUENCES TO anon, authenticated, service_role;


Seemingly, this works ok for my local development cases.
However, my deployed database has
current_user
current_user
as
supabase_admin
supabase_admin
(whereas in my local dev studio, running
select current_user
select current_user
returns
postgres
postgres
).

Since the tables are owned by
supabase_admin
supabase_admin
in my deployed database, the
ALTER DEFAULT PRIVILEGES
ALTER DEFAULT PRIVILEGES
command seems to be irrelevant (as I understand, it only grants privileges for objects created by the role that is specified, i.e.
postgres
postgres
).

(continued in comment)
Supabase banner
SupabaseJoin
Supabase gives you the tools, documentation, and community that makes managing databases, authentication, and backend infrastructure a lot less overwhelming.
45,816Members
Resources
Was this page helpful?

Similar Threads

Recent Announcements

Similar Threads

self hosted upgrade -> supabase_admin vs postgres role.
SupabaseSSupabase / help-and-questions
4mo ago
Supabase CLI on Self Hosted
SupabaseSSupabase / help-and-questions
4y ago
Supabase self hosted won't connect to local postgres
SupabaseSSupabase / help-and-questions
4y ago
Supabase CLI - Generating types from local hosted supabase possible?
SupabaseSSupabase / help-and-questions
4y ago