Skip to content

ERROR: Resetting databases failing on all new databases & feature branches (ERROR 42501) #3551

Closed

Description

@jsonMartin

Describe the bug

Resetting databases on ANY new database (primary, or feature branch databases) now fails due to role based error:

ERROR: must be owner of sequence refresh_tokens_id_seq (SQLSTATE 42501)

Other users are also having this same problem, as noted here in this previously closed issue: #128

Summary:
  • This error occurs on ALL newly created databases, including feature branches.
  • Resets still work fine on older pre-existing databases before this issue was introduced.
  • Investigation suggests new databases are missing the ⁠supabase_auth_admin role, which owns ⁠refresh_tokens_id_seq. This causes reset operations to fail because the role performing the reset operation does not have appropriate permissions for the Auth schema.
  • Caveat: Resetting newly created feature branches with branch type to persistent DOES allow resets directly via Supabase UI (even though it is still missing role permissions).
    • HOWEVER: resetting persistent feature branches via CLI still fails, which throws exactly the same error message as when resetting primary databases (which require CLI).
    • Resetting persistent feature branches via Supabase UI seems to be performing the action with different context or set of permissions than Ephemeral branches or via CLI (primary or feature branch)
Key Findings
  • Older, pre-existing databases & feature branches which still have the supabase_auth_admin role work when resetting database (both via UI & CLI).
  • New databases & feature branches lack the supabase_auth_admin role, causing all reset operations to fail.
  • Cannot manually grant or alter ownership for the required role.
  • Issue affects ALL projects, including brand new ones with no migrations.
  • Changing a feature branch to persistent allows resets ONLY via UI, even though the role still doesn't appear in permissions.

To Reproduce
Steps to reproduce the behavior:

  1. Create a brand new database, or feature branch
  2. Run the command, note the lack of supabase_auth_admin
SELECT rolname
FROM pg_roles
WHERE pg_has_role(current_user, oid, 'member')
ORDER BY rolname ASC;
  1. (Optional) If there is an older database or feature branch available, run the same command and note how it DOES have supabase_auth_admin
  2. Try to reset the database, using CLI command supabase db reset --db-url postgresql://postgres.[DB_URL]:[DB_PASS]@aws-0-us-east-2.pooler.supabase.com:5432/postgres, or via the Supabase UI Reset Branch button
  3. You will encounter this error: ERROR: must be owner of sequence refresh_tokens_id_seq (SQLSTATE 42501)

Expected behavior
Database resets through both CLI and Supabase UI work properly as intended, including feature branches (both ephemeral and persistent).

Additional context

Evidence

Role Query Results Comparison

Query used to check roles

SELECT rolname
FROM pg_roles
WHERE pg_has_role(current_user, oid, 'member')
ORDER BY rolname ASC;

Pre-existing database results:

rolname
pg_database_owner
pg_read_all_data
pg_monitor
pg_read_all_settings
pg_read_all_stats
pg_stat_scan_tables
pg_signal_backend
pgsodium_keyiduser
pgsodium_keyholder
pgsodium_keymaker
authenticated
anon
service_role
postgres
authenticator
supabase_auth_admin
supabase_storage_admin
supabase_realtime_admin

New database results:

rolname
pg_database_owner
pg_read_all_data
pg_monitor
pg_read_all_settings
pg_read_all_stats
pg_stat_scan_tables
pg_signal_backend
authenticated
anon
service_role
postgres
supabase_realtime_admin

Failed Role Creation Attempts

GRANT supabase_auth_admin TO postgres;
-- ERROR: 42501: "supabase_auth_admin" role memberships are reserved, only superusers can grant them

ALTER SEQUENCE auth.refresh_tokens_id_seq OWNER TO postgres;
-- ERROR: permission denied

Workarounds (only for feature branches)

  • Use persistent branches (remember to delete after merge)
  • Delete and recreate feature branches whenever reset is needed
  • Only reset feature branches through Supabase UI, not CLI

Hypothesis

This appears to be a platform-level issue with how Supabase provisions roles in feature branches rather than a project-specific configuration problem. I'm not sure exactly when this started happening, but it's happening for me in all projects now. The fact that changing to persistent branch type allows resets suggests there may be additional permissions/configurations applied to persistent branches and running the reset in the Supabase UI vs the CLI.

