AI & Agent Dev Bug Sandbox logo
AI & Agent Dev Bug Sandbox
Back to Radar

GoTrue Returns "Database Error Querying Schema" On Password Auth After Direct Psql Schema Application

A Supabase branch database fails all password authentication attempts with HTTP 500 and error "Database error querying schema" after the public schema was applied via direct psql. The main branch with identical auth schema and data works correctly. Root cause is likely missing privileges or incorrect ownership on auth schema objects (especially auth.schema_migrations) caused by direct psql operations, breaking GoTrue's startup schema introspection.

highConfidence 75%GoTrue

Origin Analysis

Direct psql operations (pg_dump --schema-only piped through psql, manual INSERTs) altered ownership or privileges of objects in the auth schema. The supabase_auth_admin role, used by GoTrue, lacks necessary SELECT privileges or ownership on critical auth tables such as auth.schema_migrations. This causes GoTrue's loadSchema() query to fail, wrapping the PostgreSQL error as "Database error querying schema" and preventing token issuance.
1. Create a Supabase branch from a project with existing auth users. 2. Apply the public schema to the branch via direct psql using pg_dump --schema-only output. 3. Import auth.users rows via INSERT statements (e.g., from CSV export). 4. Create corresponding auth.identities rows with provider='email'. 5. Send POST /auth/v1/token?grant_type=password with valid credentials. 6. Receive HTTP 500: {"code":"unexpected_failure","message":"Database error querying schema"}. 7. Restart the project from Dashboard; error persists.

Fixing Code Block

Edge Case Audit

This fix changes ownership and privileges across the entire auth schema. Before running, ensure a full database backup is available. If any custom extensions or services rely on postgres ownership of auth objects, this may break them. Rollback requires restoring original owners and revoking the newly granted privileges. Test thoroughly in a non-production branch before applying to production. Avoid running REASSIGN OWNED BY postgres, as that would affect the entire database and may cause severe disruptions.

Ecosystem Topology