Activity

  1. changed the title [-]ERROR: Resetting databases failing on all new database & feature branches (ERROR 42501)[/-] [+]ERROR: Resetting databases failing on all new databases & feature branches (ERROR 42501)[/+] on May 9, 2025
  2. dvorakjt commented on May 9, 2025

    @dvorakjt

    I experienced this issue, as well. I was not using feature branches. As a temporary workaround, I had to delete the whole project and recreate it. It would be great to see if this can be addressed. Please let me know if I can provide any additional information to assist in getting to the bottom of this. Thank you!

  3. nbinobied commented on May 10, 2025

    @nbinobied

    I'm having the same issue with fresh Db/account. Supabase Version: @supabase/supabase-js": "^2.49.4

    I've gone through the following commands, supabase init > supabase login > supabase link --project-ref <project ref> > supabase migration new initial, and it breaks at the last command supabase db reset --linked.

    Do you want to reset the remote database? [y/N] y
    Resetting remote database...
    NOTICE (00000): truncate cascades to table "sso_domains"
    NOTICE (00000): truncate cascades to table "saml_providers"
    NOTICE (00000): truncate cascades to table "saml_relay_states"
    ERROR: must be owner of sequence refresh_tokens_id_seq (SQLSTATE 42501)                                                                                    
    
    At statement 0:                                                                                                                                            
    
    do $$ declare                                                                                                                                              
    
      rec record;                                                                                                                                              
    
    begin                                                                                                                                                      
    
      -- extensions                                                                                                                                            
    
      for rec in                                                                                                                                               
    
        select *                                                                                                                                               
    
        from pg_extension p                                                                                                                                    
    
        where p.extname not in ('pg_graphql', 'pg_net', 'pg_stat_statements', 'pgcrypto', 'pgjwt', 'pgsodium', 'plpgsql', 'supabase_vault', 'uuid-ossp')       
    
      loop                                                                                                                                                     
    
        execute format('drop extension if exists %I cascade', rec.extname);                                                                                    
    
      end loop;                                                                                                                                                
    
                                                                                                                                                               
    
      -- functions                                                                                                                                             
    
      for rec in                                                                                                                                               
    
        select *                                                                                                                                               
    
        from pg_proc p                                                                                                                                         
    
        where p.pronamespace::regnamespace::name = 'public'                                                                                                    
    
      loop                                                                                                                                                     
    
        -- supports aggregate, function, and procedure                                                                                                         
    
        execute format('drop routine if exists %I.%I(%s) cascade', rec.pronamespace::regnamespace::name, rec.proname, pg_catalog.pg_get_function_identity_arguments(rec.oid));
      end loop;                                                                                                                                                
    
                                                                                                                                                               
    
      -- views (necessary for views referencing objects in Supabase-managed schemas)                                                                           
    
      for rec in                                                                                                                                               
    
        select *                                                                                                                                               
    
        from pg_class c                                                                                                                                        
    
        where                                                                                                                                                  
    
          c.relnamespace::regnamespace::name = 'public'                                                                                                        
    
          and c.relkind = 'v'                                                                                                                                  
    
      loop                                                                                                                                                     
    
        execute format('drop view if exists %I.%I cascade', rec.relnamespace::regnamespace::name, rec.relname);                                                
    
      end loop;                                                                                                                                                
    
                                                                                                                                                               
    
      -- materialized views (necessary for materialized views referencing objects in Supabase-managed schemas)                                                 
    
      for rec in                                                                                                                                               
    
        select *                                                                                                                                               
    
        from pg_class c                                                                                                                                        
    
        where                                                                                                                                                  
    
          c.relnamespace::regnamespace::name = 'public'                                                                                                        
    
          and c.relkind = 'm'                                                                                                                                  
    
      loop                                                                                                                                                     
    
        execute format('drop materialized view if exists %I.%I cascade', rec.relnamespace::regnamespace::name, rec.relname);                                   
    
      end loop;                                                                                                                                                
    
                                                                                                                                                               
    
      -- tables (cascade to views)                                                                                                                             
    
      for rec in                                                                                                                                               
    
        select *                                                                                                                                               
    
        from pg_class c                                                                                                                                        
    
        where                                                                                                                                                  
    
          c.relnamespace::regnamespace::name = 'public'                                                                                                        
    
          and c.relkind not in ('c', 'S', 'v', 'm')                                                                                                            
    
        order by c.relkind desc                                                                                                                                
    
      loop                                                                                                                                                     
    
        -- supports all table like relations, except views, complex types, and sequences                                                                       
    
        execute format('drop table if exists %I.%I cascade', rec.relnamespace::regnamespace::name, rec.relname);                                               
    
      end loop;                                                                                                                                                
    
                                                                                                                                                               
    
      -- truncate tables in auth, webhooks, and migrations schema                                                                                              
    
      for rec in                                                                                                                                               
    
        select *                                                                                                                                               
    
        from pg_class c                                                                                                                                        
    
        where                                                                                                                                                  
    
          (c.relnamespace::regnamespace::name = 'auth' and c.relname != 'schema_migrations'                                                                    
    
          or c.relnamespace::regnamespace::name = 'supabase_functions' and c.relname != 'migrations'                                                           
    
          or c.relnamespace::regnamespace::name = 'supabase_migrations')                                                                                       
    
          and c.relkind = 'r'                                                                                                                                  
    
      loop                                                                                                                                                     
    
        execute format('truncate %I.%I restart identity cascade', rec.relnamespace::regnamespace::name, rec.relname);                                          
    
      end loop;                                                                                                                                                
    
                                                                                                                                                               
    
      -- sequences                                                                                                                                             
    
      for rec in                                                                                                                                               
    
        select *                                                                                                                                               
    
        from pg_class c                                                                                                                                        
    
        where                                                                                                                                                  
    
          c.relnamespace::regnamespace::name = 'public'                                                                                                        
    
          and c.relkind = 's'                                                                                                                                  
    
      loop                                                                                                                                                     
    
        execute format('drop sequence if exists %I.%I cascade', rec.relnamespace::regnamespace::name, rec.relname);                                            
    
      end loop;                                                                                                                                                
    
                                                                                                                                                               
    
      -- types                                                                                                                                                 
    
      for rec in                                                                                                                                               
    
        select *                                                                                                                                               
    
        from pg_type t                                                                                                                                         
    
        where                                                                                                                                                  
    
          t.typnamespace::regnamespace::name = 'public'                                                                                                        
    
          and typtype != 'b'                                                                                                                                   
    
      loop                                                                                                                                                     
    
        execute format('drop type if exists %I.%I cascade', rec.typnamespace::regnamespace::name, rec.typname);                                                
    
      end loop;                                                                                                                                                
    
                                                                                                                                                               
    
      -- policies                                                                                                                                              
    
      for rec in                                                                                                                                               
    
        select *                                                                                                                                               
    
        from pg_policies p                                                                                                                                     
    
      loop                                                                                                                                                     
    
        execute format('drop policy if exists %I on %I.%I cascade', rec.policyname, rec.schemaname, rec.tablename);                                            
    
      end loop;                                                                                                                                                
    
                                                                                                                                                               
    
      -- publications                                                                                                                                          
    
      for rec in                                                                                                                                               
    
        select *                                                                                                                                               
    
        from pg_publication p                                                                                                                                  
    
        where                                                                                                                                                  
    
          p.pubname not like 'supabase_realtime%' and p.pubname not like 'realtime_messages%'                                                                  
    
      loop                                                                                                                                                     
    
        execute format('drop publication if exists %I', rec.pubname);                                                                                          
    
      end loop;                                                                                                                                                
    
    end $$;                                                                                                                                                    
    
                                                                                                                                                               
    
    Try rerunning the command with --debug to troubleshoot the error.
    

    However, I tried to run the same migration through UI CLI and it seems to be working fine.

    Migration:

    drop table if exists projects;
    
    drop type if exists project_status CASCADE;
    create type project_status as enum (
        'in_progress',
        'completed'
    );
    
    create table projects (
        id bigint primary key generated always as identity not null,
        name text not null,
        slug text unique not null,
        status project_status not null default 'in_progress',
        created_at timestamptz default now() not null,
        collaborators text array default array[]::varchar[] not null
    );
    
  4. sadikekin commented on May 10, 2025

    @sadikekin

    I am also experiencing this issue!

  5. sweatybridge commented on May 10, 2025

    @sweatybridge
    Contributor

    Thanks for the detailed report. I will work on a fix for both cli and branching.

  6. sweatybridge commented on May 10, 2025

    @sweatybridge
    Contributor

    We have released the fix to branching.

    You should also be able to reset using cli beta version.

    npx supabase@beta db reset --db-url 'postgres://...'
    
  7. sadikekin commented on May 11, 2025

    @sadikekin

    Thank you for your work @sweatybridge

  8. rrcabrera9625 commented on Jun 26, 2025

    @rrcabrera9625

    Any progress with this? I am having the same error:

    ERROR: must be owner of table objects (SQLSTATE 42501)
    At statement: 0
    -- ENABLE ROW LEVEL SECURITY
    ALTER TABLE storage.objects ENABLE ROW LEVEL SECURITY

    This happens when running migrations while starting the local project using npx supabase start

  9. rrcabrera9625 commented on Sep 3, 2025

    @rrcabrera9625

    Any progress??? Having now the same error when creating a new branch:

    2025/09/03 17:56:10 ERROR: must be owner of table objects (SQLSTATE 42501)
    At statement: 0
    -- ENABLE ROW LEVEL SECURITY
    ALTER TABLE storage.objects ENABLE ROW LEVEL SECURITY

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